Skip to content

Commit 31b97bc

Browse files
committed
Revert "SILGen: Move even more abstraction patterns over to interface types, NFC"
This reverts commit 0188258 because we now assert when compiling a performance test.
1 parent f9caa46 commit 31b97bc

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class Callee {
159159
};
160160
SILValue SelfValue;
161161
ArrayRef<Substitution> Substitutions;
162+
CanType OrigFormalOldType;
162163
CanType OrigFormalInterfaceType;
163164
CanAnyFunctionType SubstFormalType;
164165
Optional<SILLocation> SpecializeLoc;
@@ -176,11 +177,18 @@ class Callee {
176177
SILLocation L)
177178
: kind(Kind::IndirectValue),
178179
IndirectValue(indirectValue),
180+
OrigFormalOldType(origFormalType),
179181
OrigFormalInterfaceType(origFormalType),
180182
SubstFormalType(substFormalType),
181183
Loc(L)
182184
{}
183185

186+
static CanAnyFunctionType getConstantFormalType(SILGenFunction &gen,
187+
SILDeclRef fn)
188+
SIL_FUNCTION_TYPE_DEPRECATED {
189+
return gen.SGM.Types.getConstantInfo(fn.atUncurryLevel(0)).FormalType;
190+
}
191+
184192
static CanAnyFunctionType getConstantFormalInterfaceType(SILGenFunction &gen,
185193
SILDeclRef fn) {
186194
return gen.SGM.Types.getConstantInfo(fn.atUncurryLevel(0))
@@ -191,6 +199,7 @@ class Callee {
191199
CanAnyFunctionType substFormalType,
192200
SILLocation l)
193201
: kind(Kind::StandaloneFunction), Constant(standaloneFunction),
202+
OrigFormalOldType(getConstantFormalType(gen, standaloneFunction)),
194203
OrigFormalInterfaceType(getConstantFormalInterfaceType(gen,
195204
standaloneFunction)),
196205
SubstFormalType(substFormalType),
@@ -205,6 +214,7 @@ class Callee {
205214
CanAnyFunctionType substFormalType,
206215
SILLocation l)
207216
: kind(methodKind), Constant(methodName), SelfValue(selfValue),
217+
OrigFormalOldType(getConstantFormalType(gen, methodName)),
208218
OrigFormalInterfaceType(getConstantFormalInterfaceType(gen, methodName)),
209219
SubstFormalType(substFormalType),
210220
Loc(l)
@@ -237,18 +247,11 @@ class Callee {
237247
return CanType(TupleType::get(field, ctx));
238248
}
239249

250+
// These first two asserts will crash before they return if
251+
// they're actually wrong.
252+
assert(getArchetypeForSelf(origParamType));
253+
assert(getArchetypeForSelf(selfType));
240254
assert(isa<MetatypeType>(origParamType) == isa<MetatypeType>(selfType));
241-
242-
if (auto mt = dyn_cast<MetatypeType>(origParamType))
243-
assert(mt.getInstanceType()->isTypeParameter());
244-
else
245-
assert(origParamType->isTypeParameter());
246-
247-
if (auto mt = dyn_cast<MetatypeType>(selfType))
248-
assert(isa<ArchetypeType>(mt.getInstanceType()));
249-
else
250-
assert(isa<ArchetypeType>(selfType));
251-
252255
return selfType;
253256
}
254257

@@ -287,13 +290,13 @@ class Callee {
287290

288291
// Add the 'self' parameter back. We want it to look like a
289292
// substitution of the appropriate clause from the original type.
290-
auto origFormalType = cast<AnyFunctionType>(OrigFormalInterfaceType);
293+
auto polyFormalType = cast<PolymorphicFunctionType>(OrigFormalOldType);
291294
auto substSelfType =
292-
buildSubstSelfType(origFormalType.getInput(), protocolSelfType, ctx);
295+
buildSubstSelfType(polyFormalType.getInput(), protocolSelfType, ctx);
293296

294297
auto extInfo = FunctionType::ExtInfo(FunctionType::Representation::Thin,
295298
/*noreturn*/ false,
296-
/*throws*/ origFormalType->throws());
299+
/*throws*/ polyFormalType->throws());
297300

