Skip to content

Commit

Permalink
Unrolled build for rust-lang#137501
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#137501 - nnethercote:mv-impls-out-of-syntax, r=compiler-errors

Move `impl` blocks out of `rustc_middle/src/mir/syntax.rs`

Best reviewed one commit at a time.
  • Loading branch information
rust-timer authored Feb 24, 2025
2 parents f43e549 + 4183c08 commit 8216b99
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 116 deletions.
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
}

impl MirPhase {
pub fn name(&self) -> &'static str {
match *self {
MirPhase::Built => "built",
MirPhase::Analysis(AnalysisPhase::Initial) => "analysis",
MirPhase::Analysis(AnalysisPhase::PostCleanup) => "analysis-post-cleanup",
MirPhase::Runtime(RuntimePhase::Initial) => "runtime",
MirPhase::Runtime(RuntimePhase::PostCleanup) => "runtime-post-cleanup",
MirPhase::Runtime(RuntimePhase::Optimized) => "runtime-optimized",
}
}

/// Gets the (dialect, phase) index of the current `MirPhase`. Both numbers
/// are 1-indexed.
pub fn index(&self) -> (usize, usize) {
Expand Down
57 changes: 57 additions & 0 deletions compiler/rustc_middle/src/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ impl Statement<'_> {
}

impl<'tcx> StatementKind<'tcx> {
/// Returns a simple string representation of a `StatementKind` variant, independent of any
/// values it might hold (e.g. `StatementKind::Assign` always returns `"Assign"`).
pub const fn name(&self) -> &'static str {
match self {
StatementKind::Assign(..) => "Assign",
StatementKind::FakeRead(..) => "FakeRead",
StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
StatementKind::Deinit(..) => "Deinit",
StatementKind::StorageLive(..) => "StorageLive",
StatementKind::StorageDead(..) => "StorageDead",
StatementKind::Retag(..) => "Retag",
StatementKind::PlaceMention(..) => "PlaceMention",
StatementKind::AscribeUserType(..) => "AscribeUserType",
StatementKind::Coverage(..) => "Coverage",
StatementKind::Intrinsic(..) => "Intrinsic",
StatementKind::ConstEvalCounter => "ConstEvalCounter",
StatementKind::Nop => "Nop",
StatementKind::BackwardIncompatibleDropHint { .. } => "BackwardIncompatibleDropHint",
}
}
pub fn as_assign_mut(&mut self) -> Option<&mut (Place<'tcx>, Rvalue<'tcx>)> {
match self {
StatementKind::Assign(x) => Some(x),
Expand Down Expand Up @@ -862,3 +882,40 @@ impl<'tcx> BinOp {
})
}
}

impl From<Mutability> for RawPtrKind {
fn from(other: Mutability) -> Self {
match other {
Mutability::Mut => RawPtrKind::Mut,
Mutability::Not => RawPtrKind::Const,
}
}
}

impl RawPtrKind {
pub fn is_fake(self) -> bool {
match self {
RawPtrKind::Mut | RawPtrKind::Const => false,
RawPtrKind::FakeForPtrMetadata => true,
}
}

pub fn to_mutbl_lossy(self) -> Mutability {
match self {
RawPtrKind::Mut => Mutability::Mut,
RawPtrKind::Const => Mutability::Not,

// We have no type corresponding to a fake borrow, so use
// `*const` as an approximation.
RawPtrKind::FakeForPtrMetadata => Mutability::Not,
}
}

pub fn ptr_str(self) -> &'static str {
match self {
RawPtrKind::Mut => "mut",
RawPtrKind::Const => "const",
RawPtrKind::FakeForPtrMetadata => "const (fake)",
}
}
}
112 changes: 0 additions & 112 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,6 @@ pub enum MirPhase {
Runtime(RuntimePhase),
}

impl MirPhase {
pub fn name(&self) -> &'static str {
match *self {
MirPhase::Built => "built",
MirPhase::Analysis(AnalysisPhase::Initial) => "analysis",
MirPhase::Analysis(AnalysisPhase::PostCleanup) => "analysis-post-cleanup",
MirPhase::Runtime(RuntimePhase::Initial) => "runtime",
MirPhase::Runtime(RuntimePhase::PostCleanup) => "runtime-post-cleanup",
MirPhase::Runtime(RuntimePhase::Optimized) => "runtime-optimized",
}
}
}

