-
Notifications
You must be signed in to change notification settings - Fork 265
Refactor Dataflow Analysis of Casts #883
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit hard to tell what changed vs. just moved in this PR. For f2b89e3, there are 2 moves, but also a few changes. Could those be split out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kkysen 47a053f wasn't meant to signify a movement. It's just some additional checks that were made elsewhere previously. Yes, checks that were in one place are now present in another, but semantically those two commits represent 1. cutting out unnecessary checks given what's now returned (the labeled casted-to type) and 2. adding some cast-specific type checks to As far as 57ff503 itself is concerned, before we were taking portions of the casted-from type (T) and the casted-to type (U) and combining them into another type (X). This instead just labels U and returns LTy(U). |
Any idea why this changes the behavior on the Otherwise all tests are producing identical output, with the exception of |
@spernsteiner here is the MIR. I think the difference is in how we label the // WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn array_as_ptr_load(_1: &[i32; 10]) -> i32 {
debug x => _1; // in scope 0 at [src/lib.rs:5:33: 5:34](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
let mut _0: i32; // return place in scope 0 at [src/lib.rs:5:51: 5:54](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
let _2: *const i32; // in scope 0 at [src/lib.rs:7:9: 7:10](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
let mut _3: &[i32]; // in scope 0 at [src/lib.rs:7:13: 7:23](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
let mut _4: &[i32; 10]; // in scope 0 at [src/lib.rs:7:13: 7:23](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
scope 1 {
debug p => _2; // in scope 1 at [src/lib.rs:7:9: 7:10](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
}
bb0: {
_4 = _1; // scope 0 at [src/lib.rs:7:13: 7:23](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
_3 = move _4 as &[i32] (Pointer(Unsize)); // scope 0 at [src/lib.rs:7:13: 7:23](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
_2 = core::slice::<impl [i32]>::as_ptr(move _3) -> bb1; // scope 0 at [src/lib.rs:7:13: 7:23](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
// mir::Constant
// + span: [src/lib.rs:7:15: 7:21](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
// + literal: Const { ty: for<'a> fn(&'a [i32]) -> *const i32 {core::slice::<impl [i32]>::as_ptr}, val: Value(<ZST>) }
}
bb1: {
_0 = (*_2); // scope 1 at [src/lib.rs:8:5: 8:7](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
return; // scope 0 at [src/lib.rs:9:2: 9:2](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
}
}
array_as_ptr_load::{constant#0}: usize = {
let mut _0: usize; // return place in scope 0 at [src/lib.rs:5:43: 5:45](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
bb0: {
_0 = const 10_usize; // scope 0 at [src/lib.rs:5:43: 5:45](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
return; // scope 0 at [src/lib.rs:5:43: 5:45](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)
}
} |
fdef6d0
to
c400932
Compare
I think there is actually a bug in this Both this branch and
However, -_4 (37: x.as_ptr()): addr_of = UNIQUE, type = READ | UNIQUE | OFFSET_ADD | OFFSET_SUB#&[i32; 10][(empty)#[i32; 10][(empty)#i32[]]]
+_4 (36: x.as_ptr()): addr_of = UNIQUE, type = UNIQUE#&[i32; 10][(empty)#[i32; 10][(empty)#i32[]]] This branch similarly gives no permissions to |
Ah yes, I see that the way |
@spernsteiner I put the old functionality back for now. I'm thinking about how to avoid combining |
I think it would be cleaner and more in line with the purpose of this branch to revert that last commit (so the |
Forgot to mention - since this branch is meant to be purely a refactor, it's probably better to leave fixes like the |
@spernsteiner reverted the last commit and setup dataflow rules in 2807326. I'm fine saving fixes for another PR but am still curious if you agree whether or not I have the right idea regarding the cause. |
@spernsteiner would you mind taking another look at this? |
Sounds plausible to me. And I think your proposed fix sounds good - the |
Thanks @spernsteiner, I will look into this and add the fix in another PR |
As per the discussion [here](#839 (comment)), type_of_rvalue was combining portions of types T and U and returning labeled type X. This forced some similarity checking in the types that ideally should be placed in a yet-to-exist is-castable-to check. This commit labels the type U and makes that the LabeledTy for the RValue of each cast.
…from T and types of U
…guments from T and types of U" This reverts commit 2bbf77e.
…ataflow edges inside dataflow::type_check
8473be0
to
8560dda
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#900) This cleans up and simplifies some of the code from #883 in preparation for the string cast PRs, #739 and #741. It extracts things into a separate `visit_cast` method, simplifies a few things, and clarifies exactly which `Ty`s and `LTy`s are from and to in a cast. This makes it easier to understand and read, and makes it simpler to rebase #739 onto it.
…cker::do_unify` (back to strict equality) as #883 resolved this (#839 (comment)).
…cker::do_unify` (back to strict equality) as #883 resolved this (#839 (comment)).
…#883. It's not complete, but fixes the crash in `as_ptr.rs`.
Fixes #878.
Lays the groundwork to check whether or not certain types of ptr-to-ptr casts are supported.
Implements the reorganization specified in #878, and lays the groundwork for #839 as outlined in #839 (comment)