Skip to content

Commit

Permalink
Auto merge of #116455 - matthiaskrgr:rollup-p226a5u, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #116220 (stabilize `Option::as_`(`mut_`)`slice`)
 - #116288 (Add Span to various smir types)
 - #116415 (Move subtyper below reveal_all and change reveal_all)
 - #116428 (Add a note to duplicate diagnostics)
 - #116452 (Do not assert that hidden types don't have erased regions.)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 5, 2023
2 parents 3bcad65 + 76d0b79 commit cdca82c
Show file tree
Hide file tree
Showing 182 changed files with 762 additions and 356 deletions.
11 changes: 8 additions & 3 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,16 +1376,16 @@ impl HandlerInner {
self.emitted_diagnostic_codes.insert(code.clone());
}

let already_emitted = |this: &mut Self| {
let already_emitted = {
let mut hasher = StableHasher::new();
diagnostic.hash(&mut hasher);
let diagnostic_hash = hasher.finish();
!this.emitted_diagnostics.insert(diagnostic_hash)
!self.emitted_diagnostics.insert(diagnostic_hash)
};

// Only emit the diagnostic if we've been asked to deduplicate or
// haven't already emitted an equivalent diagnostic.
if !(self.flags.deduplicate_diagnostics && already_emitted(self)) {
if !(self.flags.deduplicate_diagnostics && already_emitted) {
debug!(?diagnostic);
debug!(?self.emitted_diagnostics);
let already_emitted_sub = |sub: &mut SubDiagnostic| {
Expand All @@ -1401,6 +1401,11 @@ impl HandlerInner {
};

diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
if already_emitted {
diagnostic.note(
"duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`",
);
}

self.emitter.emit_diagnostic(diagnostic);
if diagnostic.is_error() {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(box_patterns)]
#![feature(min_specialization)]
#![feature(control_flow_enum)]
#![feature(option_as_slice)]
#![recursion_limit = "256"]

#[macro_use]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
rvalue: &mut Rvalue<'tcx>,
location: Location,
) {
// We don't need to do anything for deref temps as they are
// not part of the source code, but used for desugaring purposes.
if self.local_decls[place.local].is_deref_temp() {
return;
}
let mut place_ty = place.ty(self.local_decls, self.tcx).ty;
let mut rval_ty = rvalue.ty(self.local_decls, self.tcx);
// Not erasing this causes `Free Regions` errors in validator,
Expand All @@ -48,7 +53,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
// // gets transformed to
// let temp: rval_ty = rval;
// let place: place_ty = temp as place_ty;
//
pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let patch = MirPatch::new(body);
let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls };
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
/// After this series of passes, no lifetime analysis based on borrowing can be done.
fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let passes: &[&dyn MirPass<'tcx>] = &[
&add_subtyping_projections::Subtyper,
&cleanup_post_borrowck::CleanupPostBorrowck,
&remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::EarlyOpt,
Expand All @@ -483,6 +482,7 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// These next passes must be executed together
&add_call_guards::CriticalCallEdges,
&reveal_all::RevealAll, // has to be done before drop elaboration, since we need to drop opaque types, too.
&add_subtyping_projections::Subtyper, // calling this after reveal_all ensures that we don't deal with opaque types
&elaborate_drops::ElaborateDrops,
// This will remove extraneous landing pads which are no longer
// necessary as well as well as forcing any call in a non-unwinding
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_transform/src/reveal_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
.filter(|elem| !matches!(elem, ProjectionElem::OpaqueCast(_)))
.collect::<Vec<_>>(),
);
self.super_place(place, _context, _location);
}

#[inline]
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, _: Location) {
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, location: Location) {
// We have to use `try_normalize_erasing_regions` here, since it's
// possible that we visit impossible-to-satisfy where clauses here,
// see #91745
if let Ok(c) = self.tcx.try_normalize_erasing_regions(self.param_env, constant.const_) {
constant.const_ = c;
}
self.super_constant(constant, location);
}

#[inline]
Expand Down
175 changes: 116 additions & 59 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{alloc_range, AllocId};
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_target::abi::FieldIdx;
use stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx};
use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy};
use stable_mir::{self, opaque, Context};
use tracing::debug;
Expand Down Expand Up @@ -106,7 +106,14 @@ impl<'tcx> Context for Tables<'tcx> {
.collect(),
})
.collect(),
locals: mir.local_decls.iter().map(|decl| self.intern_ty(decl.ty)).collect(),
locals: mir
.local_decls
.iter()
.map(|decl| stable_mir::mir::LocalDecl {
ty: self.intern_ty(decl.ty),
span: decl.source_info.span.stable(self),
})
.collect(),
}
}

