Skip to content

Commit a37bfa4

Browse files
committed
Auto merge of rust-lang#136506 - matthiaskrgr:rollup-4ku9gdr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#134807 (fix(rustdoc): always use a channel when linking to doc.rust-lang.org) - rust-lang#134814 (Add `kl` and `widekl` target features, and the feature gate) - rust-lang#135836 (bootstrap: only build `crt{begin,end}.o` when compiling to MUSL) - rust-lang#136022 (Port ui/simd tests to use the intrinsic macro) - rust-lang#136309 (set rustc dylib on manually constructed rustc command) - rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros) - rust-lang#136462 (mir_build: Simplify `lower_pattern_range_endpoint`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents affdb59 + 9bd6a06 commit a37bfa4

File tree

82 files changed

+729
-471
lines changed

Some content is hidden

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

82 files changed

+729
-471
lines changed

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ declare_features! (
529529
(unstable, inline_const_pat, "1.58.0", Some(76001)),
530530
/// Allows using `pointer` and `reference` in intra-doc links
531531
(unstable, intra_doc_pointers, "1.51.0", Some(80896)),
532+
// Allows using the `kl` and `widekl` target features and the associated intrinsics
533+
(unstable, keylocker_x86, "CURRENT_RUSTC_VERSION", Some(134813)),
532534
// Allows setting the threshold for the `large_assignments` lint.
533535
(unstable, large_assignments, "1.52.0", Some(83518)),
534536
/// Allow to have type alias types for inter-crate use.

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+42-39
Original file line numberDiff line numberDiff line change
@@ -155,42 +155,41 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
155155
fn lower_pattern_range_endpoint(
156156
&mut self,
157157
expr: Option<&'tcx hir::PatExpr<'tcx>>,
158-
) -> Result<
159-
(Option<PatRangeBoundary<'tcx>>, Option<Ascription<'tcx>>, Option<LocalDefId>),
160-
ErrorGuaranteed,
161-
> {
162-
match expr {
163-
None => Ok((None, None, None)),
164-
Some(expr) => {
165-
let (kind, ascr, inline_const) = match self.lower_lit(expr) {
166-
PatKind::ExpandedConstant { subpattern, def_id, is_inline: true } => {
167-
(subpattern.kind, None, def_id.as_local())
168-
}
169-
PatKind::ExpandedConstant { subpattern, is_inline: false, .. } => {
170-
(subpattern.kind, None, None)
171-
}
172-
PatKind::AscribeUserType { ascription, subpattern: box Pat { kind, .. } } => {
173-
(kind, Some(ascription), None)
174-
}
175-
kind => (kind, None, None),
176-
};
177-
let value = match kind {
178-
PatKind::Constant { value } => value,
179-
PatKind::ExpandedConstant { subpattern, .. }
180-
if let PatKind::Constant { value } = subpattern.kind =>
181-
{
182-
value
183-
}
184-
_ => {
185-
let msg = format!(
186-
"found bad range pattern endpoint `{expr:?}` outside of error recovery"
187-
);
188-
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
158+
// Out-parameters collecting extra data to be reapplied by the caller
159+
ascriptions: &mut Vec<Ascription<'tcx>>,
160+
inline_consts: &mut Vec<LocalDefId>,
161+
) -> Result<Option<PatRangeBoundary<'tcx>>, ErrorGuaranteed> {
162+
let Some(expr) = expr else { return Ok(None) };
163+
164+
// Lower the endpoint into a temporary `PatKind` that will then be
165+
// deconstructed to obtain the constant value and other data.
166+
let mut kind: PatKind<'tcx> = self.lower_lit(expr);
167+
168+
// Unpeel any ascription or inline-const wrapper nodes.
169+
loop {
170+
match kind {
171+
PatKind::AscribeUserType { ascription, subpattern } => {
172+
ascriptions.push(ascription);
173+
kind = subpattern.kind;
174+
}
175+
PatKind::ExpandedConstant { is_inline, def_id, subpattern } => {
176+
if is_inline {
177+
inline_consts.extend(def_id.as_local());
189178
}
190-
};
191-
Ok((Some(PatRangeBoundary::Finite(value)), ascr, inline_const))
179+
kind = subpattern.kind;
180+
}
181+
_ => break,
192182
}
193183
}
184+
185+
// The unpeeled kind should now be a constant, giving us the endpoint value.
186+
let PatKind::Constant { value } = kind else {
187+
let msg =
188+
format!("found bad range pattern endpoint `{expr:?}` outside of error recovery");
189+
return Err(self.tcx.dcx().span_delayed_bug(expr.span, msg));
190+
};
191+
192+
Ok(Some(PatRangeBoundary::Finite(value)))
194193
}
195194

196195
/// Overflowing literals are linted against in a late pass. This is mostly fine, except when we
@@ -253,11 +252,15 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
253252
self.tcx.dcx().span_bug(span, msg);
254253
}
255254

256-
let (lo, lo_ascr, lo_inline) = self.lower_pattern_range_endpoint(lo_expr)?;
257-
let (hi, hi_ascr, hi_inline) = self.lower_pattern_range_endpoint(hi_expr)?;
255+
// Collect extra data while lowering the endpoints, to be reapplied later.
256+
let mut ascriptions = vec![];
257+
let mut inline_consts = vec![];
258+
259+
let mut lower_endpoint =
260+
|expr| self.lower_pattern_range_endpoint(expr, &mut ascriptions, &mut inline_consts);
258261

259-
let lo = lo.unwrap_or(PatRangeBoundary::NegInfinity);
260-
let hi = hi.unwrap_or(PatRangeBoundary::PosInfinity);
262+
let lo = lower_endpoint(lo_expr)?.unwrap_or(PatRangeBoundary::NegInfinity);
263+
let hi = lower_endpoint(hi_expr)?.unwrap_or(PatRangeBoundary::PosInfinity);
261264

262265
let cmp = lo.compare_with(hi, ty, self.tcx, self.typing_env);
263266
let mut kind = PatKind::Range(Box::new(PatRange { lo, hi, end, ty }));
@@ -298,13 +301,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
298301
// If we are handling a range with associated constants (e.g.
299302
// `Foo::<'a>::A..=Foo::B`), we need to put the ascriptions for the associated
300303
// constants somewhere. Have them on the range pattern.
301-
for ascription in [lo_ascr, hi_ascr].into_iter().flatten() {
304+
for ascription in ascriptions {
302305
kind = PatKind::AscribeUserType {
303306
ascription,
304307
subpattern: Box::new(Pat { span, ty, kind }),
305308
};
306309
}
307-
for def in [lo_inline, hi_inline].into_iter().flatten() {
310+
for def in inline_consts {
308311
kind = PatKind::ExpandedConstant {
309312
def_id: def.to_def_id(),
310313
is_inline: true,

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ symbols! {
11481148
iterator,
11491149
iterator_collect_fn,
11501150
kcfi,
1151+
keylocker_x86,
11511152
keyword,
11521153
kind,
11531154
kreg,

compiler/rustc_target/src/target_features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
409409
("fma", Stable, &["avx"]),
410410
("fxsr", Stable, &[]),
411411
("gfni", Unstable(sym::avx512_target_feature), &["sse2"]),
412+
("kl", Unstable(sym::keylocker_x86), &["sse2"]),
412413
("lahfsahf", Unstable(sym::lahfsahf_target_feature), &[]),
413414
("lzcnt", Stable, &[]),
414415
("movbe", Stable, &[]),
@@ -435,6 +436,7 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
435436
("tbm", Unstable(sym::tbm_target_feature), &[]),
436437
("vaes", Unstable(sym::avx512_target_feature), &["avx2", "aes"]),
437438
("vpclmulqdq", Unstable(sym::avx512_target_feature), &["avx", "pclmulqdq"]),
439+
("widekl", Unstable(sym::keylocker_x86), &["kl"]),
438440
("x87", Unstable(sym::x87_target_feature), &[]),
439441
("xop", Unstable(sym::xop_target_feature), &[/*"fma4", */ "avx", "sse4a"]),
440442
("xsave", Stable, &[]),

src/bootstrap/src/bin/main.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use std::str::FromStr;
1111
use std::{env, process};
1212

1313
use bootstrap::{
14-
Build, CONFIG_CHANGE_HISTORY, Config, Flags, Subcommand, find_recent_config_change_ids,
14+
Build, CONFIG_CHANGE_HISTORY, Config, Flags, Subcommand, debug, find_recent_config_change_ids,
1515
human_readable_changes, t,
1616
};
1717
use build_helper::ci::CiEnv;
1818
#[cfg(feature = "tracing")]
19-
use tracing::{debug, instrument};
19+
use tracing::instrument;
2020

2121
#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "main"))]
2222
fn main() {
@@ -29,10 +29,8 @@ fn main() {
2929
return;
3030
}
3131

32-
#[cfg(feature = "tracing")]
3332
debug!("parsing flags");
3433
let flags = Flags::parse(&args);
35-
#[cfg(feature = "tracing")]
3634
debug!("parsing config based on flags");
3735
let config = Config::parse(flags);
3836

@@ -95,7 +93,6 @@ fn main() {
9593
let dump_bootstrap_shims = config.dump_bootstrap_shims;
9694
let out_dir = config.out.clone();
9795

98-
#[cfg(feature = "tracing")]
9996
debug!("creating new build based on config");
10097
Build::new(config).build();
10198

@@ -207,8 +204,9 @@ fn check_version(config: &Config) -> Option<String> {
207204
// Due to the conditional compilation via the `tracing` cargo feature, this means that `tracing`
208205
// usages in bootstrap need to be also gated behind the `tracing` feature:
209206
//
210-
// - `tracing` macros (like `trace!`) and anything from `tracing`, `tracing_subscriber` and
211-
// `tracing-tree` will need to be gated by `#[cfg(feature = "tracing")]`.
207+
// - `tracing` macros with log levels (`trace!`, `debug!`, `warn!`, `info`, `error`) should not be
208+
// used *directly*. You should use the wrapped `tracing` macros which gate the actual invocations
209+
// behind `feature = "tracing"`.
212210
// - `tracing`'s `#[instrument(..)]` macro will need to be gated like `#![cfg_attr(feature =
213211
// "tracing", instrument(..))]`.
214212
#[cfg(feature = "tracing")]

src/bootstrap/src/core/build_steps/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn copy_self_contained_objects(
339339
// to using gcc from a glibc-targeting toolchain for linking.
340340
// To do that we have to distribute musl startup objects as a part of Rust toolchain
341341
// and link with them manually in the self-contained mode.
342-
if target.contains("musl") && !target.contains("unikraft") {
342+
if target.needs_crt_begin_end() {
343343
let srcdir = builder.musl_libdir(target).unwrap_or_else(|| {
344344
panic!("Target {:?} does not have a \"musl-libdir\" key", target.triple)
345345
});

src/bootstrap/src/core/build_steps/llvm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,9 @@ impl Step for CrtBeginEnd {
12951295
}
12961296

12971297
fn make_run(run: RunConfig<'_>) {
1298-
run.builder.ensure(CrtBeginEnd { target: run.target });
1298+
if run.target.needs_crt_begin_end() {
1299+
run.builder.ensure(CrtBeginEnd { target: run.target });
1300+
}
12991301
}
13001302

13011303
/// Build crtbegin.o/crtend.o for musl target.

src/bootstrap/src/core/builder/cargo.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,18 @@ impl Builder<'_> {
659659
// Build proc macros both for the host and the target unless proc-macros are not
660660
// supported by the target.
661661
if target != compiler.host && cmd_kind != Kind::Check {
662-
let error = command(self.rustc(compiler))
662+
let mut rustc_cmd = command(self.rustc(compiler));
663+
self.add_rustc_lib_path(compiler, &mut rustc_cmd);
664+
665+
let error = rustc_cmd
663666
.arg("--target")
664667
.arg(target.rustc_target_arg())
665668
.arg("--print=file-names")
666669
.arg("--crate-type=proc-macro")
667670
.arg("-")
668671
.run_capture(self)
669672
.stderr();
673+
670674
let not_supported = error
671675
.lines()
672676
.any(|line| line.contains("unsupported crate type `proc-macro`"));

src/bootstrap/src/core/config/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ impl TargetSelection {
575575
env::var("OSTYPE").is_ok_and(|v| v.to_lowercase().contains("cygwin"))
576576
}
577577

578+
pub fn needs_crt_begin_end(&self) -> bool {
579+
self.contains("musl") && !self.contains("unikraft")
580+
}
581+
578582
/// Path to the file defining the custom target, if any.
579583
pub fn filepath(&self) -> Option<&Path> {
580584
self.file.as_ref().map(Path::new)

src/bootstrap/src/lib.rs

+43-44
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ use std::{env, fs, io, str};
2828
use build_helper::ci::gha;
2929
use build_helper::exit;
3030
use termcolor::{ColorChoice, StandardStream, WriteColor};
31-
#[cfg(feature = "tracing")]
32-
use tracing::{debug, instrument, span, trace};
3331
use utils::build_stamp::BuildStamp;
3432
use utils::channel::GitInfo;
3533

@@ -46,6 +44,8 @@ pub use core::builder::PathSet;
4644
pub use core::config::Config;
4745
pub use core::config::flags::{Flags, Subcommand};
4846

47+
#[cfg(feature = "tracing")]
48+
use tracing::{instrument, span};
4949
pub use utils::change_tracker::{
5050
CONFIG_CHANGE_HISTORY, find_recent_config_change_ids, human_readable_changes,
5151
};
@@ -541,72 +541,71 @@ impl Build {
541541
/// Executes the entire build, as configured by the flags and configuration.
542542
#[cfg_attr(feature = "tracing", instrument(level = "debug", name = "Build::build", skip_all))]
543543
pub fn build(&mut self) {
544-
#[cfg(feature = "tracing")]
545544
trace!("setting up job management");
546545
unsafe {
547546
crate::utils::job::setup(self);
548547
}
549548

550-
#[cfg(feature = "tracing")]
551-
trace!("downloading rustfmt early");
552-
553549
// Download rustfmt early so that it can be used in rust-analyzer configs.
550+
trace!("downloading rustfmt early");
554551
let _ = &builder::Builder::new(self).initial_rustfmt();
555552

556-
#[cfg(feature = "tracing")]
557-
let hardcoded_span =
558-
span!(tracing::Level::DEBUG, "handling hardcoded subcommands (Format, Suggest, Perf)")
559-
.entered();
560-
561-
// hardcoded subcommands
562-
match &self.config.cmd {
563-
Subcommand::Format { check, all } => {
564-
return core::build_steps::format::format(
565-
&builder::Builder::new(self),
566-
*check,
567-
*all,
568-
&self.config.paths,
569-
);
570-
}
571-
Subcommand::Suggest { run } => {
572-
return core::build_steps::suggest::suggest(&builder::Builder::new(self), *run);
573-
}
574-
Subcommand::Perf { .. } => {
575-
return core::build_steps::perf::perf(&builder::Builder::new(self));
576-
}
577-
_cmd => {
578-
#[cfg(feature = "tracing")]
579-
debug!(cmd = ?_cmd, "not a hardcoded subcommand; returning to normal handling");
553+
// Handle hard-coded subcommands.
554+
{
555+
#[cfg(feature = "tracing")]
556+
let _hardcoded_span = span!(
557+
tracing::Level::DEBUG,
558+
"handling hardcoded subcommands (Format, Suggest, Perf)"
559+
)
560+
.entered();
561+
562+
match &self.config.cmd {
563+
Subcommand::Format { check, all } => {
564+
return core::build_steps::format::format(
565+
&builder::Builder::new(self),
566+
*check,
567+
*all,
568+
&self.config.paths,
569+
);
570+
}
571+
Subcommand::Suggest { run } => {
572+
return core::build_steps::suggest::suggest(&builder::Builder::new(self), *run);
573+
}
574+
Subcommand::Perf { .. } => {
575+
return core::build_steps::perf::perf(&builder::Builder::new(self));
576+
}
577+
_cmd => {
578+
debug!(cmd = ?_cmd, "not a hardcoded subcommand; returning to normal handling");
579+
}
580580
}
581-
}
582581

583-
#[cfg(feature = "tracing")]
584-
drop(hardcoded_span);
585-
#[cfg(feature = "tracing")]
586-
debug!("handling subcommand normally");
582+
debug!("handling subcommand normally");
583+
}
587584

588585
if !self.config.dry_run() {
589586
#[cfg(feature = "tracing")]
590587
let _real_run_span = span!(tracing::Level::DEBUG, "executing real run").entered();
591588

589+
// We first do a dry-run. This is a sanity-check to ensure that
590+
// steps don't do anything expensive in the dry-run.
592591
{
593592
#[cfg(feature = "tracing")]
594593
let _sanity_check_span =
595594
span!(tracing::Level::DEBUG, "(1) executing dry-run sanity-check").entered();
596-
597-
// We first do a dry-run. This is a sanity-check to ensure that
598-
// steps don't do anything expensive in the dry-run.
599595
self.config.dry_run = DryRun::SelfCheck;
600596
let builder = builder::Builder::new(self);
601597
builder.execute_cli();
602598
}
603599

604-
#[cfg(feature = "tracing")]
605-
let _actual_run_span =
606-
span!(tracing::Level::DEBUG, "(2) executing actual run").entered();
607-
self.config.dry_run = DryRun::Disabled;
608-
let builder = builder::Builder::new(self);
609-
builder.execute_cli();
600+
// Actual run.
601+
{
602+
#[cfg(feature = "tracing")]
603+
let _actual_run_span =
604+
span!(tracing::Level::DEBUG, "(2) executing actual run").entered();
605+
self.config.dry_run = DryRun::Disabled;
606+
let builder = builder::Builder::new(self);
607+
builder.execute_cli();
608+
}
610609
} else {
611610
#[cfg(feature = "tracing")]
612611
let _dry_run_span = span!(tracing::Level::DEBUG, "executing dry run").entered();

src/bootstrap/src/utils/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub(crate) mod render_tests;
1414
pub(crate) mod shared_helpers;
1515
pub(crate) mod tarball;
1616

17+
pub(crate) mod tracing;
18+
1719
#[cfg(feature = "build-metrics")]
1820
pub(crate) mod metrics;
1921

0 commit comments

Comments
 (0)