/// See [`MirPhase::Analysis`].
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(HashStable)]
Expand Down Expand Up @@ -206,43 +193,6 @@ pub enum RawPtrKind {
FakeForPtrMetadata,
}

impl From<Mutability> for RawPtrKind {
fn from(other: Mutability) -> Self {
match other {
Mutability::Mut => RawPtrKind::Mut,
Mutability::Not => RawPtrKind::Const,
}
}
}

impl RawPtrKind {
pub fn is_fake(self) -> bool {
match self {
RawPtrKind::Mut | RawPtrKind::Const => false,
RawPtrKind::FakeForPtrMetadata => true,
}
}

pub fn to_mutbl_lossy(self) -> Mutability {
match self {
RawPtrKind::Mut => Mutability::Mut,
RawPtrKind::Const => Mutability::Not,

// We have no type corresponding to a fake borrow, so use
// `*const` as an approximation.
RawPtrKind::FakeForPtrMetadata => Mutability::Not,
}
}

pub fn ptr_str(self) -> &'static str {
match self {
RawPtrKind::Mut => "mut",
RawPtrKind::Const => "const",
RawPtrKind::FakeForPtrMetadata => "const (fake)",
}
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, TyEncodable, TyDecodable)]
#[derive(Hash, HashStable)]
pub enum MutBorrowKind {
Expand Down Expand Up @@ -515,29 +465,6 @@ pub enum StatementKind<'tcx> {
},
}

impl StatementKind<'_> {
/// Returns a simple string representation of a `StatementKind` variant, independent of any
/// values it might hold (e.g. `StatementKind::Assign` always returns `"Assign"`).
pub const fn name(&self) -> &'static str {
match self {
StatementKind::Assign(..) => "Assign",
StatementKind::FakeRead(..) => "FakeRead",
StatementKind::SetDiscriminant { .. } => "SetDiscriminant",
StatementKind::Deinit(..) => "Deinit",
StatementKind::StorageLive(..) => "StorageLive",
StatementKind::StorageDead(..) => "StorageDead",
StatementKind::Retag(..) => "Retag",
StatementKind::PlaceMention(..) => "PlaceMention",
StatementKind::AscribeUserType(..) => "AscribeUserType",
StatementKind::Coverage(..) => "Coverage",
StatementKind::Intrinsic(..) => "Intrinsic",
StatementKind::ConstEvalCounter => "ConstEvalCounter",
StatementKind::Nop => "Nop",
StatementKind::BackwardIncompatibleDropHint { .. } => "BackwardIncompatibleDropHint",
}
}
}

#[derive(
Clone,
TyEncodable,
Expand Down Expand Up @@ -673,12 +600,6 @@ pub enum CallSource {
Normal,
}

impl CallSource {
pub fn from_hir_call(self) -> bool {
matches!(self, CallSource::Normal)
}
}

#[derive(Clone, Copy, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
#[derive(TypeFoldable, TypeVisitable)]
/// The macro that an inline assembly block was created by
Expand All @@ -689,15 +610,6 @@ pub enum InlineAsmMacro {
NakedAsm,
}

impl InlineAsmMacro {
pub const fn diverges(self, options: InlineAsmOptions) -> bool {
match self {
InlineAsmMacro::Asm => options.contains(InlineAsmOptions::NORETURN),
InlineAsmMacro::NakedAsm => true,
}
}
}

///////////////////////////////////////////////////////////////////////////
// Terminators

Expand Down Expand Up @@ -999,30 +911,6 @@ pub enum BackwardIncompatibleDropReason {
Edition2024,
}

impl TerminatorKind<'_> {
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
/// values it might hold (e.g. `TerminatorKind::Call` always returns `"Call"`).
pub const fn name(&self) -> &'static str {
match self {
TerminatorKind::Goto { .. } => "Goto",
TerminatorKind::SwitchInt { .. } => "SwitchInt",
TerminatorKind::UnwindResume => "UnwindResume",
TerminatorKind::UnwindTerminate(_) => "UnwindTerminate",
TerminatorKind::Return => "Return",
TerminatorKind::Unreachable => "Unreachable",
TerminatorKind::Drop { .. } => "Drop",
TerminatorKind::Call { .. } => "Call",
TerminatorKind::TailCall { .. } => "TailCall",
TerminatorKind::Assert { .. } => "Assert",
TerminatorKind::Yield { .. } => "Yield",
TerminatorKind::CoroutineDrop => "CoroutineDrop",
TerminatorKind::FalseEdge { .. } => "FalseEdge",
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
TerminatorKind::InlineAsm { .. } => "InlineAsm",
}
}
}

#[derive(Debug, Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
pub struct SwitchTargets {
/// Possible values. For each value, the location to branch to is found in
Expand Down
40 changes: 39 additions & 1 deletion compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
use std::slice;

use rustc_ast::InlineAsmOptions;
use rustc_data_structures::packed::Pu128;
use rustc_hir::LangItem;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use smallvec::{SmallVec, smallvec};

use super::{TerminatorKind, *};
use super::*;

impl SwitchTargets {
/// Creates switch targets from an iterator of values and target blocks.
Expand Down Expand Up @@ -414,6 +415,28 @@ impl<'tcx> Terminator<'tcx> {
}

impl<'tcx> TerminatorKind<'tcx> {
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
/// values it might hold (e.g. `TerminatorKind::Call` always returns `"Call"`).
pub const fn name(&self) -> &'static str {
match self {
TerminatorKind::Goto { .. } => "Goto",
TerminatorKind::SwitchInt { .. } => "SwitchInt",
TerminatorKind::UnwindResume => "UnwindResume",
TerminatorKind::UnwindTerminate(_) => "UnwindTerminate",
TerminatorKind::Return => "Return",
TerminatorKind::Unreachable => "Unreachable",
TerminatorKind::Drop { .. } => "Drop",
TerminatorKind::Call { .. } => "Call",
TerminatorKind::TailCall { .. } => "TailCall",
TerminatorKind::Assert { .. } => "Assert",
TerminatorKind::Yield { .. } => "Yield",
TerminatorKind::CoroutineDrop => "CoroutineDrop",
TerminatorKind::FalseEdge { .. } => "FalseEdge",
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
TerminatorKind::InlineAsm { .. } => "InlineAsm",
}
}

#[inline]
pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) }
Expand Down Expand Up @@ -698,3 +721,18 @@ impl<'tcx> TerminatorKind<'tcx> {
}
}
}

impl CallSource {
pub fn from_hir_call(self) -> bool {
matches!(self, CallSource::Normal)
}
}

impl InlineAsmMacro {
pub const fn diverges(self, options: InlineAsmOptions) -> bool {
match self {
InlineAsmMacro::Asm => options.contains(InlineAsmOptions::NORETURN),
InlineAsmMacro::NakedAsm => true,
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub use rustc_session::lint::RegisteredTools;
use rustc_span::hygiene::MacroKind;
use rustc_span::{ExpnId, ExpnKind, Ident, Span, Symbol, kw, sym};
pub use rustc_type_ir::relate::VarianceDiagInfo;
pub use rustc_type_ir::{Movability, Mutability, *};
pub use rustc_type_ir::*;
use tracing::{debug, instrument};
pub use vtable::*;
use {rustc_ast as ast, rustc_attr_parsing as attr, rustc_hir as hir};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/builder/matches/match_pair.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use rustc_middle::mir::*;
use rustc_middle::thir::{self, *};
use rustc_middle::thir::*;
use rustc_middle::ty::{self, Ty, TypeVisitableExt};

use crate::builder::Builder;
Expand Down Expand Up @@ -134,7 +134,7 @@ impl<'tcx> MatchPairTree<'tcx> {
PatKind::Constant { value } => TestCase::Constant { value },

PatKind::AscribeUserType {
ascription: thir::Ascription { ref annotation, variance },
ascription: Ascription { ref annotation, variance },
ref subpattern,
..
} => {
Expand Down

0 comments on commit 8216b99

Please sign in to comment.