Factor out SILDeclRef::getInitializationExpr

This commit is contained in:
Hamish Knight
2022-10-14 17:45:12 +01:00
parent d0ffd29860
commit d1e2ac15d4
3 changed files with 59 additions and 23 deletions

View File

@@ -944,22 +944,10 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
auto *pbd = var->getParentPatternBinding();
unsigned idx = pbd->getPatternEntryIndexForVarDecl(var);
auto *init = pbd->getInit(idx);
auto *initDC = pbd->getInitContext(idx);
auto captureInfo = pbd->getCaptureInfo(idx);
assert(!pbd->isInitializerSubsumed(idx));
// If this is the backing storage for a property with an attached wrapper
// that was initialized with `=`, use that expression as the initializer.
if (auto originalProperty = var->getOriginalWrappedProperty()) {
if (originalProperty
->isPropertyMemberwiseInitializedWithWrappedType()) {
auto wrapperInfo =
originalProperty->getPropertyWrapperInitializerInfo();
assert(wrapperInfo.getWrappedValuePlaceholder()->getOriginalWrappedValue());
init = wrapperInfo.getWrappedValuePlaceholder()->getOriginalWrappedValue();
}
}
auto *init = constant.getInitializationExpr();
assert(init);
auto loc = RegularLocation::getAutoGeneratedLocation(init);
preEmitFunction(constant, f, loc);
@@ -989,13 +977,14 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
preEmitFunction(constant, f, loc);
PrettyStackTraceSILFunction X(
"silgen emitPropertyWrapperBackingInitializer", f);
auto wrapperInfo = var->getPropertyWrapperInitializerInfo();
assert(wrapperInfo.hasInitFromWrappedValue());
f->createProfiler(wrapperInfo.getInitFromWrappedValue(), constant);
auto *init = constant.getInitializationExpr();
assert(init);
f->createProfiler(init, constant);
auto varDC = var->getInnermostDeclContext();
SILGenFunction SGF(*this, *f, varDC);
SGF.emitGeneratorFunction(constant, wrapperInfo.getInitFromWrappedValue(),
/*EmitProfilerIncrement*/ true);
SGF.emitGeneratorFunction(constant, init, /*EmitProfilerIncrement*/ true);
postEmitFunction(constant, f);
break;
}
@@ -1007,12 +996,14 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
preEmitFunction(constant, f, loc);
PrettyStackTraceSILFunction X(
"silgen emitPropertyWrapperInitFromProjectedValue", f);
auto initInfo = var->getPropertyWrapperInitializerInfo();
assert(initInfo.hasInitFromProjectedValue());
f->createProfiler(initInfo.getInitFromProjectedValue(), constant);
auto *init = constant.getInitializationExpr();
assert(init);
f->createProfiler(init, constant);
auto varDC = var->getInnermostDeclContext();
SILGenFunction SGF(*this, *f, varDC);
SGF.emitGeneratorFunction(constant, initInfo.getInitFromProjectedValue());
SGF.emitGeneratorFunction(constant, init);
postEmitFunction(constant, f);
break;
}