Skip to content

Rollup of 8 pull requests #138516

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

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
86492fa
Emit function declarations for functions with #[linkage="extern_weak"]
1c3t3a Mar 11, 2025
6f214c5
Fix pluralization of tests
Kobzol Mar 13, 2025
208cef4
Add note about the experimental status
Kobzol Mar 13, 2025
2192d5c
Print the compared SHAs
Kobzol Mar 13, 2025
7ed913b
Add cache for downloading job metrics
Kobzol Mar 13, 2025
5a7f227
Collapse report in `<details>`
Kobzol Mar 13, 2025
d5d633d
Group diffs by tests, rather than job groups
Kobzol Mar 13, 2025
f981a0a
Do not print doctest diffs in the report
Kobzol Mar 13, 2025
e885122
Add a pretty printing test for fn params.
nnethercote Mar 12, 2025
c437178
Create libgccjit.so.0 alias also for CI-downloaded GCC
Kobzol Mar 12, 2025
955aef5
Change GCC build flags
Kobzol Mar 12, 2025
3fc7ca0
Use GCC for building GCC
Kobzol Mar 13, 2025
34272a5
Do not overwrite original `config.toml` in `opt-dist`
Kobzol Mar 13, 2025
38fc116
Store libgccjit.so in a lib directory in the GCC CI tarball
Kobzol Mar 13, 2025
9714f60
Inline and remove `FnParam::name`.
nnethercote Mar 13, 2025
958bc7b
Handle `_` properly in a couple of places.
nnethercote Mar 13, 2025
bebd91f
Fix HIR param pretty printing some more.
nnethercote Mar 13, 2025
79e4be1
Remove the ref from `FnParam::Ident`.
nnethercote Mar 13, 2025
d989bf5
rustc_target: Add target features for LoongArch v1.1
heiher Mar 5, 2025
aad1db7
Pass precise HirId when calling check_stability
xizheyin Mar 13, 2025
6ef465b
Add clarification about doctests
Kobzol Mar 14, 2025
bf095f6
Ensure that GCC is not built using Clang, as it misbehaves
Kobzol Mar 14, 2025
9e3805d
Mirror NetBSD sources
Kobzol Mar 14, 2025
66c49c7
Make `Parser::parse_expr_cond` public.
mohe2015 Mar 14, 2025
1a33473
Rollup merge of #138056 - heiher:loong64v1.1-features, r=petrochenkov
fmease Mar 14, 2025
fce0c7a
Rollup merge of #138349 - 1c3t3a:external-weak-cfi, r=rcvalle
fmease Mar 14, 2025
93647cf
Rollup merge of #138451 - Kobzol:gcc-ci-build-gcc, r=GuillaumeGomez
fmease Mar 14, 2025
2d99c88
Rollup merge of #138454 - Kobzol:post-merge-workflow-fixes, r=jieyouxu
fmease Mar 14, 2025
f64f517
Rollup merge of #138460 - xizheyin:issue-138319, r=petrochenkov
fmease Mar 14, 2025
2b5ce07
Rollup merge of #138482 - nnethercote:fix-hir-printing, r=compiler-er…
fmease Mar 14, 2025
ed39d31
Rollup merge of #138507 - Kobzol:netbsd-mirror, r=Mark-Simulacrum
fmease Mar 14, 2025
5472e59
Rollup merge of #138511 - mohe2015:rustc-parse-pub-parse-expr-cond, r…
fmease Mar 14, 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
7 changes: 6 additions & 1 deletion .github/workflows/post-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ jobs:
cd src/ci/citool
echo "Post-merge analysis result" > output.log
printf "*This is an experimental post-merge analysis report. You can ignore it.*\n\n" > output.log
printf "<details>\n<summary>Post-merge report</summary>\n\n" >> output.log
cargo run --release post-merge-report ${PARENT_COMMIT} ${{ github.sha }} >> output.log
printf "</details>\n" >> output.log
cat output.log
gh pr comment ${HEAD_PR} -F output.log
9 changes: 8 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
PatKind::Ident(_, ident, _) => self.lower_ident(ident),
_ => Ident::new(kw::Empty, self.lower_span(param.pat.span)),
PatKind::Wild => Ident::new(kw::Underscore, self.lower_span(param.pat.span)),
_ => {
self.dcx().span_delayed_bug(
param.pat.span,
"non-ident/wild param pat must trigger an error",
);
Ident::new(kw::Empty, self.lower_span(param.pat.span))
}
}))
}

