-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Clang Importer] Do not rely on being able to always import Foundation on-demand #34331
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
[Clang Importer] Do not rely on being able to always import Foundation on-demand #34331
Conversation
@swift-ci please test |
@swift-ci please smoke test |
@brentdax, @slavapestov, I don't have as deep of an understanding to know what I may be breaking here, really curious to hear what you think. |
@swift-ci please test |
@swift-ci Please Test Source Compatibility |
4 similar comments
@swift-ci Please Test Source Compatibility |
@swift-ci Please Test Source Compatibility |
@swift-ci Please Test Source Compatibility |
@swift-ci Please Test Source Compatibility |
@swift-ci Please Test Source Compatibility Debug |
2 similar comments
@swift-ci Please Test Source Compatibility Debug |
@swift-ci Please Test Source Compatibility Debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will be okay, but I wouldn't be surprised if we see regressions in some weird edge cases where ClangImporter implicitly loading Foundation turns out to have been load-bearing. We'll need to keep an eye out for that.
@@ -5583,8 +5583,7 @@ namespace { | |||
} | |||
|
|||
static bool conformsToProtocolInOriginalModule(NominalTypeDecl *nominal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Now that we're not passing in Foundation, this should probably be called something like conformsToProtocolInFoundationModule()
.
@swift-ci please smoke test |
@swift-ci please smoke test Windows platform |
@swift-ci please smoke test |
@swift-ci please smoke test macOS platform |
…n on-demand When importing Clang types. This is not an option with Explicit Module Builds. If the module being built does not (directly or transitively) depend on `Foundation`, then attempting to load it will produce an error because Implicit module loading is no longer allowed.. This change addresses a small number of cases where ClangImporter relies on being able to load `Foundation` on-demand: - When importing a single Decl from a clang module, we check whether it has certain conformances by checking all extensions of the NominalTypeDecl of the Decl in question, to see if any of the extensions contain the conformance we are looking for, but we only check extensions whose parent module is either the original module of the NominalTypeDecl or the overlay module of the NominalTypeDecl or Foundation. It seems that we do not need to actually import `Foundation` here, just checking the module Identifier should be sufficient. - In `maybeImportNSErrorOutParameter`, change the behavior to have an exit condition based on whether `Foundation` can be imported, before attempting to load it. - When checking whether or not we are allowed to bridge an Objective-C type, it also looks sufficient the query whether or not `Foundation` *can* be imported, without loading it.
It looks like it wasn't load-bearing when I put up the PR, but became so since then for these tests:
|
a30cb65
to
e98dbc8
Compare
@swift-ci please smoke test |
@swift-ci please smoke test macOS platform |
4 similar comments
@swift-ci please smoke test macOS platform |
@swift-ci please smoke test macOS platform |
@swift-ci please smoke test macOS platform |
@swift-ci please smoke test macOS platform |
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
@swift-ci please smoke test Windows platform |
1 similar comment
@swift-ci please smoke test Windows platform |
When importing Clang types.
This is not an option with Explicit Module Builds. If the module being built does not (directly or transitively) depend on
Foundation
, then attempting to loadFoundation
will produce an error because implicit module loading is no longer allowed.This change addresses a small number of cases where ClangImporter relies on being able to load
Foundation
on-demand:NominalTypeDecl
of theDecl
in question, to see if any of the extensions contain the conformance we are looking for, but we only check extensions whose parent module is either the original module of theNominalTypeDecl
or the overlay module of theNominalTypeDecl
orFoundation
. It seems that we do not need to actually importFoundation
here, just checking the moduleIdentifier
should be sufficient.maybeImportNSErrorOutParameter
, change the behavior to have an exit condition based on whetherFoundation
can be imported, before attempting to load it.Foundation
can be imported, without loading it.Resolves rdar://70381338