Skip to content

cl: preserve diagnostics for invalid method receivers - #2417

Open
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/nonlocal-method-diagnostic-20260826
Open

cl: preserve diagnostics for invalid method receivers#2417
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/nonlocal-method-diagnostic-20260826

Conversation

@cpunion

@cpunion cpunion commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • make receiver metadata naming reject unsupported AST forms without panicking
  • preserve local named, generic, parenthesized, and pointer receiver naming
  • leave invalid and non-local receiver declarations to go/types so LLGo reports the Go-compatible diagnostic
  • add the Go issue5089 receiver as a regression test

Behavior

Before this change, compiling fixedbugs/issue5089.go panics in cl.recvTypeName while preloading the *bufio.Reader method declaration. After this change, metadata collection skips that invalid declaration and the compiler reports:

cannot define new methods on non-local type bufio.Reader

This fixes 1 Go 1.26 GOROOT compatibility case. It also addresses the receiver-AST crash behind the issue5089 xfail proposed in #2265; if #2265 lands first, that entry should be removed when this PR is rebased.

Validation

  • go test -count=1 ./cl -run TestRecvTypeName|TestAstAndTypesFuncNameCoverage|TestParsePkgSyntaxSkipsNonLocalMethodReceiver
  • go test -count=1 ./internal/build
  • Go 1.26.5 fixedbugs/issue5089.go errorcheck on macOS arm64
  • Go 1.26.5 fixedbugs/issue5089.go errorcheck on OrbStack Linux arm64
  • Go 1.26.5 fixedbugs/issue5089.go errorcheck on Windows arm64 through the Windows integration branch
  • full cl suite audited; its only local failures are unrelated LTO output mismatches caused by LLVM warnings for RISC-V +zcm/+zcz features

Xfail history

This PR intentionally has no test/goroot/xfail.yaml deletion for fixedbugs/issue5089.go: the entry was added by 3f3090f71 and then removed from main by 4da2efa8a, so it is absent from this PR base (6fe8babd4). Commit 15c415828 restores the entry on the separate, unmerged #2265 line of work and is not an ancestor of this PR. If that commit is integrated before this fix, its stale issue5089 entry must be dropped while rebasing. The Go 1.26 errorcheck case also passes with an empty xfail configuration after this fix.

@cpunion cpunion added go-test-compat Go standard-library and GOROOT test compatibility go1.26 Go 1.26 compatibility and support labels Aug 26, 2026

@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: nonlocal method receiver diagnostic

Clean, well-scoped refactor. Converting recvTypeName and astFuncName from panic-on-invalid to returning an ok boolean is the right call — it lets the type checker surface the real diagnostic (e.g. func (b *bufio.Reader) Buffered()) instead of the compiler dying with an internal panic. Pointer handling is correctly consolidated into recvTypeName, pointer-to-pointer is properly rejected, and all three call sites (initFiles, ParsePkgSyntaxWithOptions, compileFuncDecl) check ok and skip cleanly.

Reviewed across four dimensions:

  • Correctness/quality — recursion covers Ident/IndexExpr/IndexListExpr/ParenExpr/StarExpr; nested *(*T) correctly rejected. Good.
  • Performance — no regression; runs once per decl, bounded recursion, no extra allocations.
  • Security — no unbounded-recursion/DoS surface; ASTs come from go/parser which enforces its own nesting limit. Change is a net panic-surface improvement (fail-closed).
  • Documentation — new doc comments accurately describe the ok-boolean behavior; removal of the // TODO: support generic type is justified since the new code handles IndexExpr/IndexListExpr.

Two minor, non-blocking notes inline. No blocking issues found.

Comment thread cl/import.go
Comment thread cl/import.go Outdated
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.09677% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cl/import.go 86.20% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown

LLGo baseline benchmarks

46dec45b3986 | workflow run | long-term charts

Program measurements

Platform Workload File size vs base Text size vs base Build vs base Run vs base
Linux cprintf 19256 B 0 B / +0.0% 387 B 0 B / +0.0% 321.734 ms -3.464 ms / -1.1% (better) 1.290 ms -110.9 us / -7.9% (better)
Linux cprintf-lto 19088 B 0 B / +0.0% 368 B 0 B / +0.0% 329.165 ms -8.601 ms / -2.5% (better) 1.309 ms -70.23 us / -5.1% (better)
Linux fmtprintf 1653232 B 0 B / +0.0% 501083 B 0 B / +0.0% 2.828 s +8.13 ms / +0.3% (worse) 3.257 ms -29.08 us / -0.9% (better)
Linux fmtprintf-lto 1525824 B 0 B / +0.0% 459700 B 0 B / +0.0% 8.685 s -2.715 ms / -0.03125% (better) 3.115 ms +30.76 us / +1.0% (worse)
Linux println 62032 B 0 B / +0.0% 15261 B 0 B / +0.0% 330.599 ms +485.5 us / +0.1% (worse) 1.708 ms +113.2 us / +7.1% (worse)
Linux println-lto 53840 B 0 B / +0.0% 12882 B 0 B / +0.0% 517.943 ms +6.918 ms / +1.4% (worse) 1.604 ms -19.87 us / -1.2% (better)
macOS cprintf 84480 B 0 B / +0.0% 16493 B 0 B / +0.0% 467.159 ms -203 ms / -30.3% (better) 3.703 ms -1.727 ms / -31.8% (better)
macOS cprintf-lto 100704 B 0 B / +0.0% 16473 B 0 B / +0.0% 579.789 ms +3.054 ms / +0.5% (worse) 3.895 ms +231.3 us / +6.3% (worse)
macOS fmtprintf 1498256 B 0 B / +0.0% 882133 B 0 B / +0.0% 3.639 s -658.8 ms / -15.3% (better) 6.982 ms -1.474 ms / -17.4% (better)
macOS fmtprintf-lto 1208976 B 0 B / +0.0% 875129 B 0 B / +0.0% 7.836 s -727.3 ms / -8.5% (better) 7.275 ms +509.2 us / +7.5% (worse)
macOS println 114832 B 0 B / +0.0% 34849 B 0 B / +0.0% 440.333 ms -126.4 ms / -22.3% (better) 4.464 ms -570.5 us / -11.3% (better)
macOS println-lto 118656 B 0 B / +0.0% 32489 B 0 B / +0.0% 629.881 ms -128.9 ms / -17.0% (better) 4.529 ms +216.4 us / +5.0% (worse)
Core language and compiler benchmarks
Platform Benchmark ns/op vs base
Linux BenchmarkLookupPCRandom 13.250 ns/op +0.01 ns/op / +0.1% (worse)
Linux BenchmarkMergeCompilerFlags 150.600 ns/op -0.5 ns/op / -0.3% (better)
Linux BenchmarkMergeLinkerFlags 94.710 ns/op -0.3 ns/op / -0.3% (better)
Linux BenchmarkChannelBuffered 35.570 ns/op +0.02 ns/op / +0.1% (worse)
Linux BenchmarkChannelHandoff 29282 ns/op +847 ns/op / +3.0% (worse)
Linux BenchmarkDefer 47.490 ns/op -0.85 ns/op / -1.8% (better)
Linux BenchmarkDirectCall 1.557 ns/op -0.025 ns/op / -1.6% (better)
Linux BenchmarkGlobalRead 1.869 ns/op +0.001 ns/op / +0.1% (worse)
Linux BenchmarkGlobalWrite 2.482 ns/op -0.025 ns/op / -1.0% (better)
Linux BenchmarkGoroutine 31664 ns/op -363 ns/op / -1.1% (better)
Linux BenchmarkInterfaceCall 8.407 ns/op -0.001 ns/op / -0.01189% (better)
Linux BenchmarkRuntimeGetG 2.181 ns/op +0.001 ns/op / +0.04587% (worse)
macOS BenchmarkLookupPCRandom 13.040 ns/op -5.49 ns/op / -29.6% (better)
macOS BenchmarkMergeCompilerFlags 138.600 ns/op -95.9 ns/op / -40.9% (better)
macOS BenchmarkMergeLinkerFlags 104.700 ns/op -8.3 ns/op / -7.3% (better)
macOS BenchmarkChannelBuffered 26.180 ns/op -7.04 ns/op / -21.2% (better)
macOS BenchmarkChannelHandoff 8278 ns/op -266 ns/op / -3.1% (better)
macOS BenchmarkDefer 38.530 ns/op -4.33 ns/op / -10.1% (better)
macOS BenchmarkDirectCall 1.144 ns/op -0.071 ns/op / -5.8% (better)
macOS BenchmarkGlobalRead 1.192 ns/op -0.233 ns/op / -16.4% (better)
macOS BenchmarkGlobalWrite 1.140 ns/op -0.372 ns/op / -24.6% (better)
macOS BenchmarkGoroutine 49788 ns/op -6167 ns/op / -11.0% (better)
macOS BenchmarkInterfaceCall 5.346 ns/op -0.437 ns/op / -7.6% (better)
macOS BenchmarkRuntimeGetG 2.712 ns/op +0.048 ns/op / +1.8% (worse)

Compared with 6fe8babd468c measured in the same runner job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go1.26 Go 1.26 compatibility and support go-test-compat Go standard-library and GOROOT test compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant