Skip to content

Commit 53ed390

Browse files
committed
Swift: tweak location extractor using new concept
1 parent eb8997d commit 53ed390

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

swift/extractor/infra/SwiftDispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class SwiftDispatcher {
175175
CODEQL_ASSERT(found != store.end(), "createEntry called on non-fetched label");
176176
using Tag = ConcreteTrapTagOf<E>;
177177
auto label = TrapLabel<Tag>::unsafeCreateFromUntyped(found->second);
178-
if constexpr (requires { locationExtractor.attachLocation(sourceManager, e, label); }) {
178+
if constexpr (IsLocatable<E>) {
179179
locationExtractor.attachLocation(sourceManager, e, label);
180180
}
181181
return TrapClassOf<E>{label};

swift/extractor/infra/SwiftLocationExtractor.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
5959
auto endRange = getSourceRange(locatables.back());
6060
return {startRange.Start, endRange.End};
6161
}
62-
63-
// default case, no location
64-
swift::SourceRange getSourceRange(const auto&) {
65-
return {};
66-
}
6762
} // namespace detail
6863

64+
template <typename E>
65+
concept IsLocatable = requires(E e) { detail::getSourceRange(e); };
66+
6967
class SwiftLocationExtractor {
7068
public:
7169
explicit SwiftLocationExtractor(TrapDomain& trap) : trap(trap) {}
@@ -75,13 +73,13 @@ class SwiftLocationExtractor {
7573

7674
// Emits a Location TRAP entry and attaches it to a `Locatable` trap label
7775
void attachLocation(const swift::SourceManager& sourceManager,
78-
const auto& locatable,
76+
const IsLocatable auto& locatable,
7977
TrapLabel<LocatableTag> locatableLabel) {
8078
attachLocationImpl(sourceManager, detail::getSourceRange(locatable), locatableLabel);
8179
}
8280

8381
void attachLocation(const swift::SourceManager& sourceManager,
84-
const auto* locatable,
82+
const IsLocatable auto* locatable,
8583
TrapLabel<LocatableTag> locatableLabel) {
8684
attachLocation(sourceManager, *locatable, locatableLabel);
8785
}

0 commit comments

Comments
 (0)