Skip to content

Rollup of 8 pull requests #136481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a375d1d
compiletest: cleanup `is_rustdoc` logic
jieyouxu Feb 2, 2025
788a389
miri: improve error when offset_from preconditions are violated
RalfJung Feb 2, 2025
4d0cb42
compiletest: remove useless path join in `rustdoc_json` runtest logic
jieyouxu Feb 2, 2025
17e4aec
`TypeVisitable` doesn't require `Clone`.
nnethercote Feb 2, 2025
f0b6d66
Derive `Clone` on fewer THIR types.
nnethercote Feb 2, 2025
c371363
LTA: Check where-clauses for well-formedness at the def site
fmease Feb 2, 2025
baa1cdd
Docs for f16 and f128: correct a typo and add details
pthariensflame Jan 31, 2025
f88f0a8
Remove a footgun-y feature / relic of the past from the compiletest DSL
fmease Feb 1, 2025
e661514
Remove hook calling via `TyCtxtAt`.
nnethercote Jan 31, 2025
8c5e6a2
override default config profile on tarballs
onur-ozkan Feb 3, 2025
7be7f3b
Rollup merge of #136356 - pthariensflame:patch-1, r=tgross35
jieyouxu Feb 3, 2025
ca23707
Rollup merge of #136404 - fmease:rm-compiletest-relic-of-the-past, r=…
jieyouxu Feb 3, 2025
1df7b30
Rollup merge of #136432 - fmease:lta-fix-def-site-checks, r=compiler-…
jieyouxu Feb 3, 2025
43764db
Rollup merge of #136438 - RalfJung:offset_from_ub_errors, r=oli-obk
jieyouxu Feb 3, 2025
bdc6b4d
Rollup merge of #136441 - jieyouxu:cleanup-is-rustdoc, r=compiler-errors
jieyouxu Feb 3, 2025
40d1cb4
Rollup merge of #136455 - nnethercote:less-Clone, r=compiler-errors
jieyouxu Feb 3, 2025
5bd0f32
Rollup merge of #136464 - nnethercote:rm-TyCtxtAt-for-hooks, r=oli-obk
jieyouxu Feb 3, 2025
f65c6af
Rollup merge of #136467 - onur-ozkan:override-default-profile-on-tarb…
jieyouxu Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading