Refactor well-definedness of field acesses and permission division #451
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.
Now, the well-definedness of a field access first checks the well-definedness of a receiver and only afterwards checks whether there is enough permission (previously the order was reversed). Now, the well-definedness of a permission division first checks the well-definedness of the dividend and the divisor and only afterwards checks the whether the divisor is nonzero (before the order was reversed).
In the case of acc(e.f) and perm(e.f) (“PermAccess case”), the well-definedness check for e.f need not be checked. In all other cases (“NonPermAccess case”) such as “x := e.f”, the well-definedness check requires a permission check. In both cases, e.f is represented by the same AST subnode. Previously, Carbon differentiated the two cases in the well-definedness check with global state in a fragile way that relied on the fact that for the “NonPermAccess case” permission to e.f was checked before well-definedness of e was checke. Now, Carbon does not use global state for this differentiation (which then allowed me to also change the order of the checks). Instead, the expression module (responsible for orchestrating the definedness checks) makes sure that the components contributing to the definedness check never obtain field accesses as an input for which no definedness check is required.