Skip to content

Commit 90f9fce

Browse files
Merge pull request #82665 from swiftlang/jepa4
Bridging: Bridge some basic classes like `swift::SourceLoc` directly
2 parents 1a406a2 + 5620abb commit 90f9fce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2104
-2431
lines changed

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,14 @@ public struct DiagnosticEngine {
7878
at position: SourceLoc?,
7979
highlight: CharSourceRange? = nil,
8080
fixIts: [DiagnosticFixIt] = []) {
81-
82-
let bridgedSourceLoc: BridgedSourceLoc = position.bridged
83-
let highlightStart: BridgedSourceLoc
81+
let bridgedSourceLoc = position.bridgedLocation
82+
let highlightStart: swift.SourceLoc
8483
let highlightLength: UInt32
8584
if let highlight = highlight {
8685
highlightStart = highlight.start.bridged
8786
highlightLength = highlight.byteLength
8887
} else {
89-
highlightStart = BridgedSourceLoc()
88+
highlightStart = .init()
9089
highlightLength = 0
9190
}
9291
var bridgedArgs: [BridgedDiagnosticArgument] = []

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -17,24 +17,20 @@ import BasicBridging
1717
/// In contrast to just having a filename+line+column, this allows displaying the context around
1818
/// the location when printing diagnostics.
1919
public struct SourceLoc {
20-
public let bridged: BridgedSourceLoc
20+
public let bridged: swift.SourceLoc
2121

22-
public init?(bridged: BridgedSourceLoc) {
23-
guard bridged.isValid else {
22+
public init?(bridged: swift.SourceLoc) {
23+
guard bridged.isValid() else {
2424
return nil
2525
}
2626
self.bridged = bridged
2727
}
2828
}
2929

30-
extension SourceLoc {
31-
public func advanced(by n: Int) -> SourceLoc {
32-
SourceLoc(bridged: bridged.advanced(by: n))!
33-
}
34-
}
35-
36-
extension Optional where Wrapped == SourceLoc {
37-
public var bridged: BridgedSourceLoc {
30+
extension Optional<SourceLoc> {
31+
// TODO: This can go back to being 'bridged' once we upgrade to a toolchain
32+
// where https://github.com/swiftlang/swift/issues/82609 is fixed.
33+
public var bridgedLocation: swift.SourceLoc {
3834
self?.bridged ?? .init()
3935
}
4036
}
@@ -48,7 +44,7 @@ public struct CharSourceRange {
4844
self.byteLength = byteLength
4945
}
5046

51-
public init?(bridgedStart: BridgedSourceLoc, byteLength: UInt32) {
47+
public init?(bridgedStart: swift.SourceLoc, byteLength: UInt32) {
5248
guard let start = SourceLoc(bridged: bridgedStart) else {
5349
return nil
5450
}

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -242,7 +242,9 @@ class SDKContext {
242242
void diagnose(YAMLNodeTy node, Diag<ArgTypes...> ID,
243243
typename detail::PassArgument<ArgTypes>::type... args) {
244244
auto smRange = node->getSourceRange();
245-
auto range = SourceRange(SourceLoc(smRange.Start), SourceLoc(smRange.End));
245+
auto range =
246+
SourceRange(SourceLoc::getFromPointer(smRange.Start.getPointer()),
247+
SourceLoc::getFromPointer(smRange.End.getPointer()));
246248
Diags.diagnose(range.Start, ID, std::forward<ArgTypes>(args)...)
247249
.highlight(range);
248250
}

0 commit comments

Comments
 (0)