Expand Down
28 changes: 24 additions & 4 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use rustc_abi::{
};
use rustc_codegen_ssa::common;
use rustc_codegen_ssa::traits::*;
use rustc_hir::LangItem;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::interpret::{
Allocation, ConstAllocation, ErrorHandled, InitChunk, Pointer, Scalar as InterpScalar,
read_target_uint,
};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::Instance;
use rustc_middle::mir::mono::{Linkage, MonoItem};
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
use rustc_middle::ty::{self, Instance};
use rustc_middle::{bug, span_bug};
use tracing::{debug, instrument, trace};

Expand Down Expand Up @@ -171,8 +172,27 @@ fn check_and_apply_linkage<'ll, 'tcx>(
if let Some(linkage) = attrs.import_linkage {
debug!("get_static: sym={} linkage={:?}", sym, linkage);

// Declare a symbol `foo` with the desired linkage.
let g1 = cx.declare_global(sym, cx.type_i8());
// Declare a symbol `foo`. If `foo` is an extern_weak symbol, we declare
// an extern_weak function, otherwise a global with the desired linkage.
let g1 = if matches!(attrs.import_linkage, Some(Linkage::ExternalWeak)) {
// An `extern_weak` function is represented as an `Option<unsafe extern ...>`,
// we extract the function signature and declare it as an extern_weak function
// instead of an extern_weak i8.
let instance = Instance::mono(cx.tcx, def_id);
if let ty::Adt(struct_def, args) = instance.ty(cx.tcx, cx.typing_env()).kind()
&& cx.tcx.is_lang_item(struct_def.did(), LangItem::Option)
&& let ty::FnPtr(sig, header) = args.type_at(0).kind()
{
let fn_sig = sig.with(*header);

let fn_abi = cx.fn_abi_of_fn_ptr(fn_sig, ty::List::empty());
cx.declare_fn(sym, &fn_abi, None)
} else {
cx.declare_global(sym, cx.type_i8())
}
} else {
cx.declare_global(sym, cx.type_i8())
};
llvm::set_linkage(g1, base::linkage_to_llvm(linkage));

// Declare an internal global `extern_with_linkage_foo` which
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,9 +2148,11 @@ impl<'a> State<'a> {
s.print_implicit_self(&decl.implicit_self);
} else {
if let Some(arg_name) = arg_names.get(i) {
s.word(arg_name.to_string());
s.word(":");
s.space();
if arg_name.name != kw::Empty {
s.word(arg_name.to_string());
s.word(":");
s.space();
}
} else if let Some(body_id) = body_id {
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
s.word(":");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// struct-like enums (yet...), but it's definitely not
// a bug to have constructed one.
if adt_kind != AdtKind::Enum {
tcx.check_stability(v_field.did, Some(expr.hir_id), field.span, None);
tcx.check_stability(v_field.did, Some(field.hir_id), field.span, None);
}

self.field_ty(field.span, v_field, args)
Expand Down
40 changes: 23 additions & 17 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_session::Session;
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_span::{DUMMY_SP, Ident, Span, kw, sym};
use rustc_trait_selection::error_reporting::infer::{FailureCode, ObligationCauseExt};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt, SelectionContext};
Expand Down Expand Up @@ -2679,7 +2679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
params.get(is_method as usize..params.len() - sig.decl.c_variadic as usize)?;
debug_assert_eq!(params.len(), fn_inputs.len());
Some((
fn_inputs.zip(params.iter().map(|param| FnParam::Name(param))).collect(),
fn_inputs.zip(params.iter().map(|&param| FnParam::Name(param))).collect(),
generics,
))
}
Expand Down Expand Up @@ -2710,32 +2710,38 @@ impl<'tcx> Visitor<'tcx> for FindClosureArg<'tcx> {
#[derive(Clone, Copy)]
enum FnParam<'hir> {
Param(&'hir hir::Param<'hir>),
Name(&'hir Ident),
Name(Ident),
}

impl FnParam<'_> {
fn span(&self) -> Span {
match self {
Self::Param(x) => x.span,
Self::Name(x) => x.span,
}
}

fn name(&self) -> Option<Symbol> {
match self {
Self::Param(x) if let hir::PatKind::Binding(_, _, ident, _) = x.pat.kind => {
Some(ident.name)
}
Self::Name(x) if x.name != kw::Empty => Some(x.name),
_ => None,
Self::Param(param) => param.span,
Self::Name(ident) => ident.span,
}
}

fn display(&self, idx: usize) -> impl '_ + fmt::Display {
struct D<'a>(FnParam<'a>, usize);
impl fmt::Display for D<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(name) = self.0.name() {
write!(f, "`{name}`")
// A "unique" param name is one that (a) exists, and (b) is guaranteed to be unique
// among the parameters, i.e. `_` does not count.
let unique_name = match self.0 {
FnParam::Param(param)
if let hir::PatKind::Binding(_, _, ident, _) = param.pat.kind =>
{
Some(ident.name)
}
FnParam::Name(ident)
if ident.name != kw::Empty && ident.name != kw::Underscore =>
{
Some(ident.name)
}
_ => None,
};
if let Some(unique_name) = unique_name {
write!(f, "`{unique_name}`")
} else {
write!(f, "parameter #{}", self.1 + 1)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

self.tcx.check_stability(
variant.fields[FieldIdx::from_usize(i)].did,
Some(pat.hir_id),
Some(subpat.hir_id),
subpat.span,
None,
);
Expand Down Expand Up @@ -1686,7 +1686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.get(&ident)
.map(|(i, f)| {
self.write_field_index(field.hir_id, *i);
self.tcx.check_stability(f.did, Some(pat.hir_id), span, None);
self.tcx.check_stability(f.did, Some(field.hir_id), span, None);
self.field_ty(span, f, args)
})
.unwrap_or_else(|| {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn hir_body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> {
self.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
self.hir_body(id).params.iter().map(|param| match param.pat.kind {
PatKind::Binding(_, _, ident, _) => ident,
PatKind::Wild => Ident::new(kw::Underscore, param.pat.span),
_ => Ident::empty(),
})
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,8 @@ impl<'a> Parser<'a> {
}

/// Parses the condition of a `if` or `while` expression.
fn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>> {
// Public because it is used in rustfmt forks such as https://github.com/tucant/rustfmt/blob/30c83df9e1db10007bdd16dafce8a86b404329b2/src/parse/macros/html.rs#L57 for custom if expressions.
pub fn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>> {
let attrs = self.parse_outer_attributes()?;
let (mut cond, _) =
self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, attrs)?;
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,18 @@ static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("d", Unstable(sym::loongarch_target_feature), &["f"]),
("div32", Unstable(sym::loongarch_target_feature), &[]),
("f", Unstable(sym::loongarch_target_feature), &[]),
("frecipe", Unstable(sym::loongarch_target_feature), &[]),
("lam-bh", Unstable(sym::loongarch_target_feature), &[]),
("lamcas", Unstable(sym::loongarch_target_feature), &[]),
("lasx", Unstable(sym::loongarch_target_feature), &["lsx"]),
("lbt", Unstable(sym::loongarch_target_feature), &[]),
("ld-seq-sa", Unstable(sym::loongarch_target_feature), &[]),
("lsx", Unstable(sym::loongarch_target_feature), &["d"]),
("lvz", Unstable(sym::loongarch_target_feature), &[]),
("relax", Unstable(sym::loongarch_target_feature), &[]),
("scq", Unstable(sym::loongarch_target_feature), &[]),
("ual", Unstable(sym::loongarch_target_feature), &[]),
// tidy-alphabetical-end
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.iter()
.enumerate()
.map(|(i, ident)| {
if ident.name.is_empty() || ident.name == kw::SelfLower {
if ident.name.is_empty()
|| ident.name == kw::Underscore
|| ident.name == kw::SelfLower
{
format!("arg{i}")
} else {
format!("{ident}")
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,7 @@ impl Step for Gcc {
fn run(self, builder: &Builder<'_>) -> Self::Output {
let tarball = Tarball::new(builder, "gcc", &self.target.triple);
let output = builder.ensure(super::gcc::Gcc { target: self.target });
tarball.add_file(output.libgccjit, ".", 0o644);
tarball.add_file(output.libgccjit, "lib", 0o644);
tarball.generate()
}
}
38 changes: 24 additions & 14 deletions src/bootstrap/src/core/build_steps/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,23 @@ impl Step for Gcc {
}

build_gcc(&metadata, builder, target);

let lib_alias = metadata.install_dir.join("lib/libgccjit.so.0");
if !lib_alias.exists() {
t!(builder.symlink_file(&libgccjit_path, lib_alias));
}
create_lib_alias(builder, &libgccjit_path);

t!(metadata.stamp.write());

GccOutput { libgccjit: libgccjit_path }
}
}

/// Creates a libgccjit.so.0 alias next to libgccjit.so if it does not
/// already exist
fn create_lib_alias(builder: &Builder<'_>, libgccjit: &PathBuf) {
let lib_alias = libgccjit.parent().unwrap().join("libgccjit.so.0");
if !lib_alias.exists() {
t!(builder.symlink_file(libgccjit, lib_alias));
}
}

pub struct Meta {
stamp: BuildStamp,
out_dir: PathBuf,
Expand Down Expand Up @@ -109,8 +114,10 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
builder.config.download_ci_gcc(&sha, &root);
t!(gcc_stamp.write());
}
// FIXME: put libgccjit.so into a lib directory in dist::Gcc
Some(root.join("libgccjit.so"))

let libgccjit = root.join("lib").join("libgccjit.so");
create_lib_alias(builder, &libgccjit);
Some(libgccjit)
}

#[cfg(test)]
Expand Down Expand Up @@ -177,6 +184,14 @@ fn libgccjit_built_path(install_dir: &Path) -> PathBuf {
}

fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
if builder.build.cc_tool(target).is_like_clang()
|| builder.build.cxx_tool(target).is_like_clang()
{
panic!(
"Attempting to build GCC using Clang, which is known to misbehave. Please use GCC as the host C/C++ compiler. "
);
}

let Meta { stamp: _, out_dir, install_dir, root } = metadata;

t!(fs::create_dir_all(out_dir));
Expand All @@ -203,18 +218,13 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
let mut configure_cmd = command(src_dir.join("configure"));
configure_cmd
.current_dir(out_dir)
// On CI, we compile GCC with Clang.
// The -Wno-everything flag is needed to make GCC compile with Clang 19.
// `-g -O2` are the default flags that are otherwise used by Make.
// FIXME(kobzol): change the flags once we have [gcc] configuration in config.toml.
.env("CXXFLAGS", "-Wno-everything -g -O2")
.env("CFLAGS", "-Wno-everything -g -O2")
.arg("--enable-host-shared")
.arg("--enable-languages=jit")
.arg("--enable-languages=c,jit,lto")
.arg("--enable-checking=release")
.arg("--disable-bootstrap")
.arg("--disable-multilib")
.arg(format!("--prefix={}", install_dir.display()));

let cc = builder.build.cc(target).display().to_string();
let cc = builder
.build
Expand Down
11 changes: 11 additions & 0 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{env, fs, io, str};

use build_helper::ci::gha;
use build_helper::exit;
use cc::Tool;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::build_stamp::BuildStamp;
use utils::channel::GitInfo;
Expand Down Expand Up @@ -1218,6 +1219,16 @@ Executed at: {executed_at}"#,
self.cc.borrow()[&target].path().into()
}

/// Returns the internal `cc::Tool` for the C compiler.
fn cc_tool(&self, target: TargetSelection) -> Tool {
self.cc.borrow()[&target].clone()
}

/// Returns the internal `cc::Tool` for the C++ compiler.
fn cxx_tool(&self, target: TargetSelection) -> Tool {
self.cxx.borrow()[&target].clone()
}

/// Returns C flags that `cc-rs` thinks should be enabled for the
/// specified target by default.
fn cc_handled_clags(&self, target: TargetSelection, c: CLang) -> Vec<String> {
Expand Down
Loading
Loading