Skip to content

Commit 27b135c

Browse files
authored
exports: restore or explain the remaining names of #2; check the reachable export set in CI (#11)
* exports: restore the names #2 left unanalysed, declare the rest unreachable Restored: - functional imports function: overloaded_function takes its targets as boost::function. The edge was invisible to the generator (partial specializations, includes inside the library's own detail/ headers). - concept_check owns boost/concept_archetype.hpp (regex reaches the archetypes again; concept_check exports them for the first time). - utility owns boost/call_traits.hpp (wave reaches call_traits again); variant imports utility for it. Declared, with the reason, by the new policy rule [[unreachable]] and listed in skipped.txt: names of include-only libraries (MPL, Parameter, Fusion) that the pre-#1 generator listed again for every specialization it met, two Container implementation details, and the names of the headers cobalt and geometry leave out. skipped.txt also names the target of each skip-directive, and a drop by the spelling an importer loses (boost::size, not std::size). * ci: check_reachable: a name importers could spell may only go with a reason gen_exports.py --check proves the committed lists are what the generator writes; it cannot see that they lost names (#5 lost nine with verify-scripts green). check_reachable.py compares what each module's importers reach with 9953323 (main before #1) and with the CI base. A lost (module, name) pair must be explained in skipped.txt by the module it went from: a drop, an unreachable, or a skip-directive whose target still has the name. An entry for a name the module does reach is an error. verify_generated.py runs it. * docs: the unreachable rule and the reachable-export check; design record
1 parent e2f10c6 commit 27b135c

38 files changed

