Skip to content

Rollup of 7 pull requests #129012

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
207ee73
std: refactor UNIX random data generation
joboet Aug 4, 2024
acb0241
Add windows-targets crate to std's sysroot
ChrisDenton Aug 9, 2024
a1b2b7f
Exclude windows-targets from the workspace
ChrisDenton Aug 9, 2024
0e4136b
Rework MIR inlining debuginfo so function parameters show up in debug…
khuey Aug 9, 2024
ed7bdbb
Store do_not_recommend-ness in impl header
compiler-errors Aug 10, 2024
20a16bb
Add test
compiler-errors Aug 10, 2024
ce9de3b
compiletest: implement `needs-lvm-zstd` directive
lqd Aug 10, 2024
002878c
mark `rust-lld-compress-debug-sections` test as needing zstd
lqd Aug 10, 2024
435405a
make `compressed-debuginfo` test about zlib only
lqd Aug 10, 2024
57b7c0a
prepare test for expanding scope
lqd Aug 10, 2024
f656c5c
expand zstd debuginfo compression test
lqd Aug 10, 2024
4d6ac1e
move and rename zstd script
lqd Aug 10, 2024
d39d465
strip whitespace for ignored tests reason comments
lqd Aug 11, 2024
a566252
enable `llvm.libzstd` on test x64 linux builder
lqd Aug 11, 2024
c5205e9
Normalize struct tail properly in borrowck and hir typeck
compiler-errors Aug 11, 2024
b5d2079
Rename normalization functions to raw
compiler-errors Aug 11, 2024
f15997f
Remove struct_tail_no_normalization
compiler-errors Aug 11, 2024
99c0d76
std: use `/scheme/rand` on Redox
joboet Aug 12, 2024
6839a8f
bootstrap: clear miri ui-test deps when miri sysroot gets rebuilt
RalfJung Aug 12, 2024
8d74688
Rollup merge of #128655 - joboet:play_with_the_dice, r=ChrisDenton
matthiaskrgr Aug 12, 2024
95716a7
Rollup merge of #128712 - compiler-errors:normalize-borrowck, r=lcnr
matthiaskrgr Aug 12, 2024
fa8f842
Rollup merge of #128861 - khuey:mir-inlining-parameters-debuginfo, r=…
matthiaskrgr Aug 12, 2024
5e3a499
Rollup merge of #128873 - ChrisDenton:windows-targets, r=Mark-Simulacrum
matthiaskrgr Aug 12, 2024
22129b3
Rollup merge of #128912 - compiler-errors:do-not-recommend-impl, r=lcnr
matthiaskrgr Aug 12, 2024
4c2362a
Rollup merge of #128935 - lqd:needs-zstd, r=Kobzol
matthiaskrgr Aug 12, 2024
23cf189
Rollup merge of #129000 - RalfJung:miri-bootstrap-clear, r=onur-ozkan
matthiaskrgr Aug 12, 2024
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
47 changes: 47 additions & 0 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast};
use rustc_span::def_id::DefId;
use rustc_span::Span;
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
use rustc_trait_selection::traits::ObligationCause;

Expand Down Expand Up @@ -165,6 +166,52 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
result.unwrap_or(value)
}

#[instrument(skip(self), level = "debug")]
pub(super) fn struct_tail(
&mut self,
ty: Ty<'tcx>,
location: impl NormalizeLocation,
) -> Ty<'tcx> {
let tcx = self.tcx();
if self.infcx.next_trait_solver() {
let body = self.body;
let param_env = self.param_env;
self.fully_perform_op(
location.to_locations(),
ConstraintCategory::Boring,
CustomTypeOp::new(
|ocx| {
let structurally_normalize = |ty| {
ocx.structurally_normalize(
&ObligationCause::misc(
location.to_locations().span(body),
body.source.def_id().expect_local(),
),
param_env,
ty,
)
.unwrap_or_else(|_| bug!("struct tail should have been computable, since we computed it in HIR"))
};

let tail = tcx.struct_tail_raw(
ty,
structurally_normalize,
|| {},
);

Ok(tail)
},
"normalizing struct tail",
),
)
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
} else {
let mut normalize = |ty| self.normalize(ty, location);
let tail = tcx.struct_tail_raw(ty, &mut normalize, || {});
normalize(tail)
}
}

