Skip to content

test: support target-matrix and post-ABI IR checks - #2319

Merged
xushiwei merged 11 commits into
xgo-dev:mainfrom
zhouguangyuan0718:codex/filecheck-post-abi-optin
Aug 18, 2026
Merged

test: support target-matrix and post-ABI IR checks#2319
xushiwei merged 11 commits into
xgo-dev:mainfrom
zhouguangyuan0718:codex/filecheck-post-abi-optin

Conversation

@zhouguangyuan0718

@zhouguangyuan0718 zhouguangyuan0718 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Add explicit, source-embedded FileCheck support for target matrices and opt-in post-ABI IR while keeping focused handwritten checks as the default.

  • // LITTEST <GOOS/GOARCH...> cross-generates the existing default IR stage for every listed target.
  • // LITTEST: POST-ABI <GOOS/GOARCH...> explicitly selects target-ABI-lowered, pre-optimization IR.
  • The fixture's current effective target is always checked; listed targets add cross-compilation coverage and a matching current target is deduplicated.
  • An unlisted CI platform still exercises portable CHECK and applicable GOARCH assertions. Add it to the matrix when it has a distinct IR contract.
  • Runtime output still runs once on the host; target-matrix IR generation is compile-only.
  • FileCheck enables a layered prefix set such as CHECK,ARM64,DARWIN-ARM64: portable assertions use CHECK, same-architecture assertions use ARM64/AMD64, and only true OS differences use the exact target prefix.
  • litgen supports automatic target-matrix maintenance at the default and post-ABI stages. It first merges all-target output, then safely merges identical gaps among two or more targets with the same GOARCH.
  • The float conversion post-ABI matrix is automatically maintained; its directive count drops from 101 to 73 by sharing identical Darwin/Linux arm64 lowering checks without weakening coverage.
  • Existing platform alternatives such as closure nest|swiftself, jmpbuf sizes, setjmp names, and stderr symbols are replaced by explicit target assertions.
  • 44 non-cgo default-stage fixtures now cross-check Darwin/arm64 and Linux/amd64 on either host. Four direct or transitive cgo fixtures retain plain // LITTEST, because cross-cgo additionally requires a target C compiler, headers, and sysroot; their explicit platform checks run on matching platform CI.
  • Obsolete literal out.ll IR-check modes remain removed; source-embedded FileCheck is the only IR golden path.

Validation

  • go fmt ./...
  • git diff --check
  • go test ./internal/littest ./internal/filecheck ./internal/llgen ./chore/litgen ./cl/cltest
  • go test ./chore/litgen -coverprofile=... (80.7% statement coverage)
  • go run ./chore/litgen -u --check cl
  • go test ./cl -count=1 on Darwin/arm64 (includes current and additional matrix targets; 307.038s)
  • Three-target POST-ABI integration coverage verifies ARM64 folding while retaining LINUX-AMD64 differences
  • Focused unit and fixture suites on goallc-ubuntu, proving Linux current-target checks are deduplicated while Darwin/arm64 and Linux/arm64 share the generated architecture contract

fennoai[bot]

This comment was marked as outdated.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch from bf3ac2a to 1c8e3cd Compare August 15, 2026 02:25
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown

LLGo baseline benchmarks

8b5e93fc852d | workflow run | long-term charts

Program measurements

