Skip to content

Commit 01e4f19

Browse files
committed
Auto merge of rust-lang#136534 - jhpratt:rollup-dnz57dq, r=jhpratt
Rollup of 6 pull requests Successful merges: - rust-lang#136398 (add UnsafeCell direct access APIs) - rust-lang#136465 (Some `rustc_middle` cleanups) - rust-lang#136479 (std::fs: further simplify dirent64 handling) - rust-lang#136504 (Fix last compare-mode false negatives in tests) - rust-lang#136511 (Add `cast_signed` and `cast_unsigned` methods for `NonZero` types) - rust-lang#136518 (Add note about `FnPtr` trait being exposed as public bound) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7b31983 + af178aa commit 01e4f19

File tree

21 files changed

+239
-167
lines changed

21 files changed

+239
-167
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

+35-111
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,3 @@
1-
//! Nodes in the dependency graph.
2-
//!
3-
//! A node in the [dependency graph] is represented by a [`DepNode`].
4-
//! A `DepNode` consists of a [`DepKind`] (which
5-
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
6-
//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
7-
//! depends on the node's `DepKind`. Together, the kind and the fingerprint
8-
//! fully identify a dependency node, even across multiple compilation sessions.
9-
//! In other words, the value of the fingerprint does not depend on anything
10-
//! that is specific to a given compilation session, like an unpredictable
11-
//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
12-
//! pointer. The concept behind this could be compared to how git commit hashes
13-
//! uniquely identify a given commit. The fingerprinting approach has
14-
//! a few advantages:
15-
//!
16-
//! * A `DepNode` can simply be serialized to disk and loaded in another session
17-
//! without the need to do any "rebasing" (like we have to do for Spans and
18-
//! NodeIds) or "retracing" (like we had to do for `DefId` in earlier
19-
//! implementations of the dependency graph).
20-
//! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
21-
//! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
22-
//! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
23-
//! memory without any post-processing (e.g., "abomination-style" pointer
24-
//! reconstruction).
25-
//! * Because a `DepNode` is self-contained, we can instantiate `DepNodes` that
26-
//! refer to things that do not exist anymore. In previous implementations
27-
//! `DepNode` contained a `DefId`. A `DepNode` referring to something that
28-
//! had been removed between the previous and the current compilation session
29-
//! could not be instantiated because the current compilation session
30-
//! contained no `DefId` for thing that had been removed.
31-
//!
32-
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
33-
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
34-
//! needed at runtime in order to construct a valid `DepNode` fingerprint.
35-
//! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
36-
//! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
37-
//!
38-
//! Because the macro sees what parameters a given `DepKind` requires, it can
39-
//! "infer" some properties for each kind of `DepNode`:
40-
//!
41-
//! * Whether a `DepNode` of a given kind has any parameters at all. Some
42-
//! `DepNode`s could represent global concepts with only one value.
43-
//! * Whether it is possible, in principle, to reconstruct a query key from a
44-
//! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
45-
//! in which case it is possible to map the node's fingerprint back to the
46-
//! `DefId` it was computed from. In other cases, too much information gets
47-
//! lost during fingerprint computation.
48-
//!
49-
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
50-
//! `DepNode::new()`, ensures that only valid `DepNode` instances can be
51-
//! constructed. For example, the API does not allow for constructing
52-
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
53-
//! More generally speaking, it relieves the user of the `DepNode` API of
54-
//! having to know how to compute the expected fingerprint for a given set of
55-
//! node parameters.
56-
//!
57-
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
58-
591
use rustc_data_structures::fingerprint::Fingerprint;
602
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
613
use rustc_hir::definitions::DefPathHash;
@@ -158,26 +100,14 @@ pub(crate) fn make_compile_mono_item<'tcx>(
158100
}
159101

