@@ -50,18 +50,16 @@ ConstraintGraph::~ConstraintGraph() {
50
50
51
51
#pragma mark Graph accessors
52
52
53
- ConstraintGraphNode &
54
- ConstraintGraph::operator [](TypeVariableType *typeVar) {
53
+ void ConstraintGraph::addTypeVariable (TypeVariableType *typeVar) {
55
54
// Check whether we've already created a node for this type variable.
56
55
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 ());
65
63
66
64
// Allocate the new node.
67
65
ConstraintGraphNode *nodePtr;
@@ -85,19 +83,21 @@ ConstraintGraph::operator[](TypeVariableType *typeVar) {
85
83
// create new nodes during an undo.
86
84
if (CS.solverState )
87
85
CS.recordChange (SolverTrail::Change::AddedTypeVariable (typeVar));
86
+ }
88
87
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 ();
99
96
}
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" );
101
101
return *nodePtr;
102
102
}
103
103
0 commit comments