Skip to content

Commit b0dd1ab

Browse files
committed
SIL: make SubstitutionMap CustomStringConvertible
1 parent a67d9c5 commit b0dd1ab

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

SwiftCompilerSources/Sources/AST/SubstitutionMap.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import ASTBridging
1818
///
1919
/// Substitution maps are primarily used when performing substitutions into any entity that
2020
/// can reference type parameters and conformances.
21-
public struct SubstitutionMap {
21+
public struct SubstitutionMap: CustomStringConvertible {
2222
public let bridged: BridgedSubstitutionMap
2323

2424
public init(bridged: BridgedSubstitutionMap) {
@@ -29,6 +29,10 @@ public struct SubstitutionMap {
2929
self.bridged = BridgedSubstitutionMap()
3030
}
3131

32+
public var description: String {
33+
return String(taking: bridged.getDebugDescription())
34+
}
35+
3236
public var isEmpty: Bool { bridged.isEmpty() }
3337

3438
public var hasAnySubstitutableParams: Bool { bridged.hasAnySubstitutableParams() }

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,7 @@ struct BridgedSubstitutionMap {
20702070
BRIDGED_INLINE BridgedSubstitutionMap(swift::SubstitutionMap map);
20712071
BRIDGED_INLINE swift::SubstitutionMap unbridged() const;
20722072
BRIDGED_INLINE BridgedSubstitutionMap();
2073+
BridgedOwnedString getDebugDescription() const;
20732074
BRIDGED_INLINE bool isEmpty() const;
20742075
BRIDGED_INLINE bool hasAnySubstitutableParams() const;
20752076
BRIDGED_INLINE SwiftInt getNumConformances() const;

lib/AST/Bridging/MiscBridging.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,28 @@ void BridgedTypeRepr_dump(void *type) { static_cast<TypeRepr *>(type)->dump(); }
5151

5252
#pragma clang diagnostic pop
5353

54+
//===----------------------------------------------------------------------===//
55+
// MARK: Conformance
56+
//===----------------------------------------------------------------------===//
57+
5458
BridgedOwnedString BridgedConformance::getDebugDescription() const {
5559
std::string str;
5660
llvm::raw_string_ostream os(str);
5761
unbridged().print(os);
5862
return str;
5963
}
6064

65+
//===----------------------------------------------------------------------===//
66+
// MARK: SubstitutionMap
67+
//===----------------------------------------------------------------------===//
68+
6169
static_assert(sizeof(BridgedSubstitutionMap) >= sizeof(swift::SubstitutionMap),
6270
"BridgedSubstitutionMap has wrong size");
71+
72+
BridgedOwnedString BridgedSubstitutionMap::getDebugDescription() const {
73+
std::string str;
74+
llvm::raw_string_ostream os(str);
75+
unbridged().dump(os);
76+
return str;
77+
}
78+

0 commit comments

Comments
 (0)