Skip to content

Commit 6efa357

Browse files
committed
Auto merge of #152358 - JonathanBrouwer:rollup-kIGpLTP, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #151455 (Fix `SourceFile::normalized_byte_pos`) - #152250 (Remove support for slugs in diagnostic messages) - #152322 (Replace some `feature(core_intrinsics)` with stable hints) - #152328 (Fix a few diagnostics) - #151640 (Cleanup offload datatransfer) - #152212 (Port some attributes to the attr parser) - #152309 (Fix bound var resolution for trait aliases) - #152339 (diagnostics: fix ICE in closure signature mismatch) - #152341 (`cfg_select!`: allow optional comma after `{ /* ... */ }`)
2 parents 286fbe5 + 78bd6ab commit 6efa357

70 files changed

Lines changed: 622 additions & 786 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_arena/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![cfg_attr(test, feature(test))]
1414
#![deny(unsafe_op_in_unsafe_fn)]
1515
#![doc(test(no_crate_inject, attr(deny(warnings), allow(internal_features))))]
16-
#![feature(core_intrinsics)]
1716
#![feature(decl_macro)]
1817
#![feature(dropck_eyepatch)]
1918
#![feature(never_type)]
@@ -26,7 +25,7 @@ use std::cell::{Cell, RefCell};
2625
use std::marker::PhantomData;
2726
use std::mem::{self, MaybeUninit};
2827
use std::ptr::{self, NonNull};
29-
use std::{cmp, intrinsics, slice};
28+
use std::{cmp, hint, slice};
3029

3130
use smallvec::SmallVec;
3231

