Fix "singleton overload" check for user lists #4129
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.
When working on #4045, I identified a case in the C Semantics where an overload set was flagged as being singletons (that is, that the productions in the set were not actually overloads of one another). Despite this warning, removing the
overload(_)
attributes broke compilation by producing a parsing ambiguity.It turns out that the issue was a difference between the main module and the disambiguation module produced during the inner parsing process. The disambiguation module adds an additional production
for user list sorts
Es
that subsorts the list element sort into the list sort. This means that two productionscan be overloads of one another.
However, this check was only using the overloads induced by the main module and not those used by the disambiguation module. The fix is simply to compute the disambiguation module1 and use its overloads for the checks. Doing so requires some changes to the plumbing; the subsorting production is previously only added when
RULE-LISTS
is imported, but we need to short-circuit that code path in this context.This PR includes a regression test minimised from the original example.
Footnotes
I tried a cheaper fix that just checks parameters of overload-attributed productions to see if they appear in a user list, but this isn't sufficiently general in the case where the overload parameter is actually a sub-/supersort of the user list element, as happens in the C semantics. ↩