Platform Workload File size vs base Build vs base Run vs base
Linux cprintf 19384 B +0.0% 341.795 ms -1.6% (better) 1.261 ms -4.9% (better)
Linux fmtprintf 1880776 B +0.0% 2.635 s -1.2% (better) 3.291 ms +0.2% (worse)
Linux println 68880 B +0.0% 338.839 ms -2.8% (better) 1.541 ms -8.4% (better)
macOS cprintf 84672 B +0.0% 448.508 ms +10.7% (worse) 2.783 ms +7.9% (worse)
macOS fmtprintf 1892208 B +0.0% 2.440 s -34.5% (better) 12.662 ms -17.7% (better)
macOS println 121376 B +0.0% 381.447 ms -2.7% (better) 4.011 ms -9.0% (better)
Core language and compiler benchmarks
Platform Benchmark ns/op vs base
Linux BenchmarkLookupPCRandom 13.230 ns/op -0.5% (better)
Linux BenchmarkMergeCompilerFlags 150.900 ns/op -0.1% (better)
Linux BenchmarkMergeLinkerFlags 94.840 ns/op +0.1% (worse)
Linux BenchmarkChannelBuffered 33.690 ns/op +0.1% (worse)
Linux BenchmarkChannelHandoff 26133 ns/op -10.9% (better)
Linux BenchmarkDefer 44.840 ns/op +0.9% (worse)
Linux BenchmarkDirectCall 1.557 ns/op -0.1% (better)
Linux BenchmarkGlobalRead 1.557 ns/op +0.1% (worse)
Linux BenchmarkGlobalWrite 2.487 ns/op +0.1% (worse)
Linux BenchmarkGoroutine 32651 ns/op -0.7% (better)
Linux BenchmarkInterfaceCall 8.106 ns/op +0.1% (worse)
Linux BenchmarkRuntimeGetG 1.868 ns/op +0.0%
macOS BenchmarkLookupPCRandom 10.970 ns/op -14.3% (better)
macOS BenchmarkMergeCompilerFlags 97.230 ns/op -9.0% (better)
macOS BenchmarkMergeLinkerFlags 61.110 ns/op -23.3% (better)
macOS BenchmarkChannelBuffered 20.470 ns/op -1.3% (better)
macOS BenchmarkChannelHandoff 6483 ns/op +0.7% (worse)
macOS BenchmarkDefer 25.620 ns/op -1.5% (better)
macOS BenchmarkDirectCall 0.941 ns/op -6.6% (better)
macOS BenchmarkGlobalRead 0.957 ns/op -5.9% (better)
macOS BenchmarkGlobalWrite 0.941 ns/op -5.9% (better)
macOS BenchmarkGoroutine 27189 ns/op -26.3% (better)
macOS BenchmarkInterfaceCall 5.356 ns/op -1.3% (better)
macOS BenchmarkRuntimeGetG 2.322 ns/op +6.4% (worse)

Compared with 0f480253029a measured in the same runner job.

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch 2 times, most recently from 11e94b6 to b8e5518 Compare August 15, 2026 10:17
@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

fennoai[bot]

This comment was marked as outdated.

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch from b8e5518 to d12e4d4 Compare August 15, 2026 10:28
@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

fennoai[bot]

This comment was marked as outdated.

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch from d12e4d4 to 45ffb53 Compare August 15, 2026 10:39
@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

fennoai[bot]

This comment was marked as outdated.

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch 3 times, most recently from 386ff27 to ac6f7b1 Compare August 16, 2026 13:36
@zhouguangyuan0718 zhouguangyuan0718 changed the title test: add opt-in post-ABI IR checks test: support pre/post-ABI target-matrix IR checks Aug 16, 2026
@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

@zhouguangyuan0718 zhouguangyuan0718 changed the title test: support pre/post-ABI target-matrix IR checks test: support target-matrix and post-ABI IR checks Aug 16, 2026
@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

fennoai[bot]

This comment was marked as outdated.

fennoai[bot]

This comment was marked as outdated.

@zhouguangyuan0718

Copy link
Copy Markdown
Contributor Author

/review

@fennoai fennoai Bot 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.

Review: target-matrix and post-ABI IR checks

Solid, well-structured PR. The Spec-based refactor of littest is a clear improvement over the old Mode enum, error handling is consistent, dead code (generalizeClosureEnvAttrs, genZip/inCompilerDir, out.ll special-casing) is cleanly removed, and the multi-target merge logic (LCS + per-GOARCH grouping) is thoughtfully separated. Empty-slice guards are present in the merge/rewrite functions, and the panicerror recovery in genTargetVariants correctly re-panics on unexpected payloads.

