Skip to content

Commit e23d442

Browse files
committed
---
yaml --- r: 349407 b: refs/heads/master-next c: 321dbc4 h: refs/heads/master i: 349405: e81ae90 349403: 00b4340 349399: 1e8c33b 349391: 13a628a 349375: 077951a
1 parent 2268832 commit e23d442

16 files changed

+82
-63
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: d3d64054941e2161b24dc3436e89a72d417fba4c
3+
refs/heads/master-next: 321dbc4aed0c1d3e0c36a82287e4ad2ffc830c78
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/lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4635,7 +4635,8 @@ namespace {
46354635
}
46364636

46374637
Expr *visitOneWayExpr(OneWayExpr *E) {
4638-
return E->getSubExpr();
4638+
auto type = simplifyType(cs.getType(E));
4639+
return coerceToType(E->getSubExpr(), type, cs.getConstraintLocator(E));
46394640
}
46404641

46414642
Expr *visitTapExpr(TapExpr *E) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
633633
}
634634
break;
635635

636-
case ConstraintKind::OneWayBind: {
636+
case ConstraintKind::OneWayEqual: {
637637
// Don't produce any bindings if this type variable is on the left-hand
638638
// side of a one-way binding.
639639
auto firstType = constraint->getFirstType();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,7 @@ namespace {
30833083
Type visitOneWayExpr(OneWayExpr *expr) {
30843084
auto locator = CS.getConstraintLocator(expr);
30853085
auto resultTypeVar = CS.createTypeVariable(locator, 0);
3086-
CS.addConstraint(ConstraintKind::OneWayBind, resultTypeVar,
3086+
CS.addConstraint(ConstraintKind::OneWayEqual, resultTypeVar,
30873087
CS.getType(expr->getSubExpr()), locator);
30883088
return resultTypeVar;
30893089
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
11461146
case ConstraintKind::BridgingConversion:
11471147
case ConstraintKind::FunctionInput:
11481148
case ConstraintKind::FunctionResult:
1149-
case ConstraintKind::OneWayBind:
1149+
case ConstraintKind::OneWayEqual:
11501150
llvm_unreachable("Not a conversion");
11511151
}
11521152

@@ -1209,7 +1209,7 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
12091209
case ConstraintKind::ValueMember:
12101210
case ConstraintKind::FunctionInput:
12111211
case ConstraintKind::FunctionResult:
1212-
case ConstraintKind::OneWayBind:
1212+
case ConstraintKind::OneWayEqual:
12131213
return false;
12141214
}
12151215

@@ -1394,7 +1394,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
13941394
case ConstraintKind::BridgingConversion:
13951395
case ConstraintKind::FunctionInput:
13961396
case ConstraintKind::FunctionResult:
1397-
case ConstraintKind::OneWayBind:
1397+
case ConstraintKind::OneWayEqual:
13981398
llvm_unreachable("Not a relational constraint");
13991399
}
14001400

@@ -2829,7 +2829,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
28292829
case ConstraintKind::ValueMember:
28302830
case ConstraintKind::FunctionInput:
28312831
case ConstraintKind::FunctionResult:
2832-
case ConstraintKind::OneWayBind:
2832+
case ConstraintKind::OneWayEqual:
28332833
llvm_unreachable("Not a relational constraint");
28342834
}
28352835
}
@@ -5267,7 +5267,7 @@ ConstraintSystem::simplifyOneWayConstraint(
52675267
}
52685268

52695269
// Translate this constraint into a one-way binding constraint.
5270-
return matchTypes(first, secondSimplified, ConstraintKind::Bind, flags,
5270+
return matchTypes(first, secondSimplified, ConstraintKind::Equal, flags,
52715271
locator);
52725272
}
52735273

@@ -7315,7 +7315,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
73157315
return simplifyFunctionComponentConstraint(kind, first, second,
73167316
subflags, locator);
73177317

7318-
case ConstraintKind::OneWayBind:
7318+
case ConstraintKind::OneWayEqual:
73197319
return simplifyOneWayConstraint(kind, first, second, subflags, locator);
73207320

73217321
case ConstraintKind::ValueMember:
@@ -7674,7 +7674,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
76747674
// Disjunction constraints are never solved here.
76757675
return SolutionKind::Unsolved;
76767676

7677-
case ConstraintKind::OneWayBind:
7677+
case ConstraintKind::OneWayEqual:
76787678
return simplifyOneWayConstraint(constraint.getKind(),
76797679
constraint.getFirstType(),
76807680
constraint.getSecondType(),

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Solution ConstraintSystem::finalize() {
7777
}
7878
}
7979

