Skip to content

Rollup of 7 pull requests #139689

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 20 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8004615
Use `BinOp::Cmp` for `iNN::signum`
scottmcm Mar 1, 2025
9491242
Cleanup the `InstSimplify` MIR transformation
yotamofek Apr 10, 2025
d25c8a8
Handle a negated literal in `eat_token_lit`.
nnethercote Apr 11, 2025
fad2535
Adjust an assertion.
nnethercote Apr 11, 2025
9eca59a
Introduce `DefPathData::AnonAssocTy`.
nnethercote Apr 11, 2025
cfa52e4
Reuse address-space computation from global alloc
oli-obk Apr 11, 2025
24efefa
Avoid a reverse map that is only used in diagnostics paths
oli-obk Apr 9, 2025
f5c60f6
Avoid another node_id_to_def_id call
oli-obk Apr 11, 2025
33a6820
Avoid storing the `LocalDefId` twice
oli-obk Apr 11, 2025
d35e830
Avoid a node_id_to_def_id call by just storing DefIds instead of NodeIds
oli-obk Apr 11, 2025
98d51fb
Only compute the `DefId` when a diagnostic is definitely emitted
oli-obk Apr 10, 2025
cdf5b8d
Change how anonymous associated types are printed.
nnethercote Apr 11, 2025
452c280
Add spastorino to users_on_vacation
spastorino Apr 11, 2025
a660829
Rollup merge of #137835 - scottmcm:signum, r=compiler-errors
jhpratt Apr 11, 2025
bc05aae
Rollup merge of #139584 - oli-obk:horrible-experiment-1, r=petrochenkov
jhpratt Apr 11, 2025
00b9060
Rollup merge of #139638 - yotamofek:pr/mir_transform/instsimplify/cle…
jhpratt Apr 11, 2025
2f873f9
Rollup merge of #139653 - nnethercote:fix-139495, r=petrochenkov
jhpratt Apr 11, 2025
2b54f9b
Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-e…
jhpratt Apr 11, 2025
eea366c
Rollup merge of #139664 - oli-obk:push-tkmurytmnsyw, r=RalfJung
jhpratt Apr 11, 2025
c8992c9
Rollup merge of #139687 - spastorino:add-spastorino-to-vacation, r=Urgau
jhpratt Apr 11, 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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4397,7 +4397,6 @@ dependencies = [
"rustc_feature",
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
"rustc_macros",
"rustc_metadata",
"rustc_middle",
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::borrow::Borrow;

use libc::{c_char, c_uint};
use rustc_abi as abi;
use rustc_abi::HasDataLayout;
use rustc_abi::Primitive::Pointer;
use rustc_abi::{AddressSpace, HasDataLayout};
use rustc_ast::Mutability;
use rustc_codegen_ssa::common::TypeKind;
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -269,7 +269,8 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
}
Scalar::Ptr(ptr, _size) => {
let (prov, offset) = ptr.into_parts();
let (base_addr, base_addr_space) = match self.tcx.global_alloc(prov.alloc_id()) {
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
let base_addr = match global_alloc {
GlobalAlloc::Memory(alloc) => {
// For ZSTs directly codegen an aligned pointer.
// This avoids generating a zero-sized constant value and actually needing a
Expand Down Expand Up @@ -301,12 +302,10 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
format!("alloc_{hash:032x}").as_bytes(),
);
}
(value, AddressSpace::DATA)
value
}
}
GlobalAlloc::Function { instance, .. } => {
(self.get_fn_addr(instance), self.data_layout().instruction_address_space)
}
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance),
GlobalAlloc::VTable(ty, dyn_ty) => {
let alloc = self
.tcx
Expand All @@ -319,14 +318,15 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
.unwrap_memory();
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
let value = self.static_addr_of_impl(init, alloc.inner().align, None);
(value, AddressSpace::DATA)
value
}
GlobalAlloc::Static(def_id) => {
assert!(self.tcx.is_static(def_id));
assert!(!self.tcx.is_thread_local_static(def_id));
(self.get_static(def_id), AddressSpace::DATA)
self.get_static(def_id)
}
};
let base_addr_space = global_alloc.address_space(self);
let llval = unsafe {
llvm::LLVMConstInBoundsGEP2(
self.type_i8(),
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_data_structures/src/unord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
pub fn collect<C: From<UnordItems<T, I>>>(self) -> C {
self.into()
}

/// If the iterator has only one element, returns it, otherwise returns `None`.
#[track_caller]
pub fn get_only(mut self) -> Option<T> {
let item = self.0.next();
if self.0.next().is_some() {
return None;
}
item
}
}

impl<T> UnordItems<T, std::iter::Empty<T>> {
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,16 @@ impl DefKind {
| DefKind::ForeignTy
| DefKind::TraitAlias
| DefKind::TyParam
| DefKind::ExternCrate => DefPathData::TypeNs(Some(name.unwrap())),

// An associated type names will be missing for an RPITIT. It will
// later be given a name with `synthetic` in it, if necessary.
DefKind::AssocTy => DefPathData::TypeNs(name),
| DefKind::ExternCrate => DefPathData::TypeNs(name.unwrap()),

// An associated type name will be missing for an RPITIT.
DefKind::AssocTy => {
if let Some(name) = name {
DefPathData::TypeNs(name)
} else {
DefPathData::AnonAssocTy
}
}

// It's not exactly an anon const, but wrt DefPathData, there
// is no difference.
Expand Down
22 changes: 9 additions & 13 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ pub enum DefPathData {
Use,
/// A global asm item.
GlobalAsm,
/// Something in the type namespace. Will be empty for RPITIT associated
/// types, which are given a synthetic name later, if necessary.
TypeNs(Option<Symbol>),
/// Something in the type namespace.
TypeNs(Symbol),
/// Something in the value namespace.
ValueNs(Symbol),
/// Something in the macro namespace.
Expand All @@ -291,6 +290,8 @@ pub enum DefPathData {
/// An existential `impl Trait` type node.
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
OpaqueTy,
/// An anonymous associated type from an RPITIT.
AnonAssocTy,
/// A synthetic body for a coroutine's by-move body.
SyntheticCoroutineBody,
}
Expand Down Expand Up @@ -413,9 +414,7 @@ impl DefPathData {
pub fn get_opt_name(&self) -> Option<Symbol> {
use self::DefPathData::*;
match *self {
TypeNs(name) => name,

ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),

Impl
| ForeignMod
Expand All @@ -426,21 +425,17 @@ impl DefPathData {
| Ctor
| AnonConst
| OpaqueTy
| AnonAssocTy
| SyntheticCoroutineBody => None,
}
}

pub fn name(&self) -> DefPathDataName {
use self::DefPathData::*;
match *self {
TypeNs(name) => {
if let Some(name) = name {
DefPathDataName::Named(name)
} else {
DefPathDataName::Anon { namespace: sym::synthetic }
}
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
DefPathDataName::Named(name)
}
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
// Note that this does not show up in user print-outs.
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
Impl => DefPathDataName::Anon { namespace: kw::Impl },
Expand All @@ -451,6 +446,7 @@ impl DefPathData {
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
AnonAssocTy => DefPathDataName::Anon { namespace: sym::anon_assoc },
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
// the children of the visible parent (as was done when computing
// `visible_parent_map`), looking for the specific child we currently have and then
// have access to the re-exported name.
DefPathData::TypeNs(Some(ref mut name)) if Some(visible_parent) != actual_parent => {
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
// Item might be re-exported several times, but filter for the one
// that's public and whose identifier isn't `_`.
let reexport = self
Expand All @@ -641,7 +641,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
}
// Re-exported `extern crate` (#43189).
DefPathData::CrateRoot => {
data = DefPathData::TypeNs(Some(self.tcx().crate_name(def_id.krate)));
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/significant_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn true_significant_drop_ty<'tcx>(
name_rev.push(tcx.crate_name(did.krate));
}
rustc_hir::definitions::DefPathData::TypeNs(symbol) => {
name_rev.push(symbol.unwrap());
name_rev.push(symbol);
}
_ => return None,
}
Expand Down
Loading