Skip to content

Support associated consts (e.g. i64::MAX) in annotations - #296

Merged
coord-e merged 5 commits into
mainfrom
claude/quirky-turing-u73mam
Sep 28, 2026
Merged

coord-e merged 5 commits into
mainfrom
claude/quirky-turing-u73mam

Conversation

@coord-e

@coord-e coord-e commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Annotation formulas (requires/ensures/etc.) translate a Rust expression's type-checked HIR into a chc::Formula, but ExprKind::Path only resolved local variables and enum-variant constructors, so a const item or an associated const such as i64::MAX fell into the catch-all unimplemented!.
  • analyze::annot_fn::AnnotFnTranslator now also resolves Res::Def(DefKind::Const | DefKind::AssocConst, ..) paths: it evaluates the constant via tcx.const_eval_resolve (mirroring how ordinary function bodies already resolve constants in analyze::basic_block) and lowers the resulting int/uint/bool scalar to a chc::Term.

Test plan

  • Added tests/ui/pass/assoc_const_annot.rs / tests/ui/fail/assoc_const_annot.rs: #[thrust_macros::requires(x == i64::MAX)], where the pass case calls with the true max and the fail case calls with MAX - 1, pinning down that the constant resolves to the correct concrete value.
  • cargo test: 292 passed (including the new pair), 0 regressions. The 92 remaining failures in this sandbox are pre-existing tests that require the PCSat solver via Docker, which isn't available in this environment; they're unrelated to this change (verified by diffing the failing set against grep -rl 'THRUST_SOLVER=tests/thrust-pcsat-wrapper' tests/ui, which is exactly 92 files).

🤖 Generated with Claude Code

https://claude.ai/code/session_01HKidXs2a4RaRhcEDvgwcKt


Generated by Claude Code

Path expressions in requires/ensures formulas only resolved local
variables and enum variant constructors, so a const item or an
associated const like i64::MAX could not be referenced. Evaluate the
constant via const_eval_resolve and lower its scalar value to a term,
mirroring how ordinary function bodies already handle constants.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HKidXs2a4RaRhcEDvgwcKt
annot_fn's new associated-const support duplicated the int/uint/bool
scalar-to-term match already in basic_block's const_value_ty. Extract
it as analyze::scalar_const_term, generic over the term's variable
type, and have both call it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HKidXs2a4RaRhcEDvgwcKt
is_bool() ? bool : int silently mapped any future non-bool addition
to scalar_const_term (e.g. a string or tuple case) to rty::Type::int(),
so extending that function would corrupt types instead of failing
loudly. Match on TyKind explicitly and panic on anything else.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HKidXs2a4RaRhcEDvgwcKt
Pairing the term with its rty::Type inside scalar_const_term (both
generic in the same unconstrained parameter, same as chc::Term)
removes the second, independently-maintained match on TyKind that a
prior fix only made panic-safe instead of eliminating.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HKidXs2a4RaRhcEDvgwcKt
@coord-e
coord-e marked this pull request as ready for review September 28, 2026 23:34
@coord-e
coord-e requested a balanced review from Copilot September 28, 2026 23:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T23:38:01.456027Z 87a3e53 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The newly supported ordinary const path lacks regression coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds scalar constant resolution to annotation formula translation.

Changes:

  • Extracts shared scalar constant lowering.
  • Evaluates constant and associated-constant paths.
  • Adds paired i64::MAX UI tests.
File Description
src/​analyze.rs Adds shared scalar constant lowering.
src/​analyze/​basic_block.rs Reuses the shared helper.
src/​analyze/​annot_fn.rs Resolves constants in formulas.
tests/​ui/​pass/​assoc_const_annot.rs Tests valid associated-constant use.
tests/​ui/​fail/​assoc_const_annot.rs Tests rejected non-matching input.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/analyze/annot_fn.rs
@coord-e
coord-e merged commit e112206 into main Sep 28, 2026
7 checks passed
@coord-e
coord-e deleted the claude/quirky-turing-u73mam branch September 28, 2026 23:38
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.

3 participants