Skip to content
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

Miri rename undef uninit #74664

Merged
merged 2 commits into from
Jul 26, 2020
Merged

Miri rename undef uninit #74664

merged 2 commits into from
Jul 26, 2020

Conversation

pnadon
Copy link
Contributor

@pnadon pnadon commented Jul 23, 2020

Renamed parts of code within the librustc_middle/mir/interpret/ directory.

Related issue #71193

Renamed the function ScalarMaybeUninit::not_undef to ScalarMaybeUninit::check_init in the file src/librustc_middle/mir/interpret/value.rs, to reflect changes in terminology used.

Related issue #71193
@lcnr
Copy link
Contributor

lcnr commented Jul 23, 2020

👍 r? @oli-obk cc @RalfJung

@@ -565,7 +565,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
})
}

pub fn mark_definedness(&mut self, ptr: Pointer<Tag>, size: Size, new_state: bool) {
pub fn mark_init(&mut self, ptr: Pointer<Tag>, size: Size, new_state: bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_state is not very clear; maybe is_init or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter does make more sense.

@RalfJung
Copy link
Member

This looks great apart from one nit. :)

@RalfJung
Copy link
Member

Looking great, thanks. :)
r? @RalfJung @bors r+

@pnadon do you think you will have time to fix https://github.com/rust-lang/miri/ as well? Let me know if you need any help with that.

@bors
Copy link
Contributor

bors commented Jul 23, 2020

📌 Commit f8c5722f9d662980ed7a3895e94741af8842e38e has been approved by RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned oli-obk Jul 23, 2020
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 23, 2020
@RalfJung
Copy link
Member

@bors rollup

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

Looking great, thanks. :)
r? @RalfJung @bors r+

@pnadon do you think you will have time to fix https://github.com/rust-lang/miri/ as well? Let me know if you need any help with that.

Do you mean the changes referenced in this comment? If so I would be glad to!

@bors
Copy link
Contributor

bors commented Jul 23, 2020

@pnadon: 🔑 Insufficient privileges: Not in reviewers

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

@pnadon do you think you will have time to fix https://github.com/rust-lang/miri/ as well? Let me know if you need any help with that.

I assume you may have been referring to the renames in src/librustc_mir/interpret, in which case I would like to get to those as well, but I think I will leave them unclaimed so that someone else has a chance to work on them while I continue working within src/librustc_middle/mir/interpret.

@RalfJung
Copy link
Member

Do you mean the changes referenced in this comment? If so I would be glad to!

