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
79 changes: 79 additions & 0 deletions .agents/docs/2026-11-28-dll-fs-republish-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
subject: generator
status: landed
---

# `boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`

来源:issue #2 的第一条验收标准,以及"建议方向"第 1 条。

## 问题

`boost/dll/config.hpp` 中 `boost::dll::fs` 的写法是
`namespace boost { namespace dll { namespace fs { using namespace boost::filesystem; } } }`
(定义 `BOOST_DLL_USE_STD_FS` 时改为 `std::filesystem`)。导入模块的一方看不到
using 指令。生成器目前只跟随 ADL 屏障形态的指令(目标命名空间嵌套在指令自身的
命名空间里),所以这条指令被跳过。

PR #5 用 `[[dll.extra]]` 手写了 33 个名称(另有上游本来就是 using 声明的
`error_code` / `system_error`)。和 #1 之前的 main 相比,`dll::fs::` 写法仍少了
49 个,其中 28 个不是运算符(`symlink_status`、`space`、`permissions`、
`create_symlink`、`unique_path` 等)。手写列表也不会随 Boost.Filesystem 升级更新。
测试只用到了 `path`、`recursive_directory_iterator`、`is_regular_file` 三个名称。

## 决定

新增策略条目 `[[<lib>.republish]]`,字段为 `namespace`、`reason`,以及可选的 `if`。

- 生成器在该库的 TU 中找到 `namespace` 里的 using 指令,拿到它的目标命名空间
(`boost::filesystem`)。
- 名称来源是上游模块实际写进 `.inc` 的导出,即应用 drop、guard 之后的结果,并且
只取直接位于目标命名空间的那些(不含 `boost::filesystem::detail` 等嵌套命名
空间)。`emit_inc` 把每个库导出的名称记进 `published`;filesystem 按拓扑序
先于 dll 处理,所以处理 dll 时这些名称已经齐备。上游名称自带的 guard 会和条目
的 `if` 用 `&&` 合并。
- 输出写成 `using ::boost::filesystem::X;`,放在 `export namespace boost::dll::fs`
中,并整体包在 `#if !defined(BOOST_DLL_USE_STD_FS)` 里。拥有这些名称的库会加进
`.deps`,保证模块 `export import` 了它。
- 缓存:dll 的条目记下所用的来源列表(`republish`),以及自己导出的
`published`。命中条件是来源列表与上游当前的导出一致:上游的输出可能因为
先认领者优先(first-wins)的归属而改变,dll 自己的 key 却没变。
- 策略失效时直接报错,不静默跳过:TU 中没有这条指令,或者没有上游模块在目标
命名空间里导出名称。
- `std::filesystem` 分支仍然是 `[[dll.extra]]`,放在
`#if defined(BOOST_DLL_USE_STD_FS)` 中。它是固定的标准接口,这次按
[fs.filesyn] 补全为 54 个名称;path 的运算符、`swap`、`hash_value` 靠 ADL
查找,不逐个列出。

结果:`dll::fs` 现在导出 138 个 `boost::filesystem` 名称,与 `filesystem.inc` 在
`boost::filesystem` 中直接导出的名称完全一致。重新生成后,只有 dll 的输出发生了
变化。

## 否决的做法