298301
SubstFormalType = CanFunctionType::get(substSelfType, SubstFormalType,
299302
extInfo);
@@ -305,18 +308,17 @@ class Callee {
305308
assert(kind == Kind::DynamicMethod);
306309

307310
// Drop the original self clause.
308-
CanType methodType = OrigFormalInterfaceType;
311+
CanType methodType = OrigFormalOldType;
309312
methodType = cast<AnyFunctionType>(methodType).getResult();
310313

311314
// Replace it with the dynamic self type.
312-
OrigFormalInterfaceType
315+
OrigFormalOldType = OrigFormalInterfaceType
313316
= getDynamicMethodFormalType(SGM, SelfValue,
314317
Constant.getDecl(),
315318
Constant, methodType);
316-
assert(!OrigFormalInterfaceType->hasTypeParameter());
317319

318320
// Add a self clause to the substituted type.
319-
auto origFormalType = cast<AnyFunctionType>(OrigFormalInterfaceType);
321+
auto origFormalType = cast<AnyFunctionType>(OrigFormalOldType);
320322
auto selfType = origFormalType.getInput();
321323
SubstFormalType
322324
= CanFunctionType::get(selfType, SubstFormalType,
@@ -415,7 +417,7 @@ class Callee {
415417
}
416418

417419
CanType getOrigFormalType() const {
418-
return OrigFormalInterfaceType;
420+
return OrigFormalOldType;
419421
}
420422

421423
CanAnyFunctionType getSubstFormalType() const {
@@ -3646,11 +3648,11 @@ SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
36463648
ArrayRef<ManagedValue> args,
36473649
SGFContext ctx) {
36483650
auto origFormalType =
3649-
cast<AnyFunctionType>(fn->getInterfaceType()->getCanonicalType());
3651+
cast<AnyFunctionType>(fn->getType()->getCanonicalType());
36503652
auto substFormalType = origFormalType;
36513653
if (!subs.empty()) {
3652-
auto genericFnType = cast<GenericFunctionType>(substFormalType);
3653-
auto applied = genericFnType->substGenericArgs(SGM.SwiftModule, subs);
3654+
auto polyFnType = cast<PolymorphicFunctionType>(substFormalType);
3655+
auto applied = polyFnType->substGenericArgs(SGM.SwiftModule, subs);
36543656
substFormalType = cast<FunctionType>(applied->getCanonicalType());
36553657
}
36563658

@@ -3669,7 +3671,7 @@ SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
36693671
== SILFunctionLanguage::Swift);
36703672

36713673
return emitApply(loc, mv, subs, args, substFnType,
3672-
AbstractionPattern(origFormalType).getFunctionResultType(),
3674+
AbstractionPattern(origFormalType.getResult()),
36733675
substFormalType.getResult(),
36743676
options, None, None, ctx);
36753677
}
@@ -3805,10 +3807,10 @@ emitSpecializedAccessorFunctionRef(SILGenFunction &gen,
38053807
SILConstantInfo constantInfo = gen.getConstantInfo(constant);
38063808

38073809
// Apply substitutions to the callee type.
3808-
CanAnyFunctionType substAccessorType = constantInfo.FormalInterfaceType;
3810+
CanAnyFunctionType substAccessorType = constantInfo.FormalType;
38093811
if (!substitutions.empty()) {
3810-
auto genericFn = cast<GenericFunctionType>(substAccessorType);
3811-
auto substFn = genericFn->substGenericArgs(gen.SGM.SwiftModule, substitutions);
3812+
auto polyFn = cast<PolymorphicFunctionType>(substAccessorType);
3813+
auto substFn = polyFn->substGenericArgs(gen.SGM.SwiftModule, substitutions);
38123814
substAccessorType = cast<FunctionType>(substFn->getCanonicalType());
38133815
}
38143816

lib/SILGen/SILGenConvert.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,18 @@ getOptionalSomeValue(SILLocation loc, ManagedValue value,
149149
return emitManagedRValueWithCleanup(result, optTL);
150150
}
151151

152-
static Substitution getSimpleSubstitution(GenericSignature *genericSig,
152+
static Substitution getSimpleSubstitution(GenericParamList &generics,
153153
CanType typeArg) {
154-
assert(genericSig->getGenericParams().size() == 1);
154+
assert(generics.getParams().size() == 1);
155155
return Substitution{typeArg, {}};
156156
}
157157

158158
/// Create the correct substitution for calling the given function at
159159
/// the given type.
160160
static Substitution getSimpleSubstitution(FuncDecl *fn, CanType typeArg) {
161-
auto genericFnType =
162-
cast<GenericFunctionType>(fn->getInterfaceType()->getCanonicalType());
163-
return getSimpleSubstitution(genericFnType->getGenericSignature(), typeArg);
161+
auto polyFnType =
162+
cast<PolymorphicFunctionType>(fn->getType()->getCanonicalType());
163+
return getSimpleSubstitution(polyFnType->getGenericParams(), typeArg);
164164
}
165165

166166
static CanType getOptionalValueType(SILType optType,

lib/SILGen/SILGenExpr.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,13 @@ emitRValueForDecl(SILLocation loc, ConcreteDeclRef declRef, Type ncRefType,
442442

443443
// Get the lowered AST types:
444444
// - the original type
445-
auto origLoweredFormalType =
446-
AbstractionPattern(constantInfo.LoweredInterfaceType);
445+
auto origLoweredFormalType = AbstractionPattern(constantInfo.LoweredType);
447446
if (hasLocalCaptures) {
448447
auto formalTypeWithoutCaptures =
449-
cast<AnyFunctionType>(constantInfo.FormalInterfaceType.getResult());
448+
cast<AnyFunctionType>(constantInfo.FormalType.getResult());
450449
origLoweredFormalType =
451450
AbstractionPattern(
452-
SGM.Types.getLoweredASTFunctionType(formalTypeWithoutCaptures, 0,
451+
SGM.Types.getLoweredASTFunctionType(formalTypeWithoutCaptures,0,
453452
silDeclRef));
454453
}
455454

0 commit comments

Comments
 (0)