Skip to content

Commit da4af64

Browse files
committed
SIL: Rip out constantInfo.{FormalType,LoweredType}, NFC
1 parent 96c6c2e commit da4af64

File tree

3 files changed

+11
-257
lines changed

3 files changed

+11
-257
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,9 @@ struct SILConstantInfo {
366366
/// The formal type of the constant, still curried. For a normal
367367
/// function, this is just its declared type; for a getter or
368368
/// setter, computing this can be more involved.
369-
CanAnyFunctionType FormalType SIL_FUNCTION_TYPE_DEPRECATED;
370369
CanAnyFunctionType FormalInterfaceType;
371370

372371
/// The uncurried and bridged type of the constant.
373-
CanAnyFunctionType LoweredType SIL_FUNCTION_TYPE_DEPRECATED;
374372
CanAnyFunctionType LoweredInterfaceType;
375373

376374
/// The SIL function type of the constant.
@@ -397,9 +395,7 @@ struct SILConstantInfo {
397395
}
398396

399397
friend bool operator==(SILConstantInfo lhs, SILConstantInfo rhs) {
400-
return lhs.FormalType == rhs.FormalType &&
401-
lhs.FormalInterfaceType == rhs.FormalInterfaceType &&
402-
lhs.LoweredType == rhs.LoweredType &&
398+
return lhs.FormalInterfaceType == rhs.FormalInterfaceType &&
403399
lhs.LoweredInterfaceType == rhs.LoweredInterfaceType &&
404400
lhs.SILFnType == rhs.SILFnType &&
405401
lhs.ContextGenericParams == rhs.ContextGenericParams &&
@@ -541,7 +537,6 @@ class TypeConverter {
541537
/// The current generic context signature.
542538
CanGenericSignature CurGenericContext;
543539

544-
CanAnyFunctionType makeConstantType(SILDeclRef constant);
545540
CanAnyFunctionType makeConstantInterfaceType(SILDeclRef constant);
546541

547542
/// Get the context parameters for a constant. Returns a pair of the innermost
@@ -714,8 +709,6 @@ class TypeConverter {
714709
}
715710

716711
/// Get a function type curried with its capture context.
717-
CanAnyFunctionType getFunctionTypeWithCaptures(CanAnyFunctionType funcType,
718-
AnyFunctionRef closure);
719712
CanAnyFunctionType getFunctionInterfaceTypeWithCaptures(
720713
CanAnyFunctionType funcType,
721714
AnyFunctionRef closure);

lib/SIL/SILFunctionType.cpp

Lines changed: 10 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,20 +1477,16 @@ SILConstantInfo TypeConverter::getConstantInfo(SILDeclRef constant) {
14771477

14781478
// First, get a function type for the constant. This creates the
14791479
// right type for a getter or setter.
1480-
auto formalType = makeConstantType(constant);
14811480
auto formalInterfaceType = makeConstantInterfaceType(constant);
14821481
GenericParamList *contextGenerics, *innerGenerics;
14831482
std::tie(contextGenerics, innerGenerics)
14841483
= getConstantContextGenericParams(constant);
14851484

14861485
// The formal type is just that with the right representation.
14871486
auto rep = getDeclRefRepresentation(constant);
1488-
formalType = adjustFunctionType(formalType, rep);
14891487
formalInterfaceType = adjustFunctionType(formalInterfaceType, rep);
14901488
// The lowered type is the formal type, but uncurried and with
14911489
// parameters automatically turned into their bridged equivalents.
1492-
auto loweredType =
1493-
getLoweredASTFunctionType(formalType, constant.uncurryLevel, constant);
14941490
auto loweredInterfaceType =
14951491
getLoweredASTFunctionType(formalInterfaceType, constant.uncurryLevel,
14961492
constant);
@@ -1503,16 +1499,16 @@ SILConstantInfo TypeConverter::getConstantInfo(SILDeclRef constant) {
15031499
DEBUG(llvm::dbgs() << "lowering type for constant ";
15041500
constant.print(llvm::dbgs());
15051501
llvm::dbgs() << "\n formal type: ";
1506-
formalType.print(llvm::dbgs());
1502+
formalInterfaceType.print(llvm::dbgs());
15071503
llvm::dbgs() << "\n lowered AST type: ";
1508-
loweredType.print(llvm::dbgs());
1504+
loweredInterfaceType.print(llvm::dbgs());
15091505
llvm::dbgs() << "\n SIL type: ";
15101506
silFnType.print(llvm::dbgs());
15111507
llvm::dbgs() << "\n");
15121508

15131509
SILConstantInfo result = {
1514-
formalType, formalInterfaceType,
1515-
loweredType, loweredInterfaceType,
1510+
formalInterfaceType,
1511+
loweredInterfaceType,
15161512
silFnType,
15171513
contextGenerics,
15181514
innerGenerics,
@@ -1749,28 +1745,6 @@ TypeConverter::substFunctionType(CanSILFunctionType origFnType,
17491745
Context);
17501746
}
17511747

1752-
// This is a hack until we eliminate contextual type usage from ConstantInfo,
1753-
// or add support for GenericFunctionType to mapTypeIntoContext().
1754-
static AnyFunctionType *mapFuncTypeIntoContext(Module *M,
1755-
GenericParamList *genericParams,
1756-
Type type) {
1757-
auto fnTy = type->castTo<AnyFunctionType>();
1758-
if (!genericParams)
1759-
return fnTy;
1760-
1761-
auto inputTy = ArchetypeBuilder::mapTypeIntoContext(M, genericParams,
1762-
fnTy->getInput());
1763-
auto resultTy = ArchetypeBuilder::mapTypeIntoContext(M, genericParams,
1764-
fnTy->getResult());
1765-
1766-
// Introduce a generic signature
1767-
if (fnTy->is<GenericFunctionType>())
1768-
return PolymorphicFunctionType::get(inputTy, resultTy, genericParams,
1769-
fnTy->getExtInfo());
1770-
else
1771-
return FunctionType::get(inputTy, resultTy, fnTy->getExtInfo());
1772-
}
1773-
17741748
/// Returns the ConstantInfo corresponding to the VTable thunk for overriding.
17751749
/// Will be the same as getConstantInfo if the declaration does not override.
17761750
SILConstantInfo TypeConverter::getConstantOverrideInfo(SILDeclRef derived,
@@ -1829,14 +1803,7 @@ SILConstantInfo TypeConverter::getConstantOverrideInfo(SILDeclRef derived,
18291803
base.uncurryLevel + 1);
18301804
}
18311805

1832-
auto overrideFormalTy = mapFuncTypeIntoContext(M.getSwiftModule(),
1833-
derivedInfo.ContextGenericParams,
1834-
overrideInterfaceTy);
1835-
1836-
// Lower the formal AST types.
1837-
auto overrideLoweredTy = getLoweredASTFunctionType(
1838-
cast<AnyFunctionType>(overrideFormalTy->getCanonicalType()),
1839-
derived.uncurryLevel, derived);
1806+
// Lower the formal AST type.
18401807
auto overrideLoweredInterfaceTy = getLoweredASTFunctionType(
18411808
cast<AnyFunctionType>(overrideInterfaceTy->getCanonicalType()),
18421809
derived.uncurryLevel, derived);
@@ -1860,7 +1827,6 @@ SILConstantInfo TypeConverter::getConstantOverrideInfo(SILDeclRef derived,
18601827

18611828
// Build the SILConstantInfo and cache it.
18621829
SILConstantInfo overrideInfo;
1863-
overrideInfo.LoweredType = overrideLoweredTy;
18641830
overrideInfo.LoweredInterfaceType = overrideLoweredInterfaceTy;
18651831
overrideInfo.SILFnType = fnTy;
18661832
overrideInfo.ContextGenericParams = derivedInfo.ContextGenericParams;
@@ -2037,29 +2003,17 @@ TypeConverter::getBridgedFunctionType(AbstractionPattern pattern,
20372003
genericSig = gft.getGenericSignature();
20382004
}
20392005

2040-
// Pull the innermost generic parameter list in the type out.
2041-
Optional<GenericParamList *> genericParams;
2006+
// Remove this when PolymorphicFunctionType goes away.
20422007
{
20432008
CanAnyFunctionType innerTy = t;
20442009
while (innerTy) {
2045-
if (auto pft = dyn_cast<PolymorphicFunctionType>(innerTy)) {
2046-
assert(!genericParams
2047-
|| pft->getGenericParams().getOuterParameters() == *genericParams);
2048-
genericParams = &pft->getGenericParams();
2049-
}
2010+
assert(!isa<PolymorphicFunctionType>(innerTy));
20502011
innerTy = dyn_cast<AnyFunctionType>(innerTy.getResult());
20512012
}
20522013
}
2053-
GenericParamList *innerGenericParams
2054-
= genericParams ? *genericParams : nullptr;
20552014

20562015
auto rebuild = [&](CanType input, CanType result) -> CanAnyFunctionType {
2057-
if (genericParams) {
2058-
assert(!genericSig && "got mix of poly/generic function type?!");
2059-
return CanPolymorphicFunctionType::get(input, result,
2060-
innerGenericParams,
2061-
extInfo);
2062-
} else if (genericSig) {
2016+
if (genericSig) {
20632017
return CanGenericFunctionType::get(genericSig, input, result, extInfo);
20642018
} else {
20652019
return CanFunctionType::get(input, result, extInfo);
@@ -2072,7 +2026,7 @@ TypeConverter::getBridgedFunctionType(AbstractionPattern pattern,
20722026
case SILFunctionTypeRepresentation::Method:
20732027
case SILFunctionTypeRepresentation::WitnessMethod:
20742028
// No bridging needed for native functions.
2075-
if (t->getExtInfo() == extInfo && !innerGenericParams)
2029+
if (t->getExtInfo() == extInfo)
20762030
return t;
20772031
return rebuild(t.getInput(), t.getResult());
20782032

@@ -2190,19 +2144,11 @@ TypeConverter::getLoweredASTFunctionType(CanAnyFunctionType fnType,
21902144
// The uncurried input types.
21912145
SmallVector<TupleTypeElt, 4> inputs;
21922146

2193-
// The innermost generic parameter list.
2194-
// FIXME: Interface types make this unnecessary.
2195-
Optional<GenericParamList *> genericParams;
2196-
21972147
// Merge inputs and generic parameters from the uncurry levels.
21982148
for (;;) {
21992149
inputs.push_back(TupleTypeElt(fnType->getInput()));
22002150

2201-
if (auto pft = dyn_cast<PolymorphicFunctionType>(fnType)) {
2202-
assert(!genericParams
2203-
|| pft->getGenericParams().getOuterParameters() == *genericParams);
2204-
genericParams = &pft->getGenericParams();
2205-
}
2151+
assert(!isa<PolymorphicFunctionType>(fnType));
22062152

22072153
// The uncurried function calls all of the intermediate function
22082154
// levels and so throws if any of them do.
@@ -2263,18 +2209,9 @@ TypeConverter::getLoweredASTFunctionType(CanAnyFunctionType fnType,
22632209

22642210
// Create the new function type.
22652211
CanType inputType = CanType(TupleType::get(inputs, Context));
2266-
GenericParamList *innerGenericParams
2267-
= genericParams ? *genericParams : nullptr;
22682212
if (genericSig) {
2269-
assert(!innerGenericParams && "got mix of Polymorphic/Generic FunctionType?!");
22702213
return CanGenericFunctionType::get(genericSig,
22712214
inputType, resultType, extInfo);
2272-
}
2273-
2274-
if (innerGenericParams) {
2275-
return CanPolymorphicFunctionType::get(inputType, resultType,
2276-
innerGenericParams,
2277-
extInfo);
22782215
} else {
22792216
return CanFunctionType::get(inputType, resultType, extInfo);
22802217
}

0 commit comments

Comments
 (0)