Skip to content

Commit 4ef33aa

Browse files
committed
---
yaml --- r: 349361 b: refs/heads/master-next c: 226cd14 h: refs/heads/master i: 349359: 7e053a7
1 parent 6aff74d commit 4ef33aa

File tree

7 files changed

+261
-207
lines changed

7 files changed

+261
-207
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 0337e5a130ef26bf4dfe49824e011b5e82e774a0
3+
refs/heads/master-next: 226cd140b9414cea26e4f43260502839f36bfae4
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/Basic/CTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ SWIFT_TYPEID_TEMPLATE1_NAMED(std::vector, Vector, typename T, T)
3939

4040
// LLVM ADT types.
4141
SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::TinyPtrVector, TinyPtrVector, typename T, T)
42-
SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::ArrayRef, ArrayRef, typename T, T)
42+
SWIFT_TYPEID_TEMPLATE1_NAMED(llvm::ArrayRef, ArrayRef, typename T, T)

branches/master-next/lib/Sema/CSStep.cpp

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,14 @@ void SplitterStep::computeFollowupSteps(
9696
CG.optimize();
9797

9898
// 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 = components.size();
105101
if (numComponents < 2) {
106102
componentSteps.push_back(llvm::make_unique<ComponentStep>(
107-
CS, 0, /*single=*/true, &CS.InactiveConstraints, Solutions));
103+
CS, 0, &CS.InactiveConstraints, Solutions));
108104
return;
109105
}
110106

111-
Components.resize(numComponents);
112-
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
113-
new SmallVector<Solution, 4>[numComponents]);
114-
115-
for (unsigned i = 0, n = numComponents; i != n; ++i) {
116-
componentSteps.push_back(llvm::make_unique<ComponentStep>(
117-
CS, i, /*single=*/false, &Components[i], PartialSolutions[i]));
118-
}
119-
120107
if (isDebugMode()) {
121108
auto &log = getDebugLogger();
122109
// Verify that the constraint graph is valid.
@@ -129,66 +116,20 @@ void SplitterStep::computeFollowupSteps(
129116
CG.printConnectedComponents(CS.TypeVariables, log);
130117
}
131118

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-
}
119+
// Take the orphaned constraints, because they'll go into a component now.
120+
OrphanedConstraints = CG.takeOrphanedConstraints();
158121

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-
}
122+
Components.resize(numComponents);
123+
PartialSolutions = std::unique_ptr<SmallVector<Solution, 4>[]>(
124+
new SmallVector<Solution, 4>[numComponents]);
168125

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);
126+
// Add components.
127+
for (unsigned i : indices(components)) {
128+
unsigned solutionIndex = components[i].solutionIndex;
129+
componentSteps.push_back(llvm::make_unique<ComponentStep>(
130+
CS, solutionIndex, &Components[i], std::move(components[i]),
131+
PartialSolutions[solutionIndex]));
177132
}
178-
179-
// Remove all of the orphaned constraints; they'll be re-introduced
180-
// by each component independently.
181-
OrphanedConstraints = CG.takeOrphanedConstraints();
182-
183-
// Create component ordering based on the information associated
184-
// with constraints in each step - e.g. number of disjunctions,
185-
// since components are going to be executed in LIFO order, we'd
186-
// want to have smaller/faster components at the back of the list.
187-
std::sort(componentSteps.begin(), componentSteps.end(),
188-
[](const std::unique_ptr<ComponentStep> &lhs,
189-
const std::unique_ptr<ComponentStep> &rhs) {
190-
return lhs->disjunctionCount() > rhs->disjunctionCount();
191-
});
192133
}
193134