No I mean that Miri (the standalone tool at https://github.com/rust-lang/miri/, not the Miri core engine which this PR touches) is using some of the APIs you renamed here, and will fail to build once this PR lands. Someone has to get it to build again. :)

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

Do you mean the changes referenced in this comment? If so I would be glad to!

No I mean that Miri (the standalone tool at https://github.com/rust-lang/miri/, not the Miri core engine which this PR touches) is using some of the APIs you renamed here, and will fail to build once this PR lands. Someone has to get it to build again. :)

Oh I see, yes I'll look into that!

@RalfJung
Copy link
Member

As for the remaining renames mentioned in #71193, that is an orthogonal question, feel free to continue working on those as well. :) Beyond what is listed in #71193 (comment), I have not yet taken stock what even needs to be done.

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

Actually, would you want me to finish the remaining renames in src/librustc_middle/mir/interpret, and then start working on https://github.com/rust-lang/miri/? That way there is less back-and-forth.

@RalfJung
Copy link
Member

RalfJung commented Jul 23, 2020

Miri should always build, so once this lands a Miri PR needs to be prepared ASAP. It would be even better if you could prepare that Miri PR before this one here lands. :D

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

Miri should always build, so once this lands a Miri PR needs to be prepared ASAP. It would be even better if you could prepare that Miri PR before this one here lands. :D

That makes sense, since this morning I have also renamed the 3 other functions / structs mentioned in that comment, I guess what I was trying to say was that I could commit them here, and then start working on https://github.com/rust-lang/miri/, once I get the changes made in the Miri repo, I could open a PR there and then we could close both simultaneously. Does that sound good?

@RalfJung
Copy link
Member

Oh sure, we can add more renames to this PR.
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 23, 2020
@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

I ripgrep'd through Miri's src and only found ScalarMaybeUninit::not_undef, as well as a function call Immediate::ScalarPair(old.to_scalar_or_undef(). The former I renamed, the latter was found within Immediate::to_scalar_or_undef in src/librustc_mir/interpret/allocation.rs

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

i also ripgrep'd the other changes I just made in Miri, and I could not find them. This seems strange to me, but I will open a PR on Miri with what I have so far and continue my work there.

@RalfJung
Copy link
Member

RalfJung commented Jul 23, 2020

The instructions at https://github.com/rust-lang/miri/blob/master/CONTRIBUTING.md#building-miri-with-a-locally-built-rustc explain how you can build-test Miri against your locally built rustc. Make sure you use a recent rustc master though to avoid build failures due to unrelated changes.

You can skip the config.toml and debug-assertions part as you don't actually do this for the extra tracing.

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

Ok, aside from the comments though I'm assuming everything looks ok. In that case, I will work on getting Miri to build, and also fix the above comments.

@pnadon
Copy link
Contributor Author

pnadon commented Jul 23, 2020

Miri seems to build correctly, and I have changed the above comments.

initial: bool,
/// The lengths of ranges that are run-length encoded.
/// The definedness of the ranges alternate starting with `initial`.
/// The initialization state of the ranges alternate starting with `initial`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The initialization state of the ranges alternate starting with `initial`.
/// The initialization state of the ranges alternates starting with `initial`.

// So if `ranges.len() > 1` then the second block is an initialized range.
!self.initial && self.ranges.len() == 1
}
}

/// Transferring the definedness mask to other allocations.
/// Transferring the initialization mask to other allocations.
impl<Tag, Extra> Allocation<Tag, Extra> {
/// Creates a run-length encoding of the undef mask.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still an "undef" left here.

///
/// Returns `Ok(())` if it's defined. Otherwise returns the range of byte
/// Returns `Ok(())` if it's initialized. Otherwise returns the range of byte
/// indexes of the first contiguous undefined access.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another remaining "undef".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched again through allocation.rs and found this comment as well as one other and a variable, which were all changed appropriately. I left comments which were for other functions / parts of the code which have yet to be changed (eg. inspect_with_undef_and_ptr_outside_interpreter).

@RalfJung
Copy link
Member

There are still two unresolved comments left (you can see them by scrolling through https://github.com/rust-lang/rust/pull/74664/files)

@pnadon
Copy link
Contributor Author

pnadon commented Jul 24, 2020

There are still two unresolved comments left (you can see them by scrolling through https://github.com/rust-lang/rust/pull/74664/files)

I had left some of them since they were related to functions which still had "undef" within their name (and are currently being discussed in the related issue) to try and group the changes in the comments with the changes in the actual code, however since many of them still use the functions which have been changed, I believe it was actually better to do the rest of the comments in allocation.rs anyways (which I did in the latest commit).

As for renaming the rest of the functions, I think I will hold off on that until we have decided on the new names in the issue, and do them all at once for both the Rust and Miri respositories.

@RalfJung
Copy link
Member

Yes this is great. :) Could you squash the commits into one (or a few; 12 seems a bit too much)? Then I'll r+.

renamed Allocation::check_defined_and_ptr to Allocation::check_init_and_ptr

renamed Allocation::check_defined_and_ptr to Allocation::check_init_and_ptr

in src/librustc_middle/mir/interpret/allocation.rs

renamed Allocation::is_defined and Allocation::check_defined, fixed documentation

renamed Allocation::is_defined and Allocation::check_defined to is_init and check_init respectively.

Fixed documentation so it correctly refers to "initialization" instead of "defined"-ness

renamed Allocation::mark_definedness

renamed Allocation::mark_definedness to Allocation::mark_init

Renamed new_state parameter in Allocation::mark_init

Renamed new_state to is_init, as the latter is more descriptive.

renamed functions in AllocationDefinedness

renamed AllocationDefinedness::all_bytes_undef and AllocationDefinedness::mark_compressed_undef_range to no_bytes_init and mark_compressed_init_range respectively.

renamed AllocationDefinedness to InitMaskCompressed

renamed Immediate::to_scalar_or_undef

renamed to to_scalar_or_uninit

fixed comment references to "undef"

Changed comments referring to "undef" and "definedness" to "initialization" and "initialization state" in src/librustc_mir/interpret/memory.rs and src/librustc_middle/mir/interpret/allocation.rs

changed references to "undef" in comments and a variable

Changed some comments referring to "undef" to use "uninitialized" instead. Also changed a variable from "undef_end" to "uninit_end".
All changes were made within src/librustc_middle/mir/interpret/allocation.rs.

Changed more comments referring to undef

Changed comments to use "uninitialized" instead of "undef" in src/librustc_middle/mir/interpret/allocation.rs.
@pnadon
Copy link
Contributor Author

pnadon commented Jul 26, 2020

Squashed into 2 commits

@RalfJung
Copy link
Member

Thanks. :) @bors r+

@bors
Copy link
Contributor

bors commented Jul 26, 2020

📌 Commit ef9c4f5 has been approved by RalfJung

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 26, 2020
@bors
Copy link
Contributor

bors commented Jul 26, 2020

⌛ Testing commit ef9c4f5 with merge 13f9aa1...

@bors
Copy link
Contributor

bors commented Jul 26, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: RalfJung
Pushing 13f9aa1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 26, 2020
@bors bors merged commit 13f9aa1 into rust-lang:master Jul 26, 2020
@pnadon
Copy link
Contributor Author

pnadon commented Jul 26, 2020

Thank you @RalfJung for your patience and help throughout this, this was my first contribution to Rust and I really appreciated the time and effort you put into making sure I did things correctly.

@RalfJung
Copy link
Member

@pnadon thanks for contributing, here's hoping that you'll continue to enjoy working on Rust. :)

bors added a commit to rust-lang/miri that referenced this pull request Jul 27, 2020
Miri rename undef uninit

The changes made here are related to [issue #71193 on Rust](rust-lang/rust#71193), and the pull request [74664 on Rust](rust-lang/rust#74664).

1. renamed `ScalarMaybeUninit::not_undef` to `check_init`
2. renamed `Immediate::to_scalar_or_undef` to `Immediate::to_scalar_or_uninit`
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants