feat(lift-go): lift leading guard-panics into preconditions#1561
Conversation
The Go production lifter emitted `pre = true` for every function — a
consumer's defensive guard (`if !P(args){panic}`) never became a contract
precondition, so it was invisible at call sites. This brings Go to parity
with the Rust (lift_function_precondition) and C# (LiftMethodPrecondition)
walkers: a leading `if !P{panic}` lifts to `pre = P == true`, a bare
`if cond{panic}` to `cond == false`.
Scans only leading guards, stops at the first non-guard statement, and
refuses to invent a precondition from an unliftable condition. CID-neutral
for existing kits (the Go self-contracts contractSetCid is unchanged —
073e4010…; no go-kit function uses the guard pattern). Lifter tests pass.
Unblocks the BZ-DETERMINISM-001 reference species: a consumer's
canonical-byte-order precondition now lifts from idiomatic Go.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR enhances function precondition derivation in the lifter by extracting conditions from leading defensive panic guards. Instead of starting with an empty precondition conjunction, ChangesGuard-Based Precondition Derivation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6eb5f5aab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ident, ok := call.Fun.(*ast.Ident) | ||
| return ok && ident.Name == "panic" |
There was a problem hiding this comment.
Resolve panic before lifting a guard
When a package-level symbol or parameter named panic shadows the predeclared builtin (for example func F(panic func(string), x int) int { if x < 0 { panic("bad") }; return x }), this syntactic name check treats the callback call as an aborting guard and emits x >= 0 as a precondition even though the call may return normally. The rest of the lifter already resolves callees through types.Info and would not record a panics effect for this shadowed call, so the new precondition is inconsistent with the modeled body; check that the callee resolves to the builtin panic before lifting the guard.
Useful? React with 👍 / 👎.
The Go production lifter emitted
pre = truefor every function, so a consumer's defensive guard (if !P(args){panic}) never became a contract precondition — invisible at call sites. This brings Go to parity with Rust (lift_function_precondition) and C# (LiftMethodPrecondition).if !P{panic}→pre = P == true; bareif cond{panic}→cond == false.contractSetCidis unchanged (073e4010…); no go-kit function uses the guard pattern. Lifter tests pass.Unblocks BZ-DETERMINISM-001: a consumer's
canonical_byte_orderprecondition now lifts from idiomatic Go — the first of the lifter features needed to build the determinism reference species honestly (no mock).🤖 Generated with Claude Code
Summary by CodeRabbit