Skip to content

Separate parsing out Swift and Clang modules from the explicit modulemap #63697

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
Feb 20, 2023

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Feb 15, 2023

Since #63178 added support for Clang modules in the explicit module map, it used the convention of specifying artifacts of a Swift module with a given name and a Clang module with the same name under the same entry. This change separates an individual entry to represent an individual module, even if they have the same name (but one is Swift and one is Clang).

The current parsing logic just overwrites the corresponding entry module in a hashmap so we always only preserved the module that comes last, with the same name. This change separates the parsing of the modulemap JSON file to produce a separate Swift module map and Clang module map. The Swift one is used by the ExplicitSwiftModuleLoader, as before, and the Clang one is only used to populate the ClangArgs with the requried -fmodule-... flags and discarded.

@artemcm artemcm requested review from allevato and nkcsgexi February 15, 2023 23:28
@artemcm
Copy link
Contributor Author

artemcm commented Feb 15, 2023

@allevato I only now noticed that this format collated Swift and Clang module details, when they share a name. I would like to separate them to have an entry per-module. This way the ExplicitModuleLoader doesn't need to filter out Clang-only entries and it generally seems a bit cleaner to have an individual entry correspond to an individual entry.

@artemcm
Copy link
Contributor Author

artemcm commented Feb 15, 2023

@swift-ci test

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

Out of curiosity, why was the old behavior problematic? It seems like it should be fine if there's just one entry with a particular name in the list. Was some other tool like the dependency scanner writing the separate Swift/Clang entries instead?

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

Just saw your other comment while I was reading over the PR. For my particular use case it's marginally less attractive to have the entries separated due to the way they'll be generated (we use a single data structure to represent Swift and Clang modules together, and the structure before this PR lets us write out all the fields at the same time). But, I can make this work, so I don't have a strong opinion here if it makes something else in your tooling easier.

@artemcm
Copy link
Contributor Author

artemcm commented Feb 15, 2023

Out of curiosity, why was the old behavior problematic? It seems like it should be fine if there's just one entry with a particular name in the list. Was some other tool like the dependency scanner writing the separate Swift/Clang entries instead?

Yeah. I ran into this when adopting the Clang module entries in the driver, which generates and specifies these module maps with a per-dependency entry, because the dependency scanner produces per-dependency entries. (Such entries ended up overwriting each other if they had the same name) I could teach it to detect and collate dependencies with the same name into one entry, but thought that this approach would be a bit more explicit.

@allevato
Copy link
Member

It sounds like our dependency managers do the exact opposite thing, then 🙂 In this case, me iterating over the dependencies twice (once to emit the Swift entries and once for the Clang entries) is probably easier than you having to collate things together before writing, so I'm ok with this.

@artemcm
Copy link
Contributor Author

artemcm commented Feb 16, 2023

@swift-ci test

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Feb 16, 2023

@swift-ci test

@artemcm artemcm force-pushed the SeparateExplicitModuleInputMaps branch from 5a0bdab to aa34acd Compare February 16, 2023 18:54
@artemcm
Copy link
Contributor Author

artemcm commented Feb 16, 2023

@swift-ci test Windows platform

… map

Since swiftlang#63178 added support for Clang modules in the explicit module map, it is possible for there to be multiple modules with the same name: a Swift module and a Clang module. The current parsing logic just overwrites the corresponding entry module in a hashmap so we always only preserved the module that comes last, with the same name.

This change separates the parsing of the modulemap JSON file to produce a separate Swift module map and Clang module map. The Swift one is used by the 'ExplicitSwiftModuleLoader', as before, and the Clang one is only used to populate the ClangArgs with the requried -fmodule-... flags.
@artemcm artemcm force-pushed the SeparateExplicitModuleInputMaps branch from aa34acd to a0b5dd4 Compare February 17, 2023 17:04
@artemcm
Copy link
Contributor Author

artemcm commented Feb 17, 2023

@swift-ci test

@artemcm artemcm merged commit 8e0e51a into swiftlang:main Feb 20, 2023
@artemcm artemcm deleted the SeparateExplicitModuleInputMaps branch February 20, 2023 18:46
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