160102
pub trait DepNodeExt: Sized {
161-
/// Extracts the DefId corresponding to this DepNode. This will work
162-
/// if two conditions are met:
163-
///
164-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
165-
/// 2. the item that the DefPath refers to exists in the current tcx.
166-
///
167-
/// Condition (1) is determined by the DepKind variant of the
168-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
169-
/// refers to something from the previous compilation session that
170-
/// has been removed.
171103
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
172104

173-
/// Used in testing
174105
fn from_label_string(
175106
tcx: TyCtxt<'_>,
176107
label: &str,
177108
def_path_hash: DefPathHash,
178109
) -> Result<Self, ()>;
179110

180-
/// Used in testing
181111
fn has_label_string(label: &str) -> bool;
182112
}
183113

@@ -399,52 +329,46 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
399329
}
400330
}
401331

402-
macro_rules! impl_for_typed_def_id {
403-
($Name:ident, $LocalName:ident) => {
404-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for $Name {
405-
#[inline(always)]
406-
fn fingerprint_style() -> FingerprintStyle {
407-
FingerprintStyle::DefPathHash
408-
}
332+
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for ModDefId {
333+
#[inline(always)]
334+
fn fingerprint_style() -> FingerprintStyle {
335+
FingerprintStyle::DefPathHash
336+
}
409337

410-
#[inline(always)]
411-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
412-
self.to_def_id().to_fingerprint(tcx)
413-
}
338+
#[inline(always)]
339+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
340+
self.to_def_id().to_fingerprint(tcx)
341+
}
414342

415-
#[inline(always)]
416-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
417-
self.to_def_id().to_debug_str(tcx)
418-
}
343+
#[inline(always)]
344+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
345+
self.to_def_id().to_debug_str(tcx)
346+
}
419347

420-
#[inline(always)]
421-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
422-
DefId::recover(tcx, dep_node).map($Name::new_unchecked)
423-
}
424-
}
348+
#[inline(always)]
349+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
350+
DefId::recover(tcx, dep_node).map(ModDefId::new_unchecked)
351+
}
352+
}
425353

426-
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for $LocalName {
427-
#[inline(always)]
428-
fn fingerprint_style() -> FingerprintStyle {
429-
FingerprintStyle::DefPathHash
430-
}
354+
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalModDefId {
355+
#[inline(always)]
356+
fn fingerprint_style() -> FingerprintStyle {
357+
FingerprintStyle::DefPathHash
358+
}
431359

432-
#[inline(always)]
433-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
434-
self.to_def_id().to_fingerprint(tcx)
435-
}
360+
#[inline(always)]
361+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
362+
self.to_def_id().to_fingerprint(tcx)
363+
}
436364

437-
#[inline(always)]
438-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
439-
self.to_def_id().to_debug_str(tcx)
440-
}
365+
#[inline(always)]
366+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
367+
self.to_def_id().to_debug_str(tcx)
368+
}
441369

442-
#[inline(always)]
443-
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
444-
LocalDefId::recover(tcx, dep_node).map($LocalName::new_unchecked)
445-
}
446-
}
447-
};
370+
#[inline(always)]
371+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
372+
LocalDefId::recover(tcx, dep_node).map(LocalModDefId::new_unchecked)
373+
}
448374
}
449-
450-
impl_for_typed_def_id! { ModDefId, LocalModDefId }

compiler/rustc_middle/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! The "main crate" of the Rust compiler. This crate contains common
22
//! type definitions that are used by the other crates in the rustc
3-
//! "family". Some prominent examples (note that each of these modules
4-
//! has their own README with further details).
3+
//! "family". The following are some prominent examples.
54
//!
65
//! - **HIR.** The "high-level (H) intermediate representation (IR)" is
76
//! defined in the [`hir`] module.
7+
//! - **THIR.** The "typed high-level (H) intermediate representation (IR)"
8+
//! is defined in the [`thir`] module.
89
//! - **MIR.** The "mid-level (M) intermediate representation (IR)" is
910
//! defined in the [`mir`] module. This module contains only the
1011
//! *definition* of the MIR; the passes that transform and operate
@@ -37,7 +38,6 @@
3738
#![feature(box_as_ptr)]
3839
#![feature(box_patterns)]
3940
#![feature(closure_track_caller)]
40-
#![feature(const_type_name)]
4141
#![feature(core_intrinsics)]
4242
#![feature(coroutines)]
4343
#![feature(debug_closure_helpers)]
@@ -50,7 +50,6 @@
5050
#![feature(intra_doc_pointers)]
5151
#![feature(iter_from_coroutine)]
5252
#![feature(let_chains)]
53-
#![feature(macro_metavar_expr)]
5453
#![feature(min_specialization)]
5554
#![feature(negative_impls)]
5655
#![feature(never_type)]

