Skip to content

psi: admit shared scalar recasts of fields and borrowed scalars - #6313

Merged
Smotto merged 1 commit into
mainfrom
work/psi-shared-scalar-recasts
Nov 27, 2026
Merged

Smotto merged 1 commit into
mainfrom
work/psi-shared-scalar-recasts

Conversation

@Smotto

@Smotto Smotto commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Shared scalar representation recasts of record fields and borrowed scalars (such as @cell.other as @i8 and byte as @i8) now check, run in Psi, and agree with native Windows x86_64 execution. Previously, the compiler refused every such recast during descriptor replay or returned-reference analysis, and native code generation encoded the source scalar's storage codec rather than the target view's codec.

Three gaps in the shared representation-view path caused these failures:

  • In locations.rs (descriptor_location_with, view_element_descriptor_prefix, resolved_path_with, and resolved_tip_with), walking a RepresentationView segment required a preceding structural type declaration, which failed whenever the prefix ended at an inline scalar field. Handling RepresentationView before requiring a structural declaration (matching primitive_place.rs while still rejecting case namespaces, opaque types, references, and atomic cells) preserves the descriptor's origin account.
  • In descriptor_regions.rs (append_projection and reference_sources_for_leaves), returned reference origins did not admit StructuralPathSegment::RepresentationView, causing machines returning @cell.other as @i8 or byte as @i8 to fail returned-origin construction.
  • In instruction_selection/selection/inputs.rs, EstablishReference stored storage.stored_scalar (for example u8, unsigned) as the scalar reference's runtime codec instead of the presented semantic_scalar (i8, signed) for same-width recasts, causing LoadEncodedScalar on x86_64 to zero-extend 0xFF to 255 instead of sign-extending it to -1.

Unproved recasts to targets with invalid bit patterns (such as @cell.other as @bool or byte as @bool) remain refused, and competing writes while a recast view is live still reject.

Updated representation_views::scalar_reference_recasts_keep_their_backing_and_presented_fields (replacing its temporary refusal assertion with acceptance, Psi execution, and competing-write rejection), added shared_scalar_recasts_of_fields_and_borrowed_scalars_read_and_return_views with negative twins, added shared_scalar_recasts_of_fields_and_borrowed_scalars_agree_natively_and_in_psi in domain_access_field_observations.rs, and removed the resolved sentences from TASKS.md.

Gate: RC-SOURCE-SEMANTICS | Shared scalar representation recasts of fields and borrowed scalars check, run in Psi, and agree natively on Windows x86_64
Spec: wiki/spec/layouts/recasts.md#shared-and-mutable-views
Proof: mbx test -p terminal-semantics --lib (332 passed), mbx test -p lowered-program-to-checked-program --lib representation_views (11 passed, updated scalar_reference_recasts_keep_their_backing_and_presented_fields from temporary refusal check to acceptance + Psi execution), mbx test -p omega --test domain_access_field_observations shared_scalar_recasts_of_fields_and_borrowed_scalars_agree_natively_and_in_psi (passed, native Windows x86_64 + Psi), mbx clippy --no-deps on touched crates, mbx xtask fmt --check --base origin/main, mbx xtask check-rules, mbx xtask check-boundary | clean (unrelated pre-existing errors in omega tests data_layout_queries.rs and build_dependency_provider_layouts.rs on --all-targets; domain_access_field_observations clean)
Agent: Antigravity | Model: unknown | Effort: high | Tokens: 10.81M in (10.51M cached), 43.5k out | Steps: 62 | Time: 36m41s | Steers: 0

Shared scalar representation recasts of record fields and borrowed scalars (such as `@cell.other as @i8` and `byte as @i8`) now check, run in Psi, and agree with native Windows x86_64 execution. Previously, the compiler refused every such recast during descriptor replay or returned-reference analysis, and native code generation encoded the source scalar's storage codec rather than the target view's codec.

Three gaps in the shared representation-view path caused these failures:
- In `locations.rs` (`descriptor_location_with`, `view_element_descriptor_prefix`, `resolved_path_with`, and `resolved_tip_with`), walking a `RepresentationView` segment required a preceding structural type declaration, which failed whenever the prefix ended at an inline scalar field. Handling `RepresentationView` before requiring a structural declaration (matching `primitive_place.rs` while still rejecting case namespaces, opaque types, references, and atomic cells) preserves the descriptor's origin account.
- In `descriptor_regions.rs` (`append_projection` and `reference_sources_for_leaves`), returned reference origins did not admit `StructuralPathSegment::RepresentationView`, causing machines returning `@cell.other as @i8` or `byte as @i8` to fail returned-origin construction.
- In `instruction_selection/selection/inputs.rs`, `EstablishReference` stored `storage.stored_scalar` (for example `u8`, unsigned) as the scalar reference's runtime codec instead of the presented `semantic_scalar` (`i8`, signed) for same-width recasts, causing `LoadEncodedScalar` on x86_64 to zero-extend `0xFF` to `255` instead of sign-extending it to `-1`.

Unproved recasts to targets with invalid bit patterns (such as `@cell.other as @bool` or `byte as @bool`) remain refused, and competing writes while a recast view is live still reject.

Updated `representation_views::scalar_reference_recasts_keep_their_backing_and_presented_fields` (replacing its temporary refusal assertion with acceptance, Psi execution, and competing-write rejection), added `shared_scalar_recasts_of_fields_and_borrowed_scalars_read_and_return_views` with negative twins, added `shared_scalar_recasts_of_fields_and_borrowed_scalars_agree_natively_and_in_psi` in `domain_access_field_observations.rs`, and removed the resolved sentences from `TASKS.md`.

Gate: RC-SOURCE-SEMANTICS | Shared scalar representation recasts of fields and borrowed scalars check, run in Psi, and agree natively on Windows x86_64
Spec: wiki/spec/layouts/recasts.md#shared-and-mutable-views
Proof: mbx test -p terminal-semantics --lib (332 passed), mbx test -p lowered-program-to-checked-program --lib representation_views (11 passed, updated scalar_reference_recasts_keep_their_backing_and_presented_fields from temporary refusal check to acceptance + Psi execution), mbx test -p omega --test domain_access_field_observations shared_scalar_recasts_of_fields_and_borrowed_scalars_agree_natively_and_in_psi (passed, native Windows x86_64 + Psi), mbx clippy --no-deps on touched crates, mbx xtask fmt --check --base origin/main, mbx xtask check-rules, mbx xtask check-boundary | clean (unrelated pre-existing errors in omega tests data_layout_queries.rs and build_dependency_provider_layouts.rs on --all-targets; domain_access_field_observations clean)
Agent: Antigravity | Model: unknown | Effort: high | Tokens: 10.81M in (10.51M cached), 43.5k out | Steps: 62 | Time: 36m41s | Steers: 0
@Smotto
Smotto merged commit 8f88320 into main Nov 27, 2026
1 check passed
@Smotto
Smotto deleted the work/psi-shared-scalar-recasts branch November 27, 2026 02:30
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.

1 participant