Skip to content

Sema: More accurate undo() of PotentialBindings::retract() #79134

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
Feb 5, 2025

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Feb 4, 2025

Consider this series of events:

  • We bind a fixed type to a type variable
  • This activates some constraints that mention this type variable
  • Some of those constraints are solved
  • The solved constraints are retracted

When we retract the solved constraints, we call PotentialBindings::retract() and record a change. Previously, when we undo this change, we would call PotentialBindings::infer(). However, infer() is not always the opposite of retract(), because it calls simplifyType(). To avoid this order dependency, have retract() record exactly what was removed in a series of individual changes.

This fixes a regression from #77174.

There are a couple of diagnostic changes, and in fact the same diagnostics also changed in #77174.

This PR also simplifies PotentialBindings a bit. The Protocols, Literals, and Defaults fields weren't really needed because we can easily reconstruct this information when we build the BindingSet. Also, a few other fields that used to be *Set types are now SmallVector instead, because we don't insert duplicate elements by construction so there's no need for the additional overhead of hashing here.

Fixes rdar://problem/143474242.

…SmallVector

These are not going to have duplicates by construction.
Instead of making an undo() do an infer(), let's record fine-grained
changes about what was retracted, and directly re-insert the same
elements into the data structures.
@slavapestov slavapestov force-pushed the smaller-potential-bindings branch from 1efafdd to 8a3300b Compare February 5, 2025 01:27
@slavapestov slavapestov changed the title Sema: Remove a few fields from PotentialBindings Sema: More accurate undo() of PotentialBindings::retract() Feb 5, 2025
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 4937d0a into swiftlang:main Feb 5, 2025
5 checks passed
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