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 10 pull requests #122031

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
313eb8f
Implement MaybeUninit::fill{,_with,_from}
ajwock Feb 18, 2024
3908a93
std support for wasm32 panic=unwind
coolreader18 Feb 21, 2024
861c7e7
Fix llvm hang
coolreader18 Feb 22, 2024
658a0a2
Unconditionally pass -wasm-enable-eh
coolreader18 Feb 22, 2024
125b26a
Use Itanium ABI for thrown exceptions
coolreader18 Feb 22, 2024
c7fcf43
Don't codegen wasm.throw unless with -Zbuild-std
coolreader18 Feb 26, 2024
a5245ef
Hint user to update nightly on ICEs produced from outdated nightly
jieyouxu Feb 27, 2024
a0ca9b1
Don't suggest update nightly if using internal features
jieyouxu Feb 27, 2024
9c963fc
Adjust wording
jieyouxu Feb 27, 2024
a9a9798
Removing absolute path in proc-macro
sundeep-kokkonda Mar 4, 2024
6e9f59f
add test for #78894
surechen Mar 4, 2024
4e03c51
hir_analysis: enums return `None` in `find_field`
davidtwco Mar 4, 2024
640e99c
Fix duplicated path in the "not found dylib" error
GuillaumeGomez Mar 4, 2024
5e6e140
Add regression ui test for duplicated path in dylib error
GuillaumeGomez Mar 4, 2024
523ab25
add test for #71450
surechen Mar 4, 2024
960dd38
will_wake tests fail on Miri and that is expected
RalfJung Mar 5, 2024
f391c07
only set noalias on Box with the global allocator
RalfJung Mar 5, 2024
da35734
Merge `impl_trait_in_assoc_types_defined_by` query back into `opaque_…
oli-obk Mar 4, 2024
955a160
Rollup merge of #121280 - ajwock:maybeuninit_fill, r=Amanieu
matthiaskrgr Mar 5, 2024
73ab3c7
Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviper
matthiaskrgr Mar 5, 2024
e788f15
Rollup merge of #121658 - jieyouxu:ice-outdated-nightly, r=oli-obk
matthiaskrgr Mar 5, 2024
5b4f049
Rollup merge of #121959 - sundeep-kokkonda:patch-2, r=davidtwco
matthiaskrgr Mar 5, 2024
8676983
Rollup merge of #121961 - surechen:add_test_20240304, r=petrochenkov
matthiaskrgr Mar 5, 2024
b7a60d8
Rollup merge of #121975 - davidtwco:issue-121757, r=petrochenkov
matthiaskrgr Mar 5, 2024
d08dcea
Rollup merge of #121978 - GuillaumeGomez:dylib-duplicated-path, r=bjorn3
matthiaskrgr Mar 5, 2024
9e3f983
Rollup merge of #121991 - oli-obk:merge_opaque_types_defined_by_queri…
matthiaskrgr Mar 5, 2024
62aed06
Rollup merge of #122016 - RalfJung:will_wake, r=dtolnay
matthiaskrgr Mar 5, 2024
8834019
Rollup merge of #122018 - RalfJung:box-custom-alloc, r=oli-obk
matthiaskrgr Mar 5, 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
7 changes: 5 additions & 2 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,9 @@ pub enum PointerKind {
SharedRef { frozen: bool },
/// Mutable reference. `unpin` indicates the absence of any pinned data.
MutableRef { unpin: bool },
/// Box. `unpin` indicates the absence of any pinned data.
Box { unpin: bool },
/// Box. `unpin` indicates the absence of any pinned data. `global` indicates whether this box
/// uses the global allocator or a custom one.
Box { unpin: bool, global: bool },
}

/// Note that this information is advisory only, and backends are free to ignore it.
Expand All @@ -1622,6 +1623,8 @@ pub enum PointerKind {
pub struct PointeeInfo {
pub size: Size,
pub align: Align,
/// If this is `None`, then this is a raw pointer, so size and alignment are not guaranteed to
/// be reliable.
pub safe: Option<PointerKind>,
}

Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_codegen_cranelift/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,11 @@ pub struct Unique<T: ?Sized> {
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}

#[lang = "global_alloc_ty"]
pub struct Global;

#[lang = "owned_box"]
pub struct Box<T: ?Sized, A = ()>(Unique<T>, A);
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);

impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}

Expand All @@ -536,7 +539,7 @@ impl<T> Box<T> {
let size = intrinsics::size_of::<T>();
let ptr = libc::malloc(size);
intrinsics::copy(&val as *const T as *const u8, ptr, size);
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, ())
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_cranelift/src/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ fn unsize_ptr<'tcx>(
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
(src, unsized_info(fx, *a, *b, old_info))
}
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
let (a, b) = (src_layout.ty.boxed_ty(), dst_layout.ty.boxed_ty());
(src, unsized_info(fx, a, b, old_info))
}
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
assert_eq!(def_a, def_b);

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ pub trait Allocator {

impl Allocator for () {}

#[lang = "global_alloc_ty"]
pub struct Global;

impl Allocator for Global {}
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,13 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
ty::RawPtr(ty::TypeAndMut { ty: pointee_type, .. }) | ty::Ref(_, pointee_type, _) => {
build_pointer_or_reference_di_node(cx, t, pointee_type, unique_type_id)
}
// Box<T, A> may have a non-1-ZST allocator A. In that case, we
// cannot treat Box<T, A> as just an owned alias of `*mut T`.
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_1zst() => {
// Some `Box` are newtyped pointers, make debuginfo aware of that.
// Only works if the allocator argument is a 1-ZST and hence irrelevant for layout
// (or if there is no allocator argument).
ty::Adt(def, args)
if def.is_box()
&& args.get(1).map_or(true, |arg| cx.layout_of(arg.expect_ty()).is_1zst()) =>
{
build_pointer_or_reference_di_node(cx, t, t.boxed_ty(), unique_type_id)
}
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::errors::{
};
use crate::llvm;
use libc::c_int;
use rustc_codegen_ssa::base::wants_wasm_eh;
use rustc_codegen_ssa::traits::PrintBackendInfo;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::small_c_str::SmallCStr;
Expand Down Expand Up @@ -98,6 +99,10 @@ unsafe fn configure_llvm(sess: &Session) {
}
}

if wants_wasm_eh(sess) {
add("-wasm-enable-eh", false);
}

if sess.target.os == "emscripten" && sess.panic_strategy() == PanicStrategy::Unwind {
add("-enable-emscripten-cxx-exceptions", false);
}
Expand Down Expand Up @@ -517,6 +522,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
.map(String::from),
);

if wants_wasm_eh(sess) && sess.panic_strategy() == PanicStrategy::Unwind {
features.push("+exception-handling".into());
}

// -Ctarget-features
let supported_features = sess.target.supported_target_features();
let mut featsmap = FxHashMap::default();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let funclet;
let llbb;
let mut bx;
if base::wants_msvc_seh(self.cx.sess()) {
if base::wants_new_eh_instructions(self.cx.sess()) {
// This is a basic block that we're aborting the program for,
// notably in an `extern` function. These basic blocks are inserted
// so that we assert that `extern` functions do indeed not panic,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {

pub fn deref<Cx: LayoutTypeMethods<'tcx>>(self, cx: &Cx) -> PlaceRef<'tcx, V> {
if self.layout.ty.is_box() {
// Derefer should have removed all Box derefs
bug!("dereferencing {:?} in codegen", self.layout.ty);
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ where
trace!("deref to {} on {:?}", val.layout.ty, *val);

if val.layout.ty.is_box() {
// Derefer should have removed all Box derefs
bug!("dereferencing {}", val.layout.ty);
}

Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(Some(match ty.kind() {
ty::Ref(_, ty, _) => *ty,
ty::RawPtr(mt) => mt.ty,
// We should only accept `Box` with the default allocator.
// It's hard to test for that though so we accept every 1-ZST allocator.
ty::Adt(def, args)
if def.is_box()
&& self.layout_of(args[1].expect_ty()).is_ok_and(|l| l.is_1zst()) =>
{
args[0].expect_ty()
}
// We only accept `Box` with the default allocator.
_ if ty.is_box_global(*self.tcx) => ty.boxed_ty(),
_ => return Ok(None),
}))
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }
serde_json = "1.0.59"
shlex = "1.0"
time = { version = "0.3", default-features = false, features = ["alloc", "formatting"] }
time = { version = "0.3", default-features = false, features = ["alloc", "formatting", "parsing", "macros"] }
tracing = { version = "0.1.35" }
# tidy-alphabetical-end

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_driver_impl/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
driver_impl_ice = the compiler unexpectedly panicked. this is a bug.
driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly
driver_impl_ice_bug_report_outdated =
it seems that this compiler `{$version}` is outdated, a newer nightly should have been released in the mean time
.update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
.url = if the problem still persists, we would appreciate a bug report: {$bug_report_url}
driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden

driver_impl_ice_flags = compiler flags: {$flags}
Expand Down
35 changes: 31 additions & 4 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use std::str;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock};
use std::time::{Instant, SystemTime};
use time::OffsetDateTime;
use time::{Date, OffsetDateTime, Time};

#[allow(unused_macros)]
macro do_not_use_print($($t:tt)*) {
Expand Down Expand Up @@ -1369,6 +1369,9 @@ pub fn install_ice_hook(
using_internal_features
}

const DATE_FORMAT: &[time::format_description::FormatItem<'static>] =
&time::macros::format_description!("[year]-[month]-[day]");

/// Prints the ICE message, including query stack, but without backtrace.
///
/// The message will point the user at `bug_report_url` to report the ICE.
Expand Down Expand Up @@ -1397,10 +1400,34 @@ fn report_ice(
dcx.emit_err(session_diagnostics::Ice);
}

if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
dcx.emit_note(session_diagnostics::IceBugReportInternalFeature);
use time::ext::NumericalDuration;

// Try to hint user to update nightly if applicable when reporting an ICE.
// Attempt to calculate when current version was released, and add 12 hours
// as buffer. If the current version's release timestamp is older than
// the system's current time + 24 hours + 12 hours buffer if we're on
// nightly.
if let Some("nightly") = option_env!("CFG_RELEASE_CHANNEL")
&& let Some(version) = option_env!("CFG_VERSION")
&& let Some(ver_date_str) = option_env!("CFG_VER_DATE")
&& let Ok(ver_date) = Date::parse(&ver_date_str, DATE_FORMAT)
&& let ver_datetime = OffsetDateTime::new_utc(ver_date, Time::MIDNIGHT)
&& let system_datetime = OffsetDateTime::from(SystemTime::now())
&& system_datetime.checked_sub(36.hours()).is_some_and(|d| d > ver_datetime)
&& !using_internal_features.load(std::sync::atomic::Ordering::Relaxed)
{
dcx.emit_note(session_diagnostics::IceBugReportOutdated {
version,
bug_report_url,
note_update: (),
note_url: (),
});
} else {
dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url });
if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
dcx.emit_note(session_diagnostics::IceBugReportInternalFeature);
} else {
dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url });
}
}

let version = util::version_str!().unwrap_or("unknown_version");
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_driver_impl/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ pub(crate) struct IceBugReport<'a> {
#[diag(driver_impl_ice_bug_report_internal_feature)]
pub(crate) struct IceBugReportInternalFeature;

#[derive(Diagnostic)]
#[diag(driver_impl_ice_bug_report_outdated)]
pub(crate) struct IceBugReportOutdated<'a> {
pub version: &'a str,
pub bug_report_url: &'a str,
#[note(driver_impl_update)]
pub note_update: (),
#[note(driver_impl_url)]
pub note_url: (),
}

#[derive(Diagnostic)]
#[diag(driver_impl_ice_version)]
pub(crate) struct IceVersion<'a> {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ language_item_table! {
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None;

OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
GlobalAlloc, sym::global_alloc_ty, global_alloc_ty, Target::Struct, GenericRequirement::None;

// Experimental language item for Miri
PtrUnique, sym::ptr_unique, ptr_unique, Target::Struct, GenericRequirement::Exact(1);

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
}

fn find_field(tcx: TyCtxt<'_>, (def_id, ident): (DefId, Ident)) -> Option<FieldIdx> {
tcx.adt_def(def_id).non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| {
let adt = tcx.adt_def(def_id);
if adt.is_enum() {
return None;
}

adt.non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| {
if field.is_unnamed() {
let field_ty = tcx.type_of(field.did).instantiate_identity();
let adt_def = field_ty.ty_adt_def().expect("expect Adt for unnamed field");
Expand Down
28 changes: 8 additions & 20 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
for &assoc_id in tcx.associated_item_def_ids(impl_def_id) {
let assoc = tcx.associated_item(assoc_id);
match assoc.kind {
ty::AssocKind::Const | ty::AssocKind::Fn => {
locator.check(assoc_id.expect_local(), ImplTraitSource::AssocTy)
}
ty::AssocKind::Const | ty::AssocKind::Fn => locator.check(assoc_id.expect_local()),
// Associated types don't have bodies, so they can't constrain hidden types
ty::AssocKind::Type => {}
}
Expand Down Expand Up @@ -182,15 +180,9 @@ struct TaitConstraintLocator<'tcx> {
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
}

#[derive(Debug)]
enum ImplTraitSource {
AssocTy,
TyAlias,
}

impl TaitConstraintLocator<'_> {
#[instrument(skip(self), level = "debug")]
fn check(&mut self, item_def_id: LocalDefId, source: ImplTraitSource) {
fn check(&mut self, item_def_id: LocalDefId) {
// Don't try to check items that cannot possibly constrain the type.
if !self.tcx.has_typeck_results(item_def_id) {
debug!("no constraint: no typeck results");
Expand Down Expand Up @@ -242,12 +234,8 @@ impl TaitConstraintLocator<'_> {
continue;
}
constrained = true;
let opaque_types_defined_by = match source {
ImplTraitSource::AssocTy => {
self.tcx.impl_trait_in_assoc_types_defined_by(item_def_id)
}
ImplTraitSource::TyAlias => self.tcx.opaque_types_defined_by(item_def_id),
};
let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id);

if !opaque_types_defined_by.contains(&self.def_id) {
self.tcx.dcx().emit_err(TaitForwardCompat {
span: hidden_type.span,
Expand Down Expand Up @@ -308,29 +296,29 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
}
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if let hir::ExprKind::Closure(closure) = ex.kind {
self.check(closure.def_id, ImplTraitSource::TyAlias);
self.check(closure.def_id);
}
intravisit::walk_expr(self, ex);
}
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
trace!(?it.owner_id);
// The opaque type itself or its children are not within its reveal scope.
if it.owner_id.def_id != self.def_id {
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
self.check(it.owner_id.def_id);
intravisit::walk_item(self, it);
}
}
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
trace!(?it.owner_id);
// The opaque type itself or its children are not within its reveal scope.
if it.owner_id.def_id != self.def_id {
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
self.check(it.owner_id.def_id);
intravisit::walk_impl_item(self, it);
}
}
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
trace!(?it.owner_id);
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
self.check(it.owner_id.def_id);
intravisit::walk_trait_item(self, it);
}
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
Err(err) => {
// Only try to recover from this specific error.
if !matches!(err, libloading::Error::LoadLibraryExW { .. }) {
return Err(err.to_string());
let err = format_dlopen_err(&err);
// We include the path of the dylib in the error ourselves, so
// if it's in the error, we strip it.
if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) {
return Err(err.to_string());
}
return Err(err);
}

last_error = Some(err);
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,6 @@ rustc_queries! {
}
}

query impl_trait_in_assoc_types_defined_by(
key: LocalDefId
) -> &'tcx ty::List<LocalDefId> {
desc {
|tcx| "computing the opaque types defined by `{}`",
tcx.def_path_str(key.to_def_id())
}
}

/// Returns the list of bounds that can be used for
/// `SelectionCandidate::ProjectionCandidate(_)` and
/// `ProjectionTyCandidate::TraitDef`.
Expand Down
Loading
Loading