Expand Down Expand Up @@ -223,41 +230,64 @@ pub(crate) trait Stable<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
type T = stable_mir::mir::Statement;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use rustc_middle::mir::StatementKind::*;
match &self.kind {
Assign(assign) => {
stable_mir::mir::Statement::Assign(assign.0.stable(tables), assign.1.stable(tables))
}
FakeRead(fake_read_place) => stable_mir::mir::Statement::FakeRead(
fake_read_place.0.stable(tables),
fake_read_place.1.stable(tables),
Statement { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) }
}
}

impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {
type T = stable_mir::mir::StatementKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
match self {
mir::StatementKind::Assign(assign) => stable_mir::mir::StatementKind::Assign(
assign.0.stable(tables),
assign.1.stable(tables),
),
SetDiscriminant { place: plc, variant_index: idx } => {
stable_mir::mir::Statement::SetDiscriminant {
place: plc.as_ref().stable(tables),
variant_index: idx.stable(tables),
mir::StatementKind::FakeRead(fake_read_place) => {
stable_mir::mir::StatementKind::FakeRead(
fake_read_place.0.stable(tables),
fake_read_place.1.stable(tables),
)
}
mir::StatementKind::SetDiscriminant { place, variant_index } => {
stable_mir::mir::StatementKind::SetDiscriminant {
place: place.as_ref().stable(tables),
variant_index: variant_index.stable(tables),
}
}
Deinit(place) => stable_mir::mir::Statement::Deinit(place.stable(tables)),
StorageLive(place) => stable_mir::mir::Statement::StorageLive(place.stable(tables)),
StorageDead(place) => stable_mir::mir::Statement::StorageDead(place.stable(tables)),
Retag(retag, place) => {
stable_mir::mir::Statement::Retag(retag.stable(tables), place.stable(tables))
mir::StatementKind::Deinit(place) => {
stable_mir::mir::StatementKind::Deinit(place.stable(tables))
}

mir::StatementKind::StorageLive(place) => {
stable_mir::mir::StatementKind::StorageLive(place.stable(tables))
}

mir::StatementKind::StorageDead(place) => {
stable_mir::mir::StatementKind::StorageDead(place.stable(tables))
}
mir::StatementKind::Retag(retag, place) => {
stable_mir::mir::StatementKind::Retag(retag.stable(tables), place.stable(tables))
}
mir::StatementKind::PlaceMention(place) => {
stable_mir::mir::StatementKind::PlaceMention(place.stable(tables))
}
PlaceMention(place) => stable_mir::mir::Statement::PlaceMention(place.stable(tables)),
AscribeUserType(place_projection, variance) => {
stable_mir::mir::Statement::AscribeUserType {
mir::StatementKind::AscribeUserType(place_projection, variance) => {
stable_mir::mir::StatementKind::AscribeUserType {
place: place_projection.as_ref().0.stable(tables),
projections: place_projection.as_ref().1.stable(tables),
variance: variance.stable(tables),
}
}
Coverage(coverage) => stable_mir::mir::Statement::Coverage(opaque(coverage)),
Intrinsic(intrinstic) => {
stable_mir::mir::Statement::Intrinsic(intrinstic.stable(tables))
mir::StatementKind::Coverage(coverage) => {
stable_mir::mir::StatementKind::Coverage(opaque(coverage))
}
mir::StatementKind::Intrinsic(intrinstic) => {
stable_mir::mir::StatementKind::Intrinsic(intrinstic.stable(tables))
}
mir::StatementKind::ConstEvalCounter => {
stable_mir::mir::StatementKind::ConstEvalCounter
}
ConstEvalCounter => stable_mir::mir::Statement::ConstEvalCounter,
Nop => stable_mir::mir::Statement::Nop,
mir::StatementKind::Nop => stable_mir::mir::StatementKind::Nop,
}
}
}
Expand Down Expand Up @@ -806,11 +836,20 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
type T = stable_mir::mir::Terminator;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use rustc_middle::mir::TerminatorKind::*;
use stable_mir::mir::Terminator;
match &self.kind {
Goto { target } => Terminator::Goto { target: target.as_usize() },
SwitchInt { discr, targets } => Terminator::SwitchInt {
Terminator { kind: self.kind.stable(tables), span: self.source_info.span.stable(tables) }
}
}

impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
type T = stable_mir::mir::TerminatorKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use stable_mir::mir::TerminatorKind;
match self {
mir::TerminatorKind::Goto { target } => {
TerminatorKind::Goto { target: target.as_usize() }
}
mir::TerminatorKind::SwitchInt { discr, targets } => TerminatorKind::SwitchInt {
discr: discr.stable(tables),
targets: targets
.iter()
Expand All @@ -821,42 +860,60 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
.collect(),
otherwise: targets.otherwise().as_usize(),
},
UnwindResume => Terminator::Resume,
UnwindTerminate(_) => Terminator::Abort,
Return => Terminator::Return,
Unreachable => Terminator::Unreachable,
Drop { place, target, unwind, replace: _ } => Terminator::Drop {
place: place.stable(tables),
target: target.as_usize(),
unwind: unwind.stable(tables),
},
Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => {
Terminator::Call {
func: func.stable(tables),
args: args.iter().map(|arg| arg.stable(tables)).collect(),
destination: destination.stable(tables),
target: target.map(|t| t.as_usize()),
mir::TerminatorKind::UnwindResume => TerminatorKind::Resume,
mir::TerminatorKind::UnwindTerminate(_) => TerminatorKind::Abort,
mir::TerminatorKind::Return => TerminatorKind::Return,
mir::TerminatorKind::Unreachable => TerminatorKind::Unreachable,
mir::TerminatorKind::Drop { place, target, unwind, replace: _ } => {
TerminatorKind::Drop {
place: place.stable(tables),
target: target.as_usize(),
unwind: unwind.stable(tables),
}
}
Assert { cond, expected, msg, target, unwind } => Terminator::Assert {
cond: cond.stable(tables),
expected: *expected,
msg: msg.stable(tables),
target: target.as_usize(),
mir::TerminatorKind::Call {
func,
args,
destination,
target,
unwind,
call_source: _,
fn_span: _,
} => TerminatorKind::Call {
func: func.stable(tables),
args: args.iter().map(|arg| arg.stable(tables)).collect(),
destination: destination.stable(tables),
target: target.map(|t| t.as_usize()),
unwind: unwind.stable(tables),
},
InlineAsm { template, operands, options, line_spans, destination, unwind } => {
Terminator::InlineAsm {
template: format!("{template:?}"),
operands: operands.iter().map(|operand| operand.stable(tables)).collect(),
options: format!("{options:?}"),
line_spans: format!("{line_spans:?}"),
destination: destination.map(|d| d.as_usize()),
mir::TerminatorKind::Assert { cond, expected, msg, target, unwind } => {
TerminatorKind::Assert {
cond: cond.stable(tables),
expected: *expected,
msg: msg.stable(tables),
target: target.as_usize(),
unwind: unwind.stable(tables),
}
}
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
mir::TerminatorKind::InlineAsm {
template,
operands,
options,
line_spans,
destination,
unwind,
} => TerminatorKind::InlineAsm {
template: format!("{template:?}"),
operands: operands.iter().map(|operand| operand.stable(tables)).collect(),
options: format!("{options:?}"),
line_spans: format!("{line_spans:?}"),
destination: destination.map(|d| d.as_usize()),
unwind: unwind.stable(tables),
},
mir::TerminatorKind::Yield { .. }
| mir::TerminatorKind::GeneratorDrop
| mir::TerminatorKind::FalseEdge { .. }
| mir::TerminatorKind::FalseUnwind { .. } => unreachable!(),
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3116,9 +3116,6 @@ fn bind_generator_hidden_types_above<'tcx>(
bty.instantiate(tcx, args)
})
.collect();
if considering_regions {
debug_assert!(!hidden_types.has_erased_regions());
}
let bound_vars =
tcx.mk_bound_variable_kinds_from_iter(bound_vars.iter().chain(
(num_bound_variables..counter).map(|_| ty::BoundVariableKind::Region(ty::BrAnon)),
Expand Down
24 changes: 21 additions & 3 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ use crate::{ty::Ty, Span};
#[derive(Clone, Debug)]
pub struct Body {
pub blocks: Vec<BasicBlock>,
pub locals: Vec<Ty>,
pub locals: Vec<LocalDecl>,
}

#[derive(Clone, Debug)]
pub struct LocalDecl {
pub ty: Ty,
pub span: Span,
}

#[derive(Clone, Debug)]
Expand All @@ -15,7 +21,13 @@ pub struct BasicBlock {
}

#[derive(Clone, Debug)]
pub enum Terminator {
pub struct Terminator {
pub kind: TerminatorKind,
pub span: Span,
}

#[derive(Clone, Debug)]
pub enum TerminatorKind {
Goto {
target: usize,
},
Expand Down Expand Up @@ -179,7 +191,13 @@ pub enum NonDivergingIntrinsic {
}

#[derive(Clone, Debug)]
pub enum Statement {
pub struct Statement {
pub kind: StatementKind,
pub span: Span,
}

#[derive(Clone, Debug)]
pub enum StatementKind {
Assign(Place, Rvalue),
FakeRead(FakeReadCause, Place),
SetDiscriminant { place: Place, variant_index: VariantIdx },
Expand Down
Loading

0 comments on commit cdca82c

Please sign in to comment.