@@ -96,25 +96,31 @@ void SplitterStep::computeFollowupSteps(
96
96
CG.optimize ();
97
97
98
98
// Compute the connected components of the constraint graph.
99
- // FIXME: We're seeding typeVars with TypeVariables so that the
100
- // connected-components algorithm only considers those type variables within
101
- // our component. There are clearly better ways to do this.
102
- std::vector<TypeVariableType *> typeVars (CS.TypeVariables );
103
- std::vector<unsigned > components;
104
- unsigned numComponents = CG.computeConnectedComponents (typeVars, components);
99
+ auto components = CG.computeConnectedComponents (CS.TypeVariables );
100
+ unsigned numComponents =
101
+ components.size () + CG.getOrphanedConstraints ().size ();
105
102
if (numComponents < 2 ) {
106
103
componentSteps.push_back (llvm::make_unique<ComponentStep>(
107
- CS, 0 , /* single= */ true , &CS.InactiveConstraints , Solutions));
104
+ CS, 0 , &CS.InactiveConstraints , Solutions));
108
105
return ;
109
106
}
110
107
111
108
Components.resize (numComponents);
112
109
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4 >[]>(
113
110
new SmallVector<Solution, 4 >[numComponents]);
114
111
115
- for (unsigned i = 0 , n = numComponents; i != n; ++i) {
112
+ // Add components.
113
+ for (unsigned i : indices (components)) {
116
114
componentSteps.push_back (llvm::make_unique<ComponentStep>(
117
- CS, i, /* single=*/ false , &Components[i], PartialSolutions[i]));
115
+ CS, i, &Components[i], std::move (components[i]), PartialSolutions[i]));
116
+ }
117
+
118
+ // Add components for the orphaned constraints.
119
+ OrphanedConstraints = CG.takeOrphanedConstraints ();
120
+ for (unsigned i : range (components.size (), numComponents)) {
121
+ auto orphaned = OrphanedConstraints[i - components.size ()];
122
+ componentSteps.push_back (llvm::make_unique<ComponentStep>(
123
+ CS, i, &Components[i], orphaned, PartialSolutions[i]));
118
124
}
119
125
120
126
if (isDebugMode ()) {
@@ -129,57 +135,6 @@ void SplitterStep::computeFollowupSteps(
129
135
CG.printConnectedComponents (CS.TypeVariables , log);
130
136
}
131
137
132
- // Map type variables and constraints into appropriate steps.
133
- llvm::DenseMap<TypeVariableType *, unsigned > typeVarComponent;
134
- llvm::DenseMap<Constraint *, unsigned > constraintComponent;
135
- for (unsigned i = 0 , n = typeVars.size (); i != n; ++i) {
136
- auto *typeVar = typeVars[i];
137
- // Record the component of this type variable.
138
- typeVarComponent[typeVar] = components[i];
139
-
140
- for (auto *constraint : CG[typeVar].getConstraints ())
141
- constraintComponent[constraint] = components[i];
142
- }
143
-
144
- // Add the orphaned components to the mapping from constraints to components.
145
- unsigned firstOrphanedComponent =
146
- numComponents - CG.getOrphanedConstraints ().size ();
147
- {
148
- unsigned component = firstOrphanedComponent;
149
- for (auto *constraint : CG.getOrphanedConstraints ()) {
150
- // Register this orphan constraint both as associated with
151
- // a given component as a regular constrant, as well as an
152
- // "orphan" constraint, so it can be proccessed correctly.
153
- constraintComponent[constraint] = component;
154
- componentSteps[component]->recordOrphan (constraint);
155
- ++component;
156
- }
157
- }
158
-
159
- for (auto *typeVar : CS.TypeVariables ) {
160
- auto known = typeVarComponent.find (typeVar);
161
- // If current type variable is associated with
162
- // a certain component step, record it as being so.
163
- if (known != typeVarComponent.end ()) {
164
- componentSteps[known->second ]->record (typeVar);
165
- continue ;
166
- }
167
- }
168
-
169
- // Transfer all of the constraints from the work list to
170
- // the appropriate component.
171
- auto &workList = CS.InactiveConstraints ;
172
- while (!workList.empty ()) {
173
- auto *constraint = &workList.front ();
174
- workList.pop_front ();
175
- assert (constraintComponent.count (constraint) > 0 && " Missed a constraint" );
176
- componentSteps[constraintComponent[constraint]]->record (constraint);
177
- }
178
-
179
- // Remove all of the orphaned constraints; they'll be re-introduced
180
- // by each component independently.
181
- OrphanedConstraints = CG.takeOrphanedConstraints ();
182
-
183
138
// Create component ordering based on the information associated
184
139
// with constraints in each step - e.g. number of disjunctions,
185
140
// since components are going to be executed in LIFO order, we'd
0 commit comments