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 7 pull requests #112966

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0d6da78
Always register sized obligation for argument
compiler-errors Jun 15, 2023
dd620aa
Don't ICE on unnormalized struct tail in layout computation
compiler-errors Jun 19, 2023
32f83e1
Better error message
compiler-errors Jun 19, 2023
c92650f
Fix standalone build
celinval Jun 20, 2023
e4b4f05
Implement Stable for AssertMessage
celinval Jun 20, 2023
97e609c
Implement a few more rvalue translation to smir
celinval Jun 13, 2023
aacd702
Stop hiding const eval limit in external macros
oli-obk Jun 22, 2023
65a7047
Add @files command
GuillaumeGomez Jun 23, 2023
752fb52
Add @files checks in rustdoc tests
GuillaumeGomez Jun 23, 2023
616469a
Fix rustdoc-gui tester
GuillaumeGomez Jun 23, 2023
d70faf3
Fix failing rustdoc GUI test
GuillaumeGomez Jun 23, 2023
2f3bed0
Add link to rustdoc book search chapter in help popover
GuillaumeGomez Jun 17, 2023
2f1939a
Link to the corresponding channel in the help popover
GuillaumeGomez Jun 23, 2023
7b55779
Make `try_run` return a `Result<(), ()>` instead of a boolean
GuillaumeGomez Jun 23, 2023
b83c009
Rollup merge of #112643 - compiler-errors:sized-obl-for-arg, r=wesley…
matthiaskrgr Jun 23, 2023
71a9222
Rollup merge of #112717 - celinval:stable-mir-rvalue-1, r=oli-obk
matthiaskrgr Jun 23, 2023
6ea7546
Rollup merge of #112740 - GuillaumeGomez:link-to-search-chapter, r=no…
matthiaskrgr Jun 23, 2023
d05c35a
Rollup merge of #112810 - compiler-errors:dont-ice-on-bad-layout, r=w…
matthiaskrgr Jun 23, 2023
961c6c1
Rollup merge of #112925 - oli-obk:timeout_lint, r=cjgillot
matthiaskrgr Jun 23, 2023
f39e544
Rollup merge of #112960 - GuillaumeGomez:rustdoc-files-check, r=notri…
matthiaskrgr Jun 23, 2023
a23b5f6
Rollup merge of #112962 - GuillaumeGomez:fix-rustdoc-gui-tester, r=oz…
matthiaskrgr Jun 23, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4099,6 +4099,7 @@ dependencies = [
"rustc_hir",
"rustc_middle",
"rustc_span",
"rustc_target",
"tracing",
]

Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.check_pat_top(&param.pat, param_ty, ty_span, None);

