Skip to content

Commit 4aa7516

Browse files
committed
SILGen: Remove curry thunks
Now that CSApply transforms partial applications into closures, we never see AST with partially-applied method calls. So all the machinery for emitting curry thunks is now gone.
1 parent 65980bd commit 4aa7516

File tree

5 files changed

+21
-296
lines changed

5 files changed

+21
-296
lines changed

lib/SILGen/SILGen.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
245245
/// Emits default argument generators for the given parameter list.
246246
void emitDefaultArgGenerators(SILDeclRef::Loc decl,
247247
ParameterList *paramList);
248-
249-
/// Emits the curry thunk between two uncurry levels of a function.
250-
void emitCurryThunk(SILDeclRef thunk);
251248

252249
/// Emits a thunk from a foreign function to the native Swift convention.
253250
void emitForeignToNativeThunk(SILDeclRef thunk);

lib/SILGen/SILGenApply.cpp

Lines changed: 19 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -556,43 +556,12 @@ class Callee {
556556
return result;
557557
}
558558

559-
SILDeclRef getCurriedConstant(bool isCurried) const {
560-
if (isCurried) {
561-
auto constant = Constant.asCurried();
562-
563-
// If we're currying a direct reference to a class-dispatched method,
564-
// make sure we emit the right set of thunks.
565-
if (kind == Kind::StandaloneFunction) {
566-
if (auto func = Constant.getAbstractFunctionDecl()) {
567-
if (getMethodDispatch(func) == MethodDispatch::Class) {
568-
return constant.asDirectReference(true);
569-
}
570-
}
571-
}
572-
573-
return constant;
574-
}
575-
576-
return Constant;
577-
}
578-
579-
ManagedValue getFnValue(SILGenFunction &SGF, bool isCurried,
559+
ManagedValue getFnValue(SILGenFunction &SGF,
580560
Optional<ManagedValue> borrowedSelf) const & {
581561
Optional<SILDeclRef> constant = None;
582562

583-
if (!Constant) {
584-
assert(!isCurried && "can't curry indirect function");
585-
} else {
586-
constant = getCurriedConstant(isCurried);
587-
588-
// If the call is curried, emit a direct call to the curry thunk.
589-
if (constant->isCurried) {
590-
auto constantInfo =
591-
SGF.getConstantInfo(SGF.getTypeExpansionContext(), *constant);
592-
SILValue ref = SGF.emitGlobalFunctionRef(Loc, *constant, constantInfo);
593-
return ManagedValue::forUnmanaged(ref);
594-
}
595-
}
563+
if (Constant)
564+
constant = Constant;
596565

597566
switch (kind) {
598567
case Kind::IndirectValue:
@@ -692,21 +661,11 @@ class Callee {
692661
llvm_unreachable("unhandled kind");
693662
}
694663

695-
CalleeTypeInfo getTypeInfo(SILGenFunction &SGF, bool isCurried) const & {
664+
CalleeTypeInfo getTypeInfo(SILGenFunction &SGF) const & {
696665
Optional<SILDeclRef> constant = None;
697666

698-
if (!Constant) {
699-
assert(!isCurried && "can't curry indirect function");
700-
} else {
701-
constant = getCurriedConstant(isCurried);
702-
703-
// If the call is curried, emit a direct call to the curry thunk.
704-
if (constant->isCurried) {
705-
auto constantInfo =
706-
SGF.getConstantInfo(SGF.getTypeExpansionContext(), *constant);
707-
return createCalleeTypeInfo(SGF, constant, constantInfo.getSILType());
708-
}
709-
}
667+
if (Constant)
668+
constant = Constant;
710669

711670
switch (kind) {
712671
case Kind::IndirectValue:
@@ -3579,14 +3538,7 @@ class CallEmission {
35793538

35803539
/// Is this a fully-applied enum element constructor call?
35813540
bool isEnumElementConstructor() {
3582-
return (callee.kind == Callee::Kind::EnumElement &&
3583-
uncurriedSites.size() == expectedSiteCount);
3584-
}
3585-
3586-
/// True if this is a completely unapplied super method call
3587-
bool isPartiallyAppliedSuperMethod() {
3588-
return (callee.kind == Callee::Kind::SuperMethod &&
3589-
uncurriedSites.size() == 1);
3541+
return (callee.kind == Callee::Kind::EnumElement);
35903542
}
35913543

35923544
CleanupHandle applyCoroutine(SmallVectorImpl<ManagedValue> &yields);
@@ -3684,8 +3636,6 @@ class CallEmission {
36843636
FirstLevelApplicationResult
36853637
applySpecializedEmitter(SpecializedEmitter &specializedEmitter, SGFContext C);
36863638

3687-
FirstLevelApplicationResult applyPartiallyAppliedSuperMethod(SGFContext C);
3688-
36893639
FirstLevelApplicationResult applyEnumElementConstructor(SGFContext C);
36903640

36913641
FirstLevelApplicationResult applyNormalCall(SGFContext C);
@@ -3743,10 +3693,8 @@ CallEmission::applyCoroutine(SmallVectorImpl<ManagedValue> &yields) {
37433693
auto origFormalType = callee.getOrigFormalType();
37443694
CanFunctionType formalType = callee.getSubstFormalType();
37453695

3746-
const bool isCurried = false;
3747-
37483696
// Get the callee type information.
3749-
auto calleeTypeInfo = callee.getTypeInfo(SGF, isCurried);
3697+
auto calleeTypeInfo = callee.getTypeInfo(SGF);
37503698

37513699
SmallVector<ManagedValue, 4> uncurriedArgs;
37523700
Optional<SILLocation> uncurriedLoc;
@@ -3764,7 +3712,7 @@ CallEmission::applyCoroutine(SmallVectorImpl<ManagedValue> &yields) {
37643712
borrowedSelf = uncurriedArgs.back();
37653713
}
37663714

3767-
auto fnValue = callee.getFnValue(SGF, isCurried, borrowedSelf);
3715+
auto fnValue = callee.getFnValue(SGF, borrowedSelf);
37683716

37693717
return SGF.emitBeginApply(uncurriedLoc.getValue(), fnValue,
37703718
callee.getSubstitutions(), uncurriedArgs,
@@ -3813,15 +3761,11 @@ SILGenFunction::emitBeginApply(SILLocation loc, ManagedValue fn,
38133761

38143762
CallEmission::FirstLevelApplicationResult
38153763
CallEmission::applyFirstLevelCallee(SGFContext C) {
3816-
// Check for a specialized emitter.
3817-
if (uncurriedSites.size() == expectedSiteCount) {
3818-
if (auto emitter = callee.getSpecializedEmitter(SGF.SGM)) {
3819-
return applySpecializedEmitter(emitter.getValue(), C);
3820-
}
3821-
}
3764+
assert(uncurriedSites.size() == expectedSiteCount);
38223765

3823-
if (isPartiallyAppliedSuperMethod()) {
3824-
return applyPartiallyAppliedSuperMethod(C);
3766+
// Check for a specialized emitter.
3767+
if (auto emitter = callee.getSpecializedEmitter(SGF.SGM)) {
3768+
return applySpecializedEmitter(emitter.getValue(), C);
38253769
}
38263770

38273771
if (isEnumElementConstructor()) {
@@ -3843,9 +3787,10 @@ CallEmission::applyNormalCall(SGFContext C) {
38433787
auto origFormalType = callee.getOrigFormalType();
38443788

38453789
bool isCurried = (uncurriedSites.size() < callee.getParameterListCount());
3790+
assert(!isCurried);
38463791

38473792
// Get the callee type information.
3848-
auto calleeTypeInfo = callee.getTypeInfo(SGF, isCurried);
3793+
auto calleeTypeInfo = callee.getTypeInfo(SGF);
38493794

38503795
// In C language modes, substitute the type of the AbstractionPattern
38513796
// so that we won't see type parameters down when we try to form bridging
@@ -3887,7 +3832,7 @@ CallEmission::applyNormalCall(SGFContext C) {
38873832
borrowedSelf = uncurriedArgs.back();
38883833
}
38893834

3890-
auto mv = callee.getFnValue(SGF, isCurried, borrowedSelf);
3835+
auto mv = callee.getFnValue(SGF, borrowedSelf);
38913836

38923837
// Emit the uncurried call.
38933838
firstLevelResult.value = SGF.emitApply(
@@ -3971,67 +3916,6 @@ CallEmission::applyEnumElementConstructor(SGFContext C) {
39713916
return firstLevelResult;
39723917
}
39733918

3974-
CallEmission::FirstLevelApplicationResult
3975-
CallEmission::applyPartiallyAppliedSuperMethod(SGFContext C) {
3976-
FirstLevelApplicationResult firstLevelResult;
3977-
3978-
// We want to emit the arguments as fully-substituted values
3979-
// because that's what the partially applied super method expects;
3980-
firstLevelResult.formalType = callee.getSubstFormalType();
3981-
auto origFormalType = AbstractionPattern(firstLevelResult.formalType);
3982-
auto substFnType = SGF.getSILFunctionType(
3983-
SGF.getTypeExpansionContext(), origFormalType, firstLevelResult.formalType);
3984-
3985-
// Emit the arguments.
3986-
SmallVector<ManagedValue, 4> uncurriedArgs;
3987-
Optional<SILLocation> uncurriedLoc;
3988-
CanFunctionType formalApplyType;
3989-
ApplyOptions options = emitArgumentsForNormalApply(
3990-
firstLevelResult.formalType, origFormalType, substFnType,
3991-
Optional<ForeignErrorConvention>(), firstLevelResult.foreignSelf,
3992-
uncurriedArgs, uncurriedLoc, formalApplyType);
3993-
(void)options;
3994-
3995-
// Emit the uncurried call.
3996-
assert(uncurriedArgs.size() == 1 && "Can only partially apply the "
3997-
"self parameter of a super "
3998-
"method call");
3999-
4000-
auto constant = callee.getMethodName();
4001-
auto loc = uncurriedLoc.getValue();
4002-
auto subs = callee.getSubstitutions();
4003-
auto upcastedSelf = uncurriedArgs.back();
4004-
4005-
// Make sure that upcasted self is at +1 since we are going to place it into a
4006-
// partial_apply.
4007-
upcastedSelf = upcastedSelf.ensurePlusOne(SGF, loc);
4008-
4009-
auto constantInfo =
4010-
SGF.getConstantInfo(SGF.getTypeExpansionContext(), callee.getMethodName());
4011-
auto functionTy = constantInfo.getSILType();
4012-
ManagedValue superMethod;
4013-
{
4014-
ArgumentScope S(SGF, loc);
4015-
ManagedValue castValue =
4016-
borrowedCastToOriginalSelfType(SGF, loc, upcastedSelf);
4017-
if (!constant.isForeign) {
4018-
superMethod = SGF.B.createSuperMethod(loc, castValue, constant,
4019-
functionTy);
4020-
} else {
4021-
superMethod = SGF.B.createObjCSuperMethod(loc, castValue, constant,
4022-
functionTy);
4023-
}
4024-
S.pop();
4025-
}
4026-
auto calleeConvention = ParameterConvention::Direct_Guaranteed;
4027-
4028-
ManagedValue pa = SGF.B.createPartialApply(loc, superMethod,
4029-
subs, {upcastedSelf},
4030-
calleeConvention);
4031-
firstLevelResult.value = RValue(SGF, loc, formalApplyType.getResult(), pa);
4032-
return firstLevelResult;
4033-
}
4034-
40353919
CallEmission::FirstLevelApplicationResult
40363920
CallEmission::applySpecializedEmitter(SpecializedEmitter &specializedEmitter,
40373921
SGFContext C) {
@@ -4086,7 +3970,7 @@ CallEmission::applySpecializedEmitter(SpecializedEmitter &specializedEmitter,
40863970
// result plan/arg scope before we prepare arguments.
40873971
if (!specializedEmitter.isLateEmitter() &&
40883972
substConv.hasIndirectSILResults()) {
4089-
calleeTypeInfo.emplace(callee.getTypeInfo(SGF, false /*isCurried*/));
3973+
calleeTypeInfo.emplace(callee.getTypeInfo(SGF));
40903974

40913975
calleeTypeInfo->origResultType = origFormalType.getFunctionResultType();
40923976
calleeTypeInfo->substResultType = callee.getSubstFormalType().getResult();
@@ -4849,13 +4733,12 @@ SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
48494733
auto origFormalType = callee.getOrigFormalType();
48504734
auto substFormalType = callee.getSubstFormalType();
48514735

4852-
auto calleeTypeInfo = callee.getTypeInfo(*this, /*isCurried=*/false);
4736+
auto calleeTypeInfo = callee.getTypeInfo(*this);
48534737

48544738
Optional<ManagedValue> borrowedSelf;
48554739
if (callee.requiresSelfValueForDispatch())
48564740
borrowedSelf = args.back();
4857-
auto mv = callee.getFnValue(*this, /*isCurried=*/false,
4858-
borrowedSelf);
4741+
auto mv = callee.getFnValue(*this, borrowedSelf);
48594742

48604743
assert(!calleeTypeInfo.foreignError);
48614744
assert(!calleeTypeInfo.foreignSelf.isImportAsMember());

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,7 @@ emitRValueForDecl(SILLocation loc, ConcreteDeclRef declRef, Type ncRefType,
907907
// If the referenced decl isn't a VarDecl, it should be a constant of some
908908
// sort.
909909
SILDeclRef silDeclRef(decl);
910-
if (silDeclRef.getParameterListCount() == 2) {
911-
// Unqualified reference to an instance method from a static context,
912-
// without applying 'self'.
913-
silDeclRef = silDeclRef.asCurried();
914-
}
915-
910+
assert(silDeclRef.getParameterListCount() == 1);
916911
ManagedValue result = emitClosureValue(loc, silDeclRef, refType,
917912
declRef.getSubstitutions());
918913
return RValue(*this, loc, refType, result);

lib/SILGen/SILGenFunction.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
652652
void emitClassMemberDestruction(ManagedValue selfValue, ClassDecl *cd,
653653
CleanupLocation cleanupLoc);
654654

655-
/// Generates code for a curry thunk from one uncurry level
656-
/// of a function to another.
657-
void emitCurryThunk(SILDeclRef thunk);
658655
/// Generates a thunk from a foreign function to the native Swift convention.
659656
void emitForeignToNativeThunk(SILDeclRef thunk);
660657
/// Generates a thunk from a native function to the conventions.

0 commit comments

Comments
 (0)