From 810a98c2effbcfbcf212a13c14acfc6e1eaf212e Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Thu, 13 Jun 2024 17:00:13 -0700 Subject: [PATCH] Teach "find imports" to equate overlay modules with their underlying modules The operation that finds the best import for a given declaration was treating an overload module as being distinct from its underlying module, even though they both have the same name and are imported together. Teach it to treat those modules as equivalent, so we correctly identify the right import declaration for something that comes from the underlying module. Fixes rdar://129401319. --- lib/AST/Module.cpp | 7 +++++-- ...edates_concurrency_import_foundation_darwin.swift | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/Concurrency/predates_concurrency_import_foundation_darwin.swift diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 7b7a88a8bfc1b..86ad07fcc1dfc 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -2668,9 +2668,11 @@ ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf, auto &ctx = sf->getASTContext(); auto imports = sf->getImports(); + auto mutModule = const_cast(module); // Look to see if the owning module was directly imported. for (const auto &import : imports) { - if (import.module.importedModule == module) + if (import.module.importedModule + ->isSameModuleLookingThroughOverlays(mutModule)) return import; } @@ -2679,7 +2681,8 @@ ImportDeclRequest::evaluate(Evaluator &evaluator, const SourceFile *sf, for (const auto &import : imports) { auto &importSet = importCache.getImportSet(import.module.importedModule); for (const auto &transitive : importSet.getTransitiveImports()) { - if (transitive.importedModule == module) { + if (transitive.importedModule + ->isSameModuleLookingThroughOverlays(mutModule)) { return import; } } diff --git a/test/Concurrency/predates_concurrency_import_foundation_darwin.swift b/test/Concurrency/predates_concurrency_import_foundation_darwin.swift new file mode 100644 index 0000000000000..3ebe07367a0e5 --- /dev/null +++ b/test/Concurrency/predates_concurrency_import_foundation_darwin.swift @@ -0,0 +1,12 @@ +// RUN: %empty-directory(%t) + +// RUN: %target-swift-frontend -swift-version 6 -I %t %s -emit-sil -o /dev/null -verify -parse-as-library + +// REQUIRES: OS=macosx + +import Foundation +@preconcurrency import Darwin + +func mach_task_self() -> mach_port_t { + return mach_task_self_ +}