Skip to content
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

Rollup of 12 pull requests #106007

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
46f6e39
add assert messages if chunks/windows are length 0
raffimolero Dec 12, 2022
1588944
interpret: add read_machine_[ui]size convenience methods
RalfJung Dec 12, 2022
8b2a7da
Rename `assert_uninit_valid` intrinsic
Noratrieb Dec 12, 2022
7f94389
str.lines() docstring: clarify that line endings are not returned
zacchiro Dec 17, 2022
a213bb3
implement the skeleton of the updated trait solver
lcnr Dec 4, 2022
750bf36
dedup assembly
lcnr Dec 19, 2022
082ca1e
docs: add long error explanation for error E0472
Ezrashaw Dec 16, 2022
168e3da
rustdoc: prevent CSS layout of line numbers shrinking into nothing
notriddle Dec 20, 2022
b29a9e3
rustdoc: simplify section anchor CSS
notriddle Dec 20, 2022
fb89ae4
Remove unused `check-stage2-T-arm-linux-androideabi-H-x86_64-unknown-…
jyn514 Dec 20, 2022
f5e776c
Refer to "Waker" rather than "RawWaker" in `drop` comment
goffrie Dec 20, 2022
5538c92
Fix typo in reading_half_a_pointer.rs
eltociear Dec 21, 2022
6f21ba4
less specific wording
RalfJung Dec 21, 2022
1286d98
Don't explicitly set C++ standard for lld
nikic Dec 20, 2022
6733a3f
Use LLVM_CMAKE_DIR for lld build
nikic Dec 20, 2022
8804de2
Rollup merge of #105584 - raffimolero:patch-1, r=JohnTitor
fee1-dead Dec 21, 2022
57f47c7
Rollup merge of #105602 - RalfJung:read-convenience, r=oli-obk
fee1-dead Dec 21, 2022
fd3c544
Rollup merge of #105613 - Nilstrieb:rename-assert_uninit_valid, r=Ral…
fee1-dead Dec 21, 2022
4fc45e5
Rollup merge of #105661 - lcnr:evaluate-new, r=compiler-errors
fee1-dead Dec 21, 2022
5ba613c
Rollup merge of #105791 - Ezrashaw:add-e0472-long-docs, r=GuillaumeGomez
fee1-dead Dec 21, 2022
ea89528
Rollup merge of #105824 - zacchiro:patch-1, r=JohnTitor
fee1-dead Dec 21, 2022
b5853f6
Rollup merge of #105964 - notriddle:notriddle/scraped-example-length,…
fee1-dead Dec 21, 2022
f6af81a
Rollup merge of #105972 - notriddle:notriddle/anchor, r=GuillaumeGomez
fee1-dead Dec 21, 2022
955b21b
Rollup merge of #105976 - jyn514:unused-make-targets, r=Mark-Simulacrum
fee1-dead Dec 21, 2022
00419d5
Rollup merge of #105980 - goffrie:waker-drop, r=thomcc
fee1-dead Dec 21, 2022
db5280a
Rollup merge of #105986 - eltociear:patch-18, r=RalfJung
fee1-dead Dec 21, 2022
f3ebf4f
Rollup merge of #106000 - nikic:lld-build, r=Mark-Simulacrum
fee1-dead Dec 21, 2022
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
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
let res = CValue::by_val(res, arg.layout());
ret.write_cvalue(fx, res);
}
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => {
intrinsic_args!(fx, args => (); intrinsic);

let layout = fx.layout_of(substs.type_at(0));
Expand Down Expand Up @@ -673,7 +673,9 @@ fn codegen_regular_intrinsic_call<'tcx>(
return;
}

if intrinsic == sym::assert_uninit_valid && !fx.tcx.permits_uninit_init(layout) {
if intrinsic == sym::assert_mem_uninitialized_valid
&& !fx.tcx.permits_uninit_init(layout)
{
with_no_trimmed_paths!({
crate::base::codegen_panic(
fx,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
enum AssertIntrinsic {
Inhabited,
ZeroValid,
UninitValid,
MemUninitializedValid,
}
let panic_intrinsic = intrinsic.and_then(|i| match i {
sym::assert_inhabited => Some(AssertIntrinsic::Inhabited),
sym::assert_zero_valid => Some(AssertIntrinsic::ZeroValid),
sym::assert_uninit_valid => Some(AssertIntrinsic::UninitValid),
sym::assert_mem_uninitialized_valid => Some(AssertIntrinsic::MemUninitializedValid),
_ => None,
});
if let Some(intrinsic) = panic_intrinsic {
Expand All @@ -679,7 +679,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let do_panic = match intrinsic {
Inhabited => layout.abi.is_uninhabited(),
ZeroValid => !bx.tcx().permits_zero_init(layout),
UninitValid => !bx.tcx().permits_uninit_init(layout),
MemUninitializedValid => !bx.tcx().permits_uninit_init(layout),
};
Some(if do_panic {
let msg_str = with_no_visible_paths!({
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
sym::offset => {
let ptr = self.read_pointer(&args[0])?;
let offset_count = self.read_scalar(&args[1])?.to_machine_isize(self)?;
let offset_count = self.read_machine_isize(&args[1])?;
let pointee_ty = substs.type_at(0);

let offset_ptr = self.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?;
self.write_pointer(offset_ptr, dest)?;
}
sym::arith_offset => {
let ptr = self.read_pointer(&args[0])?;
let offset_count = self.read_scalar(&args[1])?.to_machine_isize(self)?;
let offset_count = self.read_machine_isize(&args[1])?;
let pointee_ty = substs.type_at(0);

let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
Expand Down Expand Up @@ -428,7 +428,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
sym::transmute => {
self.copy_op(&args[0], dest, /*allow_transmute*/ true)?;
}
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
sym::assert_inhabited
| sym::assert_zero_valid
| sym::assert_mem_uninitialized_valid => {
let ty = instance.substs.type_at(0);
let layout = self.layout_of(ty)?;

Expand Down Expand Up @@ -460,7 +462,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
}

if intrinsic_name == sym::assert_uninit_valid {
if intrinsic_name == sym::assert_mem_uninitialized_valid {
let should_panic = !self.tcx.permits_uninit_init(layout);

if should_panic {
Expand Down Expand Up @@ -668,7 +670,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
nonoverlapping: bool,
) -> InterpResult<'tcx> {
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
let count = self.read_machine_usize(&count)?;
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
let (size, align) = (layout.size, layout.align.abi);
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
Expand Down Expand Up @@ -696,7 +698,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

let dst = self.read_pointer(&dst)?;
let byte = self.read_scalar(&byte)?.to_u8()?;
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
let count = self.read_machine_usize(&count)?;

// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
// but no actual allocation can be big enough for the difference to be noticeable.
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,24 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(self.read_immediate(op)?.to_scalar())
}

// Pointer-sized reads are fairly common and need target layout access, so we wrap them in
// convenience functions.

/// Read a pointer from a place.
pub fn read_pointer(
&self,
op: &OpTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> {
self.read_scalar(op)?.to_pointer(self)
}
/// Read a pointer-sized unsigned integer from a place.
pub fn read_machine_usize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, u64> {
self.read_scalar(op)?.to_machine_usize(self)
}
/// Read a pointer-sized signed integer from a place.
pub fn read_machine_isize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, i64> {
self.read_scalar(op)?.to_machine_isize(self)
}

/// Turn the wide MPlace into a string (must already be dereferenced!)
pub fn read_str(&self, mplace: &MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, &str> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ where
Index(local) => {
let layout = self.layout_of(self.tcx.types.usize)?;
let n = self.local_to_op(self.frame(), local, Some(layout))?;
let n = self.read_scalar(&n)?.to_machine_usize(self)?;
let n = self.read_machine_usize(&n)?;
self.place_index(base, n)?
}
ConstantIndex { offset, min_length, from_end } => {
Expand Down Expand Up @@ -392,7 +392,7 @@ where
Index(local) => {
let layout = self.layout_of(self.tcx.types.usize)?;
let n = self.local_to_op(self.frame(), local, Some(layout))?;
let n = self.read_scalar(&n)?.to_machine_usize(self)?;
let n = self.read_machine_usize(&n)?;
self.operand_index(base, n)?
}
ConstantIndex { offset, min_length, from_end } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ E0464: include_str!("./error_codes/E0464.md"),
E0466: include_str!("./error_codes/E0466.md"),
E0468: include_str!("./error_codes/E0468.md"),
E0469: include_str!("./error_codes/E0469.md"),
E0472: include_str!("./error_codes/E0472.md"),
E0477: include_str!("./error_codes/E0477.md"),
E0478: include_str!("./error_codes/E0478.md"),
E0482: include_str!("./error_codes/E0482.md"),
Expand Down Expand Up @@ -599,7 +600,6 @@ E0791: include_str!("./error_codes/E0791.md"),
// E0467, // removed
// E0470, // removed
// E0471, // constant evaluation error (in pattern)
E0472, // llvm_asm! is unsupported on this target
// E0473, // dereference of reference outside its lifetime
// E0474, // captured variable `..` does not outlive the enclosing closure
// E0475, // index of slice outside its lifetime
Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0472.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Inline assembly (`asm!`) is not supported on this target.

Example of erroneous code:

```ignore (cannot-change-target)
// compile-flags: --target sparc64-unknown-linux-gnu
#![no_std]

