Skip to content

Commit 198003d

Browse files
committed
[CSStep] Record all of the type vars related to component while creating a split
Before this change some of the type variables, especially the ones that have been previously bound haven't been associated with any of the component steps, so it had to be done by scope once per step, but now such recording is done once per split.
1 parent 58ad04d commit 198003d

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

lib/Sema/CSStep.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ ComponentStep::Scope::Scope(ComponentStep &component)
3030
: CS(component.CS), Component(component) {
3131
TypeVars = std::move(CS.TypeVariables);
3232

33-
for (auto *typeVar : component.TypeVars) {
34-
// Include type variables that either belong to this
35-
// component or have been bound.
36-
if (component.TypeVars.count(typeVar) > 0 ||
37-
typeVar->getImpl().getFixedType(nullptr))
38-
CS.TypeVariables.push_back(typeVar);
39-
}
33+
for (auto *typeVar : component.TypeVars)
34+
CS.TypeVariables.push_back(typeVar);
4035

4136
auto &workList = CS.InactiveConstraints;
4237
workList.splice(workList.end(), *component.Constraints);
@@ -132,21 +127,22 @@ void SplitterStep::computeFollowupSteps(
132127
}
133128

134129
// Map type variables and constraints into appropriate steps.
130+
llvm::DenseMap<TypeVariableType *, unsigned> typeVarComponent;
135131
llvm::DenseMap<Constraint *, unsigned> constraintComponent;
136132
for (unsigned i = 0, n = typeVars.size(); i != n; ++i) {
137133
auto *typeVar = typeVars[i];
138-
auto *component = componentSteps[components[i]];
134+
// Record the component of this type variable.
135+
typeVarComponent[typeVar] = components[i];
139136

140-
component->record(typeVar);
141137
for (auto *constraint : CG[typeVar].getConstraints())
142138
constraintComponent[constraint] = components[i];
143139
}
144140

145141
// Add the orphaned components to the mapping from constraints to components.
146-
unsigned firstOrphanedConstraint =
142+
unsigned firstOrphanedComponent =
147143
numComponents - CG.getOrphanedConstraints().size();
148144
{
149-
unsigned component = firstOrphanedConstraint;
145+
unsigned component = firstOrphanedComponent;
150146
for (auto *constraint : CG.getOrphanedConstraints()) {
151147
// Register this orphan constraint both as associated with
152148
// a given component as a regular constrant, as well as an
@@ -157,6 +153,22 @@ void SplitterStep::computeFollowupSteps(
157153
}
158154
}
159155

156+
for (auto *typeVar : CS.TypeVariables) {
157+
auto known = typeVarComponent.find(typeVar);
158+
// If current type variable is associated with
159+
// a certain component step, record it as being so.
160+
if (known != typeVarComponent.end()) {
161+
componentSteps[known->second]->record(typeVar);
162+
continue;
163+
}
164+
165+
// Otherwise, associate it with all of the component steps,
166+
// expect for components with orphaned constraints, they are
167+
// not supposed to have any type variables.
168+
for (unsigned i = 0; i != firstOrphanedComponent; ++i)
169+
componentSteps[i]->record(typeVar);
170+
}
171+
160172
// Transfer all of the constraints from the work list to
161173
// the appropriate component.
162174
auto &workList = CS.InactiveConstraints;

lib/Sema/CSStep.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "swift/AST/Types.h"
2424
#include "llvm/ADT/ArrayRef.h"
2525
#include "llvm/ADT/Optional.h"
26-
#include "llvm/ADT/SmallPtrSet.h"
2726
#include "llvm/ADT/SmallVector.h"
2827
#include <memory>
2928

@@ -311,7 +310,7 @@ class ComponentStep final : public SolverStep {
311310
std::unique_ptr<Scope> ComponentScope = nullptr;
312311

313312
/// Type variables and constraints "in scope" of this step.
314-
SmallPtrSet<TypeVariableType *, 16> TypeVars;
313+
SmallVector<TypeVariableType *, 16> TypeVars;
315314
/// Constraints "in scope" of this step.
316315
ConstraintList *Constraints;
317316

@@ -332,7 +331,7 @@ class ComponentStep final : public SolverStep {
332331

333332
public:
334333
/// Record a type variable as associated with this step.
335-
void record(TypeVariableType *typeVar) { TypeVars.insert(typeVar); }
334+
void record(TypeVariableType *typeVar) { TypeVars.push_back(typeVar); }
336335

337336
/// Record a constraint as associated with this step.
338337
void record(Constraint *constraint) {
@@ -349,15 +348,14 @@ class ComponentStep final : public SolverStep {
349348
}
350349

351350
void setup() override {
352-
// If this component has oprhaned constraint attached,
353-
// let's return it ot the graph.
354-
if (OrphanedConstraint)
355-
CS.CG.setOrphanedConstraint(OrphanedConstraint);
356-
357351
// If this is a single component, there is
358352
// no need to preliminary modify constraint system.
359-
if (!IsSingle)
353+
if (!IsSingle) {
360354
ComponentScope = llvm::make_unique<Scope>(*this);
355+
// If this component has oprhaned constraint attached,
356+
// let's return it ot the graph.
357+
CS.CG.setOrphanedConstraint(OrphanedConstraint);
358+
}
361359
}
362360

363361
StepResult take(bool prevFailed) override;

0 commit comments

Comments
 (0)