Skip to content

Commit

Permalink
Auto merge of rust-lang#117459 - matthiaskrgr:rollup-t3osb3c, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#113241 (rustdoc: Document lack of object safety on affected traits)
 - rust-lang#117388 (Turn const_caller_location from a query to a hook)
 - rust-lang#117417 (Add a stable MIR visitor)
 - rust-lang#117439 (prepopulate opaque ty storage before using it)
 - rust-lang#117451 (Add support for pre-unix-epoch file dates on Apple platforms (rust-lang#108277))

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 31, 2023
2 parents 9d83ac2 + d06200b commit 09ac6e4
Show file tree
Hide file tree
Showing 22 changed files with 811 additions and 103 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
&mut borrowck_context,
);

// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
// predefined opaques in the typeck root.
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
checker.register_predefined_opaques_in_new_solver();
}
checker.check_user_type_annotations();

let mut verifier = TypeVerifier::new(&mut checker, promoted);
verifier.visit_body(&body);
Expand Down Expand Up @@ -1021,7 +1017,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
borrowck_context,
reported_errors: Default::default(),
};
checker.check_user_type_annotations();

// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
// predefined opaques in the typeck root.
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
checker.register_predefined_opaques_in_new_solver();
}

checker
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn provide(providers: &mut Providers) {
const_eval::provide(providers);
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
providers.const_caller_location = util::caller_location::const_caller_location_provider;
providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
providers.eval_to_valtree = |tcx, param_env_and_value| {
let (param_env, raw) = param_env_and_value.into_parts();
const_eval::eval_to_valtree(tcx, param_env, raw)
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_const_eval/src/util/caller_location.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use rustc_hir::LangItem;
use rustc_middle::mir;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
use rustc_span::symbol::Symbol;
use rustc_type_ir::Mutability;

use crate::const_eval::{mk_eval_cx, CanAccessStatics, CompileTimeEvalContext};
Expand Down Expand Up @@ -49,11 +50,13 @@ fn alloc_caller_location<'mir, 'tcx>(
}

pub(crate) fn const_caller_location_provider(
tcx: TyCtxt<'_>,
(file, line, col): (Symbol, u32, u32),
tcx: TyCtxtAt<'_>,
file: Symbol,
line: u32,
col: u32,
) -> mir::ConstValue<'_> {
trace!("const_caller_location: {}:{}:{}", file, line, col);
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), CanAccessStatics::No);
let mut ecx = mk_eval_cx(tcx.tcx, tcx.span, ty::ParamEnv::reveal_all(), CanAccessStatics::No);

let loc_place = alloc_caller_location(&mut ecx, file, line, col);
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ declare_hooks! {
/// Tries to destructure an `mir::Const` ADT or array into its variant index
/// and its field values. This should only be used for pretty printing.
hook try_destructure_mir_constant_for_diagnostics(val: mir::ConstValue<'tcx>, ty: Ty<'tcx>) -> Option<mir::DestructuredConstant<'tcx>>;

/// Getting a &core::panic::Location referring to a span.
hook const_caller_location(file: rustc_span::Symbol, line: u32, col: u32) -> mir::ConstValue<'tcx>;
}
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,12 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn span_as_caller_location(self, span: Span) -> ConstValue<'tcx> {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.sess.source_map().lookup_char_pos(topmost.lo());
self.const_caller_location((
self.const_caller_location(
rustc_span::symbol::Symbol::intern(
&caller.file.name.for_codegen(&self.sess).to_string_lossy(),
),
caller.line as u32,
caller.col_display as u32 + 1,
))
)
}
}
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,6 @@ rustc_queries! {
desc { "destructuring type level constant"}
}

query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> mir::ConstValue<'tcx> {
desc { "getting a &core::panic::Location referring to a span" }
}

// FIXME get rid of this with valtrees
query lit_to_const(
key: LitToConstInput<'tcx>
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
tables.create_def_id(def_id)
}

fn instance_mangled_name(&self, def: InstanceDef) -> String {
let tables = self.0.borrow_mut();
let instance = tables.instances[def];
tables.tcx.symbol_name(instance).name.to_string()
}

fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance {
let mut tables = self.0.borrow_mut();
let def_id = tables[item.0];
Expand Down
7 changes: 4 additions & 3 deletions compiler/stable_mir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ pub type DefKind = Opaque;
pub type Filename = Opaque;

/// Holds information about an item in the crate.
/// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to
/// use this item.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct CrateItem(pub DefId);

Expand Down Expand Up @@ -224,6 +222,9 @@ pub trait Context {
/// Get the instance.
fn instance_def_id(&self, instance: InstanceDef) -> DefId;

/// Get the instance mangled name.
fn instance_mangled_name(&self, instance: InstanceDef) -> String;

/// Convert a non-generic crate item into an instance.
/// This function will panic if the item is generic.
fn mono_instance(&self, item: CrateItem) -> Instance;
Expand Down Expand Up @@ -259,7 +260,7 @@ pub fn with<R>(f: impl FnOnce(&dyn Context) -> R) -> R {
}

/// A type that provides internal information but that can still be used for debug purpose.
#[derive(Clone)]
#[derive(Clone, Eq, PartialEq)]
pub struct Opaque(String);

impl std::fmt::Display for Opaque {
Expand Down
2 changes: 2 additions & 0 deletions compiler/stable_mir/src/mir.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod body;
pub mod mono;
pub mod visit;

pub use body::*;
pub use visit::MirVisitor;
Loading

0 comments on commit 09ac6e4

Please sign in to comment.