From 72f14918d809b27efa118ba2f50ee6af11739e04 Mon Sep 17 00:00:00 2001 From: Daniil Kovalev Date: Mon, 6 Oct 2025 01:01:54 +0300 Subject: [PATCH] [AutoDiff][Gardening] Use `SILFunction::getSourceFile` instead of dup logic In 025902fa994d83a213f6765277605c8d2f83c247, `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. --- lib/SILOptimizer/Differentiation/ADContext.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/SILOptimizer/Differentiation/ADContext.cpp b/lib/SILOptimizer/Differentiation/ADContext.cpp index b28acdb3ccb86..3141c5b0649c0 100644 --- a/lib/SILOptimizer/Differentiation/ADContext.cpp +++ b/lib/SILOptimizer/Differentiation/ADContext.cpp @@ -62,10 +62,8 @@ ADContext::ADContext(SILModuleTransform &transform) /// Get the source file for the given `SILFunction`. static SourceFile &getSourceFile(SILFunction *f) { - if (f->hasLocation()) - if (auto *declContext = f->getLocation().getAsDeclContext()) - if (auto *parentSourceFile = declContext->getParentSourceFile()) - return *parentSourceFile; + if (SourceFile *file = f->getSourceFile()) + return *file; for (auto *file : f->getModule().getSwiftModule()->getFiles()) if (auto *sourceFile = dyn_cast(file)) return *sourceFile;