Skip to content

[silgen] Mark a bunch of functions that SILGen open-codeds as "auto-generated" and thus not user generated code. #33166

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: 2 additions & 1 deletion include/swift/SIL/SILLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ class RegularLocation : public SILLocation {
/// it may have been generated from. These locations will have an artificial
/// line location of zero in DWARF, but in CodeView we want to use the given
/// line since line zero does not represent an artificial line in CodeView.
static RegularLocation getAutoGeneratedLocation(SourceLoc L) {
template <typename InputLocTy>
static RegularLocation getAutoGeneratedLocation(InputLocTy L) {
RegularLocation AL(L);
AL.markAutoGenerated();
return AL;
Expand Down
48 changes: 29 additions & 19 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
switch (param->getDefaultArgumentKind()) {
case DefaultArgumentKind::Normal: {
auto arg = param->getTypeCheckedDefaultExpr();
SGM.preEmitFunction(constant, arg, f, arg);
auto loc = RegularLocation::getAutoGeneratedLocation(arg);
SGM.preEmitFunction(constant, arg, f, loc);
PrettyStackTraceSILFunction X("silgen emitDefaultArgGenerator ", f);
SILGenFunction SGF(SGM, *f, initDC);
SGF.emitGeneratorFunction(constant, arg);
Expand All @@ -738,7 +739,8 @@ static void emitDelayedFunction(SILGenModule &SGM,

case DefaultArgumentKind::StoredProperty: {
auto arg = param->getStoredProperty();
SGM.preEmitFunction(constant, arg, f, arg);
auto loc = RegularLocation::getAutoGeneratedLocation(arg);
SGM.preEmitFunction(constant, arg, f, loc);
PrettyStackTraceSILFunction X("silgen emitDefaultArgGenerator ", f);
SILGenFunction SGF(SGM, *f, initDC);
SGF.emitGeneratorFunction(constant, arg);
Expand Down Expand Up @@ -775,7 +777,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
}
}

SGM.preEmitFunction(constant, init, f, init);
auto loc = RegularLocation::getAutoGeneratedLocation(init);
SGM.preEmitFunction(constant, init, f, loc);
PrettyStackTraceSILFunction X("silgen emitStoredPropertyInitialization", f);
f->createProfiler(init, constant, ForDefinition);
SILGenFunction SGF(SGM, *f, initDC);
Expand All @@ -798,7 +801,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
case SILDeclRef::Kind::PropertyWrapperBackingInitializer: {
auto *var = cast<VarDecl>(constant.getDecl());

SGM.preEmitFunction(constant, var, f, var);
auto loc = RegularLocation::getAutoGeneratedLocation(var);
SGM.preEmitFunction(constant, var, f, loc);
PrettyStackTraceSILFunction X(
"silgen emitPropertyWrapperBackingInitializer", f);
auto wrapperInfo = var->getPropertyWrapperBackingPropertyInfo();
Expand All @@ -820,7 +824,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
auto *onceToken = found->second.first;
auto *onceFunc = found->second.second;

SGM.preEmitFunction(constant, global, f, global);
auto loc = RegularLocation::getAutoGeneratedLocation(global);
SGM.preEmitFunction(constant, global, f, loc);
PrettyStackTraceSILFunction X("silgen emitGlobalAccessor", f);
SILGenFunction(SGM, *f, global->getDeclContext())
.emitGlobalAccessor(global, onceToken, onceFunc);
Expand All @@ -831,7 +836,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
case SILDeclRef::Kind::EnumElement: {
auto *decl = cast<EnumElementDecl>(constant.getDecl());

SGM.preEmitFunction(constant, decl, f, decl);
auto loc = RegularLocation::getAutoGeneratedLocation(decl);
SGM.preEmitFunction(constant, decl, f, loc);
PrettyStackTraceSILFunction X("silgen enum constructor", f);
SILGenFunction(SGM, *f, decl->getDeclContext()).emitEnumConstructor(decl);
SGM.postEmitFunction(constant, f);
Expand Down Expand Up @@ -1242,7 +1248,8 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
auto ivarInitializer = SILDeclRef(cd, SILDeclRef::Kind::IVarInitializer)
.asForeign();
SILFunction *f = getFunction(ivarInitializer, ForDefinition);
preEmitFunction(ivarInitializer, dd, f, dd);
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
preEmitFunction(ivarInitializer, dd, f, loc);
PrettyStackTraceSILFunction X("silgen emitDestructor ivar initializer", f);
SILGenFunction(*this, *f, cd).emitIVarInitializer(ivarInitializer);
postEmitFunction(ivarInitializer, f);
Expand All @@ -1253,7 +1260,8 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
auto ivarDestroyer = SILDeclRef(cd, SILDeclRef::Kind::IVarDestroyer)
.asForeign();
SILFunction *f = getFunction(ivarDestroyer, ForDefinition);
preEmitFunction(ivarDestroyer, dd, f, dd);
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
preEmitFunction(ivarDestroyer, dd, f, loc);
PrettyStackTraceSILFunction X("silgen emitDestructor ivar destroyer", f);
SILGenFunction(*this, *f, cd).emitIVarDestroyer(ivarDestroyer);
postEmitFunction(ivarDestroyer, f);
Expand All @@ -1267,7 +1275,8 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
if (requiresIVarDestroyer(cd)) {
SILDeclRef ivarDestroyer(cd, SILDeclRef::Kind::IVarDestroyer);
SILFunction *f = getFunction(ivarDestroyer, ForDefinition);
preEmitFunction(ivarDestroyer, dd, f, dd);
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
preEmitFunction(ivarDestroyer, dd, f, loc);
PrettyStackTraceSILFunction X("silgen emitDestructor ivar destroyer", f);
SILGenFunction(*this, *f, dd).emitIVarDestroyer(ivarDestroyer);
postEmitFunction(ivarDestroyer, f);
Expand All @@ -1284,22 +1293,22 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
if (dd->hasBody()) {
SILDeclRef destroyer(dd, SILDeclRef::Kind::Destroyer);
SILFunction *f = getFunction(destroyer, ForDefinition);
preEmitFunction(destroyer, dd, f, dd);
RegularLocation loc(dd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems like NFC here (which would be correct). Just making sure, is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it to match the code all around to it.

preEmitFunction(destroyer, dd, f, loc);
PrettyStackTraceSILFunction X("silgen emitDestroyingDestructor", f);
SILGenFunction(*this, *f, dd).emitDestroyingDestructor(dd);
f->setDebugScope(new (M) SILDebugScope(dd, f));
postEmitFunction(destroyer, f);
}

// Emit the deallocating destructor.
{
SILDeclRef deallocator(dd, SILDeclRef::Kind::Deallocator);
SILFunction *f = getFunction(deallocator, ForDefinition);
preEmitFunction(deallocator, dd, f, dd);
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
preEmitFunction(deallocator, dd, f, loc);
PrettyStackTraceSILFunction X("silgen emitDeallocatingDestructor", f);
f->createProfiler(dd, deallocator, ForDefinition);
SILGenFunction(*this, *f, dd).emitDeallocatingDestructor(dd);
f->setDebugScope(new (M) SILDebugScope(dd, f));
postEmitFunction(deallocator, f);
}
}
Expand Down Expand Up @@ -1415,13 +1424,12 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
if (hasFunction(getterRef))
return;

RegularLocation ThunkBodyLoc(prop);
ThunkBodyLoc.markAutoGenerated();
auto thunkBodyLoc = RegularLocation::getAutoGeneratedLocation(prop);
// ObjC entry points are always externally usable, so emitting can't be
// delayed.
{
SILFunction *f = getFunction(getterRef, ForDefinition);
preEmitFunction(getterRef, prop, f, ThunkBodyLoc);
preEmitFunction(getterRef, prop, f, thunkBodyLoc);
PrettyStackTraceSILFunction X("silgen objc property getter thunk", f);
f->setBare(IsBare);
f->setThunk(IsThunk);
Expand All @@ -1437,7 +1445,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
auto setterRef = SILDeclRef(setter, SILDeclRef::Kind::Func).asForeign();

SILFunction *f = getFunction(setterRef, ForDefinition);
preEmitFunction(setterRef, prop, f, ThunkBodyLoc);
preEmitFunction(setterRef, prop, f, thunkBodyLoc);
PrettyStackTraceSILFunction X("silgen objc property setter thunk", f);
f->setBare(IsBare);
f->setThunk(IsThunk);
Expand All @@ -1456,7 +1464,8 @@ void SILGenModule::emitObjCConstructorThunk(ConstructorDecl *constructor) {
// delayed.

SILFunction *f = getFunction(thunk, ForDefinition);
preEmitFunction(thunk, constructor, f, constructor);
auto loc = RegularLocation::getAutoGeneratedLocation(constructor);
preEmitFunction(thunk, constructor, f, loc);
PrettyStackTraceSILFunction X("silgen objc constructor thunk", f);
f->setBare(IsBare);
f->setThunk(IsThunk);
Expand All @@ -1472,7 +1481,8 @@ void SILGenModule::emitObjCDestructorThunk(DestructorDecl *destructor) {
if (hasFunction(thunk))
return;
SILFunction *f = getFunction(thunk, ForDefinition);
preEmitFunction(thunk, destructor, f, destructor);
auto loc = RegularLocation::getAutoGeneratedLocation(destructor);
preEmitFunction(thunk, destructor, f, loc);
PrettyStackTraceSILFunction X("silgen objc destructor thunk", f);
f->setBare(IsBare);
f->setThunk(IsThunk);
Expand Down