Skip to content

Commit 158eff1

Browse files
authored
Merge pull request #33166 from gottesmm/pr-824f03205dd43d5614f7605c3f3ae53ac78be8cb
[silgen] Mark a bunch of functions that SILGen open-codeds as "auto-generated" and thus not user generated code.
2 parents 3f2873b + e3fa137 commit 158eff1

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

include/swift/SIL/SILLocation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ class RegularLocation : public SILLocation {
538538
/// it may have been generated from. These locations will have an artificial
539539
/// line location of zero in DWARF, but in CodeView we want to use the given
540540
/// line since line zero does not represent an artificial line in CodeView.
541-
static RegularLocation getAutoGeneratedLocation(SourceLoc L) {
541+
template <typename InputLocTy>
542+
static RegularLocation getAutoGeneratedLocation(InputLocTy L) {
542543
RegularLocation AL(L);
543544
AL.markAutoGenerated();
544545
return AL;

lib/SILGen/SILGen.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
728728
switch (param->getDefaultArgumentKind()) {
729729
case DefaultArgumentKind::Normal: {
730730
auto arg = param->getTypeCheckedDefaultExpr();
731-
SGM.preEmitFunction(constant, arg, f, arg);
731+
auto loc = RegularLocation::getAutoGeneratedLocation(arg);
732+
SGM.preEmitFunction(constant, arg, f, loc);
732733
PrettyStackTraceSILFunction X("silgen emitDefaultArgGenerator ", f);
733734
SILGenFunction SGF(SGM, *f, initDC);
734735
SGF.emitGeneratorFunction(constant, arg);
@@ -738,7 +739,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
738739

739740
case DefaultArgumentKind::StoredProperty: {
740741
auto arg = param->getStoredProperty();
741-
SGM.preEmitFunction(constant, arg, f, arg);
742+
auto loc = RegularLocation::getAutoGeneratedLocation(arg);
743+
SGM.preEmitFunction(constant, arg, f, loc);
742744
PrettyStackTraceSILFunction X("silgen emitDefaultArgGenerator ", f);
743745
SILGenFunction SGF(SGM, *f, initDC);
744746
SGF.emitGeneratorFunction(constant, arg);
@@ -775,7 +777,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
775777
}
776778
}
777779

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

801-
SGM.preEmitFunction(constant, var, f, var);
804+
auto loc = RegularLocation::getAutoGeneratedLocation(var);
805+
SGM.preEmitFunction(constant, var, f, loc);
802806
PrettyStackTraceSILFunction X(
803807
"silgen emitPropertyWrapperBackingInitializer", f);
804808
auto wrapperInfo = var->getPropertyWrapperBackingPropertyInfo();
@@ -820,7 +824,8 @@ static void emitDelayedFunction(SILGenModule &SGM,
820824
auto *onceToken = found->second.first;
821825
auto *onceFunc = found->second.second;
822826

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

834-
SGM.preEmitFunction(constant, decl, f, decl);
839+
auto loc = RegularLocation::getAutoGeneratedLocation(decl);
840+
SGM.preEmitFunction(constant, decl, f, loc);
835841
PrettyStackTraceSILFunction X("silgen enum constructor", f);
836842
SILGenFunction(SGM, *f, decl->getDeclContext()).emitEnumConstructor(decl);
837843
SGM.postEmitFunction(constant, f);
@@ -1242,7 +1248,8 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
12421248
auto ivarInitializer = SILDeclRef(cd, SILDeclRef::Kind::IVarInitializer)
12431249
.asForeign();
12441250
SILFunction *f = getFunction(ivarInitializer, ForDefinition);
1245-
preEmitFunction(ivarInitializer, dd, f, dd);
1251+
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
1252+
preEmitFunction(ivarInitializer, dd, f, loc);
12461253
PrettyStackTraceSILFunction X("silgen emitDestructor ivar initializer", f);
12471254
SILGenFunction(*this, *f, cd).emitIVarInitializer(ivarInitializer);
12481255
postEmitFunction(ivarInitializer, f);
@@ -1253,7 +1260,8 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
12531260
auto ivarDestroyer = SILDeclRef(cd, SILDeclRef::Kind::IVarDestroyer)
12541261
.asForeign();
12551262
SILFunction *f = getFunction(ivarDestroyer, ForDefinition);
1256-
preEmitFunction(ivarDestroyer, dd, f, dd);
1263+
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
1264+
preEmitFunction(ivarDestroyer, dd, f, loc);
12571265
PrettyStackTraceSILFunction X("silgen emitDestructor ivar destroyer", f);
12581266
SILGenFunction(*this, *f, cd).emitIVarDestroyer(ivarDestroyer);
12591267
postEmitFunction(ivarDestroyer, f);
@@ -1267,7 +1275,8 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
12671275
if (requiresIVarDestroyer(cd)) {
12681276
SILDeclRef ivarDestroyer(cd, SILDeclRef::Kind::IVarDestroyer);
12691277
SILFunction *f = getFunction(ivarDestroyer, ForDefinition);
1270-
preEmitFunction(ivarDestroyer, dd, f, dd);
1278+
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
1279+
preEmitFunction(ivarDestroyer, dd, f, loc);
12711280
PrettyStackTraceSILFunction X("silgen emitDestructor ivar destroyer", f);
12721281
SILGenFunction(*this, *f, dd).emitIVarDestroyer(ivarDestroyer);
12731282
postEmitFunction(ivarDestroyer, f);
@@ -1284,22 +1293,22 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
12841293
if (dd->hasBody()) {
12851294
SILDeclRef destroyer(dd, SILDeclRef::Kind::Destroyer);
12861295
SILFunction *f = getFunction(destroyer, ForDefinition);
1287-
preEmitFunction(destroyer, dd, f, dd);
1296+
RegularLocation loc(dd);
1297+
preEmitFunction(destroyer, dd, f, loc);
12881298
PrettyStackTraceSILFunction X("silgen emitDestroyingDestructor", f);
12891299
SILGenFunction(*this, *f, dd).emitDestroyingDestructor(dd);
1290-
f->setDebugScope(new (M) SILDebugScope(dd, f));
12911300
postEmitFunction(destroyer, f);
12921301
}
12931302

12941303
// Emit the deallocating destructor.
12951304
{
12961305
SILDeclRef deallocator(dd, SILDeclRef::Kind::Deallocator);
12971306
SILFunction *f = getFunction(deallocator, ForDefinition);
1298-
preEmitFunction(deallocator, dd, f, dd);
1307+
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
1308+
preEmitFunction(deallocator, dd, f, loc);
12991309
PrettyStackTraceSILFunction X("silgen emitDeallocatingDestructor", f);
13001310
f->createProfiler(dd, deallocator, ForDefinition);
13011311
SILGenFunction(*this, *f, dd).emitDeallocatingDestructor(dd);
1302-
f->setDebugScope(new (M) SILDebugScope(dd, f));
13031312
postEmitFunction(deallocator, f);
13041313
}
13051314
}
@@ -1415,13 +1424,12 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
14151424
if (hasFunction(getterRef))
14161425
return;
14171426

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

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

14581466
SILFunction *f = getFunction(thunk, ForDefinition);
1459-
preEmitFunction(thunk, constructor, f, constructor);
1467+
auto loc = RegularLocation::getAutoGeneratedLocation(constructor);
1468+
preEmitFunction(thunk, constructor, f, loc);
14601469
PrettyStackTraceSILFunction X("silgen objc constructor thunk", f);
14611470
f->setBare(IsBare);
14621471
f->setThunk(IsThunk);
@@ -1472,7 +1481,8 @@ void SILGenModule::emitObjCDestructorThunk(DestructorDecl *destructor) {
14721481
if (hasFunction(thunk))
14731482
return;
14741483
SILFunction *f = getFunction(thunk, ForDefinition);
1475-
preEmitFunction(thunk, destructor, f, destructor);
1484+
auto loc = RegularLocation::getAutoGeneratedLocation(destructor);
1485+
preEmitFunction(thunk, destructor, f, loc);
14761486
PrettyStackTraceSILFunction X("silgen objc destructor thunk", f);
14771487
f->setBare(IsBare);
14781488
f->setThunk(IsThunk);

0 commit comments

Comments
 (0)