Skip to content

Commit fa3eedd

Browse files
committed
ASTDumper: Make the SubstitutionMap dump easier to read
Don't quote generic parameter names because then the tau gets escaped in canonical types, and expand out the replacement type with printRec() instead of stringifying it.
1 parent 6bb74ab commit fa3eedd

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,35 +3718,31 @@ class PrintConformance : public PrintBase {
37183718
return;
37193719
}
37203720

3721-
printFieldQuotedRaw([&](raw_ostream &out) { genericSig->print(out); },
3722-
"generic_signature");
3723-
3724-
auto printSubstitution = [&](GenericTypeParamType * genericParam,
3725-
Type replacementType) {
3726-
printFieldQuotedRaw([&](raw_ostream &out) {
3727-
genericParam->print(out);
3728-
out << " -> ";
3729-
if (replacementType) {
3730-
PrintOptions opts;
3731-
opts.PrintForSIL = true;
3732-
opts.PrintTypesForDebugging = true;
3733-
replacementType->print(out, opts);
3734-
}
3735-
else
3736-
out << "<unresolved concrete type>";
3737-
}, "");
3738-
};
3721+
printFieldRaw([&](raw_ostream &out) { genericSig->print(out); },
3722+
"generic_signature");
37393723

37403724
auto genericParams = genericSig.getGenericParams();
37413725
auto replacementTypes =
37423726
static_cast<const SubstitutionMap &>(map).getReplacementTypesBuffer();
37433727
for (unsigned i : indices(genericParams)) {
37443728
if (style == SubstitutionMap::DumpStyle::Minimal) {
3745-
printSubstitution(genericParams[i], replacementTypes[i]);
3729+
printFieldRaw([&](raw_ostream &out) {
3730+
genericParams[i]->print(out);
3731+
out << " -> ";
3732+
if (replacementTypes[i])
3733+
out << replacementTypes[i];
3734+
else
3735+
out << "<unresolved concrete type>";
3736+
}, "");
37463737
} else {
37473738
printRecArbitrary([&](StringRef label) {
37483739
printHead("substitution", ASTNodeColor, label);
3749-
printSubstitution(genericParams[i], replacementTypes[i]);
3740+
printFieldRaw([&](raw_ostream &out) {
3741+
genericParams[i]->print(out);
3742+
out << " -> ";
3743+
}, "");
3744+
if (replacementTypes[i])
3745+
printRec(replacementTypes[i]);
37503746
printFoot();
37513747
});
37523748
}

test/Constraints/result_builder_generic_infer.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,34 @@ struct ProtocolSubstitution: P {
2222
typealias A = Int
2323

2424
// CHECK: var_decl{{.*}}x1
25-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> Int')
25+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> ProtocolSubstitution.A)
2626
var x1: [S] { S() }
2727

2828
// CHECK: var_decl{{.*}}x2
29-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> ProtocolSubstitution')
29+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> ProtocolSubstitution)
3030
var x2: [S] { S() }
3131
}
3232

3333
// CHECK: struct_decl{{.*}}ArchetypeSubstitution
3434
struct ArchetypeSubstitution<A>: P {
3535
// CHECK: var_decl{{.*}}x1
36-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> A')
36+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> A)
3737
var x1: [S] { S() }
3838

3939
// CHECK: var_decl{{.*}}x2
40-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> ArchetypeSubstitution<A>')
40+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> ArchetypeSubstitution<A>)
4141
var x2: [S] { S() }
4242
}
4343

4444
// CHECK-LABEL: struct_decl{{.*}}ExplicitGenericAttribute
4545
struct ExplicitGenericAttribute<T: P> {
4646
// CHECK: var_decl{{.*}}x1
47-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> T')
47+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> T)
4848
@Builder<T>
4949
var x1: [S] { S() }
5050