compiler/rustc_middle/src/thir.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ pub mod visit;
3737

3838
macro_rules! thir_with_elements {
3939
(
40-
$($field_name:ident: $field_ty:ty,)*
41-
42-
@elements:
4340
$($name:ident: $id:ty => $value:ty => $format:literal,)*
4441
) => {
4542
$(
@@ -55,20 +52,16 @@ macro_rules! thir_with_elements {
5552
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
5653
#[derive(Debug, HashStable)]
5754
pub struct Thir<'tcx> {
58-
$(
59-
pub $field_name: $field_ty,
60-
)*
55+
pub body_type: BodyTy<'tcx>,
6156
$(
6257
pub $name: IndexVec<$id, $value>,
6358
)*
6459
}
6560

6661
impl<'tcx> Thir<'tcx> {
67-
pub fn new($($field_name: $field_ty,)*) -> Thir<'tcx> {
62+
pub fn new(body_type: BodyTy<'tcx>) -> Thir<'tcx> {
6863
Thir {
69-
$(
70-
$field_name,
71-
)*
64+
body_type,
7265
$(
7366
$name: IndexVec::new(),
7467
)*
@@ -88,9 +81,6 @@ macro_rules! thir_with_elements {
8881
}
8982

9083
thir_with_elements! {
91-
body_type: BodyTy<'tcx>,
92-
93-
@elements:
9484
arms: ArmId => Arm<'tcx> => "a{}",
9585
blocks: BlockId => Block => "b{}",
9686
exprs: ExprId => Expr<'tcx> => "e{}",

compiler/rustc_middle/src/thir/visit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::{
2-
AdtExpr, Arm, Block, ClosureExpr, Expr, ExprKind, InlineAsmExpr, InlineAsmOperand, Pat,
3-
PatKind, Stmt, StmtKind, Thir,
2+
AdtExpr, AdtExprBase, Arm, Block, ClosureExpr, Expr, ExprKind, InlineAsmExpr, InlineAsmOperand,
3+
Pat, PatKind, Stmt, StmtKind, Thir,
44
};
5-
use crate::thir::AdtExprBase;
65

76
pub trait Visitor<'thir, 'tcx: 'thir>: Sized {
87
fn thir(&self) -> &'thir Thir<'tcx>;

compiler/rustc_middle/src/traits/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ use rustc_macros::{
2121
};
2222
use rustc_span::def_id::{CRATE_DEF_ID, LocalDefId};
2323
use rustc_span::{DUMMY_SP, Span, Symbol};
24-
// FIXME: Remove this import and import via `solve::`
25-
pub use rustc_type_ir::solve::BuiltinImplSource;
2624
use smallvec::{SmallVec, smallvec};
2725
use thin_vec::ThinVec;
2826

2927
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
3028
use crate::mir::ConstraintCategory;
29+
pub use crate::traits::solve::BuiltinImplSource;
3130
use crate::ty::abstract_const::NotConstEvaluatable;
3231
use crate::ty::{self, AdtKind, GenericArgsRef, Ty};
3332

compiler/rustc_middle/src/traits/query.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
88
use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
99
use rustc_span::Span;
10-
// FIXME: Remove this import and import via `traits::solve`.
11-
pub use rustc_type_ir::solve::NoSolution;
1210

1311
use crate::error::DropCheckOverflow;
1412
use crate::infer::canonical::{Canonical, CanonicalQueryInput, QueryResponse};
13+
pub use crate::traits::solve::NoSolution;
1514
use crate::ty::{self, GenericArg, Ty, TyCtxt};
1615

1716
pub mod type_op {

compiler/rustc_query_system/src/dep_graph/dep_node.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
//! This module defines the `DepNode` type which the compiler uses to represent
2-
//! nodes in the dependency graph. A `DepNode` consists of a `DepKind` (which
3-
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc)
4-
//! and a `Fingerprint`, a 128 bit hash value the exact meaning of which
1+
//! This module defines the [`DepNode`] type which the compiler uses to represent
2+
//! nodes in the [dependency graph]. A `DepNode` consists of a [`DepKind`] (which
3+
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
4+
//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
55
//! depends on the node's `DepKind`. Together, the kind and the fingerprint
66
//! fully identify a dependency node, even across multiple compilation sessions.
77
//! In other words, the value of the fingerprint does not depend on anything
88
//! that is specific to a given compilation session, like an unpredictable
9-
//! interning key (e.g., NodeId, DefId, Symbol) or the numeric value of a
9+
//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
1010
//! pointer. The concept behind this could be compared to how git commit hashes
11-
//! uniquely identify a given commit and has a few advantages:
11+
//! uniquely identify a given commit. The fingerprinting approach has
12+
//! a few advantages:
1213
//!
1314
//! * A `DepNode` can simply be serialized to disk and loaded in another session
14-
//! without the need to do any "rebasing (like we have to do for Spans and
15-
//! NodeIds) or "retracing" like we had to do for `DefId` in earlier
16-
//! implementations of the dependency graph.
15+
//! without the need to do any "rebasing" (like we have to do for Spans and
16+
//! NodeIds) or "retracing" (like we had to do for `DefId` in earlier
17+
//! implementations of the dependency graph).
1718
//! * A `Fingerprint` is just a bunch of bits, which allows `DepNode` to
1819
//! implement `Copy`, `Sync`, `Send`, `Freeze`, etc.
1920
//! * Since we just have a bit pattern, `DepNode` can be mapped from disk into
@@ -26,10 +27,12 @@
2627
//! could not be instantiated because the current compilation session
2728
//! contained no `DefId` for thing that had been removed.
2829
//!
29-
//! `DepNode` definition happens in `rustc_middle` with the `define_dep_nodes!()` macro.
30-
//! This macro defines the `DepKind` enum and a corresponding `DepConstructor` enum. The
31-
//! `DepConstructor` enum links a `DepKind` to the parameters that are needed at runtime in order
32-
//! to construct a valid `DepNode` fingerprint.
30+
//! `DepNode` definition happens in `rustc_middle` with the
31+
//! `define_dep_nodes!()` macro. This macro defines the `DepKind` enum. Each
32+
//! `DepKind` has its own parameters that are needed at runtime in order to
33+
//! construct a valid `DepNode` fingerprint. However, only `CompileCodegenUnit`
34+
//! and `CompileMonoItem` are constructed explicitly (with
35+
//! `make_compile_codegen_unit` and `make_compile_mono_item`).
3336
//!
3437
//! Because the macro sees what parameters a given `DepKind` requires, it can
3538
//! "infer" some properties for each kind of `DepNode`:
@@ -41,6 +44,16 @@
4144
//! in which case it is possible to map the node's fingerprint back to the
4245
//! `DefId` it was computed from. In other cases, too much information gets
4346
//! lost during fingerprint computation.
47+
//!
48+
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
49+
//! `DepNode::new()`, ensure that only valid `DepNode` instances can be
50+
//! constructed. For example, the API does not allow for constructing
51+
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
52+
//! More generally speaking, it relieves the user of the `DepNode` API of
53+
//! having to know how to compute the expected fingerprint for a given set of
54+
//! node parameters.
55+
//!
56+
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
4457
4558
use std::fmt;
4659
use std::hash::Hash;

0 commit comments

Comments
 (0)