#[instrument(skip(self), level = "debug")]
pub(super) fn ascribe_user_type(
&mut self,
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2329,17 +2329,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let cast_ty_to = CastTy::from_ty(*ty);
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
let mut normalize = |t| self.normalize(t, location);

// N.B. `struct_tail_with_normalize` only "structurally resolves"
// the type. It is not fully normalized, so we have to normalize it
// afterwards.
let src_tail =
tcx.struct_tail_with_normalize(src.ty, &mut normalize, || ());
let src_tail = normalize(src_tail);
let dst_tail =
tcx.struct_tail_with_normalize(dst.ty, &mut normalize, || ());
let dst_tail = normalize(dst_tail);
let src_tail = self.struct_tail(src.ty, location);
let dst_tail = self.struct_tail(dst.ty, location);

// This checks (lifetime part of) vtable validity for pointer casts,
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).
Expand Down
22 changes: 10 additions & 12 deletions compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn make_mir_scope<'ll, 'tcx>(
let loc = cx.lookup_debug_loc(scope_data.span.lo());
let file_metadata = file_metadata(cx, &loc.file);

let parent_dbg_scope = match scope_data.inlined {
let dbg_scope = match scope_data.inlined {
Some((callee, _)) => {
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
Expand All @@ -102,17 +102,15 @@ fn make_mir_scope<'ll, 'tcx>(
cx.dbg_scope_fn(callee, callee_fn_abi, None)
})
}
None => parent_scope.dbg_scope,
};

let dbg_scope = unsafe {
llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx),
parent_dbg_scope,
file_metadata,
loc.line,
loc.col,
)
None => unsafe {
llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx),
parent_scope.dbg_scope,
file_metadata,
loc.line,
loc.col,
)
},
};

let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::hash_map::Entry;
use std::ops::Range;

use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -447,6 +448,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}

let mut per_local = IndexVec::from_elem(vec![], &self.mir.local_decls);
let mut params_seen: FxHashMap<_, Bx::DIVariable> = Default::default();
for var in &self.mir.var_debug_info {
let dbg_scope_and_span = if full_debug_info {
self.adjusted_span_and_dbg_scope(var.source_info)
Expand Down Expand Up @@ -491,7 +493,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
VariableKind::LocalVariable
};

self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span)
if let VariableKind::ArgumentVariable(arg_index) = var_kind {
match params_seen.entry((dbg_scope, arg_index)) {
Entry::Occupied(o) => o.get().clone(),
Entry::Vacant(v) => v
.insert(
self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span),
)
.clone(),
}
} else {
self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span)
}
});

