Multi-variant layouts for generators
This allows generators to overlap fields using variants, but doesn't do any such overlapping yet. It creates one variant for every state of the generator (unresumed, returned, panicked, plus one for every yield), and puts every stored local in each of the yield-point variants.
Required for optimizing generator layouts (#52924).
There was quite a lot of refactoring needed for this change. I've done my best in later commits to eliminate assumptions in the code that only certain kinds of types are multi-variant, and to centralize knowledge of the inner mechanics of generators in as few places as possible.
This change also emits debuginfo about the fields contained in each variant, as well as preserving debuginfo about stored locals while running in the generator.
Also, fixes#59972.
Future work:
- Use this change for an optimization pass that actually overlaps locals within the generator struct (#52924)
- In the type layout fields, don't include locals that are uninitialized for a particular variant, so miri and UB sanitizers can check our memory (see https://github.com/rust-lang/rust/issues/59972#issuecomment-483058172)
- Preserve debuginfo scopes across generator yield points
rustc: factor out most of hir::def::Def's variants into DefKind, and rename to Res.
The first two commits are about introducing `DefKind`, both to simplify/orthogonalize `hir::def::Def`, and to allow reasoning about the kind of a definition without dealing with the redundant `DefId`.
(There are likely more changes to be made, such as adding enough `DefKind` variants for `tcx.def_kind(def_id)` to return just `DefKind`, not `Option<DefKind>`, but this is pretty big as-is)
The third commit frees up the `Def` name (which we may want to use in the future for "definitions", in the sense of "entities with a `DefId`") by renaming `hir::def::Def` to `Res` ("resolution").
IMO this fits, as it represents all the possible name resolution results, not just "definitions (with a `DefId`)".
Quick examples:
```rust
// Before:
if tcx.describe_def(def_id) == Some(Def::Struct(def_id)) {...}
if let Def::Struct(def_id) = path.def {...}
```
```rust
// After:
if tcx.def_kind(def_id) == Some(DefKind::Struct) {...}
if let Res::Def(DefKind::Struct, def_id) = path.res {...}
```
r? @petrochenkov cc @rust-lang/compiler
Fix potential integer overflow in SGX memory range calculation.
Thanks to Eduard Marin and David Oswald at the University of Burmingham, and Jo Van Bulck at KU Leuven for discovering this issue.
Rollup of 12 pull requests
Successful merges:
- #59928 (Make deprecation lint `ambiguous_associated_items` deny-by-default)
- #60220 (report fatal errors during doctest parsing)
- #60373 (Tidy: ensure lang features are sorted by since)
- #60388 (Disallow non-explicit elided lifetimes in async fn)
- #60393 ( Do not suggest incorrect syntax on pattern type error due to borrow)
- #60401 (Rename `RUST_LOG` to `RUSTC_LOG`)
- #60409 (Require a trait in the bounds of existential types)
- #60455 (Resolve match arm ty when arms diverge)
- #60457 (Const prop refactoring)
- #60467 (Avoid repeated interning of static strings.)
- #60478 (minor compiler doc tweaks)
- #60501 (Propagate mutability from arguments to local bindings in async fn)
Failed merges:
r? @ghost
Avoid repeated interning of static strings.
`file_metadata_raw` interns the strings `"<unknown>"` and `""` very
frequently. This commit avoids that, which reduces the number of symbols
interned significantly and reduces instruction counts by up to 0.5% on
some workloads.
Const prop refactoring
This is rebased on top of #60428 so only the top commit is new.
This is the refactoring to remove the `mir` field from `ConstPropagator` which is necessary before we can begin to actually propagate constants.
r? @oli-obk
Make `std::fs::copy` attempt to create copy-on-write clones of files on MacOS
The behaviour of MacOS now matches Linux which uses `copy_file_range` to perform CoW file copies where available and supported by the underlying filesystem.
`find_attr_val(&line, "since")` returns `Some(", issue = ")` when
`line` is set to the following line:
```
[unstable(feature = "checked_duration_since", issue = "58402")]
```
Make `find_attr_val` use regex that is a little bit more
precise (requires `=` after key name).
It still does not handle all cases (e.g., extra leading chars in key
name, or escaped quotes in value), but is good enough for now.
`file_metadata_raw` interns the strings `"<unknown>"` and `""` very
frequently. This commit avoids that, which reduces the number of symbols
interned significantly and reduces instruction counts by up to 0.5% on
some workloads.
use SecRandomCopyBytes on macOS in Miri
This is a hack to fix https://github.com/rust-lang/miri/issues/686: on macOS, rustc will open `/dev/urandom` to initialize a `HashMap`. That's quite hard to emulate properly in Miri without a full-blown implementation of file descriptors. However, Miri needs an implementation of `SecRandomCopyBytes` anyway to support [getrandom](https://crates.io/crates/getrandom), so using it here should work just as well.
This will only have an effect when libstd is compiled specifically for Miri, but that will generally be the case when people use `cargo miri`.
This is clearly a hack, so I am opening this to start a discussion about whether we are okay with such a hack or not.
Cc @oli-obk
Add const generics to infer (and transitive dependencies)
Split out from #53645. This work is a collaborative effort with @yodaldevoid.
There are a number of stubs. These are mainly to ensure we don't overlook them when completing the implementation, but are not necessary for the initial implementation. We plan to address these in follow up PRs.
r? @eddyb / @nikomatsakis
Rollup of 7 pull requests
Successful merges:
- #59634 (Added an explanation for the E0704 error.)
- #60348 (move some functions from parser.rs to diagostics.rs)
- #60385 (Emit metadata files earlier)
- #60428 (Refactor `eval_body_using_ecx` so that it doesn't need to query for MIR)
- #60437 (Ensure that drop order of `async fn` matches `fn` and that users cannot refer to generated arguments.)
- #60439 (doc: Warn about possible zombie apocalypse)
- #60452 (Remove Context and ContextKind)
Failed merges:
r? @ghost