@@ -50,18 +50,16 @@ ConstraintGraph::~ConstraintGraph() {
5050
5151#pragma mark Graph accessors
5252
53- ConstraintGraphNode &
54- ConstraintGraph::operator [](TypeVariableType *typeVar) {
53+ void ConstraintGraph::addTypeVariable (TypeVariableType *typeVar) {
5554 // Check whether we've already created a node for this type variable.
5655 auto &impl = typeVar->getImpl ();
57- if (auto nodePtr = impl.getGraphNode ()) {
58- assert (impl.getGraphIndex () < TypeVariables.size () && " Out-of-bounds index" );
59- assert (TypeVariables[impl.getGraphIndex ()] == typeVar &&
60- " Type variable mismatch" );
61- ASSERT (nodePtr->TypeVar == typeVar &&
62- " Use-after-free" );
63- return *nodePtr;
64- }
56+
57+ // ComponentStep::Scope re-introduces type variables that are already
58+ // in the graph, but not in ConstraintSystem::TypeVariables.
59+ if (impl.getGraphNode ())
60+ return ;
61+
62+ ASSERT (!impl.hasRepresentativeOrFixed ());
6563
6664 // Allocate the new node.
6765 ConstraintGraphNode *nodePtr;
@@ -85,19 +83,21 @@ ConstraintGraph::operator[](TypeVariableType *typeVar) {
8583 // create new nodes during an undo.
8684 if (CS.solverState )
8785 CS.recordChange (SolverTrail::Change::AddedTypeVariable (typeVar));
86+ }
8887
89- // If this type variable is not the representative of its equivalence class,
90- // add it to its representative's set of equivalences.
91- auto typeVarRep = CS.getRepresentative (typeVar);
92- if (typeVar != typeVarRep) {
93- mergeNodesPre (typeVar);
94- mergeNodes (typeVarRep, typeVar);
95- }
96- else if (auto fixed = CS.getFixedType (typeVarRep)) {
97- // Bind the type variable.
98- bindTypeVariable (typeVar, fixed);
88+ ConstraintGraphNode &
89+ ConstraintGraph::operator [](TypeVariableType *typeVar) {
90+ // Check whether we've already created a node for this type variable.
91+ auto &impl = typeVar->getImpl ();
92+ auto *nodePtr = impl.getGraphNode ();
93+ if (!nodePtr) {
94+ llvm::errs () << " Type variable $T" << impl.getID () << " not in constraint graph\n " ;
95+ abort ();
9996 }
100-
97+ ASSERT (nodePtr->TypeVar == typeVar && " Use-after-free" );
98+ DEBUG_ASSERT (impl.getGraphIndex () < TypeVariables.size () && " Out-of-bounds index" );
99+ DEBUG_ASSERT (TypeVariables[impl.getGraphIndex ()] == typeVar &&
100+ " Type variable mismatch" );
101101 return *nodePtr;
102102}
103103
0 commit comments