Skip to content

Commit 8916c4c

Browse files
authored
dll: boost::dll::fs follows boost::filesystem (policy republish), smoke test asserts it (#9)
* exports: boost::dll::fs follows boost::filesystem (policy republish) boost/dll/config.hpp spells boost::dll::fs as `using namespace boost::filesystem;`. The generator follows a using-directive only in the ADL-barrier shape, so #5 re-declared 33 filesystem names by hand; 28 non-operator spellings of main before #1 (symlink_status, space, permissions, unique_path, ...) stayed unreachable. A [[<lib>.republish]] policy entry names the directive's namespace: every name the owning module emitted directly in the target namespace (after its drops, with its guards) is re-exported through it, and the owner becomes a .deps edge. dll::fs now carries filesystem's 138 names under !defined(BOOST_DLL_USE_STD_FS); the std::filesystem branch stays an extra, completed to the standard's 54 names. Cached entries hold only while the owner's emitted names are unchanged. * tests/dll: assert the boost::dll::fs spelling in the smoke test Same-type checks against boost::filesystem, program_location's return type, enumerators, Boost-only functions (unevaluated) and a temp-directory round trip through functions the hand-kept list lacked, on the error_code overloads. With main's dll.inc the file fails to compile on exactly those names. * docs: the republish policy rule; design record for dll::fs
1 parent e541db7 commit 8916c4c

11 files changed

Lines changed: 719 additions & 84 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
subject: generator
3+
status: landed
4+
---
5+
6+
# `boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`
7+
8+
来源:issue #2 的第一条验收标准,以及"建议方向"第 1 条。
9+
10+
## 问题
11+
12+
`boost/dll/config.hpp` 中 `boost::dll::fs` 的写法是
13+
`namespace boost { namespace dll { namespace fs { using namespace boost::filesystem; } } }`
14+
(定义 `BOOST_DLL_USE_STD_FS` 时改为 `std::filesystem`)。导入模块的一方看不到
15+
using 指令。生成器目前只跟随 ADL 屏障形态的指令(目标命名空间嵌套在指令自身的
16+
命名空间里),所以这条指令被跳过。
17+
18+
PR #5 用 `[[dll.extra]]` 手写了 33 个名称(另有上游本来就是 using 声明的
19+
`error_code` / `system_error`)。和 #1 之前的 main 相比,`dll::fs::` 写法仍少了
20+
49 个,其中 28 个不是运算符(`symlink_status`、`space`、`permissions`、
21+
`create_symlink`、`unique_path` 等)。手写列表也不会随 Boost.Filesystem 升级更新。
22+
测试只用到了 `path`、`recursive_directory_iterator`、`is_regular_file` 三个名称。
23+
24+
## 决定
25+
26+
新增策略条目 `[[<lib>.republish]]`,字段为 `namespace`、`reason`,以及可选的 `if`。
27+
28+
- 生成器在该库的 TU 中找到 `namespace` 里的 using 指令,拿到它的目标命名空间
29+
(`boost::filesystem`)。
30+
- 名称来源是上游模块实际写进 `.inc` 的导出,即应用 drop、guard 之后的结果,并且
31+
只取直接位于目标命名空间的那些(不含 `boost::filesystem::detail` 等嵌套命名
32+
空间)。`emit_inc` 把每个库导出的名称记进 `published`;filesystem 按拓扑序
33+
先于 dll 处理,所以处理 dll 时这些名称已经齐备。上游名称自带的 guard 会和条目
34+
的 `if` 用 `&&` 合并。
35+
- 输出写成 `using ::boost::filesystem::X;`,放在 `export namespace boost::dll::fs`
36+
中,并整体包在 `#if !defined(BOOST_DLL_USE_STD_FS)` 里。拥有这些名称的库会加进
37+
`.deps`,保证模块 `export import` 了它。
38+
- 缓存:dll 的条目记下所用的来源列表(`republish`),以及自己导出的
39+
`published`。命中条件是来源列表与上游当前的导出一致:上游的输出可能因为
40+
先认领者优先(first-wins)的归属而改变,dll 自己的 key 却没变。
41+
- 策略失效时直接报错,不静默跳过:TU 中没有这条指令,或者没有上游模块在目标
42+
命名空间里导出名称。
43+
- `std::filesystem` 分支仍然是 `[[dll.extra]]`,放在
44+
`#if defined(BOOST_DLL_USE_STD_FS)` 中。它是固定的标准接口,这次按
45+
[fs.filesyn] 补全为 54 个名称;path 的运算符、`swap`、`hash_value` 靠 ADL
46+
查找,不逐个列出。
47+
48+
结果:`dll::fs` 现在导出 138 个 `boost::filesystem` 名称,与 `filesystem.inc` 在
49+
`boost::filesystem` 中直接导出的名称完全一致。重新生成后,只有 dll 的输出发生了
50+
变化。
51+
52+
## 否决的做法
53+
54+
- **自动跟随所有"目标由别的库拥有、所在命名空间不是 detail"的指令**(issue 中
55+
提到的另一种写法):会一次性改变多个库的导出面,每一条都需要单独审查。issue #2
56+
中其余几组名称仍按 issue 的计划逐个确认。显式的策略条目可以审查,也会写进
57+
`skipped.txt`。
58+
- **在 `republish` 上提供 `else`,把 std 列表放进 `#else` 分支**:当上游的部分
59+
名称带有自己的 guard 时,按名称排序后,条目的 `#if` 块会被拆成几段,`#else`
60+
行就会重复输出。所以 std 列表留在独立的 `extra` 块里。
61+
- **写成 `using boost::dll::fs::X;`(#1 之前 main 的写法)**:两种写法指向同一个
62+
实体。选用目标库的限定名,是为了让来源一目了然,也让以 `boost::filesystem::`
63+
开头的枚举项(`file_type::regular_file`)保持上游 `.inc` 原样的写法。
64+
65+
## 测试
66+
67+
- `tests/dll/smoke.cpp`:
68+
- `static_assert` 检查 `dll::fs::path` 等名称与 `boost::filesystem` 中是同一
69+
类型,`program_location()` 的返回类型是 `dll::fs::path`,枚举项可以写成
70+
`dll::fs::regular_file`;
71+
- 以不求值的方式检查只有 Boost 才有的名称(`unique_path`、`system_complete`、
72+
`portable_name`);
73+
- 在临时目录中用 `error_code` 重载调用一组旧列表里没有的函数
74+
(`symlink_status`、`resize_file`、`hard_link_count`、`space`、
75+
`status_known` 等)。
76+
77+
换回 main 的 `dll.inc` 后,这个文件在 gcc 上编译失败,报的正是这些名称。
78+
- `tools/tests/test_gen_exports_republish.py`:覆盖来源选择、guard 合并、已被
79+
认领的名称、上游不可达、过期条目、缓存失效和输出形态。

‎.agents/docs/README.md‎

Lines changed: 6 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-
共 28 篇记录(其中 0 篇已归档),1 项待办。
30+
共 29 篇记录(其中 0 篇已归档),1 项待办。
3131

3232
## 进行中
3333

@@ -43,6 +43,10 @@
4343

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

46+
### generator
47+
48+
- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed
49+
4650
### tests
4751

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

6165
### 2026-11
6266

67+
- [`boost::dll::fs` 跟随 `boost::filesystem`:策略 `republish`](2026-11-28-dll-fs-republish-design.md) — landed
6368
- [PR #5 第二轮评审的 [nit] 修复:覆盖率按测试程序列出的用例核对](2026-11-21-pr5-review-nits-design.md) — active
6469
- [子工程复用根工程的构建产物,mcpp 升级到 2026.11.20.1](2026-11-20-sub-project-build-reuse-design.md) — active
6570
- [windows-llvm-msvc 上的进程崩溃:两个 clang 模块缺陷](2026-11-18-windows-msvc-module-crashes-analysis.md) — landed

‎docs/architecture.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ libclang, no Python bindings, no LLVM release archive.
167167
deduction guides and class members are not candidates.
168168
- **Using-injections**: namespace-scope `using X::y;` / `using namespace X;`
169169
that give entities their public spelling (ADL barriers, `detail` re-exports).
170+
A `using namespace` is followed only in the ADL-barrier shape (the target is
171+
nested in the directive's own namespace); one that names another library's
172+
namespace is followed when the policy declares it (`republish` below).
170173
- **Signature closure**: entities named by the candidates' signatures
171174
(parameters, results, bases, fields, typedef targets — with typedefs looked
172175
through), so the API's own types are exported with it.
@@ -190,13 +193,15 @@ written reason and applied by the generator, never patched into its output:
190193
| `[[<lib>.guard]]` | wrap the matching exports in the upstream header's own condition (`#if defined(_WIN32)` ...), optional `#else` lines |
191194
| `[[<lib>.drop]]` | never export the matching names / namespaces |
192195
| `[[<lib>.extra]]` | verbatim declarations (the gcc `extern template` vtable workarounds) |
196+
| `[[<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`) |
193197
| `add` | names no collector reaches (body-only or ADL-only references) |
194198
| `gmf`, `defines`, `facade-includes` | the bundle's include set and macros; facade-only includes |
195199
| `inline-namespaces` | export a macro-selected inline namespace through its parent |
196200
| `[<lib>.deps]` | module edge corrections; edges of the hand-written special modules |
197201

198-
`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, so
199-
the boundary is reviewable in one file, and `generated/meta/api-surface.json`
202+
`generated/meta/skipped.txt` lists every name a rule guards, drops or adds, and
203+
each `extra` / `republish` namespace, so the boundary is reviewable in one file,
204+
and `generated/meta/api-surface.json`
200205
records the generator identity (clang release, target, defines) and per-library
201206
GMF, export count and edges. A diff after a compiler update therefore shows as a
202207
generator change, not as an unexplained API change.

‎docs/architecture.zh.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
147147
friend 形式出现的声明、显式与偏特化(经由主模板可达)、推导指引以及类成员都
148148
不是候选。
149149
- **using 注入**:赋予实体公开拼写的命名空间作用域 `using X::y;` /
150-
`using namespace X;`(ADL 屏障、`detail` 再导出)。
150+
`using namespace X;`(ADL 屏障、`detail` 再导出)。`using namespace` 只在 ADL
151+
屏障形态下跟随(目标嵌套在指令自身的命名空间内);指向其他库命名空间的指令,
152+
由策略声明后才跟随(见下文 `republish`)。
151153
- **签名闭包**:候选签名中点名的实体(形参、返回值、基类、字段、typedef 目标——
152154
typedef 会被看穿),使 API 自身的类型随之导出。
153155
- **归属**:按依赖优先的顺序处理各库;第一个认领实体的库拥有它,之后的库在
@@ -167,13 +169,14 @@ clang++ -std=c++23 --target=x86_64-w64-mingw32 --sysroot=<pinned MinGW> \
167169
| `[[<lib>.guard]]` | 用上游头文件自身的条件包裹匹配的导出(`#if defined(_WIN32)` ...),可选 `#else` 行 |
168170
| `[[<lib>.drop]]` | 永不导出匹配的名字 / 命名空间 |
169171
| `[[<lib>.extra]]` | 原样声明(gcc `extern template` 虚表变通) |
172+
| `[[<lib>.republish]]` | 该命名空间中有指向另一个库命名空间的 `using namespace <target>;`:把那个库直接导出在 `<target>` 中的所有名字经由该命名空间再导出,可选 `if` 条件(`boost::dll::fs` 跟随 `boost::filesystem`) |
170173
| `add` | 没有收集器能到达的名字(只在函数体或 ADL 中出现的引用) |
171174
| `gmf`、`defines`、`facade-includes` | bundle 的 include 集合与宏;仅门面使用的 include |
172175
| `inline-namespaces` | 经由父命名空间导出由宏选择的 inline 命名空间 |
173176
| `[<lib>.deps]` | 模块边修正;手写特殊模块的边 |
174177

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

0 commit comments

Comments
 (0)