Swift: more mangling

This commit is contained in:
Paolo Tranquilli
2023-03-21 15:26:07 +01:00
parent 2592129d83
commit 0aed7d56c2
12 changed files with 77 additions and 99 deletions

View File

@@ -61,6 +61,14 @@ static std::string mangledDeclName(const swift::ValueDecl& decl) {
// prefix adds a couple of special symbols, we don't necessary need them
return mangler.mangleEntity(&decl);
}
if (decl.getKind() == swift::DeclKind::GenericTypeParam) {
// internal mangling does not distinguish generic type parameters with the same name and
// position of different functions. We prepend the context (that is, the function) to
// circumvent that
auto context = llvm::dyn_cast<swift::ValueDecl>(decl.getDeclContext()->getAsDecl());
assert(context);
return mangledDeclName(*context) + '_' + mangler.mangleAnyDecl(&decl, /* prefix = */ false);
}
return mangler.mangleAnyDecl(&decl, /* prefix = */ false);
}
@@ -71,6 +79,7 @@ static fs::path getFilename(swift::ModuleDecl& module,
return resolvePath(primaryFile->getFilename());
}
if (lazyDeclaration) {
<<<<<<< HEAD
// this code will be thrown away in the near future
auto decl = llvm::dyn_cast<swift::ValueDecl>(lazyDeclaration);
assert(decl);
@@ -85,6 +94,11 @@ static fs::path getFilename(swift::ModuleDecl& module,
// half a SHA2 is enough
ret += std::string_view(mangled).substr(0, mangled.size() / 2);
return ret;
=======
// static int i;
// return mangledDeclName(*lazyDeclaration) + std::to_string(i++);
return mangledDeclName(*lazyDeclaration);
>>>>>>> 4cbad80695 (Swift: more mangling)
}
// PCM clang module
if (module.isNonSwiftModule()) {