Skip to content

Commit 2965cd2

Browse files
committed
SILGen: Emit enum element constructors using the 'on-demand' mechanism
Enum element constructors are used when an enum element satisfies a protocol requirement. Instead of emitting them as part of emitGlobalFunctionRef(), let's sink it down to getFunction() where we do all other on-demand function body emission.
1 parent ee92a11 commit 2965cd2

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ static bool isEmittedOnDemand(SILModule &M, SILDeclRef constant) {
606606

607607
break;
608608
}
609+
case SILDeclRef::Kind::EnumElement:
610+
return true;
609611
default:
610612
break;
611613
}
@@ -828,7 +830,16 @@ static void emitDelayedFunction(SILGenModule &SGM,
828830
break;
829831
}
830832

831-
case SILDeclRef::Kind::EnumElement:
833+
case SILDeclRef::Kind::EnumElement: {
834+
auto *decl = cast<EnumElementDecl>(constant.getDecl());
835+
836+
SGM.preEmitFunction(constant, decl, f, decl);
837+
PrettyStackTraceSILFunction X("silgen enum constructor", f);
838+
SILGenFunction(SGM, *f, decl->getDeclContext()).emitEnumConstructor(decl);
839+
SGM.postEmitFunction(constant, f);
840+
break;
841+
}
842+
832843
case SILDeclRef::Kind::Destroyer:
833844
case SILDeclRef::Kind::Deallocator:
834845
case SILDeclRef::Kind::IVarInitializer:
@@ -1143,17 +1154,6 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
11431154
}
11441155
}
11451156

1146-
void SILGenModule::emitEnumConstructor(EnumElementDecl *decl) {
1147-
// Enum element constructors are always emitted by need, so don't need
1148-
// delayed emission.
1149-
SILDeclRef constant(decl);
1150-
SILFunction *f = getFunction(constant, ForDefinition);
1151-
preEmitFunction(constant, decl, f, decl);
1152-
PrettyStackTraceSILFunction X("silgen enum constructor", f);
1153-
SILGenFunction(*this, *f, decl->getDeclContext()).emitEnumConstructor(decl);
1154-
postEmitFunction(constant, f);
1155-
}
1156-
11571157
SILFunction *SILGenModule::emitClosure(AbstractClosureExpr *ce) {
11581158
SILDeclRef constant(ce);
11591159
SILFunction *f = getFunction(constant, ForDefinition);

lib/SILGen/SILGen.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
284284
/// SILDeclRef(cd, Destructor).
285285
void emitDestructor(ClassDecl *cd, DestructorDecl *dd);
286286

287-
/// Generates the enum constructor for the given
288-
/// EnumElementDecl under the name SILDeclRef(decl).
289-
void emitEnumConstructor(EnumElementDecl *decl);
290-
291287
/// Emits the default argument generator with the given expression.
292288
void emitDefaultArgGenerator(SILDeclRef constant, ParamDecl *param);
293289

lib/SILGen/SILGenThunk.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ SILGenFunction::emitGlobalFunctionRef(SILLocation loc, SILDeclRef constant,
138138
SGM.emitForeignToNativeThunk(constant);
139139
} else if (constant.isNativeToForeignThunk()) {
140140
SGM.emitNativeToForeignThunk(constant);
141-
} else if (constant.kind == SILDeclRef::Kind::EnumElement) {
142-
SGM.emitEnumConstructor(cast<EnumElementDecl>(constant.getDecl()));
143141
}
144142
}
145143

0 commit comments

Comments
 (0)