-
Notifications
You must be signed in to change notification settings - Fork 13.3k
transmutability: merge contiguous runs with a common destination #140509
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?
Conversation
The previous implementation was inconsistent about transitions that apply for an init byte. For example, when answering a query, an init byte could use corresponding init transition. Init byte could also use uninit transition, but only when the corresponding init transition was absent. This behaviour was incompatible with DFA union construction. Define an uninit transition to match an uninit byte only and update implementation accordingly. To describe that `Tree::uninit` is valid for any value, build an automaton that accepts any byte value. Additionally, represent byte ranges uniformly as a pair of integers to avoid special case for uninit byte.
0368f55
to
eaa8f06
Compare
This comment has been minimized.
This comment has been minimized.
eaa8f06
to
b9e0ecd
Compare
for (range, (x, y)) in union(xs, ys) { | ||
let state = join(x, y); | ||
match runs.last_mut() { | ||
// Merge contiguous runs with a common destination. |
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.
Awesome! Can you add a test for this behavior?
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.
Note that if you've linked your stage1 build to cargo, you can cd
into the rustc_transmute
folder and test the crate independently of the rest of the compiler; e.g.:
RUSTC_BOOTSTRAP=1 cargo +stage1 test
It's quite a bit faster than using x
.
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.
There is an existing test for union operation which happens to exercise merging
functionality: instead of (d, 1, a), (d, 0, a)
now we have (d, 0..=1, a)
.
rust/compiler/rustc_transmute/src/maybe_transmutable/tests.rs
Lines 301 to 324 in b9e0ecd
fn union() { | |
let [a, b, c, d] = [0, 1, 2, 3]; | |
let s = Dfa::from_edges(a, d, &[(a, 0, b), (b, 0, d), (a, 1, c), (c, 1, d)]); | |
let t = Dfa::from_edges(a, c, &[(a, 1, b), (b, 0, c)]); | |
let mut ctr = 0; | |
let new_state = || { | |
let state = crate::layout::dfa::State(ctr); | |
ctr += 1; | |
state | |
}; | |
let u = s.clone().union(t.clone(), new_state); | |
let expected_u = | |
Dfa::from_edges(b, a, &[(b, 0..=0, c), (b, 1..=1, d), (d, 0..=1, a), (c, 0..=0, a)]); | |
assert_eq!(u, expected_u); | |
assert_eq!(is_transmutable(&s, &u, Assume::default()), Answer::Yes); | |
assert_eq!(is_transmutable(&t, &u, Assume::default()), Answer::Yes); | |
} | |
} |
@bors r+ |
…=jswrenn transmutability: merge contiguous runs with a common destination Based on rust-lang#140380. r? `@jswrenn` `@joshlf`
Based on #140380.
r? @jswrenn @joshlf