Fix ks-opaque-types: true
and duplicate warnings if imports are used
#267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes kaitai-io/kaitai_struct#295
Fixes duplication of warnings and non-fatal errors as shown in kaitai-io/kaitai_struct#1063
The existing code structure hinted that the
precompile(classSpecs: ClassSpecs, topClass: ClassSpec)
overload should precompile only thetopClass
specified, but its actual implementation for the most part didn't usetopClass
at all and only passedclassSpecs
to all precompilation steps, which processed all types in the givenClassSpecs
. Given that theprecompile(classSpecs: ClassSpecs, topClass: ClassSpec)
overload is called from theprecompile(specs: ClassSpecs)
overload for each type inClassSpecs
, this resulted in unnecessary repeated precompilation of all types when imports are used (because then there is more than 1 type inClassSpecs
).If there are
N
top-level types inClassSpecs
, instead of running the precompile phase only once for each top-level type, it was runN
times per each top-level type, resulting inN**2
total precompilations of top-level types. This is not only unnecessary, but it also had some observable negative effects, e.g. a single warning being reported to the consoleN
times (andN >= 2
any time you use imports) instead of just once (see kaitai-io/kaitai_struct#1063).Another problem was caused by the only actual use of
topClass
in theprecompile(classSpecs: ClassSpecs, topClass: ClassSpec)
overload, namely for checking if opaque types are enabled or not (according to the/meta/ks-opaque-types
key) and passing the setting to theResolveTypes
precompile step. This meant that if one spec had opaque types enabled and the other disabled, they would be rejected even in the spec where they should be enabled (becauseResolveTypes
processed all specs first with opaque types enabled and then once more with them disabled), as reported in kaitai-io/kaitai_struct#295.This commit ensures that each
ClassSpec
ofClassSpecs
is precompiled only once, eliminating both of the problems mentioned.