Skip to content

Compare every variant of a multi-variant source, deterministically - #39

Merged
anakanemison merged 1 commit into
mschaller/u03-target-map-renames-one-placefrom
mschaller/u04-deterministic-variants
Nov 9, 2026
Merged

anakanemison merged 1 commit into
mschaller/u03-target-map-renames-one-placefrom
mschaller/u04-deterministic-variants

Conversation

@anakanemison

@anakanemison anakanemison commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

When one source compiles into several libraries with different flags, the differ compared only one variant per side, and which one depended on set iteration order, that is, on PYTHONHASHSEED. Pooling now keeps every variant, visits targets in sorted order, and compares each CMake variant with its best-matching Bazel variant (fewest errors, then warnings, then the smallest difference, then a stable order). A source with one variant per side takes the old path unchanged.

In any2bazel-lab, the same MySQL Server models gave 4,715 to 4,817 errors over 10 seeds, and a Blender migration's final models converged under 2 of 8. With this change, a later QGIS run's verdict was the same under three seeds. A source_map token that collapses several CMake TUs now yields one comparison per distinct TU, so the worklist can grow.

Stacked on #38 (tracking issue: #35). pytest tests/: 140 passed (132 on main). Lab proposal: P14.

🤖 Generated with Claude Code

@armandomontanez armandomontanez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we correlate various invocations with specific parts of build targets and use that to map the diffing behavior, but that's an entirely different work order.

Comment thread scripts/config.py Outdated
Comment on lines +93 to +94
# (diff._diff_variants; extra Bazel defines stay benign WARN under the
# asymmetric-subset rule). Only ever use for codegen

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff._diff_variants; is odd here. Is this the intention?

Suggested change
# (diff._diff_variants; extra Bazel defines stay benign WARN under the
# asymmetric-subset rule). Only ever use for codegen
# (extra Bazel defines stay benign WARN under the asymmetric-subset
# rule in `diff._diff_variants()`). Only ever use for codegen

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, need to invest in de-slopifying skills. Fixed.

_union_tus pooled library TUs into one source-keyed map with
dict.setdefault while iterating a set of target names. When one source is
compiled into several libraries with different flags (a full and a lite
build of the same file, a hardened variant), only one variant per side was
compared, and which one depended on set iteration order, that is, on
PYTHONHASHSEED. The verdict was not reproducible.

Measured in any2bazel-lab: the same MySQL Server models gave 4,715 to 4,817
errors over 10 hash seeds, a different error set each time, and the final
models of a Blender migration converged under 2 of 8 seeds. Projects
without multi-variant sources were unaffected (50 recorded verdicts
identical under 20 seeds).

Pooling now keeps every distinct variant per source, visiting targets in
sorted order. Each CMake variant is compared with its best-matching Bazel
variant: fewest errors, then warnings, then the smallest symmetric
difference of the two TUs' define, flag and include sets, then a stable
text order. Every CMake variant must be matched by some Bazel variant and
nothing is suppressed; an extra Bazel-only variant is tolerated, like an
extra Bazel flag. The distance term keeps a tie from choosing a variant
that only adds flags (-w, -Wno-error=...) over an exact one. A source with
one variant per side takes exactly the old path, and on every
single-variant verdict the lab has recorded, the result is unchanged.
Executables and the opt-in test union use the same pairing, and the Java
source union is visited in sorted order too.

One consequence for source_map users: a token that collapses several CMake
TUs (an AUTOMOC bundle, say) now yields one comparison, and so possibly one
discrepancy, per distinct CMake TU, so the worklist can grow. The
source_map comment in config.py says so.

In the lab's later QGIS run with this change, the differ gave the same
verdict under three seeds.

Lab-Proposal: P14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anakanemison
anakanemison removed this pull request from stack #59 November 2, 2026 17:49
@anakanemison
anakanemison force-pushed the mschaller/u04-deterministic-variants branch from 7bf197e to 8fdabc2 Compare November 2, 2026 17:50
@anakanemison
anakanemison added this pull request to stack #63 November 2, 2026 17:54
@anakanemison
anakanemison merged commit a444ce3 into main Nov 9, 2026
2 of 4 checks passed
@anakanemison
anakanemison deleted the mschaller/u04-deterministic-variants branch November 9, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants