Page MenuHomePhabricator

Allow searching for prebuilt implicit modules.
AcceptedPublic

Authored by arames on Oct 15 2019, 10:02 AM.

Details

Summary

The behavior is controlled by the -fprebuilt-implicit-modules option, and
allows searching for implicit modules in the prebuilt module cache paths.

The current command-line options for prebuilt modules do not allow to easily
maintain and use multiple versions of modules. Both the producer and users of
prebuilt modules are required to know the relationships between compilation
options and module file paths. Using a particular version of a prebuilt module
requires passing a particular option on the command line (e.g.
-fmodule-file=[<name>=]<file> or -fprebuilt-module-path=<directory>).

However the compiler already knows how to distinguish and automatically locate
implicit modules. Hence this proposal to introduce the
-fprebuilt-implicit-modules option. When set, it enables searching for
implicit modules in the prebuilt module paths (specified via
-fprebuilt-module-path). To not modify existing behavior, this search takes
place after the standard search for prebuilt modules. If not

Here is a workflow illustrating how both the producer and consumer of prebuilt
modules would need to know what versions of prebuilt modules are available and
where they are located.

clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules_v1 <config 1 options>
clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules_v2 <config 2 options>
clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules_v3 <config 3 options>

clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap -fprebuilt-module-path=prebuilt_modules_v1 <config 1 options>
clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap <non-prebuilt config options>

With prebuilt implicit modules, the producer can generate prebuilt modules as
usual, all in the same output directory. The same mechanisms as for implicit
modules take care of incorporating hashes in the path to distinguish between
module versions.

Note that we do not specify the output module filename, so -o implicit modules are generated in the cache path prebuilt_modules.

clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules <config 1 options>
clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules <config 2 options>
clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules <config 3 options>

The user can now simply enable prebuilt implicit modules and point to the
prebuilt modules cache. No need to "parse" command-line options to decide
what prebuilt modules (paths) to use.

clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap -fprebuilt-module-path=prebuilt_modules -fprebuilt-implicit-modules <config 1 options>
clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap -fprebuilt-module-path=prebuilt_modules -fprebuilt-implicit-modules <non-prebuilt config options>

This is for example particularly useful in a use-case where compilation is
expensive, and the configurations expected to be used are predictable, but not
controlled by the producer of prebuilt modules. Modules for the set of
predictable configurations can be prebuilt, and using them does not require
"parsing" the configuration (command-line options).

Diff Detail

Event Timeline

arames created this revision.Oct 15 2019, 10:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2019, 10:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
arames edited the summary of this revision. (Show Details)Oct 15 2019, 10:03 AM
arames added reviewers: bruno, rsmith.
arames updated this revision to Diff 228267.Nov 7 2019, 9:39 AM

Rebase.

Ping.
Still looking for someone to take a look. Happy to answer any questions.

arames updated this revision to Diff 264096.May 14 2020, 2:38 PM

Rebase on top of tree.

arames updated this revision to Diff 279263.Jul 20 2020, 8:39 AM

Rebase on top-of-tree.

Bigcheese added inline comments.Jul 30 2020, 1:31 PM
clang/docs/Modules.rst
231
295

I also think it's important to point out here that disabling the module hash means you are responsible for making sure the modules are compatible. How to do this is mentioned below, but it's never stated why you would want to do this.

clang/test/Modules/prebuilt-implicit-modules.m
10

Is this actually supposed to be module_e? I would expect this to be verifying that it didn't add module_a to %t1.

arames marked 2 inline comments as done.Jul 31 2020, 9:56 AM
arames added inline comments.
clang/docs/Modules.rst
295

Fixed the typo.

Good point.
I am refactoring the examples to make everything clearer.

303

Fixed a few other typos in the examples as well.

clang/test/Modules/prebuilt-implicit-modules.m
10

That was a typo. Fixed.

arames updated this revision to Diff 282335.Jul 31 2020, 3:29 PM
arames marked an inline comment as done.

Addressed review comments.

  • Fixed typos in the doc.
  • Added doc about module compatibility.
  • Cleaned and tested commands in the doc.
  • Reworked module hash code to not require -fmodules-cache-path when using -fprebuilt-implicit-modules.
arames updated this revision to Diff 282336.Jul 31 2020, 3:34 PM

Fix a typo.

arames added inline comments.Jul 31 2020, 3:36 PM
clang/include/clang/Lex/HeaderSearch.h
187

In the previous version of this patch, this value was derived from the stem of ModuleCachePath.
However we do not want to depend on ModuleCachePath being set to be able to retrieve the module hash. See the update in the test.

clang/test/Modules/prebuilt-implicit-modules.m
12

For this to be possible, the computation of the paths to (potential) implicit prebuilt modules cannot depend on the cache path being set.

This revision is now accepted and ready to land.Wed, Sep 23, 4:30 PM