Skip to content

Commit 39cd2f9

Browse files
authored
Merge pull request #17127 from CodaFi/liliput
2 parents 360d1d3 + 26d2795 commit 39cd2f9

File tree

7 files changed

+64
-38
lines changed

7 files changed

+64
-38
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ class TypeMatcher {
208208

209209
auto sugaredFirstFunc = sugaredFirstType->castTo<AnyFunctionType>();
210210
if (firstFunc->getParams().size() != secondFunc->getParams().size())
211-
return mismatch(firstFunc.getInput().getPointer(), secondFunc->getInput(),
212-
sugaredFirstFunc->getInput());
211+
return mismatch(firstFunc.getPointer(), secondFunc, sugaredFirstFunc);
213212

214213
for (unsigned i = 0, n = firstFunc->getParams().size(); i != n; ++i) {
215214
const auto &firstElt = firstFunc->getParams()[i];
@@ -218,9 +217,9 @@ class TypeMatcher {
218217
if (firstElt.getLabel() != secondElt.getLabel() ||
219218
firstElt.isVariadic() != secondElt.isVariadic() ||
220219
firstElt.isInOut() != secondElt.isInOut())
221-
return mismatch(firstFunc.getInput().getPointer(),
222-
secondFunc->getInput(),
223-
sugaredFirstFunc->getInput());
220+
return mismatch(firstElt.getType().getPointer(),
221+
secondElt.getType(),
222+
sugaredFirstFunc->getParams()[i].getType());
224223

225224
// Recurse on parameter components.
226225
if (!this->visit(firstElt.getType()->getCanonicalType(),

lib/AST/Type.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,18 @@ Type TypeBase::addCurriedSelfType(const DeclContext *dc) {
409409
GenericSignature *sig = dc->getGenericSignatureOfContext();
410410
if (auto *genericFn = type->getAs<GenericFunctionType>()) {
411411
sig = genericFn->getGenericSignature();
412-
type = FunctionType::get(genericFn->getInput(),
412+
type = FunctionType::get(genericFn->getParams(),
413413
genericFn->getResult(),
414414
genericFn->getExtInfo());
415415
}
416416

417417
auto selfTy = dc->getDeclaredInterfaceType();
418+
auto selfParam = AnyFunctionType::Param(selfTy,
419+
Identifier(), ParameterTypeFlags());
418420
if (sig)
419-
return GenericFunctionType::get(sig, selfTy, type,
421+
return GenericFunctionType::get(sig, {selfParam}, type,
420422
AnyFunctionType::ExtInfo());
421-
return FunctionType::get(selfTy, type);
423+
return FunctionType::get({selfParam}, type, AnyFunctionType::ExtInfo());
422424
}
423425

424426
void
@@ -1591,9 +1593,11 @@ bool TypeBase::isBindableTo(Type b) {
15911593
if (func->getExtInfo() != substFunc->getExtInfo())
15921594
return false;
15931595

1594-
if (!visit(func->getInput()->getCanonicalType(),
1595-
substFunc->getInput()->getCanonicalType()))
1596-
return false;
1596+
for (unsigned i : indices(func->getParams())) {
1597+
if (!visit(func->getParams()[i].getType(),
1598+
substFunc.getParams()[i].getType()))
1599+
return false;
1600+
}
15971601

15981602
return visit(func->getResult()->getCanonicalType(),
15991603
substFunc->getResult()->getCanonicalType());
@@ -2323,10 +2327,23 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
23232327
return false;
23242328

23252329
auto paramsAndResultMatch = [&]() {
2326-
// Inputs are contravariant, results are covariant.
2327-
return (matches(fn2.getInput(), fn1.getInput(), matchMode,
2328-
ParameterPosition::Parameter, OptionalUnwrapping::None) &&
2329-
matches(fn1.getResult(), fn2.getResult(), matchMode,
2330+
auto fn2Params = fn2.getParams();
2331+
auto fn1Params = fn1.getParams();
2332+
if (fn2Params.size() != fn1Params.size()) {
2333+
return false;
2334+
}
2335+
2336+
// Inputs are contravariant.
2337+
for (auto i : indices(fn2.getParams())) {
2338+
if (!matches(fn2Params[i].getType(), fn1Params[i].getType(),
2339+
matchMode, ParameterPosition::ParameterTupleElement,
2340+
OptionalUnwrapping::None)) {
2341+
return false;
2342+
}
2343+
}
2344+
2345+
// Results are covariant.
2346+
return (matches(fn1.getResult(), fn2.getResult(), matchMode,
23302347
ParameterPosition::NotParameter,
23312348
OptionalUnwrapping::None));
23322349
};
@@ -2771,9 +2788,9 @@ bool AnyFunctionType::isCanonicalFunctionInputType(Type input) {
27712788

27722789
FunctionType *
27732790
GenericFunctionType::substGenericArgs(SubstitutionMap subs) {
2774-
Type input = getInput().subst(subs);
2775-
Type result = getResult().subst(subs);
2776-
return FunctionType::get(input, result, getExtInfo());
2791+
auto substFn = Type(this).subst(subs)->castTo<AnyFunctionType>();
2792+
return FunctionType::get(substFn->getParams(),
2793+
substFn->getResult(), getExtInfo());
27772794
}
27782795

27792796
static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
@@ -2931,7 +2948,7 @@ static Type substGenericFunctionType(GenericFunctionType *genericFnType,
29312948
LookupConformanceFn lookupConformances,
29322949
SubstOptions options) {
29332950
// Substitute into the function type (without generic signature).
2934-
auto *bareFnType = FunctionType::get(genericFnType->getInput(),
2951+
auto *bareFnType = FunctionType::get(genericFnType->getParams(),
29352952
genericFnType->getResult(),
29362953
genericFnType->getExtInfo());
29372954
Type result =
@@ -3013,7 +3030,7 @@ static Type substGenericFunctionType(GenericFunctionType *genericFnType,
30133030
}
30143031

30153032
// Produce the new generic function type.
3016-
return GenericFunctionType::get(genericSig, fnType->getInput(),
3033+
return GenericFunctionType::get(genericSig, fnType->getParams(),
30173034
fnType->getResult(), fnType->getExtInfo());
30183035
}
30193036

@@ -3371,7 +3388,7 @@ Type TypeBase::adjustSuperclassMemberDeclType(const ValueDecl *baseDecl,
33713388
baseDecl, derivedDecl, /*derivedSubs=*/None);
33723389

33733390
if (auto *genericMemberType = memberType->getAs<GenericFunctionType>()) {
3374-
memberType = FunctionType::get(genericMemberType->getInput(),
3391+
memberType = FunctionType::get(genericMemberType->getParams(),
33753392
genericMemberType->getResult(),
33763393
genericMemberType->getExtInfo());
33773394
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,15 +4121,16 @@ namespace {
41214121

41224122
// Update the method type with the new result type.
41234123
auto methodTy = type->castTo<FunctionType>();
4124-
type = FunctionType::get(methodTy->getInput(), resultTy,
4124+
type = FunctionType::get(methodTy->getParams(), resultTy,
41254125
methodTy->getExtInfo());
41264126
}
41274127

41284128
// Add the 'self' parameter to the function type. NB. a method's formal
41294129
// type should be (Type) -> (Args...) -> Ret, not Type -> (Args...) ->
41304130
// Ret.
4131-
auto parenSelfType = ParenType::get(Impl.SwiftContext, selfInterfaceType);
4132-
type = FunctionType::get(parenSelfType, type);
4131+
auto selfParam = AnyFunctionType::Param(selfInterfaceType,
4132+
Identifier(), ParameterTypeFlags());
4133+
type = FunctionType::get({selfParam}, type, AnyFunctionType::ExtInfo());
41334134

41344135
auto interfaceType = getGenericMethodType(dc, type->castTo<AnyFunctionType>());
41354136
result->setInterfaceType(interfaceType);
@@ -6160,8 +6161,6 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
61606161
// Add the implicit 'self' parameter patterns.
61616162
SmallVector<ParameterList *, 4> bodyParams;
61626163
auto selfMetaVar = ParamDecl::createSelf(SourceLoc(), dc, /*static*/ true);
6163-
auto selfTy = dc->getSelfInterfaceType();
6164-
auto selfMetaTy = MetatypeType::get(selfTy);
61656164
bodyParams.push_back(ParameterList::createWithoutLoc(selfMetaVar));
61666165

61676166
// Import the type that this method will have.
@@ -6189,16 +6188,24 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
61896188
}
61906189

61916190
// Rebuild the function type with the appropriate result type;
6192-
Type resultTy = selfTy;
6191+
Type resultTy = dc->getSelfInterfaceType();
61936192
if (resultIsOptional)
61946193
resultTy = OptionalType::get(resultTy);
61956194

6196-
type = FunctionType::get(oldFnType->getInput(), resultTy,
6195+
type = FunctionType::get(oldFnType->getParams(), resultTy,
61976196
oldFnType->getExtInfo());
61986197

61996198
// Add the 'self' parameter to the function types.
6200-
Type allocType = FunctionType::get(selfMetaTy, type);
6201-
Type initType = FunctionType::get(selfTy, type);
6199+
auto selfTy = dc->getSelfInterfaceType();
6200+
auto selfParam = AnyFunctionType::Param(selfTy,
6201+
Identifier(), ParameterTypeFlags());
6202+
auto selfMetaTy = MetatypeType::get(selfTy);
6203+
auto selfMetaParam = AnyFunctionType::Param(selfMetaTy, Identifier(),
6204+
ParameterTypeFlags());
6205+
Type allocType = FunctionType::get({selfMetaParam}, type,
6206+
AnyFunctionType::ExtInfo());
6207+
Type initType = FunctionType::get({selfParam}, type,
6208+
AnyFunctionType::ExtInfo());
62026209

62036210
// Look for other imported constructors that occur in this context with
62046211
// the same name.

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ namespace {
365365
if (pointeeQualType->isFunctionType()) {
366366
auto funcTy = pointeeType->castTo<FunctionType>();
367367
return {
368-
FunctionType::get(funcTy->getInput(), funcTy->getResult(),
368+
FunctionType::get(funcTy->getParams(), funcTy->getResult(),
369369
funcTy->getExtInfo().withRepresentation(
370370
AnyFunctionType::Representation::CFunctionPointer)),
371371
ImportHint::CFunctionPointer

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ static bool hasTrivialTrailingClosure(const FuncDecl *FD,
15521552
auto param = funcType->getParams().back();
15531553
if (!param.isAutoClosure()) {
15541554
if (auto Fn = param.getType()->getAs<AnyFunctionType>()) {
1555-
return Fn->getInput()->isVoid() && Fn->getResult()->isVoid();
1555+
return Fn->getParams().empty() && Fn->getResult()->isVoid();
15561556
}
15571557
}
15581558
}

lib/IRGen/GenProto.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,8 @@ void NecessaryBindings::addTypeMetadata(CanType type) {
27692769
return;
27702770
}
27712771
if (auto fn = dyn_cast<FunctionType>(type)) {
2772-
addTypeMetadata(fn.getInput());
2772+
for (const auto &elt : fn.getParams())
2773+
addTypeMetadata(elt.getType());
27732774
addTypeMetadata(fn.getResult());
27742775
return;
27752776
}

lib/SILGen/SILGenType.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ SILFunction *SILGenModule::emitProtocolWitness(
610610
auto *genericEnv = witness.getSyntheticEnvironment();
611611

612612
// The type of the witness thunk.
613-
auto input = reqtOrigTy->getInput().subst(reqtSubMap)->getCanonicalType();
614-
auto result = reqtOrigTy->getResult().subst(reqtSubMap)->getCanonicalType();
613+
auto substReqtTy =
614+
cast<AnyFunctionType>(reqtOrigTy.subst(reqtSubMap)->getCanonicalType());
615615

616616
// If there's something to map to for the witness thunk, the conformance
617617
// should be phrased in the same terms. This particularly applies to classes
@@ -632,10 +632,12 @@ SILFunction *SILGenModule::emitProtocolWitness(
632632
auto *genericSig = genericEnv->getGenericSignature();
633633
reqtSubstTy = CanGenericFunctionType::get(
634634
genericSig->getCanonicalSignature(),
635-
input, result, reqtOrigTy->getExtInfo());
635+
substReqtTy->getParams(), substReqtTy.getResult(),
636+
reqtOrigTy->getExtInfo());
636637
} else {
637-
reqtSubstTy = CanFunctionType::get(
638-
input, result, reqtOrigTy->getExtInfo());
638+
reqtSubstTy = CanFunctionType::get(substReqtTy->getParams(),
639+
substReqtTy.getResult(),
640+
reqtOrigTy->getExtInfo());
639641
}
640642

641643
// FIXME: this needs to pull out the conformances/witness-tables for any

0 commit comments

Comments
 (0)