Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Apr 30, 2025

Based on #140380.

r? @jswrenn @joshlf

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.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 30, 2025
@tmiasko tmiasko force-pushed the merge-contiguous-ranges branch from 0368f55 to eaa8f06 Compare April 30, 2025 11:10
@tmiasko tmiasko changed the title transmutability: merge contiguous ranges with a common destination transmutability: merge contiguous runs with a common destination Apr 30, 2025
@rust-log-analyzer

This comment has been minimized.

@tmiasko tmiasko force-pushed the merge-contiguous-ranges branch from eaa8f06 to b9e0ecd Compare April 30, 2025 12:35
for (range, (x, y)) in union(xs, ys) {
let state = join(x, y);
match runs.last_mut() {
// Merge contiguous runs with a common destination.
Copy link
Contributor

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?

Copy link
Member

@jswrenn jswrenn Apr 30, 2025

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.

Copy link
Contributor Author

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).

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);
}
}

@jswrenn
Copy link
Member

jswrenn commented May 1, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 1, 2025

📌 Commit b9e0ecd has been approved by jswrenn

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 2, 2025
…=jswrenn

transmutability: merge contiguous runs with a common destination

Based on rust-lang#140380.

r? `@jswrenn` `@joshlf`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants