Skip to content

Sema: Small ConstraintGraph cleanup #77728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 21, 2024
Merged

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Nov 20, 2024

We used operator[] to both insert and find vertices in the ConstraintGraph. Split it up into two operations to better enforce invariants.

Also, when freeing a vertex, we don't have to clear it -- assuming all changes were undone correctly, then at the time we're ready to undo the creation of the vertex, it should be empty already. Just assert instead.

Finally, ConstraintGraphNode::Bindings doesn't need to be Optional anymore because we never reset it. Once again, it should be empty when we free the node.

lookupNode() returned a pair but both callers only looked at the
first element of the pair.
Also, since we add a vertex immediately after introducing a new type
variable, the code path to handle the case where the type variable
had a parent or fixed type was actually dead.
All but two remaining call sites can be changed to just check for a
non-null solverState, because we want to assert if we're inside
of an active undo.

The two places inside binding inference can check isUndoActive()
directly.
PotentialBindings is part of ConstraintGraphNode and there's no need
to store the ConstraintSystem and TypeVariableType twice.

Also it doesn't need to be optional either, because we no longer need
to reset and recompute bindings.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@ahoppen ahoppen removed their request for review November 20, 2024 22:00
@slavapestov slavapestov merged commit 25252cd into swiftlang:main Nov 21, 2024
5 checks passed
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable!

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.

2 participants