Skip to content

ssa,runtime: tighten recover to direct deferred calls (Defer-node model)#2033

Open
cpunion wants to merge 1 commit into
xgo-dev:mainfrom
cpunion:codex/stage5-recover-defer
Open

ssa,runtime: tighten recover to direct deferred calls (Defer-node model)#2033
cpunion wants to merge 1 commit into
xgo-dev:mainfrom
cpunion:codex/stage5-recover-defer

Conversation

@cpunion

@cpunion cpunion commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Based on #2023 (contains #2012/#2016/#2019). Re-expresses the surviving value of #1918 — its remaining ~11k diff lines were the pre-#2012 funcinfo draft, superseded by the stage-5 chain.

What changes

  • recover() only succeeds when called directly by a deferred function (gc semantics). The panic node records its owning Defer frame at rethrow (panicKey/panicNode + GoDeferData), and Recover checks the caller is that frame's direct deferred call — a recover() two levels down, or outside any deferred call, returns nil like gc.
  • Closure/method-value transparency: closure wraps carry StartRecoverFrameAlias/EndRecoverFrame, so adapters between the Defer frame and the user function stay invisible to the ownership check.
  • The unrecovered path keeps runtime,cl: Go-style panic tracebacks and exact log/slog/testing locations, with gc-verified acceptance suite #2023's PanicTraceback hook (gc-style traceback), now printing the panic node's argument.

goroot conformance

Retired xfails, validated darwin/arm64 go1.26 + linux/arm64 go1.24:

  • fixedbugs/issue4066.go — previously needed a 2-minute timeout entry; runs in ~2.7s with the Defer-node model.
  • fixedbugs/issue73916.go, issue73916b.go — go1.26 recover-ownership semantics.

Validation

  • macOS: full ssa (113s) and cl (467s) suites green; test/go Recover/Defer set green under llgo test.
  • linux/arm64 container: same set green; _demo/go/defer green.
  • gentests: no tracked out.ll drift.

Supersedes #1918. Note for the merge queue: this touches the same Rethrow/Recover area as #2026's RecoverMark hook — whichever lands second rebases that contact point (both keep the hook semantics).

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.20833% with 43 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ssa/eh.go 53.12% 28 Missing and 2 partials ⚠️
ssa/closure_wrap.go 45.00% 11 Missing ⚠️
ssa/expr.go 83.33% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@cpunion cpunion force-pushed the codex/stage5-recover-defer branch from e617ca2 to 174dfa3 Compare July 6, 2026 13:58
cpunion added a commit to cpunion/llgo that referenced this pull request Jul 6, 2026
…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-defer branch from 174dfa3 to f9fabc8 Compare July 8, 2026 05:28
cpunion added a commit to cpunion/llgo that referenced this pull request Jul 8, 2026
…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-defer branch from f9fabc8 to f72a070 Compare July 8, 2026 07:04
cpunion added a commit to cpunion/llgo that referenced this pull request Jul 8, 2026
…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.
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.
@cpunion cpunion force-pushed the codex/stage5-recover-defer branch from f72a070 to efa8f54 Compare July 8, 2026 11:17
cpunion added a commit to cpunion/llgo that referenced this pull request Jul 8, 2026
…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.
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.

1 participant