Skip to content

Disable AST type caching for SILFunctionTypes since the mapping isn't #2245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4180,7 +4180,7 @@ void SwiftASTContext::CacheDemangledTypeFailure(ConstString name) {
/// What we should really do is only mangle AST types in DebugInfo, but that
/// requires some more plumbing on the Swift side to properly handle generic
/// specializations.
swift::Type convertSILFunctionTypesToASTFunctionTypes(swift::Type t) {
static swift::Type ConvertSILFunctionTypesToASTFunctionTypes(swift::Type t) {
return t.transform([](swift::Type t) -> swift::Type {
if (auto *silFn = t->getAs<swift::SILFunctionType>())
return swift::FunctionType::get({}, t->getASTContext().TheEmptyTupleType);
Expand Down Expand Up @@ -4300,14 +4300,18 @@ swift::TypeBase *SwiftASTContext::ReconstructType(ConstString mangled_typename,
.getPointer();

if (found_type) {
found_type =
convertSILFunctionTypesToASTFunctionTypes(found_type).getPointer();
CacheDemangledType(mangled_typename, found_type);
CompilerType result_type = ToCompilerType(found_type);
assert(&found_type->getASTContext() == ast_ctx);
swift::TypeBase *ast_type =
ConvertSILFunctionTypesToASTFunctionTypes(found_type).getPointer();
// This transformation is lossy: all SILFunction types are mapped

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just get rid of this mapping? IIRC, the old type reconstruction code didn't handle SILFunctionType at all, always returning () -> (). When I implemented full type reconstruction, there were a few places in lldb that weren't set up to handle a SILFunctionType so I added this hack to get the old behavior back. We should just remove it.

// to the same AST type. We thus cannot cache the result, since
// the mapping isn't bijective.
if (ast_type == found_type)
CacheDemangledType(mangled_typename, ast_type);
CompilerType result_type = ToCompilerType(ast_type);
assert(&ast_type->getASTContext() == ast_ctx);
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- found %s", mangled_cstr,
result_type.GetTypeName().GetCString());
return found_type;
return ast_type;
}

LOG_PRINTF(LIBLLDB_LOG_TYPES, "(\"%s\") -- not found", mangled_cstr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,12 @@ static bool ContainsSugaredParen(swift::Demangle::NodePointer node) {
/// Compare two swift types from different type systems by comparing their
/// (canonicalized) mangled name.
template <> bool Equivalent<CompilerType>(CompilerType l, CompilerType r) {
// See comments in SwiftASTContext::ReconstructType(). For
// SILFunctionTypes the mapping isn't bijective.
auto *ast_ctx = llvm::cast<SwiftASTContext>(r.GetTypeSystem());
if (((void *)ast_ctx->ReconstructType(l.GetMangledTypeName())) ==
r.GetOpaqueQualType())
return true;
ConstString lhs = l.GetMangledTypeName();
ConstString rhs = r.GetMangledTypeName();
if (lhs == ConstString("$sSiD") && rhs == ConstString("$sSuD"))
Expand Down