Skip to content

SILGen: Emit calls to default argument generators at the right abstraction level [5.7] #59219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3436,8 +3436,7 @@ void DelayedArgument::emitDefaultArgument(SILGenFunction &SGF,
auto value = SGF.emitApplyOfDefaultArgGenerator(info.loc,
info.defaultArgsOwner,
info.destIndex,
info.resultType,
info.origResultType);
info.resultType);

SmallVector<ManagedValue, 4> loweredArgs;
SmallVector<DelayedArgument, 4> delayedArgs;
Expand Down
14 changes: 9 additions & 5 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2337,11 +2337,10 @@ RValue RValueEmitter::visitTupleElementExpr(TupleElementExpr *E,

RValue
SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
ConcreteDeclRef defaultArgsOwner,
unsigned destIndex,
CanType resultType,
AbstractionPattern origResultType,
SGFContext C) {
ConcreteDeclRef defaultArgsOwner,
unsigned destIndex,
CanType resultType,
SGFContext C) {
SILDeclRef generator
= SILDeclRef::getDefaultArgGenerator(defaultArgsOwner.getDecl(),
destIndex);
Expand All @@ -2353,6 +2352,11 @@ SILGenFunction::emitApplyOfDefaultArgGenerator(SILLocation loc,
if (fnType->isPolymorphic())
subs = defaultArgsOwner.getSubstitutions();

auto constantInfo = SGM.Types.getConstantInfo(
TypeExpansionContext::minimal(), generator);
AbstractionPattern origResultType =
constantInfo.FormalPattern.getFunctionResultType();

auto substFnType =
fnType->substGenericArgs(SGM.M, subs, getTypeExpansionContext());

Expand Down
1 change: 0 additions & 1 deletion lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
ConcreteDeclRef defaultArgsOwner,
unsigned destIndex,
CanType resultType,
AbstractionPattern origResultType,
SGFContext C = SGFContext());

RValue emitApplyOfStoredPropertyInitializer(
Expand Down
17 changes: 17 additions & 0 deletions test/SILGen/default_arguments_concrete.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swift-emit-silgen %s

func calleeWithEmptyTuple<A>(_: A = ()) {}
func calleeWithLoadable<A>(_: A = 3) {}
func calleeWithAddressOnly<A>(_: A = (3 as Any)) {}
func calleeWithTupleOfLoadable<A>(_: A = (3, 4)) {}
func calleeWithTupleOfAddressOnly<A>(_: A = (3 as Any, 4 as Any)) {}
func calleeWithTupleOfMixed<A>(_: A = (3, 4 as Any)) {}

func testConcreteDefaultArguments() {
calleeWithEmptyTuple()
calleeWithLoadable()
calleeWithAddressOnly()
calleeWithTupleOfLoadable()
calleeWithTupleOfAddressOnly()
calleeWithTupleOfMixed()
}