// Check that argument is Sized.
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
// for simple cases like `fn foo(x: Trait)`,
// where we would error once on the parameter as a whole, and once on the binding `x`.
if param.pat.simple_ident().is_none() && !params_can_be_unsized {
if !params_can_be_unsized {
fcx.require_type_is_sized(
param_ty,
param.pat.span,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3464,7 +3464,8 @@ declare_lint! {
/// out an update in your own time.
pub LONG_RUNNING_CONST_EVAL,
Deny,
"detects long const eval operations"
"detects long const eval operations",
report_in_external_macro
}

declare_lint! {
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ impl<'tcx> SizeSkeleton<'tcx> {
Ok(layout) => {
return Ok(SizeSkeleton::Known(layout.size));
}
Err(err) => err,
Err(err @ LayoutError::Unknown(_)) => err,
// We can't extract SizeSkeleton info from other layout errors
Err(
e @ LayoutError::Cycle
| e @ LayoutError::SizeOverflow(_)
| e @ LayoutError::NormalizationFailure(..),
) => return Err(e),
};

match *ty.kind() {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_smir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ version = "0.0.0"
edition = "2021"

[dependencies]
rustc_hir = { path = "../rustc_hir" }
# Use optional dependencies for rustc_* in order to support building this crate separately.
rustc_hir = { path = "../rustc_hir", optional = true }
rustc_middle = { path = "../rustc_middle", optional = true }
rustc_span = { path = "../rustc_span", optional = true }
rustc_target = { path = "../rustc_target", optional = true }
tracing = "0.1"

[features]
default = [
"rustc_hir",
"rustc_middle",
"rustc_span",
"rustc_target",
]
2 changes: 1 addition & 1 deletion compiler/rustc_smir/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-02-28"
channel = "nightly-2023-06-14"
components = [ "rustfmt", "rustc-dev" ]
11 changes: 11 additions & 0 deletions compiler/rustc_smir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
#![feature(local_key_cell_methods)]
#![feature(ptr_metadata)]
#![feature(type_alias_impl_trait)] // Used to define opaque types.

// Declare extern rustc_* crates to enable building this crate separately from the compiler.
#[cfg(not(feature = "default"))]
extern crate rustc_hir;
#[cfg(not(feature = "default"))]
extern crate rustc_middle;
#[cfg(not(feature = "default"))]
extern crate rustc_span;
#[cfg(not(feature = "default"))]
extern crate rustc_target;

pub mod rustc_internal;
pub mod stable_mir;
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
//! until stable MIR is complete.

use std::fmt::Debug;
use std::string::ToString;

use crate::{
rustc_smir::Tables,
stable_mir::{self, with},
Expand Down Expand Up @@ -49,3 +52,10 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
crate::stable_mir::run(Tables { tcx, def_ids: vec![], types: vec![] }, f);
}

/// A type that provides internal information but that can still be used for debug purpose.
pub type Opaque = impl Debug + ToString + Clone;

pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
format!("{value:?}")
}
190 changes: 153 additions & 37 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
//!
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.

use crate::rustc_internal::{self, opaque};
use crate::stable_mir::{self, ty::TyKind, Context};
use rustc_middle::mir;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_target::abi::FieldIdx;
use tracing::debug;

impl<'tcx> Context for Tables<'tcx> {
Expand Down Expand Up @@ -119,11 +121,21 @@ fn smir_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> stable_mir::Crate {
stable_mir::Crate { id: crate_num.into(), name: crate_name, is_local }
}

pub trait Stable {
/// Trait used to convert between an internal MIR type to a Stable MIR type.
pub(crate) trait Stable {
/// The stable representation of the type implementing Stable.
type T;
/// Converts an object to the equivalent Stable MIR representation.
fn stable(&self) -> Self::T;
}

impl Stable for DefId {
type T = stable_mir::CrateItem;
fn stable(&self) -> Self::T {
rustc_internal::crate_item(*self)
}
}

impl<'tcx> Stable for mir::Statement<'tcx> {
type T = stable_mir::mir::Statement;
fn stable(&self) -> Self::T {
Expand Down Expand Up @@ -155,27 +167,127 @@ impl<'tcx> Stable for mir::Rvalue<'tcx> {
match self {
Use(op) => stable_mir::mir::Rvalue::Use(op.stable()),
Repeat(_, _) => todo!(),
Ref(_, _, _) => todo!(),
ThreadLocalRef(_) => todo!(),
AddressOf(_, _) => todo!(),
Len(_) => todo!(),
Ref(region, kind, place) => {
stable_mir::mir::Rvalue::Ref(opaque(region), kind.stable(), place.stable())
}
ThreadLocalRef(def_id) => stable_mir::mir::Rvalue::ThreadLocalRef(def_id.stable()),
AddressOf(mutability, place) => {
stable_mir::mir::Rvalue::AddressOf(mutability.stable(), place.stable())
}
Len(place) => stable_mir::mir::Rvalue::Len(place.stable()),
Cast(_, _, _) => todo!(),
BinaryOp(_, _) => todo!(),
BinaryOp(bin_op, ops) => {
stable_mir::mir::Rvalue::BinaryOp(bin_op.stable(), ops.0.stable(), ops.1.stable())
}
CheckedBinaryOp(bin_op, ops) => stable_mir::mir::Rvalue::CheckedBinaryOp(
bin_op.stable(),
ops.0.stable(),
ops.1.stable(),
),
NullaryOp(_, _) => todo!(),
UnaryOp(un_op, op) => stable_mir::mir::Rvalue::UnaryOp(un_op.stable(), op.stable()),
Discriminant(_) => todo!(),
Discriminant(place) => stable_mir::mir::Rvalue::Discriminant(place.stable()),
Aggregate(_, _) => todo!(),
ShallowInitBox(_, _) => todo!(),
CopyForDeref(_) => todo!(),
CopyForDeref(place) => stable_mir::mir::Rvalue::CopyForDeref(place.stable()),
}
}
}

impl Stable for mir::Mutability {
type T = stable_mir::mir::Mutability;
fn stable(&self) -> Self::T {
use mir::Mutability::*;
match *self {
Not => stable_mir::mir::Mutability::Not,
Mut => stable_mir::mir::Mutability::Mut,
}
}
}

impl Stable for mir::BorrowKind {
type T = stable_mir::mir::BorrowKind;
fn stable(&self) -> Self::T {
use mir::BorrowKind::*;
match *self {
Shared => stable_mir::mir::BorrowKind::Shared,
Shallow => stable_mir::mir::BorrowKind::Shallow,
Unique => stable_mir::mir::BorrowKind::Unique,
Mut { allow_two_phase_borrow } => {
stable_mir::mir::BorrowKind::Mut { allow_two_phase_borrow }
}
}
}
}

impl<'tcx> Stable for mir::NullOp<'tcx> {
type T = stable_mir::mir::NullOp;
fn stable(&self) -> Self::T {
use mir::NullOp::*;
match self {
SizeOf => stable_mir::mir::NullOp::SizeOf,
AlignOf => stable_mir::mir::NullOp::AlignOf,
OffsetOf(indices) => {
stable_mir::mir::NullOp::OffsetOf(indices.iter().map(|idx| idx.stable()).collect())
}
}
}
}

impl Stable for mir::CastKind {
type T = stable_mir::mir::CastKind;
fn stable(&self) -> Self::T {
use mir::CastKind::*;
match self {
PointerExposeAddress => stable_mir::mir::CastKind::PointerExposeAddress,
PointerFromExposedAddress => stable_mir::mir::CastKind::PointerFromExposedAddress,
Pointer(cast) => stable_mir::mir::CastKind::Pointer(cast.stable()),
DynStar => stable_mir::mir::CastKind::DynStar,
IntToInt => stable_mir::mir::CastKind::IntToInt,
FloatToInt => stable_mir::mir::CastKind::FloatToInt,
FloatToFloat => stable_mir::mir::CastKind::FloatToFloat,
IntToFloat => stable_mir::mir::CastKind::IntToFloat,
PtrToPtr => stable_mir::mir::CastKind::PtrToPtr,
FnPtrToPtr => stable_mir::mir::CastKind::FnPtrToPtr,
Transmute => stable_mir::mir::CastKind::Transmute,
}
}
}

impl Stable for ty::adjustment::PointerCast {
type T = stable_mir::mir::PointerCast;
fn stable(&self) -> Self::T {
use ty::adjustment::PointerCast;
match self {
PointerCast::ReifyFnPointer => stable_mir::mir::PointerCast::ReifyFnPointer,
PointerCast::UnsafeFnPointer => stable_mir::mir::PointerCast::UnsafeFnPointer,
PointerCast::ClosureFnPointer(unsafety) => {
stable_mir::mir::PointerCast::ClosureFnPointer(unsafety.stable())
}
PointerCast::MutToConstPointer => stable_mir::mir::PointerCast::MutToConstPointer,
PointerCast::ArrayToPointer => stable_mir::mir::PointerCast::ArrayToPointer,
PointerCast::Unsize => stable_mir::mir::PointerCast::Unsize,
}
}
}

impl Stable for rustc_hir::Unsafety {
type T = stable_mir::mir::Safety;
fn stable(&self) -> Self::T {
match self {
rustc_hir::Unsafety::Unsafe => stable_mir::mir::Safety::Unsafe,
rustc_hir::Unsafety::Normal => stable_mir::mir::Safety::Normal,
}
}
}

impl Stable for FieldIdx {
type T = usize;
fn stable(&self) -> Self::T {
self.as_usize()
}
}

impl<'tcx> Stable for mir::Operand<'tcx> {
type T = stable_mir::mir::Operand;
fn stable(&self) -> Self::T {
Expand Down Expand Up @@ -211,34 +323,38 @@ impl Stable for mir::UnwindAction {
}
}

fn rustc_assert_msg_to_msg<'tcx>(
assert_message: &rustc_middle::mir::AssertMessage<'tcx>,
) -> stable_mir::mir::AssertMessage {
use rustc_middle::mir::AssertKind;
match assert_message {
AssertKind::BoundsCheck { len, index } => {
stable_mir::mir::AssertMessage::BoundsCheck { len: len.stable(), index: index.stable() }
}
AssertKind::Overflow(bin_op, op1, op2) => {
stable_mir::mir::AssertMessage::Overflow(bin_op.stable(), op1.stable(), op2.stable())
}
AssertKind::OverflowNeg(op) => stable_mir::mir::AssertMessage::OverflowNeg(op.stable()),
AssertKind::DivisionByZero(op) => {
stable_mir::mir::AssertMessage::DivisionByZero(op.stable())
}
AssertKind::RemainderByZero(op) => {
stable_mir::mir::AssertMessage::RemainderByZero(op.stable())
}
AssertKind::ResumedAfterReturn(generator) => {
stable_mir::mir::AssertMessage::ResumedAfterReturn(generator.stable())
}
AssertKind::ResumedAfterPanic(generator) => {
stable_mir::mir::AssertMessage::ResumedAfterPanic(generator.stable())
}
AssertKind::MisalignedPointerDereference { required, found } => {
stable_mir::mir::AssertMessage::MisalignedPointerDereference {
required: required.stable(),
found: found.stable(),
impl<'tcx> Stable for mir::AssertMessage<'tcx> {
type T = stable_mir::mir::AssertMessage;
fn stable(&self) -> Self::T {
use rustc_middle::mir::AssertKind;
match self {
AssertKind::BoundsCheck { len, index } => stable_mir::mir::AssertMessage::BoundsCheck {
len: len.stable(),
index: index.stable(),
},
AssertKind::Overflow(bin_op, op1, op2) => stable_mir::mir::AssertMessage::Overflow(
bin_op.stable(),
op1.stable(),
op2.stable(),
),
AssertKind::OverflowNeg(op) => stable_mir::mir::AssertMessage::OverflowNeg(op.stable()),
AssertKind::DivisionByZero(op) => {
stable_mir::mir::AssertMessage::DivisionByZero(op.stable())
}
AssertKind::RemainderByZero(op) => {
stable_mir::mir::AssertMessage::RemainderByZero(op.stable())
}
AssertKind::ResumedAfterReturn(generator) => {
stable_mir::mir::AssertMessage::ResumedAfterReturn(generator.stable())
}
AssertKind::ResumedAfterPanic(generator) => {
stable_mir::mir::AssertMessage::ResumedAfterPanic(generator.stable())
}
AssertKind::MisalignedPointerDereference { required, found } => {
stable_mir::mir::AssertMessage::MisalignedPointerDereference {
required: required.stable(),
found: found.stable(),
}
}
}
}
Expand Down Expand Up @@ -363,7 +479,7 @@ impl<'tcx> Stable for mir::Terminator<'tcx> {
Assert { cond, expected, msg, target, unwind } => Terminator::Assert {
cond: cond.stable(),
expected: *expected,
msg: rustc_assert_msg_to_msg(msg),
msg: msg.stable(),
target: target.as_usize(),
unwind: unwind.stable(),
},
Expand Down
Loading