let fragment = if let Some(ref fragment) = var.composite {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
locals: locals::Locals<'tcx, Bx::Value>,

/// All `VarDebugInfo` from the MIR body, partitioned by `Local`.
/// This is `None` if no var`#[non_exhaustive]`iable debuginfo/names are needed.
/// This is `None` if no variable debuginfo/names are needed.
per_local_var_debug_info:
Option<IndexVec<mir::Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>>,

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::any::Any;
use std::hash::Hash;

use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fx::FxIndexMap;
Expand Down Expand Up @@ -30,7 +31,7 @@ pub trait BackendTypes {

// FIXME(eddyb) find a common convention for all of the debuginfo-related
// names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
type DIScope: Copy;
type DIScope: Copy + Hash + PartialEq + Eq;
type DILocation: Copy;
type DIVariable: Copy;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub(super) fn op_to_const<'tcx>(
let pointee_ty = imm.layout.ty.builtin_deref(false).unwrap(); // `false` = no raw ptrs
debug_assert!(
matches!(
ecx.tcx.struct_tail_without_normalization(pointee_ty).kind(),
ecx.tcx.struct_tail_for_codegen(pointee_ty, ecx.param_env).kind(),
ty::Str | ty::Slice(..),
),
"`ConstValue::Slice` is for slice-tailed types only, but got {}",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/valtrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn reconstruct_place_meta<'tcx>(

let mut last_valtree = valtree;
// Traverse the type, and update `last_valtree` as we go.
let tail = tcx.struct_tail_with_normalize(
let tail = tcx.struct_tail_raw(
layout.ty,
|ty| ty,
|| {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,8 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai
trait_ref: ty::EarlyBinder::bind(trait_ref),
safety: impl_.safety,
polarity: polarity_of_impl(tcx, def_id, impl_, item.span),
do_not_recommend: tcx.features().do_not_recommend
&& tcx.has_attrs_with_path(def_id, &[sym::diagnostic, sym::do_not_recommend]),
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return Ok(Some(PointerKind::Thin));
}

let t = self.try_structurally_resolve_type(span, t);

Ok(match *t.kind() {
ty::Slice(_) | ty::Str => Some(PointerKind::Length),
ty::Dynamic(tty, _, ty::Dyn) => Some(PointerKind::VTable(tty)),
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ impl<'a, 'tcx> Expectation<'tcx> {
/// See the test case `test/ui/coerce-expect-unsized.rs` and #20169
/// for examples of where this comes up,.
pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> {
match fcx.tcx.struct_tail_without_normalization(ty).kind() {
// FIXME: This is not right, even in the old solver...
match fcx.tcx.struct_tail_raw(ty, |ty| ty, || {}).kind() {
ty::Slice(_) | ty::Str | ty::Dynamic(..) => ExpectRvalueLikeUnsized(ty),
_ => ExpectHasType(ty),
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
code: traits::ObligationCauseCode<'tcx>,
) {
if !ty.references_error() {
let tail = self.tcx.struct_tail_with_normalize(
let tail = self.tcx.struct_tail_raw(
ty,
|ty| {
if self.next_trait_solver() {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3176,6 +3176,12 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn impl_polarity(self, def_id: impl IntoQueryParam<DefId>) -> ty::ImplPolarity {
self.impl_trait_header(def_id).map_or(ty::ImplPolarity::Positive, |h| h.polarity)
}

/// Whether this is a trait implementation that has `#[diagnostic::do_not_recommend]`
pub fn do_not_recommend_impl(self, def_id: DefId) -> bool {
matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true })
&& self.impl_trait_header(def_id).is_some_and(|header| header.do_not_recommend)
}
}

/// Parameter attributes that can only be determined by examining the body of a function instead
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
let non_zero = !ty.is_unsafe_ptr();

let tail = tcx.struct_tail_with_normalize(
let tail = tcx.struct_tail_raw(
pointee,
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
Ok(ty) => ty,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ pub struct ImplTraitHeader<'tcx> {
pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>,
pub polarity: ImplPolarity,
pub safety: hir::Safety,
pub do_not_recommend: bool,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ impl<'tcx> Ty<'tcx> {
tcx: TyCtxt<'tcx>,
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
) -> Result<Ty<'tcx>, Ty<'tcx>> {
let tail = tcx.struct_tail_with_normalize(self, normalize, || {});
let tail = tcx.struct_tail_raw(self, normalize, || {});
match tail.kind() {
// Sized types
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
Expand All @@ -1614,10 +1614,10 @@ impl<'tcx> Ty<'tcx> {
| ty::Foreign(..)
// `dyn*` has metadata = ().
| ty::Dynamic(_, _, ty::DynStar)
// If returned by `struct_tail_with_normalize` this is a unit struct
// If returned by `struct_tail_raw` this is a unit struct
// without any fields, or not a struct, and therefore is Sized.
| ty::Adt(..)
// If returned by `struct_tail_with_normalize` this is the empty tuple,
// If returned by `struct_tail_raw` this is the empty tuple,
// a.k.a. unit type, which is Sized
| ty::Tuple(..) => Ok(tcx.types.unit),

Expand Down
22 changes: 8 additions & 14 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

/// Attempts to returns the deeply last field of nested structures, but
/// does not apply any normalization in its search. Returns the same type
/// if input `ty` is not a structure at all.
pub fn struct_tail_without_normalization(self, ty: Ty<'tcx>) -> Ty<'tcx> {
let tcx = self;
tcx.struct_tail_with_normalize(ty, |ty| ty, || {})
}

/// Returns the deeply last field of nested structures, or the same type if
/// not a structure at all. Corresponds to the only possible unsized field,
/// and its type can be used to determine unsizing strategy.
Expand All @@ -188,20 +180,22 @@ impl<'tcx> TyCtxt<'tcx> {
/// normalization attempt may cause compiler bugs.
pub fn struct_tail_for_codegen(self, ty: Ty<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Ty<'tcx> {
let tcx = self;
tcx.struct_tail_with_normalize(ty, |ty| tcx.normalize_erasing_regions(param_env, ty), || {})
tcx.struct_tail_raw(ty, |ty| tcx.normalize_erasing_regions(param_env, ty), || {})
}

/// Returns the deeply last field of nested structures, or the same type if
/// not a structure at all. Corresponds to the only possible unsized field,
/// and its type can be used to determine unsizing strategy.
///
/// This is parameterized over the normalization strategy (i.e. how to
/// handle `<T as Trait>::Assoc` and `impl Trait`); pass the identity
/// function to indicate no normalization should take place.
/// handle `<T as Trait>::Assoc` and `impl Trait`). You almost certainly do
/// **NOT** want to pass the identity function here, unless you know what
/// you're doing, or you're within normalization code itself and will handle
/// an unnormalized tail recursively.
///
/// See also `struct_tail_for_codegen`, which is suitable for use
/// during codegen.
pub fn struct_tail_with_normalize(
pub fn struct_tail_raw(
self,
mut ty: Ty<'tcx>,
mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
Expand Down Expand Up @@ -281,7 +275,7 @@ impl<'tcx> TyCtxt<'tcx> {
param_env: ty::ParamEnv<'tcx>,
) -> (Ty<'tcx>, Ty<'tcx>) {
let tcx = self;
tcx.struct_lockstep_tails_with_normalize(source, target, |ty| {
tcx.struct_lockstep_tails_raw(source, target, |ty| {
tcx.normalize_erasing_regions(param_env, ty)
})
}
Expand All @@ -294,7 +288,7 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// See also `struct_lockstep_tails_for_codegen`, which is suitable for use
/// during codegen.
pub fn struct_lockstep_tails_with_normalize(
pub fn struct_lockstep_tails_raw(
self,
source: Ty<'tcx>,
target: Ty<'tcx>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let mut applied_do_not_recommend = false;
loop {
if let ObligationCauseCode::ImplDerived(ref c) = base_cause {
if self.tcx.has_attrs_with_path(
c.impl_or_alias_def_id,
&[sym::diagnostic, sym::do_not_recommend],
) {
if self.tcx.do_not_recommend_impl(c.impl_or_alias_def_id) {
let code = (*c.derived.parent_code).clone();
obligation.cause.map_code(|_| code);
obligation.predicate = c.derived.parent_trait_pred.upcast(self.tcx);
Expand Down Expand Up @@ -1629,11 +1626,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.tcx
.all_impls(def_id)
// ignore `do_not_recommend` items
.filter(|def_id| {
!self
.tcx
.has_attrs_with_path(*def_id, &[sym::diagnostic, sym::do_not_recommend])
})
.filter(|def_id| !self.tcx.do_not_recommend_impl(*def_id))
// Ignore automatically derived impls and `!Trait` impls.
.filter_map(|def_id| self.tcx.impl_trait_header(def_id))
.filter_map(|header| {
Expand Down Expand Up @@ -1903,12 +1896,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let impl_candidates = impl_candidates
.into_iter()
.cloned()
.filter(|cand| {
!self.tcx.has_attrs_with_path(
cand.impl_def_id,
&[sym::diagnostic, sym::do_not_recommend],
)
})
.filter(|cand| !self.tcx.do_not_recommend_impl(cand.impl_def_id))
.collect::<Vec<_>>();

let def_id = trait_ref.def_id();
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_trait_selection/src/solve/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rustc_middle::bug;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, TyCtxt};
use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as _};
use rustc_span::symbol::sym;

use super::delegate::SolverDelegate;
use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor};
Expand Down Expand Up @@ -440,10 +439,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
source: CandidateSource::Impl(impl_def_id),
result: _,
} = candidate.kind()
&& goal
.infcx()
.tcx
.has_attrs_with_path(impl_def_id, &[sym::diagnostic, sym::do_not_recommend])
&& goal.infcx().tcx.do_not_recommend_impl(impl_def_id)
{
return ControlFlow::Break(self.obligation.clone());
}
Expand Down
Loading
Loading