Skip to content

Commit 6dceb14

Browse files
Merge pull request #2246 from adrian-prantl/70552614-next
Disable AST type caching for SILFunctionTypes since the mapping isn't
2 parents fa825fc + 9d76d97 commit 6dceb14

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4156,7 +4156,7 @@ void SwiftASTContext::CacheDemangledTypeFailure(ConstString name) {
41564156
/// What we should really do is only mangle AST types in DebugInfo, but that
41574157
/// requires some more plumbing on the Swift side to properly handle generic
41584158
/// specializations.
4159-
swift::Type convertSILFunctionTypesToASTFunctionTypes(swift::Type t) {
4159+
static swift::Type ConvertSILFunctionTypesToASTFunctionTypes(swift::Type t) {
41604160
return t.transform([](swift::Type t) -> swift::Type {
41614161
if (auto *silFn = t->getAs<swift::SILFunctionType>())
41624162
return swift::FunctionType::get({}, t->getASTContext().TheEmptyTupleType);
@@ -4276,14 +4276,18 @@ swift::TypeBase *SwiftASTContext::ReconstructType(ConstString mangled_typename,
42764276
.getPointer();
42774277

42784278
if (found_type) {
4279-
found_type =
4280-
convertSILFunctionTypesToASTFunctionTypes(found_type).getPointer();
4281-
CacheDemangledType(mangled_typename, found_type);
4282-
CompilerType result_type = ToCompilerType(found_type);
4283-
assert(&found_type->getASTContext() == ast_ctx);
4279+
swift::TypeBase *ast_type =
4280+
ConvertSILFunctionTypesToASTFunctionTypes(found_type).getPointer();
4281+
// This transformation is lossy: all SILFunction types are mapped
4282+
// to the same AST type. We thus cannot cache the result, since
4283+
// the mapping isn't bijective.
4284+
if (ast_type == found_type)
4285+
CacheDemangledType(mangled_typename, ast_type);
4286+
CompilerType result_type = ToCompilerType(ast_type);
4287+
assert(&ast_type->getASTContext() == ast_ctx);
42844288
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- found %s", mangled_cstr,
42854289
result_type.GetTypeName().GetCString());
4286-
return found_type;
4290+
return ast_type;
42874291
}
42884292

42894293
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- not found", mangled_cstr);

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,12 @@ static bool ContainsSugaredParen(swift::Demangle::NodePointer node) {
14201420
/// Compare two swift types from different type systems by comparing their
14211421
/// (canonicalized) mangled name.
14221422
template <> bool Equivalent<CompilerType>(CompilerType l, CompilerType r) {
1423+
// See comments in SwiftASTContext::ReconstructType(). For
1424+
// SILFunctionTypes the mapping isn't bijective.
1425+
auto *ast_ctx = llvm::cast<SwiftASTContext>(r.GetTypeSystem());
1426+
if (((void *)ast_ctx->ReconstructType(l.GetMangledTypeName())) ==
1427+
r.GetOpaqueQualType())
1428+
return true;
14231429
ConstString lhs = l.GetMangledTypeName();
14241430
ConstString rhs = r.GetMangledTypeName();
14251431
if (lhs == ConstString("$sSiD") && rhs == ConstString("$sSuD"))

0 commit comments

Comments
 (0)