@@ -452,7 +451,7 @@ impl DroplessArena {
452451
let bytes = align_up(layout.size(), DROPLESS_ALIGNMENT);
453452

454453
// Tell LLVM that `end` is aligned to DROPLESS_ALIGNMENT.
455-
unsafe { intrinsics::assume(end == align_down(end, DROPLESS_ALIGNMENT)) };
454+
unsafe { hint::assert_unchecked(end == align_down(end, DROPLESS_ALIGNMENT)) };
456455

457456
if let Some(sub) = end.checked_sub(bytes) {
458457
let new_end = align_down(sub, layout.align());

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ pub(crate) struct AutoTraitItems {
503503
#[primary_span]
504504
pub spans: Vec<Span>,
505505
#[suggestion(
506-
"remove the super traits or lifetime bounds",
506+
"remove the associated items",
507507
code = "",
508508
applicability = "machine-applicable",
509509
style = "tool-only"

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,41 @@ impl<S: Stage> SingleAttributeParser<S> for RustcAbiParser {
190190
Some(AttributeKind::RustcAbi { attr_span: cx.attr_span, kind })
191191
}
192192
}
193+
194+
pub(crate) struct RustcDelayedBugFromInsideQueryParser;
195+
196+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDelayedBugFromInsideQueryParser {
197+
const PATH: &[Symbol] = &[sym::rustc_delayed_bug_from_inside_query];
198+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
199+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
200+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDelayedBugFromInsideQuery;
201+
}
202+
203+
pub(crate) struct RustcEvaluateWhereClausesParser;
204+
205+
impl<S: Stage> NoArgsAttributeParser<S> for RustcEvaluateWhereClausesParser {
206+
const PATH: &[Symbol] = &[sym::rustc_evaluate_where_clauses];
207+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
208+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
209+
Allow(Target::Fn),
210+
Allow(Target::Method(MethodKind::Inherent)),
211+
Allow(Target::Method(MethodKind::Trait { body: true })),
212+
Allow(Target::Method(MethodKind::TraitImpl)),
213+
Allow(Target::Method(MethodKind::Trait { body: false })),
214+
]);
215+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcEvaluateWhereClauses;
216+
}
217+
218+
pub(crate) struct RustcOutlivesParser;
219+
220+
impl<S: Stage> NoArgsAttributeParser<S> for RustcOutlivesParser {
221+
const PATH: &[Symbol] = &[sym::rustc_outlives];
222+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
223+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
224+
Allow(Target::Struct),
225+
Allow(Target::Enum),
226+
Allow(Target::Union),
227+
Allow(Target::TyAlias),
228+
]);
229+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcOutlives;
230+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,14 @@ attribute_parsers!(
262262
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
263263
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
264264
Single<WithoutArgs<RustcDeallocatorParser>>,
265+
Single<WithoutArgs<RustcDelayedBugFromInsideQueryParser>>,
265266
Single<WithoutArgs<RustcDumpDefParentsParser>>,
266267
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
267268
Single<WithoutArgs<RustcDumpPredicatesParser>>,
268269
Single<WithoutArgs<RustcDumpUserArgsParser>>,
269270
Single<WithoutArgs<RustcDumpVtableParser>>,
270271
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
272+
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
271273
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
272274
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
273275
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
@@ -281,6 +283,7 @@ attribute_parsers!(
281283
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
282284
Single<WithoutArgs<RustcNounwindParser>>,
283285
Single<WithoutArgs<RustcOffloadKernelParser>>,
286+
Single<WithoutArgs<RustcOutlivesParser>>,
284287
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
285288
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
286289
Single<WithoutArgs<RustcReallocatorParser>>,

compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::ffi::CString;
22

3+
use bitflags::Flags;
34
use llvm::Linkage::*;
45
use rustc_abi::Align;
56
use rustc_codegen_ssa::common::TypeKind;
67
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
78
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
89
use rustc_middle::bug;
9-
use rustc_middle::ty::offload_meta::OffloadMetadata;
10+
use rustc_middle::ty::offload_meta::{MappingFlags, OffloadMetadata};
1011

1112
use crate::builder::Builder;
1213
use crate::common::CodegenCx;
@@ -28,10 +29,6 @@ pub(crate) struct OffloadGlobals<'ll> {
2829
pub mapper_fn_ty: &'ll llvm::Type,
2930

3031
pub ident_t_global: &'ll llvm::Value,
31-
32-
// FIXME(offload): Drop this, once we fully automated our offload compilation pipeline, since
33-
// LLVM will initialize them for us if it sees gpu kernels being registered.
34-
pub init_rtls: &'ll llvm::Value,
3532
}
3633

3734
impl<'ll> OffloadGlobals<'ll> {
@@ -42,9 +39,6 @@ impl<'ll> OffloadGlobals<'ll> {
4239
let (begin_mapper, _, end_mapper, mapper_fn_ty) = gen_tgt_data_mappers(cx);
4340
let ident_t_global = generate_at_one(cx);
4441

45-
let init_ty = cx.type_func(&[], cx.type_void());
46-
let init_rtls = declare_offload_fn(cx, "__tgt_init_all_rtls", init_ty);
47-
4842
// We want LLVM's openmp-opt pass to pick up and optimize this module, since it covers both
4943
// openmp and offload optimizations.
5044
llvm::add_module_flag_u32(cx.llmod(), llvm::ModuleFlagMergeBehavior::Max, "openmp", 51);
@@ -58,7 +52,6 @@ impl<'ll> OffloadGlobals<'ll> {
5852
end_mapper,
5953
mapper_fn_ty,
6054
ident_t_global,
61-
init_rtls,
6255
}
6356
}
6457
}
@@ -91,6 +84,11 @@ pub(crate) fn register_offload<'ll>(cx: &CodegenCx<'ll, '_>) {
9184
let atexit = cx.type_func(&[cx.type_ptr()], cx.type_i32());
9285
let atexit_fn = declare_offload_fn(cx, "atexit", atexit);
9386

87+
// FIXME(offload): Drop this, once we fully automated our offload compilation pipeline, since
88+
// LLVM will initialize them for us if it sees gpu kernels being registered.
89+
let init_ty = cx.type_func(&[], cx.type_void());
90+
let init_rtls = declare_offload_fn(cx, "__tgt_init_all_rtls", init_ty);
91+
9492
let desc_ty = cx.type_func(&[], cx.type_void());
9593
let reg_name = ".omp_offloading.descriptor_reg";
9694
let unreg_name = ".omp_offloading.descriptor_unreg";
@@ -104,12 +102,14 @@ pub(crate) fn register_offload<'ll>(cx: &CodegenCx<'ll, '_>) {
104102
// define internal void @.omp_offloading.descriptor_reg() section ".text.startup" {
105103
// entry:
106104
// call void @__tgt_register_lib(ptr @.omp_offloading.descriptor)
105+
// call void @__tgt_init_all_rtls()
107106
// %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
108107
// ret void
109108
// }
110109
let bb = Builder::append_block(cx, desc_reg_fn, "entry");
111110
let mut a = Builder::build(cx, bb);
112111
a.call(reg_lib_decl, None, None, register_lib, &[omp_descriptor], None, None);
112+
a.call(init_ty, None, None, init_rtls, &[], None, None);
113113
a.call(atexit, None, None, atexit_fn, &[desc_unreg_fn], None, None);
114114
a.ret_void();
115115

@@ -345,7 +345,9 @@ impl KernelArgsTy {
345345
#[derive(Copy, Clone)]
346346
pub(crate) struct OffloadKernelGlobals<'ll> {
347347
pub offload_sizes: &'ll llvm::Value,
348-
pub memtransfer_types: &'ll llvm::Value,
348+
pub memtransfer_begin: &'ll llvm::Value,
349+
pub memtransfer_kernel: &'ll llvm::Value,
350+
pub memtransfer_end: &'ll llvm::Value,
349351
pub region_id: &'ll llvm::Value,
350352
}
351353

@@ -423,18 +425,38 @@ pub(crate) fn gen_define_handling<'ll>(
423425

424426
let offload_entry_ty = offload_globals.offload_entry_ty;
425427

426-
// FIXME(Sa4dUs): add `OMP_MAP_TARGET_PARAM = 0x20` only if necessary
427428
let (sizes, transfer): (Vec<_>, Vec<_>) =
428-
metadata.iter().map(|m| (m.payload_size, m.mode.bits() | 0x20)).unzip();
429+
metadata.iter().map(|m| (m.payload_size, m.mode)).unzip();
430+
// Our begin mapper should only see simplified information about which args have to be
431+
// transferred to the device, the end mapper only about which args should be transferred back.
432+
// Any information beyond that makes it harder for LLVM's opt pass to evaluate whether it can
433+
// safely move (=optimize) the LLVM-IR location of this data transfer. Only the mapping types
434+
// mentioned below are handled, so make sure that we don't generate any other ones.
435+
let handled_mappings = MappingFlags::TO
436+
| MappingFlags::FROM
437+
| MappingFlags::TARGET_PARAM
438+
| MappingFlags::LITERAL
439+
| MappingFlags::IMPLICIT;
440+
for arg in &transfer {
441+
debug_assert!(!arg.contains_unknown_bits());
442+
debug_assert!(handled_mappings.contains(*arg));
443+
}
444+
445+
let valid_begin_mappings = MappingFlags::TO | MappingFlags::LITERAL | MappingFlags::IMPLICIT;
446+
let transfer_to: Vec<u64> =
447+
transfer.iter().map(|m| m.intersection(valid_begin_mappings).bits()).collect();
448+
let transfer_from: Vec<u64> =
449+
transfer.iter().map(|m| m.intersection(MappingFlags::FROM).bits()).collect();
450+
// FIXME(offload): add `OMP_MAP_TARGET_PARAM = 0x20` only if necessary
451+
let transfer_kernel = vec![MappingFlags::TARGET_PARAM.bits(); transfer_to.len()];
429452

430453
let offload_sizes = add_priv_unnamed_arr(&cx, &format!(".offload_sizes.{symbol}"), &sizes);
431-
// Here we figure out whether something needs to be copied to the gpu (=1), from the gpu (=2),
432-
// or both to and from the gpu (=3). Other values shouldn't affect us for now.
433-
// A non-mutable reference or pointer will be 1, an array that's not read, but fully overwritten
434-
// will be 2. For now, everything is 3, until we have our frontend set up.
435-
// 1+2+32: 1 (MapTo), 2 (MapFrom), 32 (Add one extra input ptr per function, to be used later).
436-
let memtransfer_types =
437-
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}"), &transfer);
454+
let memtransfer_begin =
455+
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}.begin"), &transfer_to);
456+
let memtransfer_kernel =
457+
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}.kernel"), &transfer_kernel);
458+
let memtransfer_end =
459+
add_priv_unnamed_arr(&cx, &format!(".offload_maptypes.{symbol}.end"), &transfer_from);
438460

