Skip to content

Commit 27fd1bd

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 4967cd5 commit 27fd1bd

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
@@ -3438,8 +3438,7 @@ void DelayedArgument::emitDefaultArgument(SILGenFunction &SGF,
34383438
auto value = SGF.emitApplyOfDefaultArgGenerator(info.loc,
34393439
info.defaultArgsOwner,
34403440
info.destIndex,
3441-
info.resultType,
3442-
info.origResultType);
3441+
info.resultType);
34433442

34443443
SmallVector<ManagedValue, 4> loweredArgs;
34453444
SmallVector<DelayedArgument, 4> delayedArgs;

lib/SILGen/SILGenExpr.cpp

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

23412341
RValue
23422342
SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
2343-
ConcreteDeclRef defaultArgsOwner,
2344-
unsigned destIndex,
2345-
CanType resultType,
2346-
AbstractionPattern origResultType,
2347-
SGFContext C) {
2343+
ConcreteDeclRef defaultArgsOwner,
2344+
unsigned destIndex,
2345+
CanType resultType,
2346+
SGFContext C) {
23482347
SILDeclRef generator
23492348
= SILDeclRef::getDefaultArgGenerator(defaultArgsOwner.getDecl(),
23502349
destIndex);
@@ -2356,6 +2355,11 @@ SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
23562355
if (fnType->isPolymorphic())
23572356
subs = defaultArgsOwner.getSubstitutions();
23582357

2358+
auto constantInfo = SGM.Types.getConstantInfo(
2359+
TypeExpansionContext::minimal(), generator);
2360+
AbstractionPattern origResultType =
2361+
constantInfo.FormalPattern.getFunctionResultType();
2362+
23592363
auto substFnType =
23602364
fnType->substGenericArgs(SGM.M, subs, getTypeExpansionContext());
23612365

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)