Skip to content

Add Vec-to-slice coercion extern specs#160

Merged
coord-e merged 1 commit into
mainfrom
claude/vec-slice-coercion
Jul 1, 2026
Merged

Add Vec-to-slice coercion extern specs#160
coord-e merged 1 commit into
mainfrom
claude/vec-slice-coercion

Conversation

@coord-e

@coord-e coord-e commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Specifies the postcondition *result == *vec for the three standard ways a Vec<T> can be coerced to &[T], letting the refinement checker propagate Seq refinements through all of them.

Changes

std.rs

  • Vec::as_slice: explicit call Vec::as_slice(&v)
  • Deref::deref: implicit coercion let s: &[T] = &v
  • AsRef::as_ref: v.as_ref()

All three specs have the postcondition *result == *vec.

Tests

2 new UI tests covering the implicit deref coercion path:

Test What it checks
pass/vec_deref.rs Push 10, 20; implicit &v coercion; assert len and element values
fail/vec_deref.rs Wrong expected value → Unsat

Specify the postcondition `*result == *vec` for the three ways a `Vec<T>`
can be coerced to `&[T]`: `as_slice`, `Deref::deref` (implicit `&v`
coercion), and `AsRef::as_ref` (`v.as_ref()`). This lets the refinement
checker propagate Seq refinements from Vec through all standard coercion paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013oVufAKCMzsLRnQ8F58PdP
@coord-e coord-e force-pushed the claude/vec-slice-coercion branch from 2dc1cc5 to 66f7a4e Compare July 1, 2026 14:51
@coord-e coord-e marked this pull request as ready for review July 1, 2026 14:52
@coord-e coord-e requested a review from Copilot July 1, 2026 14:52
@coord-e coord-e merged commit f6acc96 into main Jul 1, 2026
7 checks passed
@coord-e coord-e deleted the claude/vec-slice-coercion branch July 1, 2026 14:53

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.

Pull request overview

This PR extends Thrust’s injected std.rs extern specs so the refinement checker can propagate Seq-style refinements through the three common Vec<T> -> &[T] coercion paths (as_slice, Deref, AsRef). It also adds UI coverage for the implicit deref coercion route (&v to &[T]).

Changes:

  • Add extern specs for Vec::as_slice, <Vec<T> as Deref>::deref, and <Vec<T> as AsRef<[T]>>::as_ref, each ensuring *result == *vec.
  • Add a passing UI test validating slice contents obtained via implicit deref coercion (let s: &[T] = &v;).
  • Add a failing UI test that triggers an Unsat when asserting an incorrect element value through the same coercion path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
std.rs Adds three extern specs to equate the resulting slice model with the source Vec model for all standard Vec -> &[T] coercions.
tests/ui/pass/vec_deref.rs New passing test covering implicit &Vec<T>&[T] deref coercion and basic slice property checks.
tests/ui/fail/vec_deref.rs New failing test ensuring the deref coercion path produces an Unsat when asserting an incorrect slice element.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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