194135
bool SplitterStep::mergePartialSolutions() const {

branches/master-next/lib/Sema/CSStep.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define SWIFT_SEMA_CSSTEP_H
2020

2121
#include "Constraint.h"
22+
#include "ConstraintGraph.h"
2223
#include "ConstraintSystem.h"
2324
#include "swift/AST/Types.h"
2425
#include "llvm/ADT/ArrayRef.h"
@@ -336,50 +337,50 @@ class ComponentStep final : public SolverStep {
336337
std::unique_ptr<Scope> ComponentScope = nullptr;
337338

338339
/// Type variables and constraints "in scope" of this step.
339-
std::vector<TypeVariableType *> TypeVars;
340+
TinyPtrVector<TypeVariableType *> TypeVars;
340341
/// Constraints "in scope" of this step.
341342
ConstraintList *Constraints;
342343

343-
/// Number of disjunction constraints associated with this step,
344-
/// used to aid in ordering of the components.
345-
unsigned NumDisjunctions = 0;
346-
347344
/// Constraint which doesn't have any free type variables associated
348345
/// with it, which makes it disconnected in the graph.
349346
Constraint *OrphanedConstraint = nullptr;
350347

351348
public:
352-
ComponentStep(ConstraintSystem &cs, unsigned index, bool single,
349+
/// Create a single component step.
350+
ComponentStep(ConstraintSystem &cs, unsigned index,
353351
ConstraintList *constraints,
354352
SmallVectorImpl<Solution> &solutions)
355-
: SolverStep(cs, solutions), Index(index), IsSingle(single),
353+
: SolverStep(cs, solutions), Index(index), IsSingle(true),
356354
OriginalScore(getCurrentScore()), OriginalBestScore(getBestScore()),
357355
Constraints(constraints) {}
358356

359-
/// Record a type variable as associated with this step.
360-
void record(TypeVariableType *typeVar) { TypeVars.push_back(typeVar); }
357+
/// Create a component step from a constraint graph component.
358+
ComponentStep(ConstraintSystem &cs, unsigned index,
359+
ConstraintList *constraints,
360+
ConstraintGraph::Component &&component,
361+
SmallVectorImpl<Solution> &solutions)
362+
: SolverStep(cs, solutions), Index(index), IsSingle(false),
363+
OriginalScore(getCurrentScore()), OriginalBestScore(getBestScore()),
364+
Constraints(constraints) {
365+
if (component.isOrphaned()) {
366+
assert(component.getConstraints().size() == 1);
367+
OrphanedConstraint = component.getConstraints().front();
368+
} else {
369+
assert(component.typeVars.size() > 0);
370+
}
361371

362-
/// Record a constraint as associated with this step.
363-
void record(Constraint *constraint) {
364-
Constraints->push_back(constraint);
365-
if (constraint->getKind() == ConstraintKind::Disjunction)
366-
++NumDisjunctions;
367-
}
372+
TypeVars = std::move(component.typeVars);
368373

369-
/// Record a constraint as associated with this step but which doesn't
370-
/// have any free type variables associated with it.
371-
void recordOrphan(Constraint *constraint) {
372-
assert(!OrphanedConstraint);
373-
OrphanedConstraint = constraint;
374+
for (auto constraint : component.getConstraints()) {
375+
constraints->erase(constraint);
376+
Constraints->push_back(constraint);
377+
}
374378
}
375379

376380
StepResult take(bool prevFailed) override;
377381

378382
StepResult resume(bool prevFailed) override { return finalize(!prevFailed); }
379383

380-
// The number of disjunction constraints associated with this component.
381-
unsigned disjunctionCount() const { return NumDisjunctions; }
382-
383384
void print(llvm::raw_ostream &Out) override {
384385
Out << "ComponentStep with at #" << Index << '\n';
385386
}
@@ -395,7 +396,8 @@ class ComponentStep final : public SolverStep {
395396
getDebugLogger() << "(solving component #" << Index << '\n';
396397

397398
ComponentScope = llvm::make_unique<Scope>(*this);
398-
// If this component has oprhaned constraint attached,
399+
400+
// If this component has orphaned constraint attached,
399401
// let's return it to the graph.
400402
CS.CG.setOrphanedConstraint(OrphanedConstraint);
401403
}

0 commit comments

Comments
 (0)