Skip to content

Commit

Permalink
Auto merge of rust-lang#136481 - jieyouxu:rollup-w0lnnqb, r=jieyouxu
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#136356 (Docs for f16 and f128: correct a typo and add details)
 - rust-lang#136404 (Remove a footgun-y feature / relic of the past from the compiletest DSL)
 - rust-lang#136432 (LTA: Actually check where-clauses for well-formedness at the def site)
 - rust-lang#136438 (miri: improve error when offset_from preconditions are violated)
 - rust-lang#136441 ([`compiletest`-related cleanups 1/7] Cleanup `is_rustdoc` logic and remove a useless path join in rustdoc-json runtest logic)
 - rust-lang#136455 (Remove some `Clone` bounds and derives.)
 - rust-lang#136464 (Remove hook calling via `TyCtxtAt`.)
 - rust-lang#136467 (override default config profile on tarballs)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 3, 2025
2 parents f2c4ccd + f65c6af commit 534d79a
Show file tree
Hide file tree
Showing 33 changed files with 251 additions and 143 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ const_eval_nullary_intrinsic_fail =
could not evaluate nullary intrinsic
const_eval_offset_from_different_allocations =
`{$name}` called on pointers into different allocations
`{$name}` called on two different pointers that are not both derived from the same allocation
const_eval_offset_from_out_of_bounds =
`{$name}` called on two different pointers where the memory range between them is not in-bounds of an allocation
const_eval_offset_from_overflow =
`{$name}` called when first pointer is too far ahead of second
const_eval_offset_from_test =
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_const_eval/src/const_eval/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Not in interpret to make sure we do not use private implementation details

use rustc_abi::VariantIdx;
use rustc_middle::query::{Key, TyCtxtAt};
use rustc_middle::query::Key;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{bug, mir};
Expand Down Expand Up @@ -35,16 +35,17 @@ pub(crate) type ValTreeCreationResult<'tcx> = Result<ty::ValTree<'tcx>, ValTreeC

#[instrument(skip(tcx), level = "debug")]
pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
tcx: TyCtxtAt<'tcx>,
tcx: TyCtxt<'tcx>,
val: mir::ConstValue<'tcx>,
ty: Ty<'tcx>,
) -> Option<mir::DestructuredConstant<'tcx>> {
let typing_env = ty::TypingEnv::fully_monomorphized();
let (ecx, op) = mk_eval_cx_for_const_val(tcx, typing_env, val, ty)?;
// FIXME: use a proper span here?
let (ecx, op) = mk_eval_cx_for_const_val(tcx.at(rustc_span::DUMMY_SP), typing_env, val, ty)?;

