Skip to content

Commit 40d691e

Browse files
committed
SILGen: Emit calls to default argument generators at the right abstraction level
Fixes rdar://problem/90717725 / https://bugs.swift.org/browse/SR-16051.
1 parent e16b83f commit 40d691e

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,8 +3436,7 @@ void DelayedArgument::emitDefaultArgument(SILGenFunction &SGF,
34363436
auto value = SGF.emitApplyOfDefaultArgGenerator(info.loc,
34373437
info.defaultArgsOwner,
34383438
info.destIndex,
3439-
info.resultType,
3440-
info.origResultType);
3439+
info.resultType);
34413440

34423441
SmallVector<ManagedValue, 4> loweredArgs;
34433442
SmallVector<DelayedArgument, 4> delayedArgs;

lib/SILGen/SILGenExpr.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,11 +2337,10 @@ RValue RValueEmitter::visitTupleElementExpr(TupleElementExpr *E,
23372337

23382338
RValue
23392339
SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
2340-
ConcreteDeclRef defaultArgsOwner,
2341-
unsigned destIndex,
2342-
CanType resultType,
2343-
AbstractionPattern origResultType,
2344-
SGFContext C) {
2340+
ConcreteDeclRef defaultArgsOwner,
2341+
unsigned destIndex,
2342+
CanType resultType,
2343+
SGFContext C) {
23452344
SILDeclRef generator
23462345
= SILDeclRef::getDefaultArgGenerator(defaultArgsOwner.getDecl(),
23472346
destIndex);
@@ -2353,6 +2352,11 @@ SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
23532352
if (fnType->isPolymorphic())
23542353
subs = defaultArgsOwner.getSubstitutions();
23552354

2355+
auto constantInfo = SGM.Types.getConstantInfo(
2356+
TypeExpansionContext::minimal(), generator);
2357+
AbstractionPattern origResultType =
2358+
constantInfo.FormalPattern.getFunctionResultType();
2359+
23562360
auto substFnType =
23572361
fnType->substGenericArgs(SGM.M, subs, getTypeExpansionContext());
23582362

lib/SILGen/SILGenFunction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
16781678
ConcreteDeclRef defaultArgsOwner,
16791679
unsigned destIndex,
16801680
CanType resultType,
1681-
AbstractionPattern origResultType,
16821681
SGFContext C = SGFContext());
16831682

16841683
RValue emitApplyOfStoredPropertyInitializer(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen %s
2+
3+
func calleeWithEmptyTuple<A>(_: A = ()) {}
4+
func calleeWithLoadable<A>(_: A = 3) {}
5+
func calleeWithAddressOnly<A>(_: A = (3 as Any)) {}
6+
func calleeWithTupleOfLoadable<A>(_: A = (3, 4)) {}
7+
func calleeWithTupleOfAddressOnly<A>(_: A = (3 as Any, 4 as Any)) {}
8+
func calleeWithTupleOfMixed<A>(_: A = (3, 4 as Any)) {}
9+
10+
func testConcreteDefaultArguments() {
11+
calleeWithEmptyTuple()
12+
calleeWithLoadable()
13+
calleeWithAddressOnly()
14+
calleeWithTupleOfLoadable()
15+
calleeWithTupleOfAddressOnly()
16+
calleeWithTupleOfMixed()
17+
}

0 commit comments

Comments
 (0)