Skip to content

[Serialization] Ignore the exported module name for XRefs #41984

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 23, 2022

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Mar 23, 2022

Write the real module name for XRefs in swiftmodule files instead of the exported module name, which is taken from export_as declarations in module maps. Swiftmodule files are internal details now, they should represent the
truth. Swiftinterface files still display the export as name, so distributed modules will take care of hiding the private module with the export_as declaration.

We keep using the exported module name for the extensions lookup table as clients should still expect the exported name. However, we may need to write both alternatives in the lookup table in the future if extensions can't be found from clients not importing the exported as module.

rdar://90272035

Write the real module name for XRefs in swiftmodule files instead of the
exported module name, from `export_as` declarations in module maps.
Swiftmodule files are internal details now, they should represent the
truth.

We keep using the exported module name for the extensions lookup table
as clients should still use the exported name. However we may need to
write both alternatives in the lookup table in the future if extensions
can't be found from clients not importing the exported as module.

rdar://90272035
@xymus xymus requested a review from bnbarham March 23, 2022 19:45
@xymus
Copy link
Contributor Author

xymus commented Mar 23, 2022

@swift-ci Please smoke test

@@ -203,7 +203,8 @@ namespace {
int32_t getNameDataForBase(const NominalTypeDecl *nominal,
StringRef *dataToWrite = nullptr) {
if (nominal->getDeclContext()->isModuleScopeContext())
return -Serializer.addContainingModuleRef(nominal->getDeclContext());
return -Serializer.addContainingModuleRef(nominal->getDeclContext(),
/*ignoreExport=*/false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this one use the exported name still?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used by type-checking to lookup extensions from imported modules. At this point looking them up from what is visible by the client makes sense so I kept that logic as is.

This will likely require more work, it may be both on the lookup side and on what we write to the table. At least with the lookup table in the worst case the compiler won't see some extensions and their members, but it shouldn't crash.


// Use the overlay with private frameworks.
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -emit-sil -o /dev/null -F %S/Inputs/privateframeworks/withprivate -swift-version 4 %s -import-objc-header %S/Inputs/privateframeworks/bridging-somekitcore.h -verify
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -emit-sil -o /dev/null -F %S/Inputs/privateframeworks/withprivate -swift-version 4 %s -import-objc-header %S/Inputs/privateframeworks/bridging-somekitcore.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch from -verify -> not confused me for a little bit there, but IIUC it was superfluous before because no errors were generated. And now there's only one case with -verify, where you do actually check it errors.

So the only actual change here is the addition of that extra test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the previous presence of -verify only report unexpected warnings I suppose. We're losing this protection by removing -verify from all other RUN lines but it's not a very likely scenario to get warnings here.

The main change is really that using the binary swiftmodules doesn't work anymore, but rebuilding from the swiftinterface still provides the same old behavior.

@xymus xymus merged commit d858ac3 into swiftlang:main Mar 23, 2022
@xymus xymus deleted the export-as-xref branch March 23, 2022 22:12
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.

2 participants