Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions .agents/docs/2026-11-29-reachable-exports-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
subject: generator
status: landed
---

# 可达导出集合检查与 issue #2 剩余名称的处理

来源:issue #2 的第三、四条验收标准(未分析的小组逐个确认;verify-scripts 中加入
可达导出集合检查)。前两条见 [`republish`](2026-11-28-dll-fs-republish-design.md)
(PR #9)与 [`skip-directive`](2026-11-28-skip-directive-design.md)(PR #10)。

## 现状

在 `e2f10c68` 上与 `99533232`(#1 之前的 main)比较每个模块的可达名称。按
"模块自己原来就导出、现在够不到"归到根上,除 #10 已说明的三个 detail 组之外,
共 72 处(模块,名称)、37 个名称:issue 列出的小组,加上 issue 之后由 #5 带来的 9 个名称
(`boost::size`、cobalt 的 main 三个、geometry 的 `fusion_adapt_detail` 三个与
`mpl::count_if`、`mpl::aux::next_if`)。没有一处是只因为少了 `export import`。

## 原因

**旧生成器按特化重复导出。** 它用 libclang 的 USR 作键,签名里提到的特化有自己的
USR:`function<int(int)>` 是 `c:@N@boost@S@function>#FI(#I)`,主模板是
`c:@N@boost@ST>1#T@function`。认领表里没有前者,于是它被当成新实体,又导出一次
`using boost::function;`。用基线的 `closure_from` 对一个合成 TU 实跑确认。#1 之后按
主模板作键,名称只归第一个认领的模块;这些重复导出随之消失。

所以问题变成:每个模块对这个名称的依赖是不是真的,以及谁应当拥有它。

## 逐组处理

| 名称 | 模块 | 处理 |
|---|---|---|
| `boost::function` | functional(accumulators、bimap、multi_array、numeric 经由它) | **补回**:`[functional.deps] add = ["function"]` |
| `*_archetype` ×3 | regex | **补回**:`boost/concept_archetype.hpp` 归 concept_check |
| `boost::call_traits` | wave | **补回**:`boost/call_traits.hpp` 归 utility |
| `boost::mpl` ×14、`mpl::aux` ×2(46 处) | 13 个 | 说明:`[[unreachable]]` |
| `boost::parameter` ×4 | accumulators、graph、heap、lockfree | 说明:`[[unreachable]]` |
| `fusion::deque` | hana | 说明:`[[unreachable]]` |
| `container::(make_)transform_iterator` | interprocess | 说明:`[[unreachable]]` |
| `cobalt::main` 等 3 个 | cobalt | 说明:`[[unreachable]]` |
| `fusion_adapt_detail` ×3、`mpl::count_if`、`mpl::aux::next_if` | geometry | 说明:`[[unreachable]]` |
| `boost::size` | core | 已有 `drop`,改为按导出写法记录 |

- **function**:`boost::overloaded_function` 的构造函数以 `boost::function` 为参数,
是公开接口。写出它的是 `overloaded_function_detail::base` 的偏特化,包含它的是
functional 自己的 `detail/` 头文件;签名闭包不走偏特化,包含边不读库自己的
`detail/`,两边都看不到。上游 CMake 也链接 `Boost::function`。
- **archetype、call_traits**:两个头文件在 `boost/` 顶层,文件名不是库名,没有归属,
于是先处理到的 iterator、variant 认领了它们,而写进文档的 concept_check、utility
反而没有导出。归属改正后,regex、wave 通过已有的边可达。concept_check 多导出 74 个
名称,iterator 少 74 个;utility 多 3 个,variant 少 3 个。variant 因此需要到
utility 的边(上游 CMake 同样链接),bimap、serialization 的这条边由生成器自己得出。
- **mpl、parameter、fusion**:这些库只以头文件方式使用(usage.md §2.3),没有模块
拥有它们的名称。在官方发布包 1.92.0 的 `libs/<lib>` 全部文档、示例和测试中搜索
这 56 处的每个写法,只有两处命中:accumulators 参考手册里静态成员的类型
`parameter::keyword`,hana 的 fusion 示例(它自己包含 `<boost/fusion/...>`)。
- **cobalt、geometry**:头文件有意不进 GMF,原因早已写在 usage.md §6,只是
`skipped.txt` 没有记录。`count_if.hpp` 在 geometry 中只有 `boost_fusion.hpp` 包含。

issue 正文中"`mpl::aux::template_arity`、`mpl::order_impl`、`boost::parameter` 已在
`skipped.txt` 中"的说法不再成立:前两个现在没有条目;flyweight 的 `drop` 说明不了
heap、lockfree、graph 为什么丢了 `parameter` 的名称。

## 决定

**`[[unreachable]]`**(顶层,不属于某个库):`reason` 加 `names = {名称 = [模块]}`。
生成器每个(模块,名称)写一行 `<lib> unreachable <name> -- <reason>`;未知模块、
空原因、重复条目报错。它不影响导出,也不进入各库的策略摘要。

**`tools/ci/check_reachable.py`**,由 `verify_generated.py` 在 `gen_exports.py --check`
之后运行:

- 可达集合与 issue 中脚本的定义相同:自己的 `.inc` 加上 `src/*.cppm` 中
`export import` 的传递闭包。解析补上了运算符、别名声明和命名空间别名。
- **按(模块,名称)匹配。** 一个条目只说明它自己的模块。模块自己导出过的名称,
必须有自己的条目;只是从导入得来的名称,由丢掉它的那个模块说明。去掉了导入、
而被导入模块仍有该名称时,报在去掉导入的模块上。
- **`skip-directive` 只说明经由指令的写法**:`<ns>::X` 丢失时,要求 `<target>::X` 仍然
可达。为此 `skipped.txt` 的这些行加上了 `using <target>, ...`。否则
`ublas::detail` 自己声明的名称丢了,也会被这一行盖过去。
- **`unreachable` 过期即报错**:模块实际可达该名称。
- **两个基线**:固定的 `99533232`,以及 CI 的基准(PR 的 merge base,或 push 之前的
提交)。只有前者的话,之后新增的名称(`boost::dll::fs` 的大部分、conversion 模块)
再丢失就看不出来;只有后者的话,合并之后说明就再也不受检查。
- 基线与被删除的模块写成脚本中的常量,升级 Boost 时移动基线的办法写在旁边。

**`drop` 按导出写法记录**:`core drop std::size` 改为 `core drop boost::size`,
`align drop std::alignment_of` 同理。导入者丢失的是前者。

## 验证

- 反向路径(真实数据的副本):去掉 functional 的 function 导入、删掉
`dll.inc` 中 `unique_path`、删掉一条 `unreachable`、删掉 `core drop`、加一条过期条目、
从 `numeric.inc` 删掉 `ublas::matrix`、删掉 crc 模块,七种都报错并指出位置。
- 用 #5 的树(`34d6fc8c`,当时 verify-scripts 通过)运行:912 处未说明。
- 正向:对两个基线都是 0 处未说明;与 `e2f10c68` 相比没有任何模块少名称。

## 否决的做法

- **`drop` 不再占用无主名称的归属**:flyweight 丢弃的 `boost::parameter` 名称,后面的
库也不再导出。试做并全量生成:heap 补回 3 个名称,lockfree、graph 仍然够不到(没有到
heap 的边),而 heap 多导出 48 个 `parameter::aux`,statechart 多导出 9 个
`boost::detail` 的实现细节。收益小于代价。
- **无主名称由每个提到它的模块各自导出**:可以补回全部 mpl 名称,但每个模块的导出都会
大幅增加,且让"碰巧可达"变成接口。
- **按命名空间放行 `boost::mpl`、`boost::parameter`**:会让以后的丢失再次静默。
- **把"每个旧名称仍可达"写进 `gen_exports.py --check`**:那里没有历史,也不看
`src/*.cppm` 的导入图。
- **提交一份可达集合的快照文件**:约 16 MB,且减少只体现为 diff,不会报错。

## 顺带发现(未处理)

包含边不读库自己 `detail/` 头文件中的 `#include`(`lib_deps` 在目标库的根上停止)。
按传递闭包计算,全仓有 56 条这样的边不在 `.deps` 中(例如 numeric → units、
gil → filesystem);哪些对导入者有意义需要逐条分析。

## 测试

`tools/tests/test_check_reachable.py`(解析、可达闭包、归因、`skip-directive`、过期条目)、
`tools/tests/test_gen_exports_unreachable.py`(条目、报错、`skipped.txt` 往返)。
`tests/{functional,concept_check,utility,variant}.cpp` 与 `tests/regex/smoke.cpp`
断言补回的名称。
4 changes: 3 additions & 1 deletion .agents/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- `todos/` 放尚未完成的工作项,它们不是决定的记录。
- 移动或改名用 `tools/doc-tools/move_record.py`,它同时改写仓库中对该文件的引用。

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

## 进行中

Expand All @@ -45,6 +45,7 @@

### generator

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

Expand All @@ -65,6 +66,7 @@

### 2026-11

- [可达导出集合检查与 issue #2 剩余名称的处理](2026-11-29-reachable-exports-design.md) — landed
- [不跟随的 using 指令必须声明:策略 `skip-directive`](2026-11-28-skip-directive-design.md) — landed
- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed
- [PR #5 第二轮评审的 [nit] 修复:覆盖率按测试程序列出的用例核对](2026-11-21-pr5-review-nits-design.md) — active
Expand Down
16 changes: 13 additions & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,15 @@ written reason and applied by the generator, never patched into its output:
| `[[<lib>.extra]]` | verbatim declarations (the gcc `extern template` vtable workarounds) |
| `[[<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`) |
| `[[<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 |
| `[[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 |
| `add` | names no collector reaches (body-only or ADL-only references) |
| `gmf`, `defines`, `facade-includes` | the bundle's include set and macros; facade-only includes |
| `inline-namespaces` | export a macro-selected inline namespace through its parent |
| `[<lib>.deps]` | module edge corrections; edges of the hand-written special modules |

`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, and
each `extra` / `republish` / `skip-directive` namespace, so the boundary is reviewable in one file,
`generated/meta/skipped.txt` lists every name a rule guards, drops, adds or
declares unreachable, and each `extra` / `republish` / `skip-directive`
namespace, so the boundary is reviewable in one file,
and `generated/meta/api-surface.json`
records the generator identity (clang release, target, defines) and per-library
GMF, export count and edges. A diff after a compiler update therefore shows as a
Expand All @@ -214,6 +216,14 @@ generator change, not as an unexplained API change.
- `gen_exports.py --check` regenerates into a scratch copy and compares every
generated file byte for byte, then verifies each facade's GMF against the
bundle; it never writes the tree. CI runs it on Linux, macOS and Windows.
- `tools/ci/check_reachable.py` compares, module by module, the names an importer
reaches (the module's own list plus everything it `export import`s) with a
pinned baseline revision and, in CI, with the base of the change. A name that
went 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.
`unreachable` entries for a name the module does reach are rejected. Byte-identical
output (`--check`) says nothing about this: a name can be lost by a change the
generator reproduces exactly.
- `import_boost.py` is the single upstream import: URL, archive SHA-256, kept
entries, pruned directories/files and the CRLF-normalized files are recorded in
`upstream/boost/SOURCE.md`. The release `README.md` and `LICENSE_1_0.txt` are
Expand Down Expand Up @@ -308,7 +318,7 @@ keeps byte-identical notices.
them from the root with `mcpp test -p <member>` and the root's feature set,
so they reuse the package objects and BMIs of the root `mcpp build`.
- `tools/ci/verify_generated.py`: patch replay, `gen_exports.py --check`,
`gen_features.py --check` and the audits on a clean tree on all three host
`check_reachable.py`, `gen_features.py --check` and the audits on a clean tree on all three host
platforms, then `git status` must be clean; a second build on the same
configuration records the incremental TU count and mtimes.
- `tools/check_mwrap_release.py`: identity, version scheme, tag, licence split and
Expand Down
12 changes: 10 additions & 2 deletions docs/architecture.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
| `[[<lib>.drop]]` | 永不导出匹配的名字 / 命名空间 |
| `[[<lib>.extra]]` | 原样声明(gcc `extern template` 虚表变通) |
| `[[<lib>.republish]]` | 该命名空间中有指向另一个库命名空间的 `using namespace <target>;`:把那个库直接导出在 `<target>` 中的所有名字经由该命名空间再导出,可选 `if` 条件(`boost::dll::fs` 跟随 `boost::filesystem`) |
| `[[unreachable]]` | 列出的模块的导入者曾经能写、现在写不出的名字(例如多个模块碰巧都导出过的 Boost.MPL 名字),附原因;见 §5.4 的 `check_reachable.py` |
| `add` | 没有收集器能到达的名字(只在函数体或 ADL 中出现的引用) |
| `gmf`、`defines`、`facade-includes` | bundle 的 include 集合与宏;仅门面使用的 include |
| `inline-namespaces` | 经由父命名空间导出由宏选择的 inline 命名空间 |
| `[[<lib>.skip-directive]]` | 该命名空间中的 `using namespace X;` 只是实现上的便利,不是公开写法(`namespace ublas { namespace detail { using namespace boost::numeric::ublas; } }`):不跟随,并记录原因 |
| `[<lib>.deps]` | 模块边修正;手写特殊模块的边 |

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

Some modules export a few names of these libraries (`boost::mpl::lambda`,
`boost::parameter::keyword`) because their own signatures mention them. Which
module does is not an interface to rely on: a program that spells such a name
includes the library's header.

`static_assert` cannot be a module at all: its name is a C++ keyword, so
`export module ...boost.static_assert;` is invalid. `boost/exception/all.hpp`
must be included by consumers: gcc 16.1 fails to load the module's pendings in
Expand Down
2 changes: 2 additions & 0 deletions docs/usage.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ BOOST_SCOPE_EXIT(void) { /* ... */ } BOOST_SCOPE_EXIT_END
| 宏 API | `preprocessor`、`mpl`、`fusion`、`proto`、`spirit`、`xpressive`、`typeof`、`vmd`、`phoenix`、`parameter`、`metaparse`、`function_types`、`tti`、`local_function`、`msm`、`foreach` | 公开接口是一组宏;具名模块无法导出宏 |
| 编译器/缺陷回退 | `predef`、`static_assert`、`exception`、`describe`、`openmethod`、`scope_exit` | 宏体 API、与关键字同名的模块名、include+import 的 ODR 冲突,或 gcc 的 CMI pendings 缺陷 |

有些模块会导出这些库的少数名称(`boost::mpl::lambda`、`boost::parameter::keyword`),因为它们自己的签名提到了这些名称。由哪个模块导出不是可以依赖的接口:程序若要写出这样的名称,应包含该库的头文件。

`static_assert` 完全无法成为模块:其名称是 C++ 关键字,因此 `export module ...boost.static_assert;` 非法。消费者必须包含 `boost/exception/all.hpp`:在任何真实的消费者翻译单元中,gcc 16.1 都无法加载该模块的 pendings。

### 2.4 无模块的编译库
Expand Down
1 change: 0 additions & 1 deletion generated/exports/algorithm.deps
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mcpplibs.mwrap.boost.bind
mcpplibs.mwrap.boost.concept_check
mcpplibs.mwrap.boost.config
mcpplibs.mwrap.boost.core
mcpplibs.mwrap.boost.function
mcpplibs.mwrap.boost.range
mcpplibs.mwrap.boost.smart_ptr
mcpplibs.mwrap.boost.throw_exception
Expand Down
1 change: 1 addition & 0 deletions generated/exports/bimap.deps
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mcpplibs.mwrap.boost.functional
mcpplibs.mwrap.boost.lambda
mcpplibs.mwrap.boost.multi_index
mcpplibs.mwrap.boost.type_traits
mcpplibs.mwrap.boost.utility
Loading
Loading