Skip to content

Commit e50177d

Browse files
authored
2026.11.26.1: a private fragment after conditions, the purview read as C++ tokens, a tip for the optimization a failure may be (#1014)
Release 2026.11.26.1. Design record: `.agents/docs/2026-11-26-clang-bmi-cutoff-and-private-fragment-refinement-design.md` (v4). **A private module fragment after conditions (SPEC-019 §5).** `#if`, `#ifdef`, `#ifndef`, `#elif`, `#elifdef`, `#elifndef`, `#else`, `#endif`, `#error` and `#warning` before `module :private;` no longer keep the source from being built as two units: a condition only decides which declarations exist, and the implementation unit receives them from the interface. A condition still open at the module declaration or at the fragment, and any directive that changes the fragment's meaning (`#define`, `#undef`, `#include`, `#pragma`, `#line`, `_Pragma`), leave the source as written. `private_fragment = "conservative"` keeps the rule before this change, and is the check available on GCC. **The purview is read as C++ tokens.** A digit separator (`1'000`) no longer hides the rest of its line, a raw string may run over lines and hold `module :private;`, a `static` inside `extern "C" { … }` is at namespace scope, and a line continuation between the module declaration and the fragment leaves the source as written. Each only makes more sources built as written. **A failure says how to check the optimization (SPEC-019 §9).** When a build fails at a step an entry acted on (a source built as two units; a unit that imports a BMI kept with earlier lines; a link where either is present), it ends with a `tip:` giving the one invocation that turns that entry off. The text is made of the register's key, environment name and new `check` value. A failure of another step, a successful build and `--quiet` say nothing. **Found on the way.** `MCPP_PRIVATE_FRAGMENT`, `MCPP_BMI_SCHEDULE` and `MCPP_BUILDOPT` were not part of the request a recorded build is replayed for: a build with no edit after changing one replayed the graph the other value had written. They are now. **Not implemented: a reader for clang's `.pcm` (design item A).** Measured with clang 20.1.7, 22.1.8, 23.1.3 and 23.1.6: the operand that holds a function's hash is at an index that varies with the declaration (26, 27 and 29 for member functions of one version) and the version, and a third of the edits change the VBR width of that 32-bit value, which moves the bit offsets and three offset tables. A reader could not tell the field from an interface change, so SPEC-018 §2.2 and SPEC-019 §8 record the measurement and the conditions under which it becomes possible. **Tests.** `modules/buildopt`: about 55 verdicts of the purview (directives, conditions, lexical forms, `conservative`), a reassembly property, noise invariance, 400 random texts, the tip rules R1 to R4, the register's `check`, the `FAILED:` reader. `tests/e2e/build/basics.cpp` 1161 to 1164: conditions and macros, `conservative` and the first build after a value changes, the tip on clang and GCC with the check taking effect, an unrelated failure and `--quiet` saying nothing, a kept BMI. **Also on this branch.** The `mingw-cross-wine` job takes Wine from the `wine@11.0` package the engine's runner row names instead of apt (the step exceeded its 20 minutes three times on main on 2026-11-24): it installs the package through xlings, puts its `bin` on `PATH`, drops the i386 architecture and the `wine-debs` cache, and moves the xlings cache key to `v4`. Two checks of this pull request fail on main as well, without this change (run 45718748639): test 992 (`mcpp pack --target openkal --pkg-format polyglot` reaches its 600 s limit) and `binding-own-home/200` (the runtime binding selects the runner home's glibc). They are not part of this change.
1 parent 5032751 commit e50177d

24 files changed

Lines changed: 1591 additions & 164 deletions

‎.agents/docs/2026-11-26-clang-bmi-cutoff-and-private-fragment-refinement-design.md‎

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.

‎.agents/docs/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ superseded_by: 2026-09-07-....md # when status is superseded
1818
---
1919
```
2020

21-
373 records.
21+
374 records.
2222

2323
## By subject
2424

@@ -30,6 +30,7 @@ Records that declare one. Everything else is listed by date below.
3030

3131
### build
3232

33+
- [clang BMI 的截断与私有模块片段判定的收窄](2026-11-26-clang-bmi-cutoff-and-private-fragment-refinement-design.md) — active
3334
- [第二部分之后的补充方案:带修正的 ninja、模块重编译的级联、工作区发布与本轮遗留项](2026-11-17-ninja-cascade-publish-supplement-design.md) — active
3435
- [大型工作区的构建空间与复用(mcpp#874)](2026-10-31-workspace-space-and-reuse-design.md) — active
3536
- [依赖 image 的资源归属、模块扫描边界与锁文件稳定写入](2026-10-21-resource-ownership-module-scan-and-lock-write-design.md) — active
@@ -215,6 +216,7 @@ Records that declare one. Everything else is listed by date below.
215216

216217
### 2026-11
217218

219+
- [clang BMI 的截断与私有模块片段判定的收窄](2026-11-26-clang-bmi-cutoff-and-private-fragment-refinement-design.md) — active
218220
- [测试与 CI 一轮的收尾:平台列未命中的刷新条件(mcpp#996)、`i686-windows-msvc` 行、工作区索引与引号键的迁移、索引的全量验证](2026-11-22-test-round-wrap-up-plan.md) — active
219221
- [生态级方案:内核接口的供给与能力,派生状态的核对,存储的引用](2026-11-22-kernel-interface-and-derived-state-ecosystem-design.md) — active
220222
- [包的特性作为机器可读的回答:一个目录项,两种来源,三种状态(mcpp#992)](2026-11-21-package-features-query-design.md) — active

‎.github/workflows/cross-build-test.yml‎

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ jobs:
235235
- uses: actions/checkout@v4
236236

237237
# Restored here and saved by this job alone, on main, after its last
238-
# step (rule R3). The Wine packages were evicted with everything else
239-
# while the repository's caches exceeded their limit, and `apt` then
240-
# took 26 to 50 minutes (2026-10-01); with one writer per key they stay.
238+
# step (rule R3).
241239
- name: Restore mcpp sandbox
242240
id: sandbox
243241
uses: actions/cache/restore@v4
@@ -252,72 +250,9 @@ jobs:
252250
uses: actions/cache/restore@v4
253251
with:
254252
path: ~/.xlings
255-
key: xlings-${{ runner.os }}-mingw-cross-v3-${{ hashFiles('.xlings.json') }}
253+
key: xlings-${{ runner.os }}-mingw-cross-v4-${{ hashFiles('.xlings.json') }}
256254
restore-keys: |
257-
xlings-${{ runner.os }}-mingw-cross-v3-
258-
259-
# THE KEY NAMES THE RUNNER IMAGE, because the image is what the cached
260-
# packages have to agree with. Wine's i386 closure is Multi-Arch: same
261-
# with the amd64 libraries the image ships, and the two must be one
262-
# version. Under the old fixed key (`-v1`) the cache was saved once and
263-
# never again, the image moved on, and on 2026-10-15 (run 38695300904,
264-
# a cache HIT) the cached libxml2:i386 3.9 met the image's
265-
# libxml2:amd64 3.10: dpkg installed the stale i386 package, apt then
266-
# upgraded it, and the upgrade's shared changelog was refused. A new
267-
# image is a new key; until main has saved it, `restore-keys` hands back
268-
# the previous image's packages, which the step below only uses where
269-
# their version is still the one apt asks for.
270-
- name: Runner image version
271-
id: image
272-
run: echo "version=${ImageVersion:-unknown}" >> "$GITHUB_OUTPUT"
273-
274-
- name: Restore wine debs
275-
id: wine
276-
uses: actions/cache/restore@v4
277-
with:
278-
path: ~/wine-debs
279-
key: wine-debs-${{ runner.os }}-ubuntu24.04-${{ steps.image.outputs.version }}
280-
restore-keys: |
281-
wine-debs-${{ runner.os }}-ubuntu24.04-
282-
283-
# APT INSTALLS, ALWAYS; THE CACHE ONLY SPARES IT THE DOWNLOAD. The cached
284-
# packages are put where apt keeps what it downloaded, and apt then
285-
# resolves wine against the image as it is today: a cached package whose
286-
# version is still current is used as is, anything newer is fetched.
287-
# Nothing older than the image is ever installed, which is what
288-
# `dpkg -i` of the cached set did whenever the image had moved on. Cold
289-
# (no cache at all), this is the plain install it always was.
290-
- name: Install wine
291-
timeout-minutes: 20
292-
run: |
293-
sudo dpkg --add-architecture i386 || true
294-
# The runner image carries third-party apt lists (Google Chrome
295-
# among them) that this job does not use, and a transient
296-
# `Hash Sum mismatch` on one of them fails the whole update -- which
297-
# killed two cross-build jobs in setup, before a single byte was
298-
# compiled. Dropping the lists this job has no use for is what makes
299-
# the step's failure mean something about this job.
300-
#
301-
# BY CONTENT, NOT BY FILENAME. The first attempt removed
302-
# `google-chrome.list` and the update failed on the same URL: on
303-
# ubuntu-24.04 the runner writes deb822 `.sources` files, so the
304-
# name was a guess and the guess was wrong.
305-
sudo grep -rlE 'dl[.]google[.]com|packages[.]microsoft[.]com' \
306-
/etc/apt/sources.list.d/ 2>/dev/null | xargs -r sudo rm -f
307-
if ls ~/wine-debs/*.deb >/dev/null 2>&1; then
308-
sudo cp ~/wine-debs/*.deb /var/cache/apt/archives/
309-
fi
310-
sudo apt-get update -qq
311-
sudo apt-get install -y --download-only wine64 wine \
312-
|| sudo apt-get install -y --download-only wine
313-
# What main saves is what this image installs: packages no longer
314-
# in any index (the previous image's, carried in by restore-keys)
315-
# are dropped first, so the cache does not grow with every image.
316-
sudo apt-get autoclean -qq
317-
rm -rf ~/wine-debs && mkdir -p ~/wine-debs
318-
cp /var/cache/apt/archives/*.deb ~/wine-debs/ 2>/dev/null || true
319-
sudo apt-get install -y wine64 wine || sudo apt-get install -y wine
320-
wine --version
255+
xlings-${{ runner.os }}-mingw-cross-v4-
321256
322257
- name: Bootstrap mcpp via xlings
323258
env:
@@ -344,6 +279,21 @@ jobs:
344279
echo "XLINGS_BIN=$HOME/.xlings/subos/default/bin/xlings" >> "$GITHUB_ENV"
345280
echo "MCPP_BOOT=$MCPP_BOOT" >> "$GITHUB_ENV"
346281
282+
# Wine is the package the engine's Windows-on-Linux runner names
283+
# (`xim:wine@11.0`, builtin.toml): one portable WoW64 tree, which runs
284+
# 32- and 64-bit PE programs without the host's i386 architecture. Taken
285+
# from apt, Wine was a closure of about 200 packages whose download
286+
# depended on the runner's mirror and on a cache the repository's limit
287+
# evicts; on 2026-11-24 it exceeded the step's 20 minutes three times in
288+
# a row. The package is one archive, kept with the xlings cache.
289+
- name: Install wine
290+
run: |
291+
"$XLINGS_BIN" install wine@11.0 -y
292+
bin="$HOME/.xlings/data/xpkgs/xim-x-wine/11.0/bin"
293+
test -x "$bin/wine" || { echo "::error::wine 11.0 is not at $bin"; exit 1; }
294+
echo "$bin" >> "$GITHUB_PATH"
295+
"$bin/wine" --version
296+
347297
- uses: ./.github/actions/use-built-mcpp
348298
with:
349299
host: linux-x86_64
@@ -466,13 +416,6 @@ jobs:
466416
path: ~/.xlings
467417
key: ${{ steps.xlings.outputs.cache-primary-key }}
468418

469-
- name: Save wine debs
470-
if: ${{ github.event_name == 'push' && steps.wine.outputs.cache-hit != 'true' }}
471-
uses: actions/cache/save@v4
472-
with:
473-
path: ~/wine-debs
474-
key: ${{ steps.wine.outputs.cache-primary-key }}
475-
476419
# ── windows → linux ───────────────────────────────────────────────────────
477420
# The mirror of mingw-cross-wine. Two jobs because a Windows runner cannot
478421
# execute the ELF it produces; the artefact is handed to a Linux job and

‎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/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
| [SPEC-015](target-sets.md) | 目标集合与腿:集合的写法与展开,命令对多条腿的语义,串行规划与一起构建,测试归档,机器输出 | 评审中 v1.0 | 2026-10-30 | mcpp >= 2026.10.30.1 |
4848
| [SPEC-016](targets-and-providers.md) | 目标与提供者:行、提供者、选择规则、平台定义的行、C 环境与执行、报告、机器输出与锁 | 评审中 v1.9 | 2026-11-23 | mcpp >= 2026.11.9.1;v1.1 条款 mcpp >= 2026.11.10.1;v1.9 条款 mcpp >= 2026.11.23.1 |
4949
| [SPEC-017](test.md) | mcpp 测试规范:测试程序、测试协议、记录、存储、启动描述与框架声明;基础能力 B1–B6 与可选能力 O1–O12 | 评审中 v2.6 | 2026-11-21 | mcpp >= 2026.11.8.1;逐条标注;B5、B6 的新键、O3 的运行器一侧、O8 mcpp >= 2026.11.10.1;O9 mtest >= 0.6.0;O10 mcpp >= 2026.11.13.1;O11、O12 与 P5.6 mcpp >= 2026.11.21.1 |
50-
| [SPEC-018](module-rebuilds.md) | 模块的重编译:按 BMI 内容截断,GCC 的时间戳与行映射,`bmi_cutoff`,构建目录的记录 | 评审中 v1.0 | 2026-11-17 | mcpp >= 2026.11.17.2 |
51-
| [SPEC-019](build-optimizations.md) | 构建优化:登记表、级别、接缝、总开关,私有模块片段作为独立单元,构建后的建议 | 评审中 v1.0 | 2026-11-17 | mcpp >= 2026.11.17.2 |
50+
| [SPEC-018](module-rebuilds.md) | 模块的重编译:按 BMI 内容截断,GCC 的时间戳与行映射,`bmi_cutoff`,构建目录的记录 | 评审中 v1.1 | 2026-11-26 | mcpp >= 2026.11.17.2 |
51+
| [SPEC-019](build-optimizations.md) | 构建优化:登记表、级别、接缝、总开关,私有模块片段作为独立单元,构建后的建议,失败时的提示 | 评审中 v1.1 | 2026-11-26 | mcpp >= 2026.11.17.2;§5、§9 的新增自 2026.11.26.1 |
5252

5353
## 文档约定
5454

0 commit comments

Comments
 (0)