Skip to content

Make a new entry match what MATLAB writes, in both .sldd formats - #44

Merged
ww-mw merged 1 commit into
mainfrom
sldd-add-entry-matlab-parity
Sep 30, 2026
Merged

ww-mw merged 1 commit into
mainfrom
sldd-add-entry-matlab-parity

Conversation

@ww-mw

@ww-mw ww-mw commented Sep 30, 2026

Copy link
Copy Markdown
Member

Every createDefault the Add gallery can reach, compared against a default MATLAB itself creates — in both the JSON-text and compressed-binary formats. Method: write a 28-entry dictionary from the extension in each format, then have MATLAB open it, setValue every entry (so nothing passes through as an unread blob), saveChanges, and reopen. Four gaps came back; this is all four.

The variant-configuration section

Simulink.VariantConfigurations was listed under Configurations, which reads right — it is what the Variant Manager edits. MATLAB refuses it there by name, in both formats:

SLDD:sldd:ValueClassNotAcceptedInSection
Values of class 'Simulink.VariantConfigurations' are not supported in the
'Configurations' section of the dictionary.

The error names the section. A dictionary MATLAB writes carries its own entry of that class in the design namespace with IsDerived 0, beside the Parameters and Buses, and addEntry(…, 'Design Data') is the call MATLAB accepts. Renaming the class moved the refusal by nothing, which is what pinned it on the section rather than the value. Configurations takes a ConfigSet and a ConfigSetRef and nothing else — now a closed list with a test, since a class added there is a claim about MATLAB that has to be measured.

The ConfigSetRef name

MATLAB enforces "entry name == the value's own Name", and now raises SLDD:sldd:EntryValueNameMismatch rather than silently renaming. Name is written as a view of the entry name, and the default is MATLAB's own: Reference.

Two binary-only defects

Both were invisible to the text-path parity assertion that was supposed to cover exactly this, because it read only the text run.

  • The binary writer was not saveobj-aware. Three of the four classes whose whole state is one custom-save envelope came out carrying an invented <P Name="Value" Class="char"/> beside that envelope — a property none of those MATLAB classes has — in the binary flavour only. A property bag where the envelope belongs is the shape that has segfaulted MATLAB on Simulink.VariantVariable before.
  • An empty struct or cell survived the write and was destroyed by the read. Its field names live in <Field Name="…"/>, which only an empty struct uses (a non-empty one states them through each <Element>), so the reader fell through and answered an empty char. Merely opening a dictionary and saving it hollowed out every variant entry in it — ours or MATLAB's — into the shape that makes loadobj build an empty object.

Verification

MATLAB's rewrite of our entries now lists the same envelope fields we write, in the same order, for all four custom-saving classes, and reads Choices back as a 0x1 struct and VariantConditions as a 1x0 cell rather than as chars. Every entry loads in both formats with no rename and nothing lost (name census before and after MATLAB's own save, from a fresh reopen).

npm run verify: 168 files / 4938 tests passed, 26 skipped. New suites: newEntryEnvelopeBothFormats.test.ts (20), createDefaultMatlabParity.test.ts, plus the section claim in sectionNode.test.ts — the section move was a one-line edit that broke no test, which was the gap those close.

Every `createDefault` the Add gallery can reach was compared against a default
MATLAB itself creates, in both the JSON-text and compressed-binary formats, by
writing a 28-entry dictionary from the extension and having MATLAB open, re-set
and re-save every entry. Four gaps came back, and this is all four.

The variant-configuration section. `Simulink.VariantConfigurations` was listed
under Configurations, which reads right — it is what the Variant Manager edits —
and MATLAB refuses it there by name in both formats
(SLDD:sldd:ValueClassNotAcceptedInSection). The error names the SECTION: a
dictionary MATLAB writes carries its own entry of that class in the DESIGN
namespace with IsDerived 0, beside the Parameters and Buses. Renaming the class
moved the refusal by nothing, which is what pinned it. Configurations takes a
ConfigSet and a ConfigSetRef and nothing else, and that is now a closed list
with a test.

The ConfigSetRef name. MATLAB enforces "entry name == the value's own Name" and
now raises SLDD:sldd:EntryValueNameMismatch rather than silently renaming, so
Name is written as a view of the entry name and the default is MATLAB's own,
`Reference`.

Two binary-only defects, both invisible to the text-path parity assertion that
was supposed to cover this:

  The binary writer was not saveobj-aware. Three of the four classes whose whole
  state is one custom-save envelope came out carrying an invented
  `<P Name="Value" Class="char"/>` beside that envelope — a property none of
  those MATLAB classes has — in the binary flavour only.

  An empty struct or cell property survived the write and was destroyed by the
  read: its field names live in `<Field Name="…"/>`, which only an empty struct
  uses, so the reader fell through and answered an empty char. Opening a
  dictionary and saving it hollowed out every variant entry in it, ours or
  MATLAB's, into the shape that makes loadobj build an empty object.

MATLAB's rewrite of our entries now lists the same envelope fields we write, in
the same order, for all four classes, and reads Choices back as a 0x1 struct and
VariantConditions as a 1x0 cell rather than as chars.
@ww-mw
ww-mw merged commit 3db2b89 into main Sep 30, 2026
1 check passed
@ww-mw
ww-mw deleted the sldd-add-entry-matlab-parity branch September 30, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant