Skip to content

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

Merged
merged 1 commit into from
Mar 26, 2023
Merged

Warn if a package binary module is loaded from SDK #64600

merged 1 commit into from
Mar 26, 2023

Conversation

elsh
Copy link
Contributor

@elsh elsh commented Mar 24, 2023

  • Warns if a module loaded is a package module but not locally built.
  • Update a related diagnostic
    Resolves rdar://107074380

@elsh elsh requested review from xymus and nkcsgexi March 24, 2023 02:15
@elsh elsh force-pushed the es-warn branch 2 times, most recently from 5fe187f to 3bcd726 Compare March 24, 2023 02:17
@elsh
Copy link
Contributor Author

elsh commented Mar 24, 2023

@swift-ci smoke test

@@ -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()) {
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

@xymus
Copy link
Contributor

xymus commented Mar 24, 2023

cc @bnbarham You may like this, we're using the package knowledge and isNonUserModule to report if a module from the same project is loaded from a distributed source instead of a local build.


// 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
Copy link
Contributor

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?

Copy link
Contributor Author

@elsh elsh Mar 24, 2023

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
Copy link
Contributor

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.

@bnbarham
Copy link
Contributor

cc @bnbarham You may like this, we're using the package knowledge and isNonUserModule to report if a module from the same project is loaded from a distributed source instead of a local build.

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,
Copy link
Contributor

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?

Copy link
Contributor Author

@elsh elsh Mar 24, 2023

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.

Copy link
Contributor

@nkcsgexi nkcsgexi left a 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👍

@elsh
Copy link
Contributor Author

elsh commented Mar 24, 2023

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Mar 25, 2023

@swift-ci clean smoke test linux

@elsh
Copy link
Contributor Author

elsh commented Mar 25, 2023

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Mar 26, 2023

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Mar 26, 2023

@swift-ci test

@elsh elsh merged commit d900706 into main Mar 26, 2023
@elsh elsh deleted the es-warn branch March 26, 2023 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants