Skip to content

[Based on #2033] ssa,runtime: return runtime.Error values for assertions and faults#2034

Open
cpunion wants to merge 18 commits into
xgo-dev:mainfrom
cpunion:codex/stage5-recover-errors
Open

[Based on #2033] ssa,runtime: return runtime.Error values for assertions and faults#2034
cpunion wants to merge 18 commits into
xgo-dev:mainfrom
cpunion:codex/stage5-recover-errors

Conversation

@cpunion

@cpunion cpunion commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Depends on #2033

Dependency

Stack: #2079 -> #2090 -> #2033 -> this PR.

#2033 supplies direct-deferred-call recover ownership on top of the GLS-backed runtime state. This PR adds the error-value and fault-signal behavior that depends on those semantics.

Problem

Failed type assertions previously panicked with a plain errorString, so recovered values did not implement runtime.Error like gc. Fault recovery also omitted SIGBUS on supported Unix targets.

Implementation

  • Build a real *runtime.TypeAssertionError for failed non-comma-ok assertions, including missing-method lookup from ABI method tables.
  • Keep source-interface ABI materialization out of the assertion site to avoid references to another package's private local-generic symbols.
  • Route SIGBUS through the same recoverable fault path as SIGSEGV, using per-OS signal constants.
  • Update LLVM golden checks to assert TypeAssertError followed by Panic.
  • Inherit [Based on #2090] ssa,runtime: tighten recover to direct deferred calls #2033's GLS runtime state; this PR adds no pthread key or additional locality store.

Conformance

Removed xfails for:

  • recover2.go
  • recover4.go
  • zerodivide.go
  • fixedbugs/issue73917.go
  • fixedbugs/issue73920.go

recover1.go remains xfailed for the narrower recursive-panic residual: a plain sub-call inside the deferred function can still observe the panic. Three newly added regression cases for that unsupported behavior remain explicitly skipped with the same reason; no previously running test was disabled.

Validation

Tests were serialized with GOMAXPROCS=2, GOMEMLIMIT=8GiB, and -p=1 where supported.

This supersedes the remaining runtime-error portion of #1882 without carrying its pre-stage-5 funcinfo implementation.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cpunion
cpunion force-pushed the codex/stage5-recover-errors branch 3 times, most recently from 9662dbc to 3076e79 Compare July 8, 2026 07:04
@cpunion
cpunion force-pushed the codex/stage5-recover-errors branch 3 times, most recently from f4d93ca to 207675c Compare July 9, 2026 05:35
@cpunion cpunion added go-test-compat Go standard-library and GOROOT test compatibility bug Something isn't working bugfix Fixes an existing bug or regression go1.26 Go 1.26 compatibility and support and removed bug Something isn't working labels Jul 16, 2026
@cpunion
cpunion force-pushed the codex/stage5-recover-errors branch from 207675c to bd5f8b5 Compare July 16, 2026 04:37
@cpunion cpunion changed the title ssa,runtime: real runtime.Error values for type asserts and fault signals [Based on #2033] ssa,runtime: return runtime.Error values for assertions and faults Jul 16, 2026
@cpunion
cpunion force-pushed the codex/stage5-recover-errors branch 3 times, most recently from 94ecf4b to 1816aab Compare July 19, 2026 00:14
cpunion added 10 commits July 20, 2026 12:09
Store each immutable Func as one atomic pointer and validate the queried PC from the Func itself. This prevents concurrent cache replacement from combining a PC and function from different writers. Apply the same publication rule to the prebuilt function cache and stress multiple PCs during concurrent first use.
Give each package-backed locality block an owner-local TLS cache so hot accesses are O(1) regardless of the number of touched packages. Keep the block list only for GC reachability and teardown.

Require locality variables to be unexported and reject go:linkname aliases. Add codegen, lifecycle, and 2/4/8-package performance coverage.
Re-expresses xgo-dev#1918 on the xgo-dev#2023 base (its remaining ~11k diff lines were
the pre-xgo-dev#2012 funcinfo draft, superseded by the stage-5 chain):

- recover() only succeeds when called directly by a deferred function
  (gc semantics): the panic node records the owning Defer frame at
  rethrow (panicKey/panicNode + GoDeferData), and Recover checks the
  caller is that frame's direct deferred call. Closure wraps carry
  StartRecoverFrameAlias/EndRecoverFrame so method-value and closure
  adapters stay transparent to the ownership check.
- Rethrow keeps the xgo-dev#2023 PanicTraceback hook on the unrecovered path.
- xfail: retire fixedbugs/issue4066 (2m-timeout entries; now runs in
  ~2.7s), fixedbugs/issue73916 and issue73916b (go1.26 recover
  semantics), validated on darwin/arm64 go1.26.

Supersedes xgo-dev#1918.
…s; recover conformance

Re-expresses the surviving value of xgo-dev#1882 on top of xgo-dev#2033 (its remaining
~11k diff lines were the pre-xgo-dev#2012 funcinfo draft, superseded):

- Failed (non-comma-ok) type assertions panic with a real
  *runtime.TypeAssertionError built at runtime (TypeAssertError +
  missing-method lookup from abi tables) instead of a plain errorString;
  the recovered value implements runtime.Error, matching gc. The
  source-interface abi type is deliberately not materialized at the
  assert site: doing so can reference another package's private
  local-generic symbols (undefined at link); the message's interface
  name is the documented mdempsky/16 residual.
- SIGBUS joins SIGSEGV in the fault-to-panic signal path (per-OS signal
  constants; darwin/linux).
- goroot xfails retired, validated darwin go1.26 + go1.24: recover2.go,
  recover4.go, zerodivide.go, fixedbugs/issue73917.go, issue73920.go.
- recover1.go stays xfailed with an updated reason (recursive-panic
  sub-call recover masking - Defer-node model follow-up); three ported
  tests covering the same class are t.Skip'ed with that pointer.
- Golden CHECK updates: assert-failure sites now emit
  TypeAssertError+Panic; constants renumbered from actual IR.

Supersedes xgo-dev#1882.
@cpunion
cpunion force-pushed the codex/stage5-recover-errors branch from 1816aab to 86d61bb Compare July 20, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes an existing bug or regression 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