Skip to content

Commit eed187c

Browse files
committed
Auto merge of #144528 - matthiaskrgr:rollup-felcjc1, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #144226 (Do not assert layout in KnownPanicsLint.) - #144385 (Optimize performance by inline in macro hygiene system) - #144454 (move uefi test to run-make) - #144455 (Unify LLVM ctlz/cttz intrinsic generation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 86ef320 + dd6e4a9 commit eed187c

Some content is hidden

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

42 files changed

+275
-399
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -382,26 +382,16 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
382382
let width = size.bits();
383383
let llty = self.type_ix(width);
384384
match name {
385-
sym::ctlz | sym::cttz => {
386-
let y = self.const_bool(false);
387-
let ret = self.call_intrinsic(
388-
format!("llvm.{name}"),
389-
&[llty],
390-
&[args[0].immediate(), y],
391-
);
392-
393-
self.intcast(ret, result.layout.llvm_type(self), false)
394-
}
395-
sym::ctlz_nonzero => {
396-
let y = self.const_bool(true);
397-
let ret =
398-
self.call_intrinsic("llvm.ctlz", &[llty], &[args[0].immediate(), y]);
399-
self.intcast(ret, result.layout.llvm_type(self), false)
400-
}
401-
sym::cttz_nonzero => {
402-
let y = self.const_bool(true);
385+
sym::ctlz | sym::ctlz_nonzero | sym::cttz | sym::cttz_nonzero => {
386+
let y =
387+
self.const_bool(name == sym::ctlz_nonzero || name == sym::cttz_nonzero);
388+
let llvm_name = if name == sym::ctlz || name == sym::ctlz_nonzero {
389+
"llvm.ctlz"
390+
} else {
391+
"llvm.cttz"
392+
};
403393
let ret =
404-
self.call_intrinsic("llvm.cttz", &[llty], &[args[0].immediate(), y]);
394+
self.call_intrinsic(llvm_name, &[llty], &[args[0].immediate(), y]);
405395
self.intcast(ret, result.layout.llvm_type(self), false)
406396
}
407397
sym::ctpop => {

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
767767
DefKind::Static { .. } => {
768768
check_static_inhabited(tcx, def_id);
769769
check_static_linkage(tcx, def_id);
770-
res = res.and(wfcheck::check_static_item(tcx, def_id));
770+
let ty = tcx.type_of(def_id).instantiate_identity();
771+
res = res.and(wfcheck::check_static_item(tcx, def_id, ty, true));
771772
}
772773
DefKind::Const => res = res.and(wfcheck::check_const_item(tcx, def_id)),
773774
_ => unreachable!(),

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,12 +1180,13 @@ fn check_item_fn(
11801180
}
11811181

11821182
#[instrument(level = "debug", skip(tcx))]
1183-
pub(super) fn check_static_item(
1184-
tcx: TyCtxt<'_>,
1183+
pub(crate) fn check_static_item<'tcx>(
1184+
tcx: TyCtxt<'tcx>,
11851185
item_id: LocalDefId,
1186+
ty: Ty<'tcx>,
1187+
should_check_for_sync: bool,
11861188
) -> Result<(), ErrorGuaranteed> {
11871189
enter_wf_checking_ctxt(tcx, item_id, |wfcx| {
1188-
let ty = tcx.type_of(item_id).instantiate_identity();
11891190
let span = tcx.ty_span(item_id);
11901191
let item_ty = wfcx.deeply_normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
11911192

@@ -1212,9 +1213,9 @@ pub(super) fn check_static_item(
12121213
}
12131214

12141215
// Ensure that the end result is `Sync` in a non-thread local `static`.
1215-
let should_check_for_sync = tcx.static_mutability(item_id.to_def_id())
1216-
== Some(hir::Mutability::Not)
1216+
let should_check_for_sync = should_check_for_sync
12171217
&& !is_foreign_item
1218+
&& tcx.static_mutability(item_id.to_def_id()) == Some(hir::Mutability::Not)
12181219
&& !tcx.is_thread_local_static(item_id.to_def_id());
12191220

12201221
if should_check_for_sync {

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::{bug, span_bug};
1414
use rustc_span::{DUMMY_SP, Ident, Span};
1515

1616
use super::{HirPlaceholderCollector, ItemCtxt, bad_placeholder};
17+
use crate::check::wfcheck::check_static_item;
1718
use crate::errors::TypeofReservedKeywordUsed;
1819
use crate::hir_ty_lowering::HirTyLowerer;
1920

@@ -217,7 +218,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
217218
"static variable",
218219
)
219220
} else {
220-
icx.lower_ty(ty)
221+
let ty = icx.lower_ty(ty);
222+
// MIR relies on references to statics being scalars.
223+
// Verify that here to avoid ill-formed MIR.
224+
match check_static_item(tcx, def_id, ty, false) {
225+
Ok(()) => ty,
226+
Err(guar) => Ty::new_error(tcx, guar),
227+
}
221228
}
222229
}
223230
ItemKind::Const(ident, _, ty, body_id) => {
@@ -275,7 +282,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
275282
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
276283
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
277284
}
278-
ForeignItemKind::Static(t, _, _) => icx.lower_ty(t),
285+
ForeignItemKind::Static(ty, _, _) => {
286+
let ty = icx.lower_ty(ty);
287+
// MIR relies on references to statics being scalars.
288+
// Verify that here to avoid ill-formed MIR.
289+
match check_static_item(tcx, def_id, ty, false) {
290+
Ok(()) => ty,
291+
Err(guar) => Ty::new_error(tcx, guar),
292+
}
293+
}
279294
ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()),
280295
},
281296

compiler/rustc_span/src/hygiene.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ impl ExpnId {
322322

323323
/// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than
324324
/// `expn_id.is_descendant_of(ctxt.outer_expn())`.
325+
#[inline]
325326
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
326327
HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt)))
327328
}
@@ -394,6 +395,7 @@ impl HygieneData {
394395
}
395396
}
396397

398+
#[inline]
397399
fn with<R>(f: impl FnOnce(&mut HygieneData) -> R) -> R {
398400
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
399401
}
@@ -406,6 +408,7 @@ impl HygieneData {
406408
}
407409
}
408410

411+
#[inline]
409412
fn local_expn_data(&self, expn_id: LocalExpnId) -> &ExpnData {
410413
self.local_expn_data[expn_id].as_ref().expect("no expansion data for an expansion ID")
411414
}
@@ -437,23 +440,28 @@ impl HygieneData {
437440
}
438441
}
439442

443+
#[inline]
440444
fn normalize_to_macros_2_0(&self, ctxt: SyntaxContext) -> SyntaxContext {
441445
self.syntax_context_data[ctxt.0 as usize].opaque
442446
}
443447

448+
#[inline]
444449
fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext {
445450
self.syntax_context_data[ctxt.0 as usize].opaque_and_semiopaque
446451
}
447452

453+
#[inline]
448454
fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId {
449455
self.syntax_context_data[ctxt.0 as usize].outer_expn
450456
}
451457

458+
#[inline]
452459
fn outer_mark(&self, ctxt: SyntaxContext) -> (ExpnId, Transparency) {
453460
let data = &self.syntax_context_data[ctxt.0 as usize];
454461
(data.outer_expn, data.outer_transparency)
455462
}
456463

464+
#[inline]
457465
fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
458466
self.syntax_context_data[ctxt.0 as usize].parent
459467
}
@@ -718,11 +726,13 @@ impl SyntaxContext {
718726
SyntaxContext(raw as u32)
719727
}
720728

729+
#[inline]
721730
fn from_usize(raw: usize) -> SyntaxContext {
722731
SyntaxContext(u32::try_from(raw).unwrap())
723732
}
724733

725734
/// Extend a syntax context with a given expansion and transparency.
735+
#[inline]
726736
pub fn apply_mark(self, expn_id: ExpnId, transparency: Transparency) -> SyntaxContext {
727737
HygieneData::with(|data| data.apply_mark(self, expn_id, transparency))
728738
}
@@ -743,10 +753,12 @@ impl SyntaxContext {
743753
/// of g (call it g1), calling remove_mark will result in the SyntaxContext for the
744754
/// invocation of f that created g1.
745755
/// Returns the mark that was removed.
756+
#[inline]
746757
pub fn remove_mark(&mut self) -> ExpnId {
747758
HygieneData::with(|data| data.remove_mark(self).0)
748759
}
749760

761+
#[inline]
750762
pub fn marks(self) -> Vec<(ExpnId, Transparency)> {
751763
HygieneData::with(|data| data.marks(self))
752764
}
@@ -776,11 +788,13 @@ impl SyntaxContext {
776788
/// ```
777789
/// This returns the expansion whose definition scope we use to privacy check the resolution,
778790
/// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
791+
#[inline]
779792
pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
780793
HygieneData::with(|data| data.adjust(self, expn_id))
781794
}
782795

783796
/// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0.
797+
#[inline]
784798
pub(crate) fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
785799
HygieneData::with(|data| {
786800
*self = data.normalize_to_macros_2_0(*self);
@@ -901,10 +915,12 @@ impl SyntaxContext {
901915
HygieneData::with(|data| data.outer_mark(self))
902916
}
903917

918+
#[inline]
904919
pub(crate) fn dollar_crate_name(self) -> Symbol {
905920
HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name)
906921
}
907922

923+
#[inline]
908924
pub fn edition(self) -> Edition {
909925
HygieneData::with(|data| data.expn_data(data.outer_expn(self)).edition)
910926
}

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ where
167167
}
168168
}
169169

170+
#[inline]
170171
pub fn with_session_globals<R, F>(f: F) -> R
171172
where
172173
F: FnOnce(&SessionGlobals) -> R,

src/ci/docker/host-x86_64/test-various/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ ENV MUSL_TARGETS=x86_64-unknown-linux-musl \
7979
CXX_x86_64_unknown_linux_musl=x86_64-linux-musl-g++
8080
ENV MUSL_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $MUSL_TARGETS
8181

82-
COPY host-x86_64/test-various/uefi_qemu_test /uefi_qemu_test
8382
ENV UEFI_TARGETS=aarch64-unknown-uefi,i686-unknown-uefi,x86_64-unknown-uefi \
8483
CC_aarch64_unknown_uefi=clang-11 \
8584
CXX_aarch64_unknown_uefi=clang++-11 \
@@ -88,6 +87,8 @@ ENV UEFI_TARGETS=aarch64-unknown-uefi,i686-unknown-uefi,x86_64-unknown-uefi \
8887
CC_x86_64_unknown_uefi=clang-11 \
8988
CXX_x86_64_unknown_uefi=clang++-11
9089
ENV UEFI_SCRIPT python3 /checkout/x.py --stage 2 build --host='' --target $UEFI_TARGETS && \
91-
python3 -u /uefi_qemu_test/run.py
90+
python3 /checkout/x.py --stage 2 test tests/run-make/uefi-qemu/rmake.rs --target aarch64-unknown-uefi && \
91+
python3 /checkout/x.py --stage 2 test tests/run-make/uefi-qemu/rmake.rs --target i686-unknown-uefi && \
92+
python3 /checkout/x.py --stage 2 test tests/run-make/uefi-qemu/rmake.rs --target x86_64-unknown-uefi
9293

9394
ENV SCRIPT $WASM_SCRIPT && $NVPTX_SCRIPT && $MUSL_SCRIPT && $UEFI_SCRIPT

src/ci/docker/host-x86_64/test-various/uefi_qemu_test/run.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/tools/compiletest/src/directives.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
992992
"only-stable",
993993
"only-thumb",
994994
"only-tvos",
995+
"only-uefi",
995996
"only-unix",
996997
"only-visionos",
997998
"only-wasm32",

0 commit comments

Comments
 (0)