use core::arch::asm;

fn main() {
unsafe {
asm!(""); // error: inline assembly is not supported on this target
}
}
```

The Rust compiler does not support inline assembly, with the `asm!` macro
(previously `llvm_asm!`), for all targets. All Tier 1 targets do support this
macro but support among Tier 2 and 3 targets is not guaranteed (even when they
have `std` support). Note that this error is related to
`error[E0658]: inline assembly is not stable yet on this architecture`, but
distinct in that with `E0472` support is not planned or in progress.

There is no way to easily fix this issue, however:
* Consider if you really need inline assembly, is there some other way to
achieve your goal (intrinsics, etc)?
* Consider writing your assembly externally, linking with it and calling it
from Rust.
* Consider contributing to <https://github.com/rust-lang/rust> and help
integrate support for your target!
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
sym::abort
| sym::assert_inhabited
| sym::assert_zero_valid
| sym::assert_uninit_valid
| sym::assert_mem_uninitialized_valid
| sym::size_of
| sym::min_align_of
| sym::needs_drop
Expand Down Expand Up @@ -193,9 +193,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
}
sym::rustc_peek => (1, vec![param(0)], param(0)),
sym::caller_location => (0, vec![], tcx.caller_location_ty()),
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
(1, Vec::new(), tcx.mk_unit())
}
sym::assert_inhabited
| sym::assert_zero_valid
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()),
sym::forget => (1, vec![param(0)], tcx.mk_unit()),
sym::transmute => (2, vec![param(0)], param(1)),
sym::prefetch_read_data
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ impl<'tcx> InferCtxt<'tcx> {
})
}

fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
/// FIXME: This method should only be used for canonical queries and therefore be private.
///
/// As the new solver does canonicalization slightly differently, this is also used there
/// for now. This should hopefully change fairly soon.
pub fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
self.inner
.borrow_mut()
.opaque_type_storage
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ impl<'tcx, V> Canonical<'tcx, V> {
let Canonical { max_universe, variables, value } = self;
Canonical { max_universe, variables, value: map_op(value) }
}

/// Allows you to map the `value` of a canonical while keeping the same set of
/// bound variables.
///
/// **WARNING:** This function is very easy to mis-use, hence the name! See
/// the comment of [Canonical::unchecked_map] for more details.
pub fn unchecked_rebind<W>(self, value: W) -> Canonical<'tcx, W> {
let Canonical { max_universe, variables, value: _ } = self;
Canonical { max_universe, variables, value }
}
}

pub type QueryOutlivesConstraint<'tcx> = (
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;

#[derive(Copy, Clone, Debug, HashStable)]
#[derive(Copy, Clone, Debug, HashStable, PartialEq, Eq)]
pub struct NoSolution;

pub type Fallible<T> = Result<T, NoSolution>;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl Iterator for Ancestors<'_> {
}

/// Information about the most specialized definition of an associated item.
#[derive(Debug)]
pub struct LeafDef {
/// The associated item described by this `LeafDef`.
pub item: ty::AssocItem,
Expand Down
41 changes: 29 additions & 12 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,17 @@ impl<'tcx> Predicate<'tcx> {
self
}

#[instrument(level = "debug", skip(tcx), ret)]
pub fn is_coinductive(self, tcx: TyCtxt<'tcx>) -> bool {
match self.kind().skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
tcx.trait_is_coinductive(data.def_id())
}
ty::PredicateKind::WellFormed(_) => true,
_ => false,
}
}

/// Whether this projection can be soundly normalized.
///
/// Wf predicates must not be normalized, as normalization
Expand Down Expand Up @@ -1018,6 +1029,24 @@ pub struct ProjectionPredicate<'tcx> {
pub term: Term<'tcx>,
}

impl<'tcx> ProjectionPredicate<'tcx> {
pub fn self_ty(self) -> Ty<'tcx> {
self.projection_ty.self_ty()
}

pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ProjectionPredicate<'tcx> {
Self { projection_ty: self.projection_ty.with_self_ty(tcx, self_ty), ..self }
}

pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId {
self.projection_ty.trait_def_id(tcx)
}

pub fn def_id(self) -> DefId {
self.projection_ty.def_id
}
}

pub type PolyProjectionPredicate<'tcx> = Binder<'tcx, ProjectionPredicate<'tcx>>;

impl<'tcx> PolyProjectionPredicate<'tcx> {
Expand Down Expand Up @@ -1054,18 +1083,6 @@ impl<'tcx> PolyProjectionPredicate<'tcx> {
}
}

impl<'tcx> ProjectionPredicate<'tcx> {
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
Self {
projection_ty: tcx.mk_alias_ty(
self.projection_ty.def_id,
[self_ty.into()].into_iter().chain(self.projection_ty.substs.iter().skip(1)),
),
..self
}
}
}

pub trait ToPolyTraitRef<'tcx> {
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
}
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ pub struct AliasTy<'tcx> {
}

impl<'tcx> AliasTy<'tcx> {
pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId {
pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId {
match tcx.def_kind(self.def_id) {
DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.def_id),
DefKind::ImplTraitPlaceholder => {
Expand All @@ -1183,7 +1183,7 @@ impl<'tcx> AliasTy<'tcx> {
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
/// then this function would return a `T: Iterator` trait reference and `['a]` as the own substs
pub fn trait_ref_and_own_substs(
&self,
self,
tcx: TyCtxt<'tcx>,
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
debug_assert!(matches!(tcx.def_kind(self.def_id), DefKind::AssocTy | DefKind::AssocConst));
Expand All @@ -1202,14 +1202,18 @@ impl<'tcx> AliasTy<'tcx> {
/// WARNING: This will drop the substs for generic associated types
/// consider calling [Self::trait_ref_and_own_substs] to get those
/// as well.
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
pub fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
let def_id = self.trait_def_id(tcx);
tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
}

pub fn self_ty(&self) -> Ty<'tcx> {
pub fn self_ty(self) -> Ty<'tcx> {
self.substs.type_at(0)
}

pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)))
}
}

#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ impl<T> EarlyBinder<T> {
pub fn rebind<U>(&self, value: U) -> EarlyBinder<U> {
EarlyBinder(value)
}

pub fn skip_binder(self) -> T {
self.0
}
}

impl<T> EarlyBinder<Option<T>> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ symbols! {
assert_eq_macro,
assert_inhabited,
assert_macro,
assert_mem_uninitialized_valid,
assert_ne_macro,
assert_receiver_is_total_eq,
assert_uninit_valid,
assert_zero_valid,
asserting,
associated_const_equality,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![feature(let_chains)]
#![feature(if_let_guard)]
#![feature(never_type)]
#![feature(result_option_inspect)]
#![feature(type_alias_impl_trait)]
#![recursion_limit = "512"] // For rustdoc

Expand All @@ -37,4 +38,5 @@ extern crate smallvec;
pub mod autoderef;
pub mod errors;
pub mod infer;
pub mod solve;
pub mod traits;
Loading