MiniZinc / libminizinc

The MiniZinc compiler
http://www.minizinc.org
Other
513 stars 80 forks source link

Segfault using record types, enum and json data file #739

Open CervEdin opened 1 year ago

CervEdin commented 1 year ago

The following model

model.mzn

enum nume = { A };
type item = record(nume: x);
array[int] of item: arr;

and the following json data file

data.json

{"arr":[{"x":{"e":"A"}}]}

compiled using MiniZinc version 2.7.6, build 905165378 like this

minizinc -c model.mzn data.json

crashes with a segfault

Dekker1 commented 1 year ago

I'm afraid that the problem lies in the combination of type aliases with the JSON parser. The parser requires the types as input, but the resolves aliases are not yet known. I will have a look at fixing this in the the close future

Dekker1 commented 1 year ago

Currently a workaround is to use the record definition directly in the definition of the array:

enum nume = { A };
array[int] of record(nume: x): arr;

or to provide the data as DZN

CervEdin commented 1 year ago

Thank you Jip!

CervEdin commented 1 year ago

Currently a workaround is to use the record definition directly in the definition of the array:

enum nume = { A };
array[int] of record(nume: x): arr;

or to provide the data as DZN

The inlining work-around of the type definition didn't work on my actual and more complicated problem :/ Although, that may be a separate issue. Trying to see if I can get a small repro

CervEdin commented 1 year ago

Nested records also result in a segfault, regardless whether the type alias is inlined or not

model.mzn

enum nume = { A };
array[int] of record(record(nume: x) : drocer): arr;

data.json

{
  "arr": [
    {
      "drocer": { "x": { "e": "A" } }
    }
  ]
}
Dekker1 commented 12 months ago

A fix for the problem with nested records has already been merged into the develop branch and should be part of the upcoming release. (And the first problem is no longer a segfault, but still not possible).

CervEdin commented 11 months ago

@Dekker1 looks like the fix you mentioned (for the nested inline records) made it to the 2.8 release, right?

Dekker1 commented 11 months ago

Yes, this is part of the 2.8 release

Mommessc commented 7 months ago

I can confirm that nested arrays of records work with JSON parsing in version 2.8.3. However are there any news about the alias resolution being done before the JSON parsing? (Related to Dekker1's answer here)

Dekker1 commented 7 months ago

I'm afraid we haven't found the time yet to change the order of the process, but I will try to get around to it when I can

CervEdin commented 7 months ago

I can confirm that nested arrays of records work with JSON parsing in version 2.8.3. However are there any news about the alias resolution being done before the JSON parsing? (Related to Dekker1's answer here)

FWIW, I think the best current work-around is introducing a dummy input par

type foo = record(int:a);
array[int] of record(int:a): inline_foos;
array[int] of foo: foos = inline_foos;

example

This is basically how I get around the issue atm