Skip to content

Type scalar constants of struct type - #276

Merged
coord-e merged 3 commits into
mainfrom
claude/gallant-pasteur-2djvt2
Sep 24, 2026
Merged

coord-e merged 3 commits into
mainfrom
claude/gallant-pasteur-2djvt2

Conversation

@coord-e

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

Copy link
Copy Markdown
Owner

MIR represents a constant of a struct with scalar layout, such as a single-field newtype (Align::EIGHT = Align { pow2: 3 }, Size::ZERO, Hash64::ZERO), as ConstValue::Scalar. const_value_ty had no case for it and hit unimplemented!("const: Scalar(0x03), ty: Align").

This adds that case: the struct is built as a tuple of boxed fields, like other struct values, with the scalar given to the only non-ZST field and ConstValue::ZeroSized to ZST fields.

Tests

  • Added tests/ui/{pass,fail}/const_scalar_struct.rs. Both hit the ICE before this change and pass after it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WZXwt16ZiUmjT6hDYraDtb


Generated by Claude Code

MIR represents a constant of a struct with scalar layout, such as a
single-field newtype, as ConstValue::Scalar. const_value_ty had no case
for it and hit unimplemented!. Build the struct as a tuple of boxed
fields, giving the scalar to the only non-ZST field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WZXwt16ZiUmjT6hDYraDtb
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 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-24T12:49:46.985085Z a5c4cd5 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d422493897

ℹ️ 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".

Comment thread src/analyze/basic_block.rs

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 paired UI tests must exercise scalar placement alongside ZST fields.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds support for MIR scalar constants represented as structs.

Changes:

  • Reconstructs scalar structs from non-ZST and ZST fields.
  • Adds paired pass/fail regression tests.
  • ZST reconstruction still lacks test coverage.
File Description
tests/​ui/​pass/​const_scalar_struct.rs Adds successful scalar-struct verification coverage; should include a ZST field.
tests/​ui/​fail/​const_scalar_struct.rs Adds expected-failure coverage; should include a ZST field.
src/​analyze/​basic_block.rs Converts scalar struct constants into boxed field tuples.

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

Comment on lines +424 to +425
let field_val = if field_layout.is_zst() {
ConstValue::ZeroSized
A ZST constant of tuple or struct type became bare unit regardless of its
declared shape, so passing e.g. a ((),) constant, or a ZST field of a
scalar struct constant, to a function expecting ((),) panicked in
relate_type. Build tuples and structs field by field for ZeroSized too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WZXwt16ZiUmjT6hDYraDtb
The catch-all arm gave any ZeroSized constant unit type whatever its
declared type, silently producing a mistyped value. Tuples, structs and
closures without captures are handled by their own arms; let the rest
reach unimplemented!.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WZXwt16ZiUmjT6hDYraDtb
@coord-e
coord-e merged commit 4a88a5e into main Sep 24, 2026
6 checks passed
@coord-e
coord-e deleted the claude/gallant-pasteur-2djvt2 branch September 24, 2026 12:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5c4cd5391

ℹ️ 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".

} else {
*val
};
let pt = self.const_value_ty(&field_val, &field_ty);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Construct zero-sized enum fields from their variants

When a scalar-layout struct has a zero-sized, single-variant enum field (for example, enum Marker { M } in struct Wrap { scalar: i32, marker: Marker }), this passes ConstValue::ZeroSized back into const_value_ty, but the new match handles zero-sized tuples and structs only; the enum therefore reaches the fallback and panics instead of analyzing the constant. Fresh evidence after the prior fix is that this final match still reproduces not implemented: const: ZeroSized, ty: Marker; add construction of the enum's inhabited variant rather than recursively passing an unsupported value.

Useful? React with 👍 / 👎.

coeff-aij added a commit to coeff-aij/thrust that referenced this pull request Sep 24, 2026
…casts) into forall-sort

Brings in coord-e#114 (Rust expressions as thrust::predicate bodies,
instantiated per generic arguments), coord-e#275 (newer PCSat in CI), coord-e#276, coord-e#277
and coord-e#278 on top of forall-sort.

Resolution:
- A predicate call whose instance resolves goes through
  Analyzer::predicate_with_args, so a Rust-body predicate is defined once
  per instantiation and a raw SMT-LIB2 predicate keeps its single
  definition. A call that does not resolve (it still depends on the
  owner's type parameters) keeps the forall predicate.
- predicate_with_args takes the calling function as owner, since
  forall-sort translates type parameters relative to it; an instance
  whose arguments mention type parameters is keyed by that owner too.
- UserDefinedPredDef keeps both the new body enum and the ForallPred
  dependency set. A formula body contributes its ForallPred atoms
  directly and its calls to other user-defined predicates as edges of
  the dependency graph; a raw body is still scanned by name.
- The refinement clause builder records the value-variable origin only
  when the value term is a variable, as the singleton case substitutes
  a default term.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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