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

Support nightly-2023-01-23 #49

Merged
merged 38 commits into from
Jul 14, 2023
Merged

Support nightly-2023-01-23 #49

merged 38 commits into from
Jul 14, 2023

Conversation

RyanGlScott
Copy link
Contributor

@RyanGlScott RyanGlScott commented Jul 3, 2023

This is a fairly large overhaul of mir-json's internals to support a more recent Rust nightly (nightly-2023-01-23). The work is split between myself, @m10f, and @spernsteiner.

There is a lot happening here, so if you want to learn specifics, I'd encourage you to look at individual commits. Some of the broad themes in the patchset include:

  • Propertly support for Rust's new constant forms
  • Better support for zero-sized constants
  • Encoding enum discriminant types so that crucible-mir can know about non-isize discriminant types (e.g., Ordering, which uses an i8 discriminant)
  • Make mir-json emit a --sysroot argument when invoking rustc so that rustc knows how to disambiguate it from the default sysroot
  • Adding a special case for &str, analogous to a special case for &[T]
  • Ensure that AnonConsts aren't marked with #[test]

This should fix several issues:

spernsteiner and others added 30 commits June 3, 2022 14:53
Previously, we would incorrectly produce types like `dyn Fn<((),)>`,
where no `Output` type is specified, causing a panic later due to an
unnormalized projection.  Now we correctly look at supertraits (in this
case, `FnOnce`, where `Output` is defined) to make sure we don't miss
any associated type predicates.
Without the disambiguation, allocations from different crates can clash,
leading to inexplicable errors.
This hack is responsible for `mir-json-callgraph`'s results excluding some
important information. It is unclear why this hack was necessary in the first
place, so let's just remove it.
`&str` is an unsized type, and the `Layout` for an unsized type has a `size` of
`0`, which isn't what we want. As far as I can tell, the proper way to compute
the size of an unsized type is to use `MPlaceTy`'s `len` function, which sadly
isn't exported. I have copied it here and used it.
`AnonConst`s are like `Fn`s in that they have `DefId`s and MIR boies, but they
aren't actual functions. As such, we don't want to emit `#[test]` for
`AnonConst`s.

Fixes #47.
Copy link
Collaborator

@spernsteiner spernsteiner left a comment

Choose a reason for hiding this comment

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

Looks good overall. I left a bunch of comments, but most are trivial, like removing old commented-out code. I tried to leave suggestions for these so you can apply them directly in the github UI. The non-trivial comments are around DynKind::DynStar and test cases for non-literal array sizes (e.g. const SIZE: usize = 123; ... [i32; SIZE] ...).

src/analyz/mod.rs Outdated Show resolved Hide resolved
src/analyz/mod.rs Outdated Show resolved Hide resolved
src/analyz/mod.rs Outdated Show resolved Hide resolved
src/analyz/mod.rs Outdated Show resolved Hide resolved
Comment on lines 140 to 144
projs.push(ty::ExistentialProjection {
def_id: ai.def_id,
substs: ex_trait_ref.substs,
term: actual_ty.into(), // TO REVIEW: structure of Term has changed
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this "to review" comment refer to?

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'm honestly not sure. This came from c13957d, so perhaps @m10f could offer some insight here.

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 spoke to @m10f. This comment is referring to the fact that this rust commit (rust-lang/rust@79db32b) changed Term from an enum:

pub enum Term<'tcx> {
    Ty(Ty<'tcx>),
    Const(Const<'tcx>),
}

To a struct:

pub struct Term<'tcx> {
    ptr: NonZeroUsize,
    marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
}

And this comment served as a reminder to check if changing this line in mir-json from term: ty::Term::Ty(actual_ty) to term: actual_ty.into() is the proper way to migrate the code. That being said, I took a closer look at the rust commit, and I am fairly certain that this is correct. That commit also migrates a similar bit of code here in the exact same way:

-                    term: Term::Ty(output_ty),
+                    term: output_ty.into(),

As such, I think the current code is fine. I will remove the TO REVIEW comment and land this, but feel free to object if I've overlooked something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that sounds like the correct fix. The new Term is a sort of "packed enum" that uses (I assume) pointer tagging instead of a separate discriminant field to distinguish the Ty and Const cases, so it's only one word wide instead of two.

src/analyz/ty_json.rs Outdated Show resolved Hide resolved
src/analyz/ty_json.rs Outdated Show resolved Hide resolved
src/analyz/ty_json.rs Outdated Show resolved Hide resolved
src/analyz/ty_json.rs Show resolved Hide resolved
src/bin/mir-json-rustc-wrapper.rs Outdated Show resolved Hide resolved
RyanGlScott and others added 4 commits July 13, 2023 12:10
Co-authored-by: spernsteiner <spernsteiner@galois.com>
This is a valid way to convert from a `Ty` to a `Term`, as the commit which
changed `Term` to a struct does the same thing here:
rust-lang/rust@79db32b#diff-ea6f9d55e90333a1f5fc5e202d46862a6a031410831f2df42317ac024f821162R352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants