From 34b131f794c303b62c38d19263bcf146e538da75 Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Tue, 10 Nov 2026 08:27:30 -0600 Subject: [PATCH] Support raw-identifier module names in `Logger.currentModule`. (#535) When a module name (via `-module-alias`) is a raw identifier (SE-0451), `#fileID` formats the module component enclosed in backticks (for example, `` `/a/b/c`/File.swift ``). If the raw identifier contains '/', splitting on the first '/' in `#fileID` truncates the module name at the slash inside the backticks. When `#fileID` starts with a backtick, advance past the matching closing backtick before searching for the '/' separator that ends the module name, preserving the enclosing backticks. --- Sources/Logging/Logger.swift | 13 ++++++++++++- Tests/LoggingTests/LoggingTest.swift | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Sources/Logging/Logger.swift b/Sources/Logging/Logger.swift index 36ea9a0..d509499 100644 --- a/Sources/Logging/Logger.swift +++ b/Sources/Logging/Logger.swift @@ -1395,7 +1395,18 @@ extension Logger { @inlinable internal static func currentModule(fileID: String = #fileID) -> String { let utf8All = fileID.utf8 - if let slashIndex = utf8All.firstIndex(of: UInt8(ascii: "/")) { + let searchStart: String.UTF8View.Index + if utf8All.first == UInt8(ascii: "`") { + guard let closingBacktickIndex = utf8All.dropFirst().firstIndex(of: UInt8(ascii: "`")) else { + // It should be impossible for a well-formed module to get here, so treat it as an "n/a" case. + return "n/a" + } + // Backticks are part of raw-identifier module names as written in source and mangled, so preserve them. + searchStart = utf8All.index(after: closingBacktickIndex) + } else { + searchStart = utf8All.startIndex + } + if let slashIndex = utf8All[searchStart...].firstIndex(of: UInt8(ascii: "/")) { return String(fileID[..