Skip to content

Commit 35c96b8

Browse files
authored
Merge pull request swiftlang#14885 from gottesmm/pr-45949877cd0d0531fa472e54f24f5fb8f740583a
2 parents 81b2c46 + 337d694 commit 35c96b8

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

include/swift/SIL/SILArgumentConvention.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ struct SILArgumentConvention {
8787
return Value <= SILArgumentConvention::Indirect_Out;
8888
}
8989

90+
bool isOwnedConvention() const {
91+
switch (Value) {
92+
case SILArgumentConvention::Indirect_In:
93+
case SILArgumentConvention::Direct_Owned:
94+
return true;
95+
case SILArgumentConvention::Indirect_In_Guaranteed:
96+
case SILArgumentConvention::Direct_Guaranteed:
97+
case SILArgumentConvention::Indirect_Inout:
98+
case SILArgumentConvention::Indirect_In_Constant:
99+
case SILArgumentConvention::Indirect_Out:
100+
case SILArgumentConvention::Indirect_InoutAliasable:
101+
case SILArgumentConvention::Direct_Unowned:
102+
case SILArgumentConvention::Direct_Deallocating:
103+
return false;
104+
}
105+
llvm_unreachable("covered switch isn't covered?!");
106+
}
107+
90108
bool isGuaranteedConvention() const {
91109
switch (Value) {
92110
case SILArgumentConvention::Indirect_In_Guaranteed:

lib/SIL/SILFunctionType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ static CanSILFunctionType getNativeSILFunctionType(
12501250
case SILFunctionType::Representation::WitnessMethod: {
12511251
switch (constant ? constant->kind : SILDeclRef::Kind::Func) {
12521252
case SILDeclRef::Kind::Initializer:
1253+
case SILDeclRef::Kind::EnumElement:
12531254
return getSILFunctionType(M, origType, substInterfaceType, extInfo,
12541255
DefaultInitializerConventions(), ForeignInfo(),
12551256
constant, witnessMethodConformance);
@@ -1272,7 +1273,6 @@ static CanSILFunctionType getNativeSILFunctionType(
12721273
case SILDeclRef::Kind::StoredPropertyInitializer:
12731274
case SILDeclRef::Kind::IVarInitializer:
12741275
case SILDeclRef::Kind::IVarDestroyer:
1275-
case SILDeclRef::Kind::EnumElement:
12761276
return getSILFunctionType(M, origType, substInterfaceType, extInfo,
12771277
getNormalArgumentConvention(M), ForeignInfo(),
12781278
constant, witnessMethodConformance);

lib/SILGen/SILGenConstructor.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,25 @@ static RValue emitImplicitValueConstructorArg(SILGenFunction &SGF,
5757
RValue tuple(type);
5858
for (auto fieldType : tupleTy.getElementTypes())
5959
tuple.addElement(emitImplicitValueConstructorArg(SGF, loc, fieldType, DC));
60-
6160
return tuple;
61+
}
62+
63+
auto &AC = SGF.getASTContext();
64+
auto VD = new (AC) ParamDecl(VarDecl::Specifier::Owned, SourceLoc(), SourceLoc(),
65+
AC.getIdentifier("$implicit_value"),
66+
SourceLoc(),
67+
AC.getIdentifier("$implicit_value"), Type(),
68+
DC);
69+
VD->setInterfaceType(interfaceType);
70+
SILFunctionArgument *arg =
71+
SGF.F.begin()->createFunctionArgument(SGF.getLoweredType(type), VD);
72+
ManagedValue mvArg;
73+
if (arg->getArgumentConvention().isOwnedConvention()) {
74+
mvArg = SGF.emitManagedRValueWithCleanup(arg);
6275
} else {
63-
auto &AC = SGF.getASTContext();
64-
auto VD = new (AC) ParamDecl(VarDecl::Specifier::Owned, SourceLoc(), SourceLoc(),
65-
AC.getIdentifier("$implicit_value"),
66-
SourceLoc(),
67-
AC.getIdentifier("$implicit_value"), Type(),
68-
DC);
69-
VD->setInterfaceType(interfaceType);
70-
SILValue arg =
71-
SGF.F.begin()->createFunctionArgument(SGF.getLoweredType(type), VD);
72-
return RValue(SGF, loc, type, SGF.emitManagedRValueWithCleanup(arg));
76+
mvArg = ManagedValue::forUnmanaged(arg);
7377
}
78+
return RValue(SGF, loc, type, mvArg);
7479
}
7580

7681
static void emitImplicitValueConstructor(SILGenFunction &SGF,

0 commit comments

Comments
 (0)