Skip to content

Commit cfba005

Browse files
committed
2026.11.26.1: specs, usage chapters, README, CHANGELOG, version
1 parent 07d5b91 commit cfba005

10 files changed

Lines changed: 185 additions & 31 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,48 @@
44
> Each `## [<version>]` section is that release's notes. Entries are written in English
55
> from 2026.9.28.3 on; earlier entries remain as written.
66

7+
## [2026.11.26.1] - 2026-11-26
8+
9+
### Changed
10+
11+
- A private module fragment is still a unit of its own when the purview before it holds
12+
conditions (`#if`, `#ifdef`, `#ifndef`, `#elif`, `#else`, `#endif`) or `#error` and
13+
`#warning`: a condition only decides which declarations exist, and the implementation unit
14+
receives them from the interface. Before, any directive refused. A directive that changes what
15+
the fragment means (`#define`, `#undef`, `#include`, `#pragma`, `#line`, `_Pragma`), and a
16+
condition still open at the module declaration or at the fragment, still leave the source as
17+
written, and `--verbose` names the line (SPEC-019 §5).
18+
- The text before a fragment is read as C++ tokens. A digit separator (`1'000`) no longer hides
19+
the rest of its line, a raw string literal may run over lines and hold `module :private;`, a
20+
`static` inside `extern "C" { … }` is a `static` at namespace scope, and a line continuation
21+
between the module declaration and the fragment leaves the source as written. Each of these
22+
only makes more sources built as written (SPEC-019 §5 items 4 and 8).
23+
- `MCPP_BUILDOPT`, `MCPP_PRIVATE_FRAGMENT` and `MCPP_BMI_SCHEDULE` are part of the request a
24+
recorded build is replayed for: the first build after one of them changes writes the graph
25+
again. Before, a build with no edit replayed the graph the other value had written.
26+
27+
### Added
28+
29+
- `[build] private_fragment = "conservative"` (and `MCPP_PRIVATE_FRAGMENT=conservative`): the
30+
fragment is a unit of its own, and any directive in the purview before it leaves the source as
31+
written, as before conditions were let through. It is the way to check the entry on GCC, which
32+
cannot build a fragment as written.
33+
- A build that fails at a step an optimization acted on ends with a `tip:` that names the entry
34+
and the one invocation that checks it: a source built as two units that failed, a unit that
35+
imports a BMI kept with the lines of an earlier source that failed, a link that failed where
36+
either is in the graph. A failure of another step says nothing; `--quiet` gives none. The
37+
register states, for each entry that is on and has a key, the value that checks it
38+
(`check`), and the text is made of it (SPEC-019 §9, docs/26).
39+
40+
### Recorded
41+
42+
- A reader for clang's `.pcm`, which would keep a BMI when only the function hashes, offsets and
43+
locations differ, is not implemented. Measured with clang 20.1.7 to 23.1.6: the operand that
44+
holds a function's hash is at an index that varies with the declaration and the version, and a
45+
third of the edits change the width of that 32-bit value in the stream, which moves the bit
46+
offsets and three offset tables. Without a model of the declaration records, a reader cannot
47+
tell the field from an interface change (SPEC-019 §8, SPEC-018 §2.2).
48+
749
## [2026.11.24.1] - 2026-11-24
850

951
### Fixed

