-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Warn if a package binary module is loaded from SDK #64600
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
Conversation
5fe187f
to
3bcd726
Compare
@swift-ci smoke test |
lib/Sema/TypeCheckDeclPrimary.cpp
Outdated
@@ -1960,9 +1960,23 @@ class DeclChecker : public DeclVisitor<DeclChecker> { | |||
// diagnostics. | |||
(void)ID->getDecls(); | |||
|
|||
auto target = ID->getModule(); | |||
if (target->isNonUserModule() && // target module is in distributed SDK | |||
getASTContext().LangOpts.PackageName == target->getPackageName().str()) { |
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.
Should we check that the package name is not empty to avoid this warning between two modules without a package name?
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.
good point, will update
|
||
// RUN: %target-swift-frontend -typecheck %t/Client1.swift -package-name libPkg -sdk %t/SDK -I %t -I %t/SDK/Frameworks/LibInSDK.framework/Modules 2> %t/result.output | ||
// RUN: %FileCheck %s < %t/result.output | ||
// CHECK: warning: module 'LibInSDK' is in package 'libPkg' but was loaded from SDK; modules of the same package are expected to be loaded from local build directory: {{.*}}/SDK/Frameworks/LibInSDK.framework/Modules/LibInSDK.swiftmodule/{{.*}}.swiftmodule |
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.
Since that should be on the import itself you could use -verify
mode to check the diagnostic.
cc @bnbarham You may like this, we're using the package knowledge and |
|
||
// RUN: %target-swift-frontend -typecheck %t/Client1.swift -package-name libPkg -sdk %t/SDK -I %t -I %t/SDK/Frameworks/LibInSDK.framework/Modules 2> %t/result.output | ||
// RUN: %FileCheck %s < %t/result.output | ||
// CHECK: warning: module 'LibInSDK' is in package 'libPkg' but was loaded from SDK; modules of the same package are expected to be loaded from local build directory: {{.*}}/SDK/Frameworks/LibInSDK.framework/Modules/LibInSDK.swiftmodule/{{.*}}.swiftmodule |
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.
modules of the same package are expected to be loaded from local build directory
Adds confusion IMO. It's not strictly true, since I could have various build directories and that would still be fine. It also begs the question as to what is the "local build directory" 😅.
I think just the prior warning is good enough (ie. module 'mod' is in package 'package' but was loaded from the SDK
). Or alternatively SDK module 'mod' should not be included in user-defined package 'package'
, which IIUC is more what the warning is about?
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.
updated the confusing part in the original message as "locally built from source only"
@@ -9,7 +9,7 @@ | |||
|
|||
// RUN: not %target-swift-frontend -module-name ClientInSamePkg %t/ClientLoadInterfaceModule.swift -emit-module -emit-module-path %t/ClientInSamePkg.swiftmodule -package-name mypkg -I %t 2> %t/resultA.output | |||
// RUN: %FileCheck %s -check-prefix CHECK-A < %t/resultA.output | |||
// CHECK-A: error: module 'LibFromInterface' is in package 'mypkg' but was built from interface '{{.*}}LibFromInterface.swiftinterface'; modules of the same package can only be loaded if built from source | |||
// CHECK-A: error: module 'LibFromInterface' is in package 'mypkg' but was built from interface; modules of the same package can only be loaded if built from source: {{.*}}LibFromInterface.swiftinterface |
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 feel similar about this error message as the one above, but I'm less sure of another way to word it. As a user I'm just not sure this would mean much to me. Really I want to know what I've done wrong. Maybe this is fine though since IIUC it would be fairly uncommon for a regular user to hit this.
Nice :) |
ERROR(in_package_module_not_compiled_from_source,Fatal, | ||
"module %0 is in package '%1' but was built from interface '%2'; " | ||
"modules of the same package can only be loaded if built from source", | ||
ERROR(in_package_module_not_compiled_from_source,none, |
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.
Do we use this error somewhere?
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.
Yes, it was already added to SerializationLoader::loadAST in main; its message is just updated in this PR.
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.
Issuing a warning for this case makes sense to me👍
@swift-ci smoke test |
@swift-ci clean smoke test linux |
@swift-ci smoke test |
Resolves rdar://107074380
@swift-ci smoke test |
@swift-ci test |
Resolves rdar://107074380