Skip to content

Commit b46a095

Browse files
authored
[AutoDiff][Gardening] Use SILFunction::getSourceFile instead of dup logic (#84709)
In 025902f, `SILFunction::getSourceFile()` is introduced. This patch makes use of that to avoid duplicating the logic in `static SourceFile &getSourceFile(SILFunction *f)` in lib/SILOptimizer/Differentiation/ADContext.cpp.
1 parent 6d7d1d7 commit b46a095

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/SILOptimizer/Differentiation/ADContext.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ ADContext::ADContext(SILModuleTransform &transform)
6262

6363
/// Get the source file for the given `SILFunction`.
6464
static SourceFile &getSourceFile(SILFunction *f) {
65-
if (f->hasLocation())
66-
if (auto *declContext = f->getLocation().getAsDeclContext())
67-
if (auto *parentSourceFile = declContext->getParentSourceFile())
68-
return *parentSourceFile;
65+
if (SourceFile *file = f->getSourceFile())
66+
return *file;
6967
for (auto *file : f->getModule().getSwiftModule()->getFiles())
7068
if (auto *sourceFile = dyn_cast<SourceFile>(file))
7169
return *sourceFile;

0 commit comments

Comments
 (0)