[Serialization] Teach ASTSectionImporter to filter by triple.

On macOS it is possible for one application to contain Swift modules compiled
for different triples that are incompatible as far as the Swift compiler is
concerned. Examples include an iOS simulator application hunning on a macOS
host, or a macCatalyst application running on macOS. A debugger might see
.swift_ast sections for all triples at the same time. This patch adds an
interface to let the client provide a triple to filter Swift modules in an
ASTSection.

rdar://107869141
This commit is contained in:
Adrian Prantl
2023-05-05 15:51:08 -07:00
parent 686023861e
commit a3a43d46c5
6 changed files with 42 additions and 6 deletions

View File

@@ -91,6 +91,16 @@ static bool isTargetTooNew(const llvm::Triple &moduleTarget,
return ctxTarget.isOSVersionLT(moduleTarget);
}
namespace swift {
namespace serialization {
bool areCompatible(const llvm::Triple &moduleTarget,
const llvm::Triple &ctxTarget) {
return areCompatibleArchitectures(moduleTarget, ctxTarget) &&
areCompatibleOSs(moduleTarget, ctxTarget);
}
} // namespace serialization
} // namespace swift
ModuleFile::ModuleFile(std::shared_ptr<const ModuleFileSharedCore> core)
: Core(core) {
assert(!core->hasError());
@@ -249,8 +259,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
ASTContext &ctx = getContext();
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
if (!areCompatible(moduleTarget, ctx.LangOpts.Target)) {
status = Status::TargetIncompatible;
if (!recoverFromIncompatibility)
return error(status);