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 14 pull requests #137651

Merged
merged 33 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0842f2c
Add fast path for displaying pre-validated Wtf8Buf
thaliaarchi Feb 6, 2025
eb14652
Skip scanning for surrogates when not known valid
thaliaarchi Feb 7, 2025
cf1242c
Enable `f16` for MIPS
Feb 19, 2025
123062b
pass optimization level to llvm-bitcode-linker
usamoi Feb 5, 2025
6fc1978
fixed by differentiating glob export
tapanprakasht Feb 23, 2025
afc89a1
Fixed tidy error
tapanprakasht Feb 23, 2025
5afa6a1
ssa/mono: deduplicate `type_has_metadata`
davidtwco Dec 4, 2024
a5615d3
codegen_llvm: avoid `Deref` impls w/ extern type
davidtwco Feb 4, 2025
21d41b0
trait_sel: resolve vars in host effects
davidtwco Feb 24, 2025
cede902
cleanup few unused args
klensy Feb 24, 2025
7bf6fc1
tests: add variance test for const traits
davidtwco Feb 24, 2025
0bed12e
hir_analysis: skip self type of host effect preds
davidtwco Feb 24, 2025
db6da12
tests: Add regression test for derive token invalidation (#81099)
petrochenkov Feb 24, 2025
60fc2be
run some tests on emscripten again
folkertdev Feb 24, 2025
8467a76
remove unused field from VariantDef::new and convert debug to instrument
klensy Feb 24, 2025
00e80e7
Complete the list of resources used in rustdoc output
ColinPitrat Feb 25, 2025
eaf8fc5
Update information about NanumBarunGothic
ColinPitrat Feb 25, 2025
48483ad
fix doc in library/core/src/pin.rs
xizheyin Feb 25, 2025
4bf66c5
fix #137589
jdonszelmann Feb 25, 2025
1cdd386
Rollup merge of #136576 - usamoi:pass-more-llbc, r=fmease
fmease Feb 26, 2025
e121dcf
Rollup merge of #137154 - thaliaarchi:wtf8-fast-paths, r=ChrisDenton
fmease Feb 26, 2025
49249ea
Rollup merge of #137311 - martn3:enable-f16-mips, r=tgross35
fmease Feb 26, 2025
ef53922
Rollup merge of #137320 - tapanprakasht:fix-doc-version-stability, r=…
fmease Feb 26, 2025
292c003
Rollup merge of #137529 - klensy:unused3, r=lcnr
fmease Feb 26, 2025
ef2164f
Rollup merge of #137544 - petrochenkov:deritest, r=fmease
fmease Feb 26, 2025
f192314
Rollup merge of #137559 - folkertdev:run-more-emscripten-tests, r=fmease
fmease Feb 26, 2025
51085b2
Rollup merge of #137601 - davidtwco:deduplicate-type-has-metadata, r=…
fmease Feb 26, 2025
a579a23
Rollup merge of #137603 - davidtwco:extern-types-no-deref, r=lcnr
fmease Feb 26, 2025
677295a
Rollup merge of #137604 - davidtwco:host-effect-resolve-vars, r=compi…
fmease Feb 26, 2025
a82ad94
Rollup merge of #137609 - ColinPitrat:master, r=GuillaumeGomez
fmease Feb 26, 2025
cf8498d
Rollup merge of #137613 - davidtwco:const-traits-variances, r=compile…
fmease Feb 26, 2025
0d4af08
Rollup merge of #137614 - xizheyin:issue-134874, r=cuviper
fmease Feb 26, 2025
1bb4319
Rollup merge of #137622 - jdonszelmann:fix-137589, r=compiler-errors
fmease Feb 26, 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
5 changes: 4 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ impl<'sess> AttributeParser<'sess> {
{
lit
} else {
let guar = self.dcx().has_errors().unwrap();
let guar = self.dcx().span_delayed_bug(
args.span().unwrap_or(DUMMY_SP),
"expr in place where literal is expected (builtin attr parsing)",
);
ast::MetaItemLit {
symbol: kw::Empty,
suffix: None,
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust;
use rustc_errors::DiagCtxtHandle;
use rustc_hir::{self as hir, AttrPath};
use rustc_span::symbol::{Ident, kw};
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol};
use rustc_span::{ErrorGuaranteed, Span, Symbol};

pub struct SegmentIterator<'a> {
offset: usize,
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<'a> ArgParser<'a> {
}
AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser {
eq_span: *eq_span,
value: expr_to_lit(dcx, &expr),
value: expr_to_lit(dcx, &expr, *eq_span),
value_span: expr.span,
}),
}
Expand Down Expand Up @@ -348,16 +348,19 @@ impl NameValueParser {
}
}

fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit {
fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit {
// In valid code the value always ends up as a single literal. Otherwise, a dummy
// literal suffices because the error is handled elsewhere.
if let ExprKind::Lit(token_lit) = expr.kind
&& let Ok(lit) = MetaItemLit::from_token_lit(token_lit, expr.span)
{
lit
} else {
let guar = dcx.has_errors().unwrap();
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span: DUMMY_SP }
let guar = dcx.span_delayed_bug(
span,
"expr in place where literal is expected (builtin attr parsing)",
);
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span }
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
| StatementKind::StorageLive(..) => {}
// This does not affect borrowck
StatementKind::BackwardIncompatibleDropHint { place, reason: BackwardIncompatibleDropReason::Edition2024 } => {
self.check_backward_incompatible_drop(location, (**place, span), state);
self.check_backward_incompatible_drop(location, **place, state);
}
StatementKind::StorageDead(local) => {
self.access_place(
Expand Down Expand Up @@ -1174,7 +1174,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
fn check_backward_incompatible_drop(
&mut self,
location: Location,
(place, place_span): (Place<'tcx>, Span),
place: Place<'tcx>,
state: &BorrowckDomain,
) {
let tcx = self.infcx.tcx;
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,9 @@ pub(crate) unsafe fn optimize_thin_module(
{
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
unsafe { llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) };
unsafe {
llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target.raw())
};
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
}

Expand Down Expand Up @@ -823,7 +825,7 @@ pub(crate) unsafe fn optimize_thin_module(
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
if unsafe {
!llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target)
!llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target.raw())
} {
return Err(write::llvm_err(dcx, LlvmError::PrepareThinLtoModule));
}
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::ffi::{CStr, c_char};
use std::marker::PhantomData;
use std::ops::Deref;
use std::ptr::NonNull;

use rustc_data_structures::small_c_str::SmallCStr;
Expand Down Expand Up @@ -80,12 +79,12 @@ impl OwnedTargetMachine {
.map(|tm_unique| Self { tm_unique, phantom: PhantomData })
.ok_or_else(|| LlvmError::CreateTargetMachine { triple: SmallCStr::from(triple) })
}
}

impl Deref for OwnedTargetMachine {
type Target = llvm::TargetMachine;

fn deref(&self) -> &Self::Target {
/// Returns inner `llvm::TargetMachine` type.
///
/// This could be a `Deref` implementation, but `llvm::TargetMachine` is an extern type and
/// `Deref::Target: ?Sized`.
pub fn raw(&self) -> &llvm::TargetMachine {
// SAFETY: constructing ensures we have a valid pointer created by
// llvm::LLVMRustCreateTargetMachine.
unsafe { self.tm_unique.as_ref() }
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ pub(crate) unsafe fn llvm_optimize(
let result = unsafe {
llvm::LLVMRustOptimize(
module.module_llvm.llmod(),
&*module.module_llvm.tm,
&*module.module_llvm.tm.raw(),
to_pass_builder_opt_level(opt_level),
opt_stage,
cgcx.opts.cg.linker_plugin_lto.enabled(),
Expand Down Expand Up @@ -875,7 +875,7 @@ pub(crate) unsafe fn codegen(
};
write_output_file(
dcx,
tm,
tm.raw(),
config.no_builtins,
llmod,
&path,
Expand Down Expand Up @@ -909,7 +909,7 @@ pub(crate) unsafe fn codegen(

write_output_file(
dcx,
tm,
tm.raw(),
config.no_builtins,
llmod,
&obj_out,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {

// Emit KCFI operand bundle
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
bundles.push(kcfi_bundle);
}

Expand Down Expand Up @@ -1433,7 +1433,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {

// Emit KCFI operand bundle
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
bundles.push(kcfi_bundle);
}

Expand Down Expand Up @@ -1782,7 +1782,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {

// Emit KCFI operand bundle
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
bundles.push(kcfi_bundle);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'ll> Funclet<'ll> {
}

pub(crate) fn bundle(&self) -> &llvm::OperandBundle<'ll> {
&self.operand
self.operand.raw()
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub(crate) unsafe fn create_module<'ll>(
{
let tm = crate::back::write::create_informational_target_machine(tcx.sess, false);
unsafe {
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm.raw());
}

let llvm_data_layout = unsafe { llvm::LLVMGetDataLayoutStr(llmod) };
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_codegen_llvm/src/llvm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(non_snake_case)]

use std::ffi::{CStr, CString};
use std::ops::Deref;
use std::ptr;
use std::str::FromStr;
use std::string::FromUtf8Error;
Expand Down Expand Up @@ -355,6 +354,16 @@ impl<'a> OperandBundleOwned<'a> {
};
OperandBundleOwned { raw: ptr::NonNull::new(raw).unwrap() }
}

/// Returns inner `OperandBundle` type.
///
/// This could be a `Deref` implementation, but `OperandBundle` contains an extern type and
/// `Deref::Target: ?Sized`.
pub(crate) fn raw(&self) -> &OperandBundle<'a> {
// SAFETY: The returned reference is opaque and can only used for FFI.
// It is valid for as long as `&self` is.
unsafe { self.raw.as_ref() }
}
}

impl Drop for OperandBundleOwned<'_> {
Expand All @@ -365,16 +374,6 @@ impl Drop for OperandBundleOwned<'_> {
}
}

impl<'a> Deref for OperandBundleOwned<'a> {
type Target = OperandBundle<'a>;

fn deref(&self) -> &Self::Target {
// SAFETY: The returned reference is opaque and can only used for FFI.
// It is valid for as long as `&self` is.
unsafe { self.raw.as_ref() }
}
}

pub(crate) fn add_module_flag_u32(
module: &Module,
merge_behavior: ModuleFlagMergeBehavior,
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
if let Some(feat) = to_llvm_features(sess, feature) {
for llvm_feature in feat {
let cstr = SmallCStr::new(llvm_feature);
if !unsafe { llvm::LLVMRustHasFeature(&target_machine, cstr.as_ptr()) } {
if !unsafe { llvm::LLVMRustHasFeature(target_machine.raw(), cstr.as_ptr()) }
{
return false;
}
}
Expand Down Expand Up @@ -453,8 +454,8 @@ pub(crate) fn print(req: &PrintRequest, out: &mut String, sess: &Session) {
require_inited();
let tm = create_informational_target_machine(sess, false);
match req.kind {
PrintKind::TargetCPUs => print_target_cpus(sess, &tm, out),
PrintKind::TargetFeatures => print_target_features(sess, &tm, out),
PrintKind::TargetCPUs => print_target_cpus(sess, tm.raw(), out),
PrintKind::TargetFeatures => print_target_features(sess, tm.raw(), out),
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,14 +1939,14 @@ impl<'a> Linker for LlbcLinker<'a> {
}

fn optimize(&mut self) {
match self.sess.opts.optimize {
self.link_arg(match self.sess.opts.optimize {
OptLevel::No => "-O0",
OptLevel::Less => "-O1",
OptLevel::More => "-O2",
OptLevel::Aggressive => "-O3",
OptLevel::Size => "-Os",
OptLevel::SizeMin => "-Oz",
};
});
}

fn full_relro(&mut self) {}
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_abi::Primitive::{Int, Pointer};
use rustc_abi::{Align, BackendRepr, FieldsShape, Size, TagEncoding, VariantIdx, Variants};
use rustc_middle::mir::PlaceTy;
use rustc_middle::mir::interpret::Scalar;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty};
use rustc_middle::{bug, mir};
use tracing::{debug, instrument};
Expand Down Expand Up @@ -168,7 +168,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
};
let val = PlaceValue {
llval,
llextra: if bx.cx().type_has_metadata(field.ty) { self.val.llextra } else { None },
llextra: if bx.cx().tcx().type_has_metadata(field.ty, bx.cx().typing_env()) {
self.val.llextra
} else {
None
},
align: effective_field_align,
};
val.with_type(field)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::assert_matches::assert_matches;
use arrayvec::ArrayVec;
use rustc_abi::{self as abi, FIRST_VARIANT, FieldIdx};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::{bug, mir, span_bug};
use rustc_session::config::OptLevel;
Expand Down Expand Up @@ -878,7 +878,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

let ty = cg_place.layout.ty;
assert!(
if bx.cx().type_has_metadata(ty) {
if bx.cx().tcx().type_has_metadata(ty, bx.cx().typing_env()) {
matches!(val, OperandValue::Pair(..))
} else {
matches!(val, OperandValue::Immediate(..))
Expand Down
15 changes: 1 addition & 14 deletions compiler/rustc_codegen_ssa/src/traits/type_.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_abi::{AddressSpace, Float, Integer, Reg};
use rustc_middle::bug;
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, TyAndLayout};
use rustc_middle::ty::{self, Ty};
use rustc_target::callconv::{ArgAbi, CastTarget, FnAbi};

use super::BackendTypes;
Expand Down Expand Up @@ -84,19 +84,6 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(self.tcx(), self.typing_env())
}

fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
if ty.is_sized(self.tcx(), self.typing_env()) {
return false;
}

let tail = self.tcx().struct_tail_for_codegen(ty, self.typing_env());
match tail.kind() {
ty::Foreign(..) => false,
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
_ => bug!("unexpected unsized tail: {:?}", tail),
}
}
}

impl<'tcx, T> DerivedTypeCodegenMethods<'tcx> for T where
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,6 @@ fn lower_variant<'tcx>(
def.ctor().map(|(kind, _, def_id)| (kind, def_id.to_def_id())),
discr,
fields,
adt_kind,
parent_did.to_def_id(),
recovered,
adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive)
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ fn variance_of_opaque(
ty::ClauseKind::Trait(ty::TraitPredicate {
trait_ref: ty::TraitRef { def_id: _, args, .. },
polarity: _,
})
| ty::ClauseKind::HostEffect(ty::HostEffectPredicate {
trait_ref: ty::TraitRef { def_id: _, args, .. },
constness: _,
}) => {
for arg in &args[1..] {
arg.visit_with(&mut collector);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,6 @@ impl<'a> CrateMetadataRef<'a> {
value: self.get_default_field(did.index),
})
.collect(),
adt_kind,
parent_did,
None,
data.is_non_exhaustive,
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,23 +1184,17 @@ impl VariantDef {
///
/// If someone speeds up attribute loading to not be a performance concern, they can
/// remove this hack and use the constructor `DefId` everywhere.
#[instrument(level = "debug")]
pub fn new(
name: Symbol,
variant_did: Option<DefId>,
ctor: Option<(CtorKind, DefId)>,
discr: VariantDiscr,
fields: IndexVec<FieldIdx, FieldDef>,
adt_kind: AdtKind,
parent_did: DefId,
recover_tainted: Option<ErrorGuaranteed>,
is_field_list_non_exhaustive: bool,
) -> Self {
debug!(
"VariantDef::new(name = {:?}, variant_did = {:?}, ctor = {:?}, discr = {:?},
fields = {:?}, adt_kind = {:?}, parent_did = {:?})",
name, variant_did, ctor, discr, fields, adt_kind, parent_did,
);

let mut flags = VariantFlags::NO_VARIANT_FLAGS;
if is_field_list_non_exhaustive {
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
Expand Down
Loading
Loading