Page MenuHomePhabricator

[RFC] [C++20] [Module] Support module partitions initially
AbandonedPublic

Authored by ChuanqiXu on Nov 16 2021, 1:23 AM.

Details

Summary

This file intends to support: https://eel.is/c++draft/module.unit#3.

Module partition should be a special module interface which is imported by module units in the same module.
Note that although there is implementation module partition, it should be a module interface too since it could be imported by module units in the same module.

For a module partition primary.module.name:partition.name, the user should generate a pcm file with name primary.module.name-partition.name.pcm. Simply replace : with -. And when we try to import a partition with partition-name in primary.module.name, the compiler would try to search for primary.module.name-partition.name.pcm in the given path. The strategy to replace : with - keeps consistency with GCC.

The key problem I see in introducing module partitions is that the judgement for modules. Before, there would be only module interface unit for each module. But now, it would be many partitions which are belongs in the same module. The judgement of modules matter when the compiler want to decide whether or not a declaration is visible or reachable.

And my solution is to compare the prefix of the name before '-' to judge whether or not the two module belongs to the same module. Since '-' shouldn't show up in the original module name by the definition.
For example, 'X-A' and X-B are in the same module. But X-A and Y-A are not.

BTW, it would be problem if we want to import a module partition in another module by renaming. See clang/test/CXX/module/module.unit/p3/FromWrongModule.cpp for example.

The method looks simple and available in simple demos. I want to hear more opinions.

Test Plan: check-all

Diff Detail