Skip to content

Commit 4c33af9

Browse files
committed
[embedded] Move default arg logic from postEmitFunction to SILDeclRef::isTransparent
1 parent 9101bdc commit 4c33af9

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,20 @@ bool SILDeclRef::isTransparent() const {
820820
}
821821
}
822822

823+
// To support using metatypes as type hints in Embedded Swift. A default
824+
// argument generator might be returning a metatype, which we normally don't
825+
// support in Embedded Swift, but to still allow metatypes as type hints, we
826+
// make the generator always inline to the callee by marking it transparent.
827+
if (getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
828+
if (isDefaultArgGenerator() && hasDecl()) {
829+
auto *decl = getDecl();
830+
auto *param = getParameterAt(decl, defaultArgIndex);
831+
Type paramType = param->getTypeOfDefaultExpr();
832+
if (paramType && paramType->is<MetatypeType>())
833+
return true;
834+
}
835+
}
836+
823837
if (hasDecl()) {
824838
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(getDecl()))
825839
return AFD->isTransparent();

lib/SILGen/SILGen.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,28 +1280,6 @@ void SILGenModule::postEmitFunction(SILDeclRef constant,
12801280
F->verifyIncompleteOSSA();
12811281

12821282
emitDifferentiabilityWitnessesForFunction(constant, F);
1283-
1284-
// To support using metatypes as type hints in Embedded Swift. A default
1285-
// argument generator might be returning a metatype, which we normally don't
1286-
// support in Embedded Swift, but to still allow metatypes as type hints, we
1287-
// make the generator always inline to the callee by marking it transparent.
1288-
if (M.getOptions().EmbeddedSwift) {
1289-
if (constant.isDefaultArgGenerator()) {
1290-
bool isReturningMetatype = false;
1291-
if (F->getLoweredFunctionType()->getNumResults() == 1) {
1292-
if (F->getLoweredFunctionType()
1293-
->getSingleResult()
1294-
.getSILStorageInterfaceType()
1295-
.isMetatype()) {
1296-
isReturningMetatype = true;
1297-
}
1298-
}
1299-
1300-
if (isReturningMetatype) {
1301-
F->setTransparent(IsTransparent);
1302-
}
1303-
}
1304-
}
13051283
}
13061284

13071285
void SILGenModule::emitDifferentiabilityWitnessesForFunction(

0 commit comments

Comments
 (0)