439461
// Next: For each function, generate these three entries. A weak constant,
440462
// the llvm.rodata entry name, and the llvm_offload_entries value
@@ -469,7 +491,13 @@ pub(crate) fn gen_define_handling<'ll>(
469491

470492
cx.add_compiler_used_global(offload_entry);
471493

472-
let result = OffloadKernelGlobals { offload_sizes, memtransfer_types, region_id };
494+
let result = OffloadKernelGlobals {
495+
offload_sizes,
496+
memtransfer_begin,
497+
memtransfer_kernel,
498+
memtransfer_end,
499+
region_id,
500+
};
473501

474502
// FIXME(Sa4dUs): use this global for constant offload sizes
475503
cx.add_compiler_used_global(result.offload_sizes);
@@ -535,7 +563,13 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>(
535563
offload_dims: &OffloadKernelDims<'ll>,
536564
) {
537565
let cx = builder.cx;
538-
let OffloadKernelGlobals { memtransfer_types, region_id, .. } = offload_data;
566+
let OffloadKernelGlobals {
567+
memtransfer_begin,
568+
memtransfer_kernel,
569+
memtransfer_end,
570+
region_id,
571+
..
572+
} = offload_data;
539573
let OffloadKernelDims { num_workgroups, threads_per_block, workgroup_dims, thread_dims } =
540574
offload_dims;
541575

@@ -608,12 +642,6 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>(
608642
geps.push(gep);
609643
}
610644

611-
let init_ty = cx.type_func(&[], cx.type_void());
612-
let init_rtls_decl = offload_globals.init_rtls;
613-
614-
// call void @__tgt_init_all_rtls()
615-
builder.call(init_ty, None, None, init_rtls_decl, &[], None, None);
616-
617645
for i in 0..num_args {
618646
let idx = cx.get_const_i32(i);
619647
let gep1 = builder.inbounds_gep(ty, a1, &[i32_0, idx]);
@@ -668,14 +696,14 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>(
668696
generate_mapper_call(
669697
builder,
670698
geps,
671-
memtransfer_types,
699+
memtransfer_begin,
672700
begin_mapper_decl,
673701
fn_ty,
674702
num_args,
675703
s_ident_t,
676704
);
677705
let values =
678-
KernelArgsTy::new(&cx, num_args, memtransfer_types, geps, workgroup_dims, thread_dims);
706+
KernelArgsTy::new(&cx, num_args, memtransfer_kernel, geps, workgroup_dims, thread_dims);
679707

680708
// Step 3)
681709
// Here we fill the KernelArgsTy, see the documentation above
@@ -701,7 +729,7 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>(
701729
generate_mapper_call(
702730
builder,
703731
geps,
704-
memtransfer_types,
732+
memtransfer_end,
705733
end_mapper_decl,
706734
fn_ty,
707735
num_args,

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![allow(internal_features)]
1111
#![allow(rustc::default_hash_types)]
1212
#![allow(rustc::potential_query_instability)]
13+
#![cfg_attr(bootstrap, feature(cold_path))]
1314
#![deny(unsafe_op_in_unsafe_fn)]
1415
#![feature(allocator_api)]
1516
#![feature(ascii_char)]
@@ -19,7 +20,6 @@
1920
#![feature(cfg_select)]
2021
#![feature(const_default)]
2122
#![feature(const_trait_impl)]
22-
#![feature(core_intrinsics)]
2323
#![feature(dropck_eyepatch)]
2424
#![feature(extend_one)]
2525
#![feature(file_buffered)]

compiler/rustc_data_structures/src/profiling.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ use std::borrow::Borrow;
8585
use std::collections::hash_map::Entry;
8686
use std::error::Error;
8787
use std::fmt::Display;
88-
use std::intrinsics::unlikely;
8988
use std::path::Path;
9089
use std::sync::Arc;
9190
use std::sync::atomic::Ordering;
9291
use std::time::{Duration, Instant};
93-
use std::{fs, process};
92+
use std::{fs, hint, process};
9493

9594
pub use measureme::EventId;
9695
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
@@ -427,7 +426,8 @@ impl SelfProfilerRef {
427426
.unwrap()
428427
.increment_query_cache_hit_counters(QueryInvocationId(query_invocation_id.0));
429428
}
430-
if unlikely(profiler_ref.event_filter_mask.contains(EventFilter::QUERY_CACHE_HITS)) {
429+
if profiler_ref.event_filter_mask.contains(EventFilter::QUERY_CACHE_HITS) {
430+
hint::cold_path();
431431
profiler_ref.instant_query_event(
432432
|profiler| profiler.query_cache_hit_event_kind,
433433
query_invocation_id,
@@ -437,7 +437,8 @@ impl SelfProfilerRef {
437437

438438
// We check both kinds of query cache hit events at once, to reduce overhead in the
439439
// common case (with self-profile disabled).
440-
if unlikely(self.event_filter_mask.intersects(EventFilter::QUERY_CACHE_HIT_COMBINED)) {
440+
if self.event_filter_mask.intersects(EventFilter::QUERY_CACHE_HIT_COMBINED) {
441+
hint::cold_path();
441442
cold_call(self, query_invocation_id);
442443
}
443444
}

compiler/rustc_data_structures/src/sync/freeze.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::cell::UnsafeCell;
2-
use std::intrinsics::likely;
2+
use std::hint;
33
use std::marker::PhantomData;
44
use std::ops::{Deref, DerefMut};
55
use std::ptr::NonNull;
@@ -60,10 +60,11 @@ impl<T> FreezeLock<T> {
6060
/// Get the inner value if frozen.
6161
#[inline]
6262
pub fn get(&self) -> Option<&T> {
63-
if likely(self.frozen.load(Ordering::Acquire)) {
63+
if self.frozen.load(Ordering::Acquire) {
6464
// SAFETY: This is frozen so the data cannot be modified.
6565
unsafe { Some(&*self.data.get()) }
6666
} else {
67+
hint::cold_path();
6768
None
6869
}
6970
}

0 commit comments

Comments
 (0)