Skip to content

Commit 0b42317

Browse files
committed
---
yaml --- r: 345068 b: refs/heads/master c: 79560ad h: refs/heads/master
1 parent 018c929 commit 0b42317

26 files changed

+148
-170
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e31046dbba30f9a375191f4a1afba9fa14638781
2+
refs/heads/master: 79560ada9ee694c5a1141c0fd905ba0f60e2e253
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Types.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
907907
/// argument labels removed.
908908
Type removeArgumentLabels(unsigned numArgumentLabels);
909909

910-
/// getUnlabeledType - Retrieve a version of this type with all labels
911-
/// removed at every level. For example, given a tuple type
912-
/// \code
913-
/// (p : (x : int, y : int))
914-
/// \endcode
915-
/// the result would be the (parenthesized) type ((int, int)).
916-
Type getUnlabeledType(ASTContext &Context);
917-
918910
/// Retrieve the type without any parentheses around it.
919911
Type getWithoutParens();
920912

@@ -2697,8 +2689,9 @@ class AnyFunctionType : public TypeBase {
26972689
}
26982690

26992691
bool operator==(Param const &b) const {
2700-
return Label == b.Label && getType()->isEqual(b.getType()) &&
2701-
Flags == b.Flags;
2692+
return (Label == b.Label &&
2693+
getPlainType()->isEqual(b.getPlainType()) &&
2694+
Flags == b.Flags);
27022695
}
27032696
bool operator!=(Param const &b) const { return !(*this == b); }
27042697

@@ -2952,6 +2945,11 @@ class AnyFunctionType : public TypeBase {
29522945
/// \brief Given two arrays of parameters determine if they are equal.
29532946
static bool equalParams(CanParamArrayRef a, CanParamArrayRef b);
29542947

2948+
/// \brief Given an array of parameters and an array of labels of the
2949+
/// same length, update each parameter to have the corresponding label.
2950+
static void relabelParams(MutableArrayRef<Param> params,
2951+
ArrayRef<Identifier> labels);
2952+
29552953
Type getInput() const { return Input; }
29562954
Type getResult() const { return Output; }
29572955
ArrayRef<Param> getParams() const;

trunk/lib/AST/ASTContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,17 @@ bool AnyFunctionType::equalParams(CanParamArrayRef a, CanParamArrayRef b) {
36183618
return true;
36193619
}
36203620

3621+
void AnyFunctionType::relabelParams(MutableArrayRef<Param> params,
3622+
ArrayRef<Identifier> labels) {
3623+
assert(params.size() == labels.size());
3624+
for (auto i : indices(params)) {
3625+
auto &param = params[i];
3626+
param = AnyFunctionType::Param(param.getPlainType(),
3627+
labels[i],
3628+
param.getParameterFlags());
3629+
}
3630+
}
3631+
36213632
FunctionType *FunctionType::get(ArrayRef<AnyFunctionType::Param> params,
36223633
Type result, ExtInfo info,
36233634
bool canonicalVararg) {

trunk/lib/AST/Type.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -680,49 +680,6 @@ bool TypeBase::isExistentialWithError() {
680680
return layout.isExistentialWithError(getASTContext());
681681
}
682682

683-
684-
static Type getStrippedType(const ASTContext &context, Type type,
685-
bool stripLabels) {
686-
return type.transform([&](Type type) -> Type {
687-
auto *tuple = dyn_cast<TupleType>(type.getPointer());
688-
if (!tuple)
689-
return type;
690-
691-
SmallVector<TupleTypeElt, 4> elements;
692-
bool anyChanged = false;
693-
unsigned idx = 0;
694-
for (const auto &elt : tuple->getElements()) {
695-
Type eltTy = getStrippedType(context, elt.getRawType(),
696-
stripLabels);
697-
if (anyChanged || eltTy.getPointer() != elt.getRawType().getPointer() ||
698-
(elt.hasName() && stripLabels)) {
699-
if (!anyChanged) {
700-
elements.reserve(tuple->getNumElements());
701-
for (unsigned i = 0; i != idx; ++i) {
702-
const TupleTypeElt &elt = tuple->getElement(i);
703-
Identifier newName = stripLabels? Identifier() : elt.getName();
704-
elements.push_back(elt.getWithName(newName));
705-
}
706-
anyChanged = true;
707-
}
708-
709-
Identifier newName = stripLabels? Identifier() : elt.getName();
710-
elements.emplace_back(eltTy, newName, elt.getParameterFlags());
711-
}
712-
++idx;
713-
}
714-
715-
if (!anyChanged)
716-
return type;
717-
718-
return TupleType::get(elements, context);
719-
});
720-
}
721-
722-
Type TypeBase::getUnlabeledType(ASTContext &Context) {
723-
return getStrippedType(Context, Type(this), /*stripLabels=*/true);
724-
}
725-
726683
/// Remove argument labels from the function type.
727684
Type TypeBase::removeArgumentLabels(unsigned numArgumentLabels) {
728685
// If there is nothing to remove, don't.

trunk/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ CompilerInvocation::loadFromSerializedAST(StringRef data) {
12071207
if (info.status != serialization::Status::Valid)
12081208
return info.status;
12091209

1210+
LangOpts.EffectiveLanguageVersion = info.compatibilityVersion;
12101211
setTargetTriple(info.targetTriple);
12111212
if (!extendedInfo.getSDKPath().empty())
12121213
setSDKPath(extendedInfo.getSDKPath());

trunk/lib/SILGen/SILGenExpr.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,13 +2527,9 @@ static void emitTupleShuffleExprInto(RValueEmitter &emitter,
25272527
// Map outer initializations into a tuple of inner initializations:
25282528
// - fill out the initialization elements with null
25292529
TupleInitialization innerTupleInit;
2530-
if (E->isSourceScalar()) {
2531-
innerTupleInit.SubInitializations.push_back(nullptr);
2532-
} else {
2533-
CanTupleType innerTuple =
2534-
cast<TupleType>(E->getSubExpr()->getType()->getCanonicalType());
2535-
innerTupleInit.SubInitializations.resize(innerTuple->getNumElements());
2536-
}
2530+
CanTupleType innerTuple =
2531+
cast<TupleType>(E->getSubExpr()->getType()->getCanonicalType());
2532+
innerTupleInit.SubInitializations.resize(innerTuple->getNumElements());
25372533

25382534
// Map all the outer initializations to their appropriate targets.
25392535
for (unsigned outerIndex = 0; outerIndex != outerInits.size(); outerIndex++) {
@@ -2551,18 +2547,16 @@ static void emitTupleShuffleExprInto(RValueEmitter &emitter,
25512547
#endif
25522548

25532549
// Emit the sub-expression into the tuple initialization we just built.
2554-
if (E->isSourceScalar()) {
2555-
emitter.SGF.emitExprInto(E->getSubExpr(),
2556-
innerTupleInit.SubInitializations[0].get());
2557-
} else {
2558-
emitter.SGF.emitExprInto(E->getSubExpr(), &innerTupleInit);
2559-
}
2550+
emitter.SGF.emitExprInto(E->getSubExpr(), &innerTupleInit);
25602551

25612552
outerTupleInit->finishInitialization(emitter.SGF);
25622553
}
25632554

25642555
RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
25652556
SGFContext C) {
2557+
assert(!E->isSourceScalar());
2558+
assert(!E->isResultScalar());
2559+
25662560
// If we're emitting into an initialization, we can try shuffling the
25672561
// elements of the initialization.
25682562
if (Initialization *I = C.getEmitInto()) {
@@ -2574,11 +2568,7 @@ RValue RValueEmitter::visitTupleShuffleExpr(TupleShuffleExpr *E,
25742568

25752569
// Emit the sub-expression tuple and destructure it into elements.
25762570
SmallVector<RValue, 4> elements;
2577-
if (E->isSourceScalar()) {
2578-
elements.push_back(visit(E->getSubExpr()));
2579-
} else {
2580-
visit(E->getSubExpr()).extractElements(elements);
2581-
}
2571+
visit(E->getSubExpr()).extractElements(elements);
25822572

25832573
// Prepare a new tuple to hold the shuffled result.
25842574
RValue result(E->getType()->getCanonicalType());

trunk/lib/Sema/CSApply.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5543,27 +5543,6 @@ Expr *ExprRewriter::coerceCallArguments(
55435543
auto args = decomposeArgType(cs.getType(arg), argLabels);
55445544

55455545
// Quickly test if any further fix-ups for the argument types are necessary.
5546-
// FIXME: This hack is only necessary to work around some problems we have
5547-
// for inferring the type of an unresolved member reference expression in
5548-
// an optional context. We should seek a more holistic fix for this.
5549-
if (allParamsMatch &&
5550-
(params.size() == args.size())) {
5551-
if (auto argTuple = dyn_cast<TupleExpr>(arg)) {
5552-
auto argElts = argTuple->getElements();
5553-
5554-
for (size_t i = 0; i < params.size(); i++) {
5555-
if (auto dotExpr = dyn_cast<DotSyntaxCallExpr>(argElts[i])) {
5556-
auto paramTy = params[i].getType();
5557-
auto argTy = cs.getType(dotExpr)->getWithoutSpecifierType();
5558-
if (!paramTy->isEqual(argTy)) {
5559-
allParamsMatch = false;
5560-
break;
5561-
}
5562-
}
5563-
}
5564-
}
5565-
}
5566-
55675546
if (allParamsMatch)
55685547
return arg;
55695548

@@ -7942,12 +7921,16 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
79427921

79437922
cs.cacheSubExprTypes(call);
79447923

7924+
// Extract the arguments.
7925+
SmallVector<AnyFunctionType::Param, 8> args;
7926+
AnyFunctionType::decomposeInput(cs.getType(call->getArg()), args);
7927+
79457928
// Add the conversion from the argument to the function parameter type.
79467929
auto openedFuncType = openedType->castTo<FunctionType>();
79477930
::matchCallArguments(
79487931
cs, /*isOperator=*/false,
7949-
cs.getType(call->getArg()),
7950-
openedFuncType->getInput(),
7932+
args,
7933+
openedFuncType->getParams(),
79517934
cs.getConstraintLocator(call,
79527935
ConstraintLocator::ApplyArgument));
79537936

trunk/lib/Sema/CSGen.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,10 +1330,17 @@ namespace {
13301330
}
13311331
auto *constr = cast<ConstructorDecl>(constrs.front());
13321332
auto constrParamType = tc.getObjectLiteralParameterType(expr, constr);
1333+
1334+
// Extract the arguments.
1335+
SmallVector<AnyFunctionType::Param, 8> args;
1336+
AnyFunctionType::decomposeInput(CS.getType(expr->getArg()), args);
1337+
1338+
// Extract the parameters.
1339+
SmallVector<AnyFunctionType::Param, 8> params;
1340+
AnyFunctionType::decomposeInput(constrParamType, params);
1341+
13331342
::matchCallArguments(
1334-
CS, /*isOperator=*/false,
1335-
CS.getType(expr->getArg()),
1336-
constrParamType,
1343+
CS, /*isOperator=*/false, args, params,
13371344
CS.getConstraintLocator(expr,
13381345
ConstraintLocator::ApplyArgument));
13391346

trunk/lib/Sema/CSRanking.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,19 @@ Comparison TypeChecker::compareDeclarations(DeclContext *dc,
726726
return decl1Better? Comparison::Better : Comparison::Worse;
727727
}
728728

729+
static Type getUnlabeledType(Type type, ASTContext &ctx) {
730+
if (auto *tupleType = dyn_cast<TupleType>(type.getPointer())) {
731+
SmallVector<TupleTypeElt, 8> elts;
732+
for (auto elt : tupleType->getElements()) {
733+
elts.push_back(elt.getWithoutName());
734+
}
735+
736+
return TupleType::get(elts, ctx);
737+
}
738+
739+
return type;
740+
}
741+
729742
SolutionCompareResult ConstraintSystem::compareSolutions(
730743
ConstraintSystem &cs, ArrayRef<Solution> solutions,
731744
const SolutionDiff &diff, unsigned idx1, unsigned idx2,
@@ -1033,8 +1046,8 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10331046
++score2;
10341047

10351048
// Prefer the unlabeled form of a type.
1036-
auto unlabeled1 = type1->getUnlabeledType(cs.getASTContext());
1037-
auto unlabeled2 = type2->getUnlabeledType(cs.getASTContext());
1049+
auto unlabeled1 = getUnlabeledType(type1, cs.getASTContext());
1050+
auto unlabeled2 = getUnlabeledType(type2, cs.getASTContext());
10381051
if (unlabeled1->isEqual(unlabeled2)) {
10391052
if (type1->isEqual(unlabeled1)) {
10401053
++score1;

0 commit comments

Comments
 (0)