- **自动跟随所有"目标由别的库拥有、所在命名空间不是 detail"的指令**(issue 中
提到的另一种写法):会一次性改变多个库的导出面,每一条都需要单独审查。issue #2
中其余几组名称仍按 issue 的计划逐个确认。显式的策略条目可以审查,也会写进
`skipped.txt`。
- **在 `republish` 上提供 `else`,把 std 列表放进 `#else` 分支**:当上游的部分
名称带有自己的 guard 时,按名称排序后,条目的 `#if` 块会被拆成几段,`#else`
行就会重复输出。所以 std 列表留在独立的 `extra` 块里。
- **写成 `using boost::dll::fs::X;`(#1 之前 main 的写法)**:两种写法指向同一个
实体。选用目标库的限定名,是为了让来源一目了然,也让以 `boost::filesystem::`
开头的枚举项(`file_type::regular_file`)保持上游 `.inc` 原样的写法。

## 测试

- `tests/dll/smoke.cpp`:
- `static_assert` 检查 `dll::fs::path` 等名称与 `boost::filesystem` 中是同一
类型,`program_location()` 的返回类型是 `dll::fs::path`,枚举项可以写成
`dll::fs::regular_file`;
- 以不求值的方式检查只有 Boost 才有的名称(`unique_path`、`system_complete`、
`portable_name`);
- 在临时目录中用 `error_code` 重载调用一组旧列表里没有的函数
(`symlink_status`、`resize_file`、`hard_link_count`、`space`、
`status_known` 等)。

换回 main 的 `dll.inc` 后,这个文件在 gcc 上编译失败,报的正是这些名称。
- `tools/tests/test_gen_exports_republish.py`:覆盖来源选择、guard 合并、已被
认领的名称、上游不可达、过期条目、缓存失效和输出形态。
7 changes: 6 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`,它同时改写仓库中对该文件的引用。

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

## 进行中

Expand All @@ -43,6 +43,10 @@

- [设计记录的管理:只增不删、按年归档、生成的索引与 `tools/doc-tools/`](2026-11-08-design-records-management-design.md) — landed

### generator

- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed

### tests

- [PR #5 第二轮评审的 [nit] 修复:覆盖率按测试程序列出的用例核对](2026-11-21-pr5-review-nits-design.md) — active
Expand All @@ -60,6 +64,7 @@

### 2026-11

- [`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
- [子工程复用根工程的构建产物,mcpp 升级到 2026.11.20.1](2026-11-20-sub-project-build-reuse-design.md) — active
- [windows-llvm-msvc 上的进程崩溃:两个 clang 模块缺陷](2026-11-18-windows-msvc-module-crashes-analysis.md) — landed
Expand Down
9 changes: 7 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ libclang, no Python bindings, no LLVM release archive.
deduction guides and class members are not candidates.
- **Using-injections**: namespace-scope `using X::y;` / `using namespace X;`
that give entities their public spelling (ADL barriers, `detail` re-exports).
A `using namespace` is followed only in the ADL-barrier shape (the target is
nested in the directive's own namespace); one that names another library's
namespace is followed when the policy declares it (`republish` below).
- **Signature closure**: entities named by the candidates' signatures
(parameters, results, bases, fields, typedef targets — with typedefs looked
through), so the API's own types are exported with it.
Expand All @@ -190,13 +193,15 @@ written reason and applied by the generator, never patched into its output:
| `[[<lib>.guard]]` | wrap the matching exports in the upstream header's own condition (`#if defined(_WIN32)` ...), optional `#else` lines |
| `[[<lib>.drop]]` | never export the matching names / namespaces |
| `[[<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`) |
| `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, so
the boundary is reviewable in one file, and `generated/meta/api-surface.json`
`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, and
each `extra` / `republish` 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
generator change, not as an unexplained API change.
Expand Down
9 changes: 6 additions & 3 deletions docs/architecture.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
friend 形式出现的声明、显式与偏特化(经由主模板可达)、推导指引以及类成员都
不是候选。
- **using 注入**:赋予实体公开拼写的命名空间作用域 `using X::y;` /
`using namespace X;`(ADL 屏障、`detail` 再导出)。
`using namespace X;`(ADL 屏障、`detail` 再导出)。`using namespace` 只在 ADL
屏障形态下跟随(目标嵌套在指令自身的命名空间内);指向其他库命名空间的指令,
由策略声明后才跟随(见下文 `republish`)。
- **签名闭包**:候选签名中点名的实体(形参、返回值、基类、字段、typedef 目标——
typedef 会被看穿),使 API 自身的类型随之导出。
- **归属**:按依赖优先的顺序处理各库;第一个认领实体的库拥有它,之后的库在
Expand All @@ -167,13 +169,14 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
| `[[<lib>.guard]]` | 用上游头文件自身的条件包裹匹配的导出(`#if defined(_WIN32)` ...),可选 `#else` 行 |
| `[[<lib>.drop]]` | 永不导出匹配的名字 / 命名空间 |
| `[[<lib>.extra]]` | 原样声明(gcc `extern template` 虚表变通) |
| `[[<lib>.republish]]` | 该命名空间中有指向另一个库命名空间的 `using namespace <target>;`:把那个库直接导出在 `<target>` 中的所有名字经由该命名空间再导出,可选 `if` 条件(`boost::dll::fs` 跟随 `boost::filesystem`) |
| `add` | 没有收集器能到达的名字(只在函数体或 ADL 中出现的引用) |
| `gmf`、`defines`、`facade-includes` | bundle 的 include 集合与宏;仅门面使用的 include |
| `inline-namespaces` | 经由父命名空间导出由宏选择的 inline 命名空间 |
| `[<lib>.deps]` | 模块边修正;手写特殊模块的边 |

`generated/meta/skipped.txt` 列出每条规则守卫、丢弃或添加的名字,边界可以在一个
文件里审阅;`generated/meta/api-surface.json` 记录生成器身份(clang 版本、目标、
`generated/meta/skipped.txt` 列出每条规则守卫、丢弃或添加的名字,以及每个
`extra` / `republish` 命名空间,边界可以在一个文件里审阅;`generated/meta/api-surface.json` 记录生成器身份(clang 版本、目标、
宏定义)以及每个库的 GMF、导出数和边。因此编译器升级后的差异会显示为生成器
变化,而不是无法解释的 API 变化。

Expand Down
Loading
Loading