-
Notifications
You must be signed in to change notification settings - Fork 84
MIR: relax requirement that slice backing allocations must be the same size when applying overrides #3070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
MIR: relax requirement that slice backing allocations must be the same size when applying overrides #3070
Changes from 3 commits
e528298
3ac148a
b17c110
62c9b76
1d06288
7272e25
585b0ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| all: ; | ||
| clean: | ||
| sh ./test.sh clean | ||
|
|
||
| .PHONY: all clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.rawlog | ||
| *.log | ||
| *.diff | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| all: ; | ||
| clean: | ||
| sh ./test.sh clean | ||
|
|
||
| .PHONY: all clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| libtest.rlib | ||
| libtest.mir |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| MIR_SRCS=test | ||
| include ../support/mir-blobs.mk |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| versions | ||
| rustc 1.91.0-nightly (02c7b1a7a 2025-09-13) | ||
| mir-json 0.1.0 (JSON schema version 9) | ||
| Rust toolchain nightly-2025-09-14 | ||
| mir-json mtime: Mar 18 15:26:04 2026 | ||
| mir-json version from cargo: mir-json v0.1.0 | ||
| probable mir-json commit: 71700ee8a69e1b7d84f4eed7cbd43373b29d4373 from Tue Mar 17 13:41:39 2026 and/or Tue Mar 17 13:41:39 2026 | ||
| versions-notes | ||
| Generated by update-from.sh version 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| fn f(_: &[u8]) {} | ||
|
|
||
| pub fn g(a: [u8; 2]) { | ||
| f(&a) | ||
| } | ||
|
|
||
| pub fn h(a: [u8; 5]) { | ||
| f(&a[0..2]) | ||
| } | ||
|
|
||
| pub fn i(a: [u8; 5]) { | ||
| f(&a[3..5]) | ||
| } | ||
|
|
||
| fn f_u32(_: &[u32]) {} | ||
|
|
||
| pub fn h_u32(a: [u32; 5]) { | ||
| f_u32(&a[0..2]) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| enable_experimental; | ||
|
|
||
| let f_spec = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 2 mir_u8); | ||
| a_ref <- mir_ref_of (mir_term a_array); | ||
| mir_execute_func [mir_slice_value a_ref]; | ||
| }; | ||
|
|
||
| let f_spec_len3 = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 3 mir_u8); | ||
| a_ref <- mir_ref_of (mir_term a_array); | ||
| mir_execute_func [mir_slice_value a_ref]; | ||
| }; | ||
|
|
||
| let g_spec = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 2 mir_u8); | ||
| mir_execute_func [mir_term a_array]; | ||
| }; | ||
|
|
||
| let h_spec = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 5 mir_u8); | ||
| mir_execute_func [mir_term a_array]; | ||
| }; | ||
|
|
||
| let i_spec = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 5 mir_u8); | ||
| mir_execute_func [mir_term a_array]; | ||
| }; | ||
|
|
||
| let f_u32_spec = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 2 mir_u32); | ||
| a_ref <- mir_ref_of (mir_term a_array); | ||
| mir_execute_func [mir_slice_value a_ref]; | ||
| }; | ||
|
|
||
| let h_u32_spec = do { | ||
| a_array <- mir_fresh_var "a_array" (mir_array 5 mir_u32); | ||
| mir_execute_func [mir_term a_array]; | ||
| }; | ||
|
|
||
| m <- mir_load_module "test.linked-mir.json"; | ||
|
|
||
| f_ov <- mir_verify m "test::f" [] false f_spec z3; | ||
| mir_verify m "test::g" [f_ov] false g_spec z3; | ||
| mir_verify m "test::h" [f_ov] false h_spec z3; | ||
| mir_verify m "test::i" [f_ov] false i_spec z3; | ||
|
|
||
| f_u32_ov <- mir_verify m "test::f_u32" [] false f_u32_spec z3; | ||
| mir_verify m "test::h_u32" [f_u32_ov] false h_u32_spec z3; | ||
|
|
||
| f_ov_len3 <- mir_verify m "test::f" [] false f_spec_len3 z3; | ||
| fails (mir_verify m "test::h" [f_ov_len3] false h_spec z3); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/sh | ||
| SAW=${SAW:-saw} | ||
| ${SAW} test.saw |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.rawlog | ||
| *.log | ||
| *.diff |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| all: ; | ||
| clean: | ||
| sh ./test.sh clean | ||
|
|
||
| .PHONY: all clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| all: ; | ||
| clean: | ||
| sh ./test.sh clean | ||
|
|
||
| .PHONY: all clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| all: ; | ||
| clean: | ||
| sh ./test.sh clean | ||
|
|
||
| .PHONY: all clean |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.rawlog | ||
| *.log | ||
| *.diff |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.rawlog | ||
| *.log | ||
| *.diff |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| test.ys | ||
| test.log |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2148,8 +2148,9 @@ valueToSC sym fail_ tval (MIRVal shp val) = | |
| -- TypeShape might differ from the actual length of the RegValue, so we | ||
| -- need to check both. | ||
| | toInteger len == n | ||
| , length (Mir.mirAggregate_entries sym val) == fromIntegral len | ||
| -> do terms <- accessMirAggregateArray sym elemSz elemShp len val $ | ||
| , length (Mir.mirAggregate_entries sym val) >= fromIntegral len | ||
| -> do let agg = Mir.resizeMirAggregate val $ fromIntegral len * elemSz | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the way this new implementation (which only reads from the slice's backing array without overwriting its original contents) much better. That being said, I think there is at least one case that this won't cover. Consider this example: // test.rs
// PRECONDITION: `a` must have at least two elements.
fn f(a: &[u8]) -> (u8, u8) {
(a[0], a[1])
}
pub fn g1(a: [u8; 5]) -> (u8, u8) {
f(&a[0..2])
}
pub fn g2(a: [u8; 5]) -> (u8, u8) {
f(&a)
}
I suspect that we will need to relax some of the checks around slice lengths in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I fixed this, but there are still other issues...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What other issues are you encountering?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed two more (failing) tests -- do they make sense to you or am I misunderstanding something about how this is supposed to work?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thank you for providing an example. To shrink the example a bit, we have: // test.rs
// PRECONDITION: `a` must have at least two elements.
fn tup(a: &[u8]) -> (u8, u8) {
(a[0], a[1])
}
pub fn g3(a: [u8; 5]) -> (u8, u8) {
tup(&a[1..3])
}We would expect to be able to use And yet, SAW fails to verify I think what is happening here is that when matching the To make this work, I think we will need to modify the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er, slight clarification: the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's another approach that seems to work: create a new reference to a properly-sized backing allocation at the correct offset via edit: blegh, nevermind!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm less convinced that this is a good idea. The problem is that Instead of resizing the |
||
| terms <- accessMirAggregateArray sym elemSz elemShp len agg $ | ||
| \_off val' -> valueToSC sym fail_ cryty (MIRVal elemShp val') | ||
| t <- shapeToTerm sc elemShp | ||
| liftIO (scVectorReduced sc t terms) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.