Support associated consts (e.g. i64::MAX) in annotations - #296
Merged
Merged
Conversation
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
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
marked this pull request as ready for review
September 28, 2026 23:34
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The newly supported ordinary const path lacks regression coverage.
Review effort: Balanced
Findings: 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::MAXUI 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
requires/ensures/etc.) translate a Rust expression's type-checked HIR into achc::Formula, butExprKind::Pathonly resolved local variables and enum-variant constructors, so aconstitem or an associated const such asi64::MAXfell into the catch-allunimplemented!.analyze::annot_fn::AnnotFnTranslatornow also resolvesRes::Def(DefKind::Const | DefKind::AssocConst, ..)paths: it evaluates the constant viatcx.const_eval_resolve(mirroring how ordinary function bodies already resolve constants inanalyze::basic_block) and lowers the resulting int/uint/bool scalar to achc::Term.Test plan
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 withMAX - 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 againstgrep -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