Findings below are non-blocking; the first is the one most worth confirming. No blocking correctness bugs found.

Verification: four review dimensions (quality, performance, security, docs) run against the fixed diff range 7f954d6...17d1c86.

Additional notes (no inline location)

  • Performance (informational): per-target compiles in testFrom/testIRTargets and genTargetVariants scale linearly with the target matrix, and ForceRebuild=true (required for correctness — a cache hit skips the module text) means each compile pays full build cost. Fine for test tooling; just keep LITTEST matrices deliberately small.
  • Docs (cosmetic): CLAUDE.md:80-83 shows both // LITTEST ... and // LITTEST: POST-ABI ... markers in one fenced block. They are mutually exclusive first-line markers; splitting into two blocks (as dev/README.md does) would avoid reading them as one header.

Comment thread cl/cltest/cltest.go
func additionalIRTargets(targets []littest.Target, currentPrefix string) []littest.Target {
additional := make([]littest.Target, 0, len(targets))
for _, target := range targets {
prefixes := filecheck.TargetPrefixes(target.GOOS, target.GOARCH, "")

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.

[P2] additionalIRTargets dedup uses inconsistent prefix derivation

currentPrefix is computed by the caller from the actual generated base target via filecheck.TargetPrefixes(goos, goarch, generated.Target), so if the base build has a non-empty named Target it becomes TARGET-<X>. But here each matrix entry's prefix is recomputed with an empty target string (TargetPrefixes(target.GOOS, target.GOARCH, "")), yielding <GOOS>-<GOARCH>. When the base target is named, the equality check never matches, so the entry equal to the base is not skipped and gets recompiled/rechecked redundantly. In the common golden-test flow Target is empty so this is latent, but the two sides derive the prefix from different inputs. Consider deduplicating on GOOS/GOARCH directly, or feeding the same TargetPrefixes inputs on both sides.

Comment on lines +151 to +152
default:
return Spec{}, false, nil

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.

[P3] Malformed LITTEST marker silently disables the spec file

A first line that starts with the marker but doesn't parse — e.g. // LITTEST: POST-ABI-EXTRA or // LITTESTfoo — fails the exact-match switch and both HasPrefix(marker, X+" ") cases, so it falls into default and returns found=false, treating the file as having no marker at all. Given the fail-loud handling elsewhere (parseTargets errors on bad targets), a mistyped LITTEST/LITTEST: POST-ABI directive vanishing silently is inconsistent and could mask an author error. Consider returning an error when the line begins with the marker prefix but doesn't parse.

seen := make(map[string]struct{}, len(fields))
for _, field := range fields {
goos, goarch, ok := strings.Cut(field, "/")
if !ok || goos == "" || goarch == "" || strings.Contains(goarch, "/") {

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.

[P3] parseTargets: whitelist GOOS/GOARCH characters

parseTargets rejects empty components and a goarch containing /, but not ., .., backslashes, or other path-meaningful characters. These values later flow into a result.<GOOS>-<GOARCH>.txt filename (cltest.go) and into a FileCheck --check-prefix= arg. Practical path traversal is blocked (only one / is guaranteed and it's stripped; reaching the write requires the target to actually compile), and prefixes are passed as separate argv entries so there's no injection — but a defensive whitelist like ^[a-z0-9_]+$ on GOOS/GOARCH would remove the ambiguity cheaply. Also note the strings.Contains(goarch, "/") guard is what rejects a/b/c (since Cut splits on the first /); a brief comment there would clarify intent.

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch 2 times, most recently from 62dc5f3 to d1aedbd Compare August 17, 2026 08:39
@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch 2 times, most recently from 9df1593 to 64ac44b Compare August 17, 2026 10:49
@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/filecheck-post-abi-optin branch from 64ac44b to 8b5e93f Compare August 17, 2026 11:15
@xushiwei
xushiwei merged commit f98b8d9 into xgo-dev:main Aug 18, 2026
36 of 38 checks passed
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