[PATCH] D113972: [RFC] [C++20] [Module] Support module partitions initially

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 16 01:23:54 PST 2021


ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, urnathan, hubert.reinterpretcast, erichkeane.
ChuanqiXu added a project: clang.
Herald added a subscriber: dexonsmith.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113972

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CXX/module/module.global.frag/Inputs/X-A.cppm
  clang/test/CXX/module/module.global.frag/Inputs/header.h
  clang/test/CXX/module/module.global.frag/p2.cpp
  clang/test/CXX/module/module.import/Inputs/M-Part.cppm
  clang/test/CXX/module/module.import/p8.cpp
  clang/test/CXX/module/module.private.frag/p1.cpp
  clang/test/CXX/module/module.reach/Inputs/p4/M-A.cppm
  clang/test/CXX/module/module.reach/Inputs/p4/M-B.cppm
  clang/test/CXX/module/module.reach/Inputs/p4/M.cppm
  clang/test/CXX/module/module.reach/p4/M-C.cppm
  clang/test/CXX/module/module.reach/p4/X.cpp
  clang/test/CXX/module/module.unit/Inputs/p3/X.cppm
  clang/test/CXX/module/module.unit/Inputs/p3/parta.cppm
  clang/test/CXX/module/module.unit/Inputs/p3/partb.cppm
  clang/test/CXX/module/module.unit/Inputs/p4/A-Foo.cppm
  clang/test/CXX/module/module.unit/Inputs/p4/A-Impl.cpp
  clang/test/CXX/module/module.unit/Inputs/p4/A-Internals.cppm
  clang/test/CXX/module/module.unit/Inputs/p4/A.cppm
  clang/test/CXX/module/module.unit/Inputs/p8/B-X1.cppm
  clang/test/CXX/module/module.unit/Inputs/p8/B-X2.cppm
  clang/test/CXX/module/module.unit/Inputs/p8/B-Y.cppm
  clang/test/CXX/module/module.unit/Inputs/p8/B.cppm
  clang/test/CXX/module/module.unit/p3.cpp
  clang/test/CXX/module/module.unit/p3/FromNonModule.cpp
  clang/test/CXX/module/module.unit/p3/FromWrongModule.cpp
  clang/test/CXX/module/module.unit/p3/simple.cpp
  clang/test/CXX/module/module.unit/p3/user.cpp
  clang/test/CXX/module/module.unit/p4/user.cpp
  clang/test/CXX/module/module.unit/p8.cpp
  clang/test/CXX/module/module.unit/p8/B-Impl.cppm
  clang/test/CXX/module/module.unit/p8/ImplicitImport.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113972.387526.patch
Type: text/x-patch
Size: 29938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211116/eedb6768/attachment-0001.bin>


More information about the cfe-commits mailing list