80-
for (auto tv : TypeVariables) {
80+
for (auto tv : getTypeVariables()) {
8181
if (getFixedType(tv))
8282
continue;
8383

@@ -95,7 +95,7 @@ Solution ConstraintSystem::finalize() {
9595
}
9696

9797
// For each of the type variables, get its fixed type.
98-
for (auto tv : TypeVariables) {
98+
for (auto tv : getTypeVariables()) {
9999
solution.typeBindings[tv] = simplifyType(tv)->reconstituteSugar(false);
100100
}
101101

@@ -198,12 +198,9 @@ void ConstraintSystem::applySolution(const Solution &solution) {
198198
CurrentScore += solution.getFixedScore();
199199

200200
// Assign fixed types to the type variables solved by this solution.
201-
llvm::SmallPtrSet<TypeVariableType *, 4>
202-
knownTypeVariables(TypeVariables.begin(), TypeVariables.end());
203201
for (auto binding : solution.typeBindings) {
204202
// If we haven't seen this type variable before, record it now.
205-
if (knownTypeVariables.insert(binding.first).second)
206-
TypeVariables.push_back(binding.first);
203+
addTypeVariable(binding.first);
207204

208205
// If we don't already have a fixed type for this type variable,
209206
// assign the fixed type from the solution.
@@ -475,7 +472,8 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
475472
ConstraintSystem::SolverScope::~SolverScope() {
476473
// Erase the end of various lists.
477474
cs.resolvedOverloadSets = resolvedOverloadSets;
478-
truncate(cs.TypeVariables, numTypeVariables);
475+
while (cs.TypeVariables.size() > numTypeVariables)
476+
cs.TypeVariables.pop_back();
479477

480478
// Restore bindings.
481479
cs.restoreTypeVariableBindings(cs.solverState->savedBindings.size() -
@@ -1683,7 +1681,7 @@ void ConstraintSystem::ArgumentInfoCollector::walk(Type argType) {
16831681
case ConstraintKind::SelfObjectOfProtocol:
16841682
case ConstraintKind::ConformsTo:
16851683
case ConstraintKind::Defaultable:
1686-
case ConstraintKind::OneWayBind:
1684+
case ConstraintKind::OneWayEqual:
16871685
break;
16881686
}
16891687
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ComponentStep::Scope::Scope(ComponentStep &component)
3232
TypeVars = std::move(CS.TypeVariables);
3333

3434
for (auto *typeVar : component.TypeVars)
35-
CS.TypeVariables.push_back(typeVar);
35+
CS.addTypeVariable(typeVar);
3636

3737
auto &workList = CS.InactiveConstraints;
3838
workList.splice(workList.end(), *component.Constraints);
@@ -92,7 +92,7 @@ void SplitterStep::computeFollowupSteps(
9292
CG.optimize();
9393

9494
// Compute the connected components of the constraint graph.
95-
auto components = CG.computeConnectedComponents(CS.TypeVariables);
95+
auto components = CG.computeConnectedComponents(CS.getTypeVariables());
9696
unsigned numComponents = components.size();
9797
if (numComponents < 2) {
9898
steps.push_back(llvm::make_unique<ComponentStep>(
@@ -106,10 +106,10 @@ void SplitterStep::computeFollowupSteps(
106106
CG.verify();
107107

108108
log << "---Constraint graph---\n";
109-
CG.print(CS.TypeVariables, log);
109+
CG.print(CS.getTypeVariables(), log);
110110

111111
log << "---Connected components---\n";
112-
CG.printConnectedComponents(CS.TypeVariables, log);
112+
CG.printConnectedComponents(CS.getTypeVariables(), log);
113113
}
114114

115115
// Take the orphaned constraints, because they'll go into a component now.
@@ -312,7 +312,7 @@ StepResult ComponentStep::take(bool prevFailed) {
312312
// Activate all of the one-way constraints.
313313
SmallVector<Constraint *, 4> oneWayConstraints;
314314
for (auto &constraint : CS.InactiveConstraints) {
315-
if (constraint.getKind() == ConstraintKind::OneWayBind)
315+
if (constraint.isOneWayConstraint())
316316
oneWayConstraints.push_back(&constraint);
317317
}
318318
for (auto constraint : oneWayConstraints) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class ComponentStep final : public SolverStep {
342342
ConstraintSystem &CS;
343343
ConstraintSystem::SolverScope *SolverScope;
344344

345-
std::vector<TypeVariableType *> TypeVars;
345+
SetVector<TypeVariableType *> TypeVars;
346346
ConstraintSystem::SolverScope *PrevPartialScope = nullptr;
347347

348348
// The component this scope is associated with.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
6666
case ConstraintKind::FunctionInput:
6767
case ConstraintKind::FunctionResult:
6868
case ConstraintKind::OpaqueUnderlyingType:
69-
case ConstraintKind::OneWayBind:
69+
case ConstraintKind::OneWayEqual:
7070
assert(!First.isNull());
7171
assert(!Second.isNull());
7272
break;
@@ -135,7 +135,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
135135
case ConstraintKind::FunctionInput:
136136
case ConstraintKind::FunctionResult:
137137
case ConstraintKind::OpaqueUnderlyingType:
138-
case ConstraintKind::OneWayBind:
138+
case ConstraintKind::OneWayEqual:
139139
llvm_unreachable("Wrong constructor");
140140

141141
case ConstraintKind::KeyPath:
@@ -239,7 +239,7 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
239239
case ConstraintKind::FunctionInput:
240240
case ConstraintKind::FunctionResult:
241241
case ConstraintKind::OpaqueUnderlyingType:
242-
case ConstraintKind::OneWayBind:
242+
case ConstraintKind::OneWayEqual:
243243
return create(cs, getKind(), getFirstType(), getSecondType(), getLocator());
244244

245245
case ConstraintKind::BindOverload:
@@ -312,7 +312,7 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
312312
case ConstraintKind::DynamicTypeOf: Out << " dynamicType type of "; break;
313313
case ConstraintKind::EscapableFunctionOf: Out << " @escaping type of "; break;
314314
case ConstraintKind::OpenedExistentialOf: Out << " opened archetype of "; break;
315-
case ConstraintKind::OneWayBind: Out << " one-way bind to "; break;
315+
case ConstraintKind::OneWayEqual: Out << " one-way bind to "; break;
316316
case ConstraintKind::KeyPath:
317317
Out << " key path from ";
318318
getSecondType()->print(Out);
@@ -521,7 +521,7 @@ gatherReferencedTypeVars(Constraint *constraint,
521521
case ConstraintKind::FunctionInput:
522522
case ConstraintKind::FunctionResult:
523523
case ConstraintKind::OpaqueUnderlyingType:
524-
case ConstraintKind::OneWayBind:
524+
case ConstraintKind::OneWayEqual:
525525
constraint->getFirstType()->getTypeVariables(typeVars);
526526
constraint->getSecondType()->getTypeVariables(typeVars);
527527
break;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ enum class ConstraintKind : char {
150150
/// The first type is a type that's a candidate to be the underlying type of
151151
/// the second opaque archetype.
152152
OpaqueUnderlyingType,
153-
/// The first type will be bound to the second type, but only when the
153+
/// The first type will be equal to the second type, but only when the
154154
/// second type has been fully determined (and mapped down to a concrete
155-
/// type). At that point, this constraint will be treated like a `Bind`
155+
/// type). At that point, this constraint will be treated like an `Equal`
156156
/// constraint.
157-
OneWayBind,
157+
OneWayEqual,
158158
};
159159

160160
/// Classification of the different kinds of constraints.
@@ -495,7 +495,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
495495
case ConstraintKind::BindOverload:
496496
case ConstraintKind::OptionalObject:
497497
case ConstraintKind::OpaqueUnderlyingType:
498-
case ConstraintKind::OneWayBind:
498+
case ConstraintKind::OneWayEqual:
499499
return ConstraintClassification::Relational;
500500

501501
case ConstraintKind::ValueMember:
@@ -609,6 +609,11 @@ class Constraint final : public llvm::ilist_node<Constraint>,
609609
/// e.g. coercion constraint "as X" which forms a disjunction.
610610
bool isExplicitConversion() const;
611611

612+
/// Whether this is a one-way constraint.
613+
bool isOneWayConstraint() const {
614+
return Kind == ConstraintKind::OneWayEqual;
615+
}
616+
612617
/// Retrieve the overload choice for an overload-binding constraint.
613618
OverloadChoice getOverloadChoice() const {
614619
assert(Kind == ConstraintKind::BindOverload);

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,24 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
379379
llvm::TinyPtrVector<Constraint *> constraints;
380380

381381
// Whether we should consider this constraint at all.
382-
auto &reprNode = (*this)[CS.getRepresentative(typeVar)];
383-
auto equivClass = reprNode.getEquivalenceClass();
382+
auto rep = CS.getRepresentative(typeVar);
384383
auto shouldConsiderConstraint = [&](Constraint *constraint) {
385384
// For a one-way constraint, only consider it when the type variable
386-
// is on the left-hand side of the the binding. Otherwise, it is not
387-
// relevant.
388-
if (constraint->getKind() == ConstraintKind::OneWayBind) {
385+
// is on the right-hand side of the the binding, and the left-hand side of
386+
// the binding is one of the type variables currently under consideration.
387+
if (constraint->isOneWayConstraint()) {
389388
auto lhsTypeVar =
390389
constraint->getFirstType()->castTo<TypeVariableType>();
391-
if (std::find(equivClass.begin(), equivClass.end(), lhsTypeVar)
392-
== equivClass.end())
390+
if (!CS.isActiveTypeVariable(lhsTypeVar))
393391
return false;
392+
393+
SmallVector<TypeVariableType *, 2> rhsTypeVars;
394+
constraint->getSecondType()->getTypeVariables(rhsTypeVars);
395+
for (auto rhsTypeVar : rhsTypeVars) {
396+
if (CS.getRepresentative(rhsTypeVar) == rep)
397+
return true;
398+
}
399+
return false;
394400
}
395401

396402
return true;
@@ -421,6 +427,8 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
421427
}
422428
};
423429

430+
auto &reprNode = (*this)[CS.getRepresentative(typeVar)];
431+
auto equivClass = reprNode.getEquivalenceClass();
424432
for (auto typeVar : equivClass) {
425433
auto &node = (*this)[typeVar];
426434
for (auto constraint : node.getConstraints()) {
@@ -625,7 +633,7 @@ namespace {
625633
continue;
626634

627635
TypeVariableType *typeVar;
628-
if (constraint.getKind() == ConstraintKind::OneWayBind) {
636+
if (constraint.isOneWayConstraint()) {
629637
// For one-way constraints, associate the constraint with the
630638
// left-hand type variable.
631639
typeVar = constraint.getFirstType()->castTo<TypeVariableType>();
@@ -772,7 +780,7 @@ namespace {
772780
},
773781
[&](Constraint *constraint) {
774782
// Record and skip one-way constraints.
775-
if (constraint->getKind() == ConstraintKind::OneWayBind) {
783+
if (constraint->isOneWayConstraint()) {
776784
oneWayConstraints.push_back(constraint);
777785
return false;
778786
}
@@ -1275,7 +1283,7 @@ void ConstraintGraph::dump() {
12751283
void ConstraintGraph::dump(llvm::raw_ostream &out) {
12761284
llvm::SaveAndRestore<bool>
12771285
debug(CS.getASTContext().LangOpts.DebugConstraintSolver, true);
1278-
print(CS.TypeVariables, out);
1286+
print(CS.getTypeVariables(), out);
12791287
}
12801288

12811289
void ConstraintGraph::printConnectedComponents(
@@ -1314,7 +1322,7 @@ void ConstraintGraph::printConnectedComponents(
13141322
void ConstraintGraph::dumpConnectedComponents() {
13151323
llvm::SaveAndRestore<bool>
13161324
debug(CS.getASTContext().LangOpts.DebugConstraintSolver, true);
1317-
printConnectedComponents(CS.TypeVariables, llvm::dbgs());
1325+
printConnectedComponents(CS.getTypeVariables(), llvm::dbgs());
13181326
}
13191327

13201328
#pragma mark Verification of graph invariants

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class ConstraintGraph {
337337
ConstraintSystem &CS;
338338

339339
/// The type variables in this graph, in stable order.
340-
SmallVector<TypeVariableType *, 4> TypeVariables;
340+
std::vector<TypeVariableType *> TypeVariables;
341341

342342
/// Constraints that are "orphaned" because they contain no type variables.
343343
SmallVector<Constraint *, 4> OrphanedConstraints;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool ConstraintSystem::hasFreeTypeVariables() {
107107
}
108108

109109
void ConstraintSystem::addTypeVariable(TypeVariableType *typeVar) {
110-
TypeVariables.push_back(typeVar);
110+
TypeVariables.insert(typeVar);
111111

112112
// Notify the constraint graph.
113113
(void)CG[typeVar];

0 commit comments

Comments
 (0)