[SourceKit] Use canonical type in printTypeUSR

Mangling a non-canonical type can run into
unexpected type sugar such as the newly introduced
LocatableType. USRs should be based on canonical
types anyway, so make sure we canonicalize before
mangling.

rdar://141168628
This commit is contained in:
Hamish Knight
2024-12-09 22:04:10 +00:00
parent 5aacff40ed
commit 30a8f1988a
3 changed files with 19 additions and 2 deletions

View File

@@ -39,8 +39,9 @@ static inline StringRef getUSRSpacePrefix() {
bool ide::printTypeUSR(Type Ty, raw_ostream &OS) {
assert(!Ty->hasArchetype() && "cannot have contextless archetypes mangled.");
Ty = Ty->getCanonicalType()->getRValueType();
Mangle::ASTMangler Mangler(Ty->getASTContext());
OS << Mangler.mangleTypeAsUSR(Ty->getRValueType());
OS << Mangler.mangleTypeAsUSR(Ty);
return false;
}

View File

@@ -0,0 +1,16 @@
@resultBuilder struct Builder {
static func buildBlock<T>(_ x: T) -> T { x }
}
struct S {}
struct R<T> {
init(@Builder fn: () -> T) {}
}
// rdar://141168628 - Make sure we can compute the USR here without crashing.
R {
S()
// RUN: %sourcekitd-test -req=conformingmethods -pos %(line + 1):2 %s -- %s | %FileCheck %s
}
// CHECK: key.typeusr: "$s13rdar1411686281RVyAA1SVGD"

View File

@@ -65,4 +65,4 @@ func SArrayGen() -> [S] { return [] }
// CHECK6: <Container>$s21cursor_info_container1EOmD</Container>
// RUN: %sourcekitd-test -req=cursor -pos=37:22 %s -- %s | %FileCheck -check-prefix=CHECK7 %s
// CHECK7: <Container>$s21cursor_info_container1SVXSaD</Container>
// CHECK7: <Container>$sSay21cursor_info_container1SVGD</Container>