// We go to `usize` as we cannot allocate anything bigger anyway.
let (field_count, variant, down) = match ty.kind() {
ty::Array(_, len) => (len.try_to_target_usize(tcx.tcx)? as usize, None, op),
ty::Array(_, len) => (len.try_to_target_usize(tcx)? as usize, None, op),
ty::Adt(def, _) if def.variants().is_empty() => {
return None;
}
Expand Down
20 changes: 19 additions & 1 deletion compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,25 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {

// Check that the memory between them is dereferenceable at all, starting from the
// origin pointer: `dist` is `a - b`, so it is based on `b`.
self.check_ptr_access_signed(b, dist, CheckInAllocMsg::OffsetFromTest)?;
self.check_ptr_access_signed(b, dist, CheckInAllocMsg::OffsetFromTest)
.map_err_kind(|_| {
// This could mean they point to different allocations, or they point to the same allocation
// but not the entire range between the pointers is in-bounds.
if let Ok((a_alloc_id, ..)) = self.ptr_try_get_alloc_id(a, 0)
&& let Ok((b_alloc_id, ..)) = self.ptr_try_get_alloc_id(b, 0)
&& a_alloc_id == b_alloc_id
{
err_ub_custom!(
fluent::const_eval_offset_from_out_of_bounds,
name = intrinsic_name,
)
} else {
err_ub_custom!(
fluent::const_eval_offset_from_different_allocations,
name = intrinsic_name,
)
}
})?;
// Then check that this is also dereferenceable from `a`. This ensures that they are
// derived from the same allocation.
self.check_ptr_access_signed(
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_const_eval/src/util/caller_location.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rustc_hir::LangItem;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self};
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::{bug, mir};
use rustc_span::Symbol;
use tracing::trace;
Expand Down Expand Up @@ -48,15 +47,15 @@ fn alloc_caller_location<'tcx>(
}

pub(crate) fn const_caller_location_provider(
tcx: TyCtxtAt<'_>,
tcx: TyCtxt<'_>,
file: Symbol,
line: u32,
col: u32,
) -> mir::ConstValue<'_> {
trace!("const_caller_location: {}:{}:{}", file, line, col);
let mut ecx = mk_eval_cx_to_read_const_val(
tcx.tcx,
tcx.span,
tcx,
rustc_span::DUMMY_SP, // FIXME: use a proper span here?
ty::TypingEnv::fully_monomorphized(),
CanAccessMutGlobal::No,
);
Expand Down
24 changes: 13 additions & 11 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,20 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
// `ForeignItem`s are handled separately.
hir::ItemKind::ForeignMod { .. } => Ok(()),
hir::ItemKind::TyAlias(hir_ty, hir_generics) => {
if tcx.type_alias_is_lazy(item.owner_id) {
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
let res = check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow);
check_variances_for_type_defn(tcx, item, hir_generics);
res
} else {
hir::ItemKind::TyAlias(hir_ty, hir_generics) if tcx.type_alias_is_lazy(item.owner_id) => {
let res = enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
let ty = tcx.type_of(def_id).instantiate_identity();
let item_ty = wfcx.normalize(hir_ty.span, Some(WellFormedLoc::Ty(def_id)), ty);
wfcx.register_wf_obligation(
hir_ty.span,
Some(WellFormedLoc::Ty(def_id)),
item_ty.into(),
);
check_where_clauses(wfcx, item.span, def_id);
Ok(())
}
});
check_variances_for_type_defn(tcx, item, hir_generics);
res
}
_ => Ok(()),
};
Expand Down Expand Up @@ -1276,7 +1280,6 @@ fn check_item_fn(

enum UnsizedHandling {
Forbid,
Allow,
AllowIfForeignTail,
}

Expand All @@ -1294,7 +1297,6 @@ fn check_item_type(

let forbid_unsized = match unsized_handling {
UnsizedHandling::Forbid => true,
UnsizedHandling::Allow => false,
UnsizedHandling::AllowIfForeignTail => {
let tail =
tcx.struct_tail_for_codegen(item_ty, wfcx.infcx.typing_env(wfcx.param_env));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_middle::util::Providers;
#[allow(missing_docs)]
pub fn provide(providers: &mut Providers) {
providers.hooks.save_dep_graph =
|tcx| tcx.sess.time("serialize_dep_graph", || persist::save_dep_graph(tcx.tcx));
|tcx| tcx.sess.time("serialize_dep_graph", || persist::save_dep_graph(tcx));
}

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ fn provide_cstore_hooks(providers: &mut Providers) {
providers.hooks.def_path_hash_to_def_id_extern = |tcx, hash, stable_crate_id| {
// If this is a DefPathHash from an upstream crate, let the CrateStore map
// it to a DefId.
let cstore = CStore::from_tcx(tcx.tcx);
let cstore = CStore::from_tcx(tcx);
let cnum = *tcx
.untracked()
.stable_crate_ids
Expand All @@ -702,11 +702,11 @@ fn provide_cstore_hooks(providers: &mut Providers) {
};

providers.hooks.expn_hash_to_expn_id = |tcx, cnum, index_guess, hash| {
let cstore = CStore::from_tcx(tcx.tcx);
let cstore = CStore::from_tcx(tcx);
cstore.get_crate_data(cnum).expn_hash_to_expn_id(tcx.sess, index_guess, hash)
};
providers.hooks.import_source_files = |tcx, cnum| {
let cstore = CStore::from_tcx(tcx.tcx);
let cstore = CStore::from_tcx(tcx);
let cdata = cstore.get_crate_data(cnum);
for file_index in 0..cdata.root.source_map.size() {
cdata.imported_source_file(file_index as u32, tcx.sess);
Expand Down
20 changes: 3 additions & 17 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
use rustc_hir::def_id::{DefId, DefPathHash};
use rustc_session::StableCrateId;
use rustc_span::def_id::{CrateNum, LocalDefId};
use rustc_span::{DUMMY_SP, ExpnHash, ExpnId};
use tracing::instrument;
use rustc_span::{ExpnHash, ExpnId};

use crate::mir;
use crate::query::TyCtxtAt;
use crate::ty::{Ty, TyCtxt};

macro_rules! declare_hooks {
Expand All @@ -22,26 +20,14 @@ macro_rules! declare_hooks {
#[inline(always)]
pub fn $name(self, $($arg: $K,)*) -> $V
{
self.at(DUMMY_SP).$name($($arg,)*)
}
)*
}

impl<'tcx> TyCtxtAt<'tcx> {
$(
$(#[$attr])*
#[inline(always)]
#[instrument(level = "debug", skip(self), ret)]
pub fn $name(self, $($arg: $K,)*) -> $V
{
(self.tcx.hooks.$name)(self, $($arg,)*)
(self.hooks.$name)(self, $($arg,)*)
}
)*
}

pub struct Providers {
$(pub $name: for<'tcx> fn(
TyCtxtAt<'tcx>,
TyCtxt<'tcx>,
$($arg: $K,)*
) -> $V,)*
}
Expand Down
Loading

0 comments on commit 534d79a

Please sign in to comment.