‎docs/04-mcpp-toml.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ dependency_linkage = "static" # How dependencies arrive: static (default) |
684684
cache = "global" # Global dependency cache: global (default) | local | off (§2.10)
685685
jobs = "auto" # Concurrent compiles: a positive number, or "auto" (§ below)
686686
bmi_schedule = "auto" # Module-edge scheduling: auto (= off) | on | off (§ below)
687-
private_fragment = "unit" # A private module fragment: unit (built as a unit of its own, default) | as-written (chapter 26)
687+
private_fragment = "unit" # A private module fragment: unit (default) | conservative (a unit; any purview directive refuses) | as-written (chapter 26)
688688
```
689689

690690
A file a word of `[build] ldflags` names by absolute path is an input of every

‎docs/26-build-optimizations.md‎

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ by default; the others are stated by a parameter.
2727
| `gcm-locations` | on | `[profile.<name>] bmi_cutoff`, `MCPP_BMI_CUTOFF` | GCC: a BMI whose line maps alone moved is kept; importers name the earlier lines |
2828
| `scan-pass` | on | — | The scans of a graph run before its compiles, as a pass of their own |
2929
| `split-schedule` | off | `[build] bmi_schedule`, `MCPP_BMI_SCHEDULE` | Importers start when a BMI exists, not when its compiler exits |
30-
| `private-fragment` | on | `[build] private_fragment`, `MCPP_PRIVATE_FRAGMENT` | A private module fragment is built as a unit of its own |
30+
| `private-fragment` | on | `[build] private_fragment` (`unit`, `conservative`, `as-written`), `MCPP_PRIVATE_FRAGMENT` | A private module fragment is built as a unit of its own |
3131

3232
`MCPP_BUILDOPT=off mcpp build` is the standard build for one invocation: every entry
3333
off. An entry with no parameter produces the bytes the standard build produces, so
@@ -68,10 +68,20 @@ links; an edit above it reaches the importers, as it must.
6868
- GCC does not implement `module :private;`. Built as a unit of its own, the file builds
6969
with GCC as well.
7070
- A fragment that reads what is local to the interface's translation unit — a macro
71-
defined in the module's purview, an unnamed namespace, a `static` at namespace scope,
72-
a using-directive at namespace scope — is built as written, and `--verbose` says which
73-
line decided it. With a compiler that builds no fragment as written, that is a warning.
71+
defined in the module's purview (`#define`, `#undef`, `#include`, `#pragma`, `#line`), an
72+
unnamed namespace, a `static` at namespace scope (`extern "C" { … }` is namespace scope), a
73+
using-directive at namespace scope, a line continuation between the module declaration and
74+
the fragment — is built as written, and `--verbose` says which line decided it. With a
75+
compiler that builds no fragment as written, that is a warning.
76+
- A condition (`#if`, `#ifdef`, `#ifndef`, `#elif`, `#else`, `#endif`) and `#error` or
77+
`#warning` before the fragment do not keep it from being a unit: a condition only decides
78+
which declarations exist, and the implementation unit receives them from the interface. A
79+
condition still open at the module declaration or at the fragment does.
80+
- The text is read as C++ tokens: comments and the contents of string, character and raw
81+
string literals are not code, and a digit separator (`1'000`) is part of a number.
7482
- `[build] private_fragment = "as-written"` hands the file to the compiler unchanged.
83+
`"conservative"` builds the fragment as a unit of its own and refuses any directive in the
84+
purview, as before conditions were let through; it is the check available on GCC.
7585
7686
## The notes of a build
7787
@@ -86,6 +96,32 @@ The note is given when the rebuild started at a module of one file with at least
8696
importing units, once a build directory. Beside it, a build that replaced or kept BMIs
8797
states which ([04](04-mcpp-toml.md), `bmi_cutoff`).
8898
99+
## Checking whether an optimization is the cause
100+
101+
Every entry is on because most projects build the same with it and sooner. When a build
102+
fails at a step an entry acted on, it ends with a `tip:` that names the entry and the one
103+
invocation that checks it:
104+
105+
```
106+
tip: src/c.cppm was built as two units (private-fragment), and one of them failed.
107+
To check whether that is the cause: MCPP_PRIVATE_FRAGMENT=as-written mcpp build ([build] private_fragment = "as-written" keeps it)
108+
If it builds, report the file; MCPP_BUILDOPT=off turns every optimization off for one run.
109+
```
110+
111+
The tip is given for the step that failed, so a failure of another file says nothing. The
112+
ladder is the same for every entry:
113+
114+
1. Turn off the one entry for one invocation: `MCPP_PRIVATE_FRAGMENT=as-written mcpp build`
115+
(`conservative` on GCC), `MCPP_BMI_CUTOFF=exact mcpp build` (it removes the BMIs kept with
116+
earlier lines first, so the products are those of a build from nothing).
117+
2. Turn off every entry: `MCPP_BUILDOPT=off mcpp build`.
118+
3. A failure that remains after both is not an entry's. A failure that goes with one is worth
119+
a report naming the file, and the manifest keys above keep the statement.
120+
121+
Three tips exist: a source built as two units that failed, a unit that imports a BMI kept
122+
with earlier lines that failed, and a failed link where either is in the graph (which cannot
123+
say which unit). A test program that fails when it runs gives none.
124+
89125
## What the home's cache places (2026.11.21.1+)
90126
91127
Beside the entries, the home's build cache (`build-cache/v1/`, [25](25-home-indices-and-store.md))
@@ -125,7 +161,7 @@ run for a minute is named once on a `Running` line, with the package and source
125161
126162
```toml
127163
[build]
128-
private_fragment = "as-written" # "unit" (default) | "as-written"
164+
private_fragment = "as-written" # "unit" (default) | "conservative" | "as-written"
129165
bmi_schedule = "on" # "auto" (default, = off) | "on" | "off"
130166
131167
[profile.dev]

‎docs/specs/build-optimizations.md‎

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
| 项 | 值 |
44
|---|---|
55
| 规范编号 | SPEC-019 |
6-
| 标题 | mcpp 在标准构建之外所做的事:登记表、级别、接缝、总开关,私有模块片段作为独立单元,构建后的建议 |
7-
| 状态 | 评审中 v1.0 |
8-
| 版本 | 1.0 |
9-
| 最后修改 | 2026-11-17 |
10-
| 对应实现 | mcpp >= 2026.11.17.2 |
11-
| 相关设计文档 | `.agents/docs/2026-11-17-ninja-cascade-publish-supplement-design.md` §11 |
6+
| 标题 | mcpp 在标准构建之外所做的事:登记表、级别、接缝、总开关,私有模块片段作为独立单元,构建后的建议,失败时的提示 |
7+
| 状态 | 评审中 v1.1 |
8+
| 版本 | 1.1 |
9+
| 最后修改 | 2026-11-26 |
10+
| 对应实现 | mcpp >= 2026.11.17.2;§5 第 4、7、8 条与 §9 自 2026.11.26.1 |
11+
| 相关设计文档 | `.agents/docs/2026-11-17-ninja-cascade-publish-supplement-design.md` §11、`.agents/docs/2026-11-26-clang-bmi-cutoff-and-private-fragment-refinement-design.md` |
1212
| 相关 issue | #946 |
1313
| 使用文档 | [26 — 构建优化](../zh/26-build-optimizations.md)、[13 — 代码与工程风格](../zh/13-code-and-project-style.md) |
1414

@@ -26,7 +26,8 @@
2626

2727
1. mcpp 在标准构建之外所做的每一项**必须**是登记表(`mcpp.buildopt.registry`)的一个条目;
2828
表外**禁止**有这样的行为。
29-
2. 条目**必须**说明:标识、作用的接缝、级别、默认是否开启、改变它的清单键与环境变量。
29+
2. 条目**必须**说明:标识、作用的接缝、级别、默认是否开启、改变它的清单键与环境变量。默认开启而有清单键的条目**必须**另说明
30+
`check`:只关闭这一项以做验证的取值(§9);编译器之间不同时,另说明 GCC 上的取值。
3031
3. 包的 README **必须**以表格列出全部条目及其默认值与参数;测试保证二者一致。
3132

3233
| 条目 | 接缝 | 级别 | 默认 | 参数 | 作用 |
@@ -37,7 +38,7 @@
3738
| `gcm-locations` | 边 | 有条件 | 开 | `[profile.<name>] bmi_cutoff`,`MCPP_BMI_CUTOFF` | GCC BMI 只有行映射移动时保留(SPEC-018 §3) |
3839
| `scan-pass` | 图 | 严格 | 开 | — | 图的扫描先于编译,作为单独的一遍执行 |
3940
| `split-schedule` | 图 | 形态 | 关 | `[build] bmi_schedule`,`MCPP_BMI_SCHEDULE` | BMI 存在时导入者即开始,不等编译器退出(SPEC-011) |
40-
| `private-fragment` | 源码 | 源码 | 开 | `[build] private_fragment`,`MCPP_PRIVATE_FRAGMENT` | 私有模块片段构建为独立单元(§5) |
41+
| `private-fragment` | 源码 | 源码 | 开 | `[build] private_fragment`(`unit`、`conservative`、`as-written`),`MCPP_PRIVATE_FRAGMENT` | 私有模块片段构建为独立单元(§5) |
4142

4243
## 2. 级别
4344

@@ -99,16 +100,29 @@ int f() { return 1; } → module m; // 实现单元
99100
编译数据库除两个单元之外**必须**有原文件的一项(接口单元的命令作用于原文件),供语言服务器
100101
查询;按改动选择测试时,原文件的改动等同于由它构建的单元的改动。
101102
4. 下列情况**必须**按原样构建,并说明所在行与原因:
102-
- 片段之前、模块范围之内有预处理指令(片段可能使用的宏);
103-
- 片段之前有未命名的命名空间,或命名空间作用域的 `static`;
103+
- 片段之前、模块范围之内有改变片段含义的预处理指令:`#define`、`#undef`、`#include`、
104+
`#pragma`、`#line`,以及下面没有列出的指令,或 `_Pragma`、`__pragma`(宏与编译状态不随 BMI
105+
进入实现单元)。条件指令(`#if`、`#ifdef`、`#ifndef`、`#elif`、`#elifdef`、`#elifndef`、
106+
`#else`、`#endif`)与 `#error`、`#warning` 不在此列:条件只决定哪些声明存在,实现单元
107+
经 BMI 取得声明;
108+
- 在 `export module` 声明所在行或片段所在行,条件指令尚未闭合(两个单元不会闭合它);
109+
- 片段之前有未命名的命名空间,或命名空间作用域的 `static`(`extern "C" { … }` 与
110+
`extern "C++" { … }` 是命名空间作用域);
104111
- 片段之前有命名空间作用域的 using 指令;
112+
- 自模块声明至片段之间有行连接(行末的 `\`);
105113
- 该单元是分区,或片段之前读不到 `export module` 声明。
106114
107115
编译器不支持按原样构建私有片段时,该说明为警告;否则只在 `--verbose` 中给出。
108116
5. 判定只读文本,不做语义分析;没有把握时按原样构建。通过上述判定而仍不能作为独立单元
109117
编译的片段,其错误由编译器给出并指向原文件;`private_fragment = "as-written"` 按原样构建。
110118
6. 取值按层次:`MCPP_PRIVATE_FRAGMENT`、`[build] private_fragment`、默认值。其他取值
111119
**必须**给出警告并取默认值。
120+
7. 取值 `conservative` 仍把片段构建为独立单元,而第 4 条的预处理指令一项回到放宽之前的规则:
121+
片段之前的模块范围内出现任何预处理指令即按原样构建。它是只退回这一处放宽的办法,在不能
122+
按原样构建片段的编译器(GCC)上,`as-written` 不是可用的验证办法时由它代替。
123+
8. 判定读文本的记号而不是行:注释与字符串、字符、原始字符串字面量的内容不是代码;数字分隔符
124+
(`1'000`)属于数字,不是字符字面量的开始;原始字符串可以跨行并含任何文本。第 4 条的
125+
词法修正不设开关:它只使更多的源文件按原样构建。
112126
113127
## 6. 构建后的建议
114128
@@ -134,12 +148,36 @@ int f() { return 1; } → module m; // 实现单元
134148
| 项 | 预期收益 | 未实现的原因 |
135149
|---|---|---|
136150
| 无标记地把单文件模块拆为接口与实现 | 编辑函数体不达导入者,无需写 `module :private;` | 需要语义分析(§7 第 3 条);gcc 上编辑函数体本不级联,收益主要在 clang |
137-
| clang:导入者可观察的接口不变时保留 BMI | clang 上函数体与注释的编辑止于该模块 | 需要两版接口的语义差异;clang 接受源文件已变的旧 BMI,仅在一个三单元的例子上测得 |
151+
| clang:导入者可观察的接口不变时保留 BMI | clang 上函数体与注释的编辑止于该模块 | 2026-11-26 的实测(clang 20.1.7 至 23.1.6):非 inline 函数的哈希在记录中的下标随声明而不同(同一版本的成员函数在 26、27、29),需要复刻序列化器的布局;32 位哈希随机,约三分之一的编辑改变其 VBR 宽度,之后的位偏移与三类偏移表(声明上下文的词法偏移、`TYPE_OFFSET`、`DECL_OFFSET`)随之移动;不屏蔽哈希则只覆盖最后一个声明之后的编辑。没有误屏蔽接口差异的保证,不实现 |
138152
| 按符号计算受一次改动影响的测试 | `mcpp test --since` 运行更少的测试 | 需要跨导入的引用;动态分派可能遗漏测试 |
139153
| 同一程序中一个库的两个版本各自改名 | 依赖链指定两个版本时可以构建 | 只对纯模块的包可行;头文件、C 库与宏不能改名;出现的频率没有测量 |
140154
155+
## 9. 失败时的提示
156+
157+
默认开启的条目在绝大多数工程上正确;少数工程遇到预料之外的失败时,构建**必须**说明怎样只关闭
158+
这一项来判断它是不是原因,且**禁止**在与它无关的失败与成功的构建上说。
159+
160+
1. 提示以 `tip:` 行给出,在命令的输出之后,不改变退出状态,`--quiet` 下不给出(`diag::on_failure`)。
161+
2. 提示从失败的**步骤**出发,不从"这次构建用过哪些条目"出发:
162+
163+
| 规则 | 失败的步骤 | 强度 |
164+
|---|---|---|
165+
| R1 | 源文件是私有片段拆出的单元 | 点名原文件 |
166+
| R2 | 编译一个单元,它导入了当前以此前的行号保留着的 BMI | 点名模块 |
167+
| R3 | 链接,而图中有拆出的片段或保留着的 BMI | 说明无法归属到单元 |
168+
| R4 | 其他任何步骤 | 不给出 |
169+
170+
3. 失败的步骤取自 ninja 的 `FAILED:` 行与步骤记录;取不到时按 R4。测试程序的运行失败不给出提示。
171+
4. 文本由登记表行的清单键、环境变量与 `check` 组成:`MCPP_PRIVATE_FRAGMENT=as-written mcpp build`
172+
(GCC 上为 `conservative`)、`MCPP_BMI_CUTOFF=exact mcpp build`;并写出 `MCPP_BUILDOPT=off`
173+
是下一级。两步之后失败依旧,原因不在这些条目之中。
174+
5. 构建图与此前的取值不同时,第一次构建**必须**按新的取值重新生成图:`MCPP_BUILDOPT`、
175+
`MCPP_PRIVATE_FRAGMENT`、`MCPP_BMI_SCHEDULE` 是快速路径所比较的请求的一部分。
176+
6. 提示所读的计划数据写在构建目录的 `buildopt-applied.tsv`,快速路径(没有计划)读同一个文件。
177+
141178
## 变更记录
142179
143180
| 版本 | 日期 | 变更 |
144181
|---|---|---|
145182
| 1.0 | 2026-11-17 | 首版(mcpp 2026.11.17.2):登记表、级别、接缝、总开关;私有模块片段作为独立单元;构建后的建议;语义提供者的边界;四项已记录、未实现 |
183+
| 1.1 | 2026-11-26 | 私有片段的判定:条件指令与 `#error`、`#warning` 放行,条件须在声明与片段处闭合;词法修正(数字分隔符、原始字符串、`extern "C"`、行连接);取值 `conservative`;登记表的 `check`;新增 §9 失败时的提示;§8 记录 clang 读者的实测结论 |

‎docs/specs/module-rebuilds.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
|---|---|
55
| 规范编号 | SPEC-018 |
66
| 标题 | 一次编辑之后哪些单元重新编译:按 BMI 内容截断、`bmi_cutoff`、构建目录的记录 |
7-
| 状态 | 评审中 v1.0 |
8-
| 版本 | 1.0 |
9-
| 最后修改 | 2026-11-17 |
7+
| 状态 | 评审中 v1.1 |
8+
| 版本 | 1.1 |
9+
| 最后修改 | 2026-11-26 |
1010
| 对应实现 | mcpp >= 2026.11.17.2;§2.1 的时间戳在 UTC 下自 2026.8 起成立 |
1111
| 相关设计文档 | `.agents/docs/2026-11-17-ninja-cascade-publish-supplement-design.md` §3 |
1212
| 相关 issue | #946 |
@@ -71,6 +71,12 @@ mcpp 不认识的格式按字节比较,结果只有"相同"与"变化"。
7171
没有读者。BMI 不含时间戳;改变文件字节的编辑(包括注释)即改变 BMI,且没有可按段隔离位置的
7272
结构。`bmi_cutoff` 对它无效。
7373

74+
2026-11-26 对 clang 20.1.7、22.1.8、23.1.3、23.1.6 的测量(SPEC-019 §8):非 inline 函数体不在
75+
BMI 中,函数的 32 位 ODR 哈希仍在,并随函数体变化;该哈希在记录中的下标随声明的形式而不同
76+
(同一版本的 `DECL_CXX_METHOD` 为 26、27、29),且随版本移动;哈希随机,约三分之一的编辑改变
77+
其 VBR 宽度,使其后的位偏移与偏移表同时变化。可靠地屏蔽它们需要声明记录的布局模型,
78+
没有这个模型不能保证不遮住接口的差异,因此 clang 的 BMI 仍按字节比较。
79+
7480
## 3. `bmi_cutoff`
7581

7682
| 取值 | "仅位置"的 BMI |
@@ -122,3 +128,4 @@ mcpp 不认识的格式按字节比较,结果只有"相同"与"变化"。
122128
| 版本 | 日期 | 变更 |
123129
|---|---|---|
124130
| 1.0 | 2026-11-17 | 首版(mcpp 2026.11.17.2,mcpp#946):按 BMI 内容截断;GCC 的时间戳屏蔽到终止符,"仅位置"的判定与两条排除;`bmi_cutoff`;构建目录的三个文件与运行结束时的两行;`mcpp.buildopt.keep` 与格式读者的分工;保留与比较由执行器完成,各宿主相同;对象按字节保留;判定登记于 SPEC-019 |
131+
| 1.1 | 2026-11-26 | §2.2 记录 clang 的 BMI 为何仍无读者(哈希下标随声明而异、VBR 宽度翻转与偏移表) |

0 commit comments

Comments
 (0)