Skip to content
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

Unify ConstraintGraph change tracking with SavedTypeVariableBindings #76759

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

slavapestov
Copy link
Contributor

I'd like to get rid of all the state that's inside SolverScope today, and instead record a trail of changes to individual data structures. This is a preliminary PR which moves the ConstraintGraph change tracking into a new CSTrail.cpp, which defines a SolverTrail. I also refactored the existing logic for saving and restoring the fixed types of type variables to use SolverTrail.

For now, there's a hack in there to preserve the previous behavior where type variable bindings are restored before all constraint graph changes. Once I untangle some other issues I will streamline this. Next steps after that are converting all other state tracking to use the new mechanism, which will hopefully reduce memory usage and improve performance.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

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 great, thank you!

} Update;
};

Change() : Kind(ChangeKind::AddedTypeVariable), TypeVar(nullptr) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed because eg this calls the default constructor and it won't synthesize one for us because of the unions:

SolverTrail::Change
SolverTrail::Change::addedConstraint(Constraint *constraint) {
  Change result;
  result.Kind = ChangeKind::AddedConstraint;
  result.TheConstraint = constraint;
  return result;
}

If there's another way to initialize this without the default constructor I can refactor it later, because I'll be adding lots more Change kinds soon. :)

Previously, retractFromInference() was the last step in
unbindTypeVariable(). This doesn't really make sense,
because bindTypeVariable() doesn't call introduceToInference();
its two callers do it later.

Start untangling this by splitting off introduceToInference()
into its own Change, but for now, record this change at the
incorrect place to maintain the same behavior as before.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

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