Lines changed: 1196 additions & 136 deletions
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
subject: generator
3+
status: landed
4+
---
5+
6+
# 可达导出集合检查与 issue #2 剩余名称的处理
7+
8+
来源:issue #2 的第三、四条验收标准(未分析的小组逐个确认;verify-scripts 中加入
9+
可达导出集合检查)。前两条见 [`republish`](2026-11-28-dll-fs-republish-design.md)
10+
(PR #9)与 [`skip-directive`](2026-11-28-skip-directive-design.md)(PR #10)。
11+
12+
## 现状
13+
14+
在 `e2f10c68` 上与 `99533232`(#1 之前的 main)比较每个模块的可达名称。按
15+
"模块自己原来就导出、现在够不到"归到根上,除 #10 已说明的三个 detail 组之外,
16+
共 72 处(模块,名称)、37 个名称:issue 列出的小组,加上 issue 之后由 #5 带来的 9 个名称
17+
(`boost::size`、cobalt 的 main 三个、geometry 的 `fusion_adapt_detail` 三个与
18+
`mpl::count_if`、`mpl::aux::next_if`)。没有一处是只因为少了 `export import`。
19+
20+
## 原因
21+
22+
**旧生成器按特化重复导出。** 它用 libclang 的 USR 作键,签名里提到的特化有自己的
23+
USR:`function<int(int)>` 是 `c:@N@boost@S@function>#FI(#I)`,主模板是
24+
`c:@N@boost@ST>1#T@function`。认领表里没有前者,于是它被当成新实体,又导出一次
25+
`using boost::function;`。用基线的 `closure_from` 对一个合成 TU 实跑确认。#1 之后按
26+
主模板作键,名称只归第一个认领的模块;这些重复导出随之消失。
27+
28+
所以问题变成:每个模块对这个名称的依赖是不是真的,以及谁应当拥有它。
29+
30+
## 逐组处理
31+
32+
| 名称 | 模块 | 处理 |
33+
|---|---|---|
34+
| `boost::function` | functional(accumulators、bimap、multi_array、numeric 经由它) | **补回**:`[functional.deps] add = ["function"]` |
35+
| `*_archetype` ×3 | regex | **补回**:`boost/concept_archetype.hpp` 归 concept_check |
36+
| `boost::call_traits` | wave | **补回**:`boost/call_traits.hpp` 归 utility |
37+
| `boost::mpl` ×14、`mpl::aux` ×2(46 处) | 13 个 | 说明:`[[unreachable]]` |
38+
| `boost::parameter` ×4 | accumulators、graph、heap、lockfree | 说明:`[[unreachable]]` |
39+
| `fusion::deque` | hana | 说明:`[[unreachable]]` |
40+
| `container::(make_)transform_iterator` | interprocess | 说明:`[[unreachable]]` |
41+
| `cobalt::main` 等 3 个 | cobalt | 说明:`[[unreachable]]` |
42+
| `fusion_adapt_detail` ×3、`mpl::count_if`、`mpl::aux::next_if` | geometry | 说明:`[[unreachable]]` |
43+
| `boost::size` | core | 已有 `drop`,改为按导出写法记录 |
44+
45+
- **function**:`boost::overloaded_function` 的构造函数以 `boost::function` 为参数,
46+
是公开接口。写出它的是 `overloaded_function_detail::base` 的偏特化,包含它的是
47+
functional 自己的 `detail/` 头文件;签名闭包不走偏特化,包含边不读库自己的
48+
`detail/`,两边都看不到。上游 CMake 也链接 `Boost::function`。
49+
- **archetype、call_traits**:两个头文件在 `boost/` 顶层,文件名不是库名,没有归属,
50+
于是先处理到的 iterator、variant 认领了它们,而写进文档的 concept_check、utility
51+
反而没有导出。归属改正后,regex、wave 通过已有的边可达。concept_check 多导出 74 个
52+
名称,iterator 少 74 个;utility 多 3 个,variant 少 3 个。variant 因此需要到
53+
utility 的边(上游 CMake 同样链接),bimap、serialization 的这条边由生成器自己得出。
54+
- **mpl、parameter、fusion**:这些库只以头文件方式使用(usage.md §2.3),没有模块
55+
拥有它们的名称。在官方发布包 1.92.0 的 `libs/<lib>` 全部文档、示例和测试中搜索
56+
这 56 处的每个写法,只有两处命中:accumulators 参考手册里静态成员的类型
57+
`parameter::keyword`,hana 的 fusion 示例(它自己包含 `<boost/fusion/...>`)。
58+
- **cobalt、geometry**:头文件有意不进 GMF,原因早已写在 usage.md §6,只是
59+
`skipped.txt` 没有记录。`count_if.hpp` 在 geometry 中只有 `boost_fusion.hpp` 包含。
60+
61+
issue 正文中"`mpl::aux::template_arity`、`mpl::order_impl`、`boost::parameter` 已在
62+
`skipped.txt` 中"的说法不再成立:前两个现在没有条目;flyweight 的 `drop` 说明不了
63+
heap、lockfree、graph 为什么丢了 `parameter` 的名称。
64+
65+
## 决定
66+
67+
**`[[unreachable]]`**(顶层,不属于某个库):`reason` 加 `names = {名称 = [模块]}`。
68+
生成器每个(模块,名称)写一行 `<lib> unreachable <name> -- <reason>`;未知模块、
69+
空原因、重复条目报错。它不影响导出,也不进入各库的策略摘要。
70+
71+
**`tools/ci/check_reachable.py`**,由 `verify_generated.py` 在 `gen_exports.py --check`
72+
之后运行:
73+
74+
- 可达集合与 issue 中脚本的定义相同:自己的 `.inc` 加上 `src/*.cppm` 中
75+
`export import` 的传递闭包。解析补上了运算符、别名声明和命名空间别名。
76+
- **按(模块,名称)匹配。** 一个条目只说明它自己的模块。模块自己导出过的名称,
77+
必须有自己的条目;只是从导入得来的名称,由丢掉它的那个模块说明。去掉了导入、
78+
而被导入模块仍有该名称时,报在去掉导入的模块上。
79+
- **`skip-directive` 只说明经由指令的写法**:`<ns>::X` 丢失时,要求 `<target>::X` 仍然
80+
可达。为此 `skipped.txt` 的这些行加上了 `using <target>, ...`。否则
81+
`ublas::detail` 自己声明的名称丢了,也会被这一行盖过去。
82+
- **`unreachable` 过期即报错**:模块实际可达该名称。
83+
- **两个基线**:固定的 `99533232`,以及 CI 的基准(PR 的 merge base,或 push 之前的
84+
提交)。只有前者的话,之后新增的名称(`boost::dll::fs` 的大部分、conversion 模块)
85+
再丢失就看不出来;只有后者的话,合并之后说明就再也不受检查。
86+
- 基线与被删除的模块写成脚本中的常量,升级 Boost 时移动基线的办法写在旁边。
87+
88+
**`drop` 按导出写法记录**:`core drop std::size` 改为 `core drop boost::size`,
89+
`align drop std::alignment_of` 同理。导入者丢失的是前者。
90+
91+
## 验证
92+
93+
- 反向路径(真实数据的副本):去掉 functional 的 function 导入、删掉
94+
`dll.inc` 中 `unique_path`、删掉一条 `unreachable`、删掉 `core drop`、加一条过期条目、
95+
从 `numeric.inc` 删掉 `ublas::matrix`、删掉 crc 模块,七种都报错并指出位置。
96+
- 用 #5 的树(`34d6fc8c`,当时 verify-scripts 通过)运行:912 处未说明。
97+
- 正向:对两个基线都是 0 处未说明;与 `e2f10c68` 相比没有任何模块少名称。
98+
99+
## 否决的做法
100+
101+
- **`drop` 不再占用无主名称的归属**:flyweight 丢弃的 `boost::parameter` 名称,后面的
102+
库也不再导出。试做并全量生成:heap 补回 3 个名称,lockfree、graph 仍然够不到(没有到
103+
heap 的边),而 heap 多导出 48 个 `parameter::aux`,statechart 多导出 9 个
104+
`boost::detail` 的实现细节。收益小于代价。
105+
- **无主名称由每个提到它的模块各自导出**:可以补回全部 mpl 名称,但每个模块的导出都会
106+
大幅增加,且让"碰巧可达"变成接口。
107+
- **按命名空间放行 `boost::mpl`、`boost::parameter`**:会让以后的丢失再次静默。
108+
- **把"每个旧名称仍可达"写进 `gen_exports.py --check`**:那里没有历史,也不看
109+
`src/*.cppm` 的导入图。
110+
- **提交一份可达集合的快照文件**:约 16 MB,且减少只体现为 diff,不会报错。
111+
112+
## 顺带发现(未处理)
113+
114+
包含边不读库自己 `detail/` 头文件中的 `#include`(`lib_deps` 在目标库的根上停止)。
115+
按传递闭包计算,全仓有 56 条这样的边不在 `.deps` 中(例如 numeric → units、
116+
gil → filesystem);哪些对导入者有意义需要逐条分析。
117+
118+
## 测试
119+
120+
`tools/tests/test_check_reachable.py`(解析、可达闭包、归因、`skip-directive`、过期条目)、
121+
`tools/tests/test_gen_exports_unreachable.py`(条目、报错、`skipped.txt` 往返)。
122+
`tests/{functional,concept_check,utility,variant}.cpp` 与 `tests/regex/smoke.cpp`
123+
断言补回的名称。

‎.agents/docs/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
- `todos/` 放尚未完成的工作项,它们不是决定的记录。
2828
- 移动或改名用 `tools/doc-tools/move_record.py`,它同时改写仓库中对该文件的引用。
2929

30-
共 30 篇记录(其中 0 篇已归档),1 项待办。
30+
共 31 篇记录(其中 0 篇已归档),1 项待办。
3131

3232
## 进行中
3333

@@ -45,6 +45,7 @@
4545

4646
### generator
4747

48+
- [可达导出集合检查与 issue #2 剩余名称的处理](2026-11-29-reachable-exports-design.md) — landed
4849
- [不跟随的 using 指令必须声明:策略 `skip-directive`](2026-11-28-skip-directive-design.md) — landed
4950
- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed
5051

@@ -65,6 +66,7 @@
6566

6667
### 2026-11
6768

69+
- [可达导出集合检查与 issue #2 剩余名称的处理](2026-11-29-reachable-exports-design.md) — landed
6870
- [不跟随的 using 指令必须声明:策略 `skip-directive`](2026-11-28-skip-directive-design.md) — landed
6971
- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed
7072
- [PR #5 第二轮评审的 [nit] 修复:覆盖率按测试程序列出的用例核对](2026-11-21-pr5-review-nits-design.md) — active

‎docs/architecture.md‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,15 @@ written reason and applied by the generator, never patched into its output:
197197
| `[[<lib>.extra]]` | verbatim declarations (the gcc `extern template` vtable workarounds) |
198198
| `[[<lib>.republish]]` | the namespace holds `using namespace <target>;` for another library's namespace: every name that library exports directly in `<target>` is re-exported through it, optionally under `if` (`boost::dll::fs` follows `boost::filesystem`) |
199199
| `[[<lib>.skip-directive]]` | the namespace's `using namespace X;` is an implementation convenience, not a public spelling (`namespace ublas { namespace detail { using namespace boost::numeric::ublas; } }`): it is not followed, and the reason is recorded |
200+
| `[[unreachable]]` | names importers of the listed modules could once spell and no longer can (a Boost.MPL name several modules exported by accident), with the reason; see `check_reachable.py` in §5.4 |
200201
| `add` | names no collector reaches (body-only or ADL-only references) |
201202
| `gmf`, `defines`, `facade-includes` | the bundle's include set and macros; facade-only includes |
202203
| `inline-namespaces` | export a macro-selected inline namespace through its parent |
203204
| `[<lib>.deps]` | module edge corrections; edges of the hand-written special modules |
204205

205-
`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, and
206-
each `extra` / `republish` / `skip-directive` namespace, so the boundary is reviewable in one file,
206+
`generated/meta/skipped.txt` lists every name a rule guards, drops, adds or
207+
declares unreachable, and each `extra` / `republish` / `skip-directive`
208+
namespace, so the boundary is reviewable in one file,
207209
and `generated/meta/api-surface.json`
208210
records the generator identity (clang release, target, defines) and per-library
209211
GMF, export count and edges. A diff after a compiler update therefore shows as a
@@ -214,6 +216,14 @@ generator change, not as an unexplained API change.
214216
- `gen_exports.py --check` regenerates into a scratch copy and compares every
215217
generated file byte for byte, then verifies each facade's GMF against the
216218
bundle; it never writes the tree. CI runs it on Linux, macOS and Windows.
219+
- `tools/ci/check_reachable.py` compares, module by module, the names an importer
220+
reaches (the module's own list plus everything it `export import`s) with a
221+
pinned baseline revision and, in CI, with the base of the change. A name that
222+
went must be explained in `skipped.txt` by the module it went from: a `drop`,
223+
an `unreachable`, or a `skip-directive` whose target still has the name.
224+
`unreachable` entries for a name the module does reach are rejected. Byte-identical
225+
output (`--check`) says nothing about this: a name can be lost by a change the
226+
generator reproduces exactly.
217227
- `import_boost.py` is the single upstream import: URL, archive SHA-256, kept
218228
entries, pruned directories/files and the CRLF-normalized files are recorded in
219229
`upstream/boost/SOURCE.md`. The release `README.md` and `LICENSE_1_0.txt` are
@@ -308,7 +318,7 @@ keeps byte-identical notices.
308318
them from the root with `mcpp test -p <member>` and the root's feature set,
309319
so they reuse the package objects and BMIs of the root `mcpp build`.
310320
- `tools/ci/verify_generated.py`: patch replay, `gen_exports.py --check`,
311-
`gen_features.py --check` and the audits on a clean tree on all three host
321+
`check_reachable.py`, `gen_features.py --check` and the audits on a clean tree on all three host
312322
platforms, then `git status` must be clean; a second build on the same
313323
configuration records the incremental TU count and mtimes.
314324
- `tools/check_mwrap_release.py`: identity, version scheme, tag, licence split and

‎docs/architecture.zh.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
171171
| `[[<lib>.drop]]` | 永不导出匹配的名字 / 命名空间 |
172172
| `[[<lib>.extra]]` | 原样声明(gcc `extern template` 虚表变通) |
173173
| `[[<lib>.republish]]` | 该命名空间中有指向另一个库命名空间的 `using namespace <target>;`:把那个库直接导出在 `<target>` 中的所有名字经由该命名空间再导出,可选 `if` 条件(`boost::dll::fs` 跟随 `boost::filesystem`) |
174+
| `[[unreachable]]` | 列出的模块的导入者曾经能写、现在写不出的名字(例如多个模块碰巧都导出过的 Boost.MPL 名字),附原因;见 §5.4 的 `check_reachable.py` |
174175
| `add` | 没有收集器能到达的名字(只在函数体或 ADL 中出现的引用) |
175176
| `gmf`、`defines`、`facade-includes` | bundle 的 include 集合与宏;仅门面使用的 include |
176177
| `inline-namespaces` | 经由父命名空间导出由宏选择的 inline 命名空间 |
177178
| `[[<lib>.skip-directive]]` | 该命名空间中的 `using namespace X;` 只是实现上的便利,不是公开写法(`namespace ublas { namespace detail { using namespace boost::numeric::ublas; } }`):不跟随,并记录原因 |
178179
| `[<lib>.deps]` | 模块边修正;手写特殊模块的边 |
179180

180-
`generated/meta/skipped.txt` 列出每条规则守卫、丢弃或添加的名字,以及每个
181+
`generated/meta/skipped.txt` 列出每条规则守卫、丢弃、添加或声明不可达的名字,以及每个
181182
`extra` / `republish` / `skip-directive` 命名空间,边界可以在一个文件里审阅;`generated/meta/api-surface.json` 记录生成器身份(clang 版本、目标、
182183
宏定义)以及每个库的 GMF、导出数和边。因此编译器升级后的差异会显示为生成器
183184
变化,而不是无法解释的 API 变化。
@@ -187,6 +188,12 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
187188
- `gen_exports.py --check` 在临时副本中重新生成,逐字节比较每个生成文件,再对照
188189
bundle 校验每个门面的 GMF;它从不写代码树。CI 在 Linux、macOS、Windows 上
189190
运行它。
191+
- `tools/ci/check_reachable.py` 逐模块比较导入者可达的名字(模块自己的列表加上它
192+
`export import` 的一切)与一个固定的基线版本,在 CI 中还与本次改动的基准比较。
193+
少掉的名字必须由丢掉它的那个模块在 `skipped.txt` 中说明:`drop`、
194+
`unreachable`,或目标命名空间中仍有该名字的 `skip-directive`。模块实际可达的
195+
名字若有 `unreachable` 条目则报错。逐字节一致(`--check`)不能说明这一点:
196+
生成器能精确复现的改动同样可能丢掉名字。
190197
- `import_boost.py` 是唯一的上游导入入口:URL、压缩包 SHA-256、保留的条目、
191198
裁剪掉的目录/文件以及做过 CRLF 规范化的文件,全部记录在
192199
`upstream/boost/SOURCE.md` 中。发行版自带的 `README.md` 和
@@ -269,7 +276,8 @@ feature(两种 Boost.Test 形态绝不能链接在一起)。
269276
排除。它们是根工作区的成员,CI 在根目录以 `mcpp test -p <成员>` 和根工程
270277
的 feature 集合运行,从而复用根工程 `mcpp build` 的目标文件与 BMI。
271278
- `tools/ci/verify_generated.py`:在三种宿主平台的干净代码树上跑补丁重放、
272-
`gen_exports.py --check`、`gen_features.py --check` 和审计,最后 `git status`
279+
`gen_exports.py --check`、`check_reachable.py`、`gen_features.py --check` 和审计,
280+
最后 `git status`
273281
必须干净;在同一配置上再做一次构建,记录增量 TU 数量和 mtime。
274282
- `tools/check_mwrap_release.py`:校验标识、版本方案、tag、许可证拆分以及保留
275283
文档的字节。

‎docs/usage.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ Some libraries are consumed by header only. They have no module and no feature.
8686
| Macro APIs | `preprocessor`, `mpl`, `fusion`, `proto`, `spirit`, `xpressive`, `typeof`, `vmd`, `phoenix`, `parameter`, `metaparse`, `function_types`, `tti`, `local_function`, `msm`, `foreach` | The public surface is a macro family; a named module cannot export macros |
8787
| Compiler/defect fallbacks | `predef`, `static_assert`, `exception`, `describe`, `openmethod`, `scope_exit` | Macro-body API, a keyword module name, include+import ODR conflicts, or gcc CMI pendings bugs |
8888
89+
Some modules export a few names of these libraries (`boost::mpl::lambda`,
90+
`boost::parameter::keyword`) because their own signatures mention them. Which
91+
module does is not an interface to rely on: a program that spells such a name
92+
includes the library's header.
93+
8994
`static_assert` cannot be a module at all: its name is a C++ keyword, so
9095
`export module ...boost.static_assert;` is invalid. `boost/exception/all.hpp`
9196
must be included by consumers: gcc 16.1 fails to load the module's pendings in

‎docs/usage.zh.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ BOOST_SCOPE_EXIT(void) { /* ... */ } BOOST_SCOPE_EXIT_END
7070
| 宏 API | `preprocessor`、`mpl`、`fusion`、`proto`、`spirit`、`xpressive`、`typeof`、`vmd`、`phoenix`、`parameter`、`metaparse`、`function_types`、`tti`、`local_function`、`msm`、`foreach` | 公开接口是一组宏;具名模块无法导出宏 |
7171
| 编译器/缺陷回退 | `predef`、`static_assert`、`exception`、`describe`、`openmethod`、`scope_exit` | 宏体 API、与关键字同名的模块名、include+import 的 ODR 冲突,或 gcc 的 CMI pendings 缺陷 |
7272
73+
有些模块会导出这些库的少数名称(`boost::mpl::lambda`、`boost::parameter::keyword`),因为它们自己的签名提到了这些名称。由哪个模块导出不是可以依赖的接口:程序若要写出这样的名称,应包含该库的头文件。
74+
7375
`static_assert` 完全无法成为模块:其名称是 C++ 关键字,因此 `export module ...boost.static_assert;` 非法。消费者必须包含 `boost/exception/all.hpp`:在任何真实的消费者翻译单元中,gcc 16.1 都无法加载该模块的 pendings。
7476
7577
### 2.4 无模块的编译库

‎generated/exports/algorithm.deps‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ mcpplibs.mwrap.boost.bind
33
mcpplibs.mwrap.boost.concept_check
44
mcpplibs.mwrap.boost.config
55
mcpplibs.mwrap.boost.core
6-
mcpplibs.mwrap.boost.function
76
mcpplibs.mwrap.boost.range
87
mcpplibs.mwrap.boost.smart_ptr
98
mcpplibs.mwrap.boost.throw_exception

‎generated/exports/bimap.deps‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ mcpplibs.mwrap.boost.functional
66
mcpplibs.mwrap.boost.lambda
77
mcpplibs.mwrap.boost.multi_index
88
mcpplibs.mwrap.boost.type_traits
9+
mcpplibs.mwrap.boost.utility

0 commit comments

Comments
 (0)