5151
// CHECK: var_decl{{.*}}x2
52-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> T.A')
52+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> T.A)
5353
@Builder<T.A>
5454
var x2: [S] { S() }
5555
}
@@ -61,10 +61,10 @@ extension ConcreteTypeSubstitution: P where Value == Int {
6161
typealias A = Value
6262

6363
// CHECK: var_decl{{.*}}x1
64-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> Int')
64+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> ConcreteTypeSubstitution<Int>.A)
6565
var x1: [S] { S() }
6666

6767
// CHECK: var_decl{{.*}}x2
68-
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature='<T>' 'T -> ConcreteTypeSubstitution<Int>')
68+
// CHECK: Builder.buildBlock{{.*}}(substitution_map generic_signature=<T> T -> ConcreteTypeSubstitution<Int>)
6969
var x2: [S] { S() }
7070
}

test/Frontend/debug-generic-signatures.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ extension Super: P2 where T: P2, U: P2 {
118118
// CHECK-LABEL: ClassDecl name=Sub
119119
// CHECK-NEXT: (inherited_conformance type="Sub" protocol="P2"
120120
// CHECK-NEXT: (specialized_conformance type="Super<NonRecur, Recur>" protocol="P2"
121-
// CHECK-NEXT: (substitution_map generic_signature="<T, U where T : P2, U : P2>"
122-
// CHECK-NEXT: (substitution "T -> NonRecur")
123-
// CHECK-NEXT: (substitution "U -> Recur")
121+
// CHECK-NEXT: (substitution_map generic_signature=<T, U where T : P2, U : P2>
122+
// CHECK-NEXT: (substitution T ->
123+
// CHECK-NEXT: (struct_type decl="{{.*}}"))
124+
// CHECK-NEXT: (substitution U ->
125+
// CHECK-NEXT: (struct_type decl="{{.*}}"))
124126
// CHECK-NEXT: (conformance type="T"
125127
// CHECK-NEXT: (normal_conformance type="NonRecur" protocol="P2"
126128
// CHECK-NEXT: (assoc_type req="A" type="Recur")
@@ -166,8 +168,9 @@ struct RecurGeneric<T: P3>: P3 {
166168
// CHECK-NEXT: (assoc_type req="A" type="RecurGeneric<Specialize>")
167169
// CHECK-NEXT: (assoc_conformance type="Self.A" proto="P3"
168170
// CHECK-NEXT: (specialized_conformance type="Specialize.A" protocol="P3"
169-
// CHECK-NEXT: (substitution_map generic_signature="<T where T : P3>"
170-
// CHECK-NEXT: (substitution "T -> Specialize")
171+
// CHECK-NEXT: (substitution_map generic_signature=<T where T : P3>
172+
// CHECK-NEXT: (substitution T ->
173+
// CHECK-NEXT: (struct_type decl="{{.*}}"))
171174
// CHECK-NEXT: (conformance type="T"
172175
// CHECK-NEXT: (normal_conformance type="Specialize" protocol="P3" <details printed above>)))
173176
// CHECK-NEXT: (normal_conformance type="RecurGeneric<T>" protocol="P3"

test/Frontend/dump-parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enum TrailingSemi {
5858
// CHECK-AST-LABEL: (func_decl{{.*}}"generic(_:)" "<T : Hashable>" interface type="<T where T : Hashable> (T) -> ()" access=internal captures=(<generic> )
5959
func generic<T: Hashable>(_: T) {}
6060
// CHECK-AST: (pattern_binding_decl
61-
// CHECK-AST: (processed_init=declref_expr type="(Int) -> ()" location={{.*}} range={{.*}} decl="main.(file).generic@{{.*}} [with (substitution_map generic_signature='<T where T : Hashable>' 'T -> Int')]" function_ref=unapplied))
61+
// CHECK-AST: (processed_init=declref_expr type="(Int) -> ()" location={{.*}} range={{.*}} decl="main.(file).generic@{{.*}} [with (substitution_map generic_signature=<T where T : Hashable> T -> Int)]" function_ref=unapplied))
6262
let _: (Int) -> () = generic
6363

6464
// Closures should be marked as escaping or not.

0 commit comments

Comments
 (0)