Swift: deal with incomplete ASTs #11131
Merged
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.
This PR makes the Swift extractor deal gracefully with incomplete ASTs, which may come from compilation errors, wrong assumptions on our side or plain extractor bugs. Any label which is left unspecified in the extractor will instead point to an instance of
UnspecifiedElement
.Commit by commit review is strongly encouraged.
The implementation of this can be roughly divided into:
@unspecified_element
. What element is used is marked with the@use_for_null
decorator inschema.py
. Each property type@bar
is then replaced with@bar_or_none
.cppgen
must also account for this (using typeTrapLabel<BarOrNoneTag>
). A special treatment must be given to the case where the property type is the root classElement
, as the null type is already also of root type, so@element_or_none
is unneeded (and would introduce some ambiguities in the tag hierarchy on C++).SwiftDispatcher
. In order to do so,trapgen
andcppgen
generate the member functionforEachLabel
allowing to iterate through and possibly modify all labels in the trap or class entry.SwiftDispatcher
is then able to locate the undefined labels and emitUnspecifiedElement
instances in their place. If this is not possible, which can happen if the class id is unspecified or for some direct trap emissions (which is now rare), emission is skipped altogether.On the QL side this is for now mostly transparent: missing elements will result in the relevant predicates not having results, but can be queried directly through the
UnspecifiedElement
class. Whether we want those predicates to actually returnUnspecifiedElement
, or whether we wantUnspecifiedElement
to appear in the AST printer is left for future discussion and implementation.For the moment the extractor will print on standard error information about missing labels, but this shall be moved to proper diagnostics once we have that.
Notice that
@unspecified_element
can be used in upgrade/downgrade scripts to "discard" an element.