Skip to content

Commit 7905a9a

Browse files
committed
Swift Bridging: remove C bridging functions for SILDebugLocation
1 parent 82d9da5 commit 7905a9a

File tree

5 files changed

+39
-47
lines changed

5 files changed

+39
-47
lines changed

SwiftCompilerSources/Sources/SIL/Location.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public struct Location: Equatable, CustomStringConvertible {
1616
let bridged: swift.SILDebugLocation
1717

1818
public var description: String {
19-
let stdString = SILLocation_debugDescription(bridged)
19+
let stdString = bridged.getDebugDescription()
2020
return String(_cxxString: stdString)
2121
}
2222

2323
/// Keeps the debug scope but marks it as auto-generated.
2424
public var autoGenerated: Location {
25-
Location(bridged: SILLocation_getAutogeneratedLocation(bridged))
25+
Location(bridged: bridged.getAutogeneratedLocation())
2626
}
2727

2828
public var hasValidLineNumber: Bool { bridged.hasValidLineNumber() }
@@ -31,10 +31,10 @@ public struct Location: Equatable, CustomStringConvertible {
3131
public var isDebugSteppable: Bool { hasValidLineNumber && !isAutoGenerated }
3232

3333
public static func ==(lhs: Location, rhs: Location) -> Bool {
34-
SILLocation_equal(lhs.bridged, rhs.bridged)
34+
lhs.bridged.isEqualTo(rhs.bridged)
3535
}
3636

3737
public func hasSameSourceLocation(as other: Location) -> Bool {
38-
SILLocation_hasSameSourceLocation(bridged, other.bridged)
38+
bridged.hasSameSourceLocation(other.bridged)
3939
}
4040
}

include/swift/SIL/SILBridging.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,6 @@ void PassContext_eraseBlock(BridgedPassContext passContext,
897897

898898
std::string SILNode_debugDescription(BridgedNode node);
899899

900-
std::string SILLocation_debugDescription(swift::SILDebugLocation loc);
901-
swift::SILDebugLocation
902-
SILLocation_getAutogeneratedLocation(swift::SILDebugLocation loc);
903-
bool SILLocation_equal(swift::SILDebugLocation lhs, swift::SILDebugLocation rhs);
904-
bool SILLocation_hasSameSourceLocation(swift::SILDebugLocation lhs, swift::SILDebugLocation rhs);
905-
906900
BridgedInstruction SILBuilder_createBuiltinBinaryFunction(
907901
BridgedBuilder builder, llvm::StringRef name,
908902
swift::SILType operandType, swift::SILType resultType,

include/swift/SIL/SILLocation.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,23 @@ class SILDebugLocation {
702702
bool hasValidLineNumber() const { return location.hasValidLineNumber(); }
703703
bool isAutoGenerated() const { return location.isAutoGenerated(); }
704704
operator bool() const { return bool(location) && debugScope; }
705+
706+
std::string getDebugDescription() const;
707+
708+
SWIFT_IMPORT_UNSAFE
709+
SILDebugLocation getAutogeneratedLocation() const {
710+
SILDebugLocation autoGenLoc(RegularLocation::getAutoGeneratedLocation(), getScope());
711+
return autoGenLoc;
712+
}
713+
714+
bool isEqualTo(SILDebugLocation rhs) const {
715+
return getLocation() == rhs.getLocation() && getScope() == rhs.getScope();
716+
}
717+
718+
bool hasSameSourceLocation(swift::SILDebugLocation rhs) const {
719+
return getLocation().hasSameSourceLocation(rhs.getLocation()) &&
720+
getScope() == rhs.getScope();
721+
}
705722
};
706723

707724
} // end swift namespace

lib/SIL/IR/SILLocation.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,21 @@ ImplicitReturnLocation::ImplicitReturnLocation(SILLocation L)
280280
L.isASTNode<PatternBindingDecl>() ||
281281
L.isNull());
282282
}
283+
284+
std::string SILDebugLocation::getDebugDescription() const {
285+
std::string str;
286+
llvm::raw_string_ostream os(str);
287+
SILLocation loc = getLocation();
288+
loc.print(os);
289+
#ifndef NDEBUG
290+
if (const SILDebugScope *scope = getScope()) {
291+
if (DeclContext *dc = loc.getAsDeclContext()) {
292+
os << ", scope=";
293+
scope->print(dc->getASTContext().SourceMgr, os, /*indent*/ 2);
294+
} else {
295+
os << ", scope=?";
296+
}
297+
}
298+
#endif
299+
return str;
300+
}

lib/SIL/Utils/SILBridging.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -189,43 +189,6 @@ BridgedValue::Kind BridgedValue::getKind() const {
189189
llvm_unreachable("unknown SILValue");
190190
}
191191

192-
//===----------------------------------------------------------------------===//
193-
// SILLocation
194-
//===----------------------------------------------------------------------===//
195-
196-
std::string SILLocation_debugDescription(swift::SILDebugLocation dloc) {
197-
std::string str;
198-
llvm::raw_string_ostream os(str);
199-
SILLocation loc = dloc.getLocation();
200-
loc.print(os);
201-
#ifndef NDEBUG
202-
if (const SILDebugScope *scope = dloc.getScope()) {
203-
if (DeclContext *dc = loc.getAsDeclContext()) {
204-
os << ", scope=";
205-
scope->print(dc->getASTContext().SourceMgr, os, /*indent*/ 2);
206-
} else {
207-
os << ", scope=?";
208-
}
209-
}
210-
#endif
211-
return str;
212-
}
213-
214-
SILDebugLocation SILLocation_getAutogeneratedLocation(SILDebugLocation loc) {
215-
SILDebugLocation autoGenLoc(RegularLocation::getAutoGeneratedLocation(),
216-
loc.getScope());
217-
return autoGenLoc;
218-
}
219-
220-
bool SILLocation_equal(swift::SILDebugLocation lhs, swift::SILDebugLocation rhs) {
221-
return lhs.getLocation() == rhs.getLocation() && lhs.getScope() == rhs.getScope();
222-
}
223-
224-
bool SILLocation_hasSameSourceLocation(swift::SILDebugLocation lhs, swift::SILDebugLocation rhs) {
225-
return lhs.getLocation().hasSameSourceLocation(rhs.getLocation()) &&
226-
lhs.getScope() == rhs.getScope();
227-
}
228-
229192
//===----------------------------------------------------------------------===//
230193
// SILGlobalVariable
231194
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)