Skip to content

Commit f485f5a

Browse files
committed
Merge remote-tracking branch 'origin' into mingw-split
2 parents 0a084e3 + 2cf7908 commit f485f5a

File tree

51 files changed

+1419
-199
lines changed

Some content is hidden

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

51 files changed

+1419
-199
lines changed

Cargo.lock

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,9 +1965,9 @@ checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
19651965

19661966
[[package]]
19671967
name = "libc"
1968-
version = "0.2.161"
1968+
version = "0.2.164"
19691969
source = "registry+https://github.com/rust-lang/crates.io-index"
1970-
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
1970+
checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f"
19711971

19721972
[[package]]
19731973
name = "libdbus-sys"
@@ -3685,6 +3685,8 @@ version = "0.0.0"
36853685
dependencies = [
36863686
"rustc_data_structures",
36873687
"rustc_span",
3688+
"serde",
3689+
"serde_json",
36883690
]
36893691

36903692
[[package]]
@@ -3988,6 +3990,7 @@ name = "rustc_metadata"
39883990
version = "0.0.0"
39893991
dependencies = [
39903992
"bitflags 2.6.0",
3993+
"libc",
39913994
"libloading",
39923995
"odht",
39933996
"rustc_abi",

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,24 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
209209
}
210210
}
211211

212+
pub fn is_single_vector_element<C>(self, cx: &C, expected_size: Size) -> bool
213+
where
214+
Ty: TyAbiInterface<'a, C>,
215+
C: HasDataLayout,
216+
{
217+
match self.backend_repr {
218+
BackendRepr::Vector { .. } => self.size == expected_size,
219+
BackendRepr::Memory { .. } => {
220+
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
221+
self.field(cx, 0).is_single_vector_element(cx, expected_size)
222+
} else {
223+
false
224+
}
225+
}
226+
_ => false,
227+
}
228+
}
229+
212230
pub fn is_adt<C>(self) -> bool
213231
where
214232
Ty: TyAbiInterface<'a, C>,

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,14 +777,24 @@ fn link_natively(
777777
info!("preparing {:?} to {:?}", crate_type, out_filename);
778778
let (linker_path, flavor) = linker_and_flavor(sess);
779779
let self_contained_components = self_contained_components(sess, crate_type);
780+
781+
// On AIX, we ship all libraries as .a big_af archive
782+
// the expected format is lib<name>.a(libname.so) for the actual
783+
// dynamic library. So we link to a temporary .so file to be archived
784+
// at the final out_filename location
785+
let should_archive = crate_type != CrateType::Executable && sess.target.is_like_aix;
786+
let archive_member =
787+
should_archive.then(|| tmpdir.join(out_filename.file_name().unwrap()).with_extension("so"));
788+
let temp_filename = archive_member.as_deref().unwrap_or(out_filename);
789+
780790
let mut cmd = linker_with_args(
781791
&linker_path,
782792
flavor,
783793
sess,
784794
archive_builder_builder,
785795
crate_type,
786796
tmpdir,
787-
out_filename,
797+
temp_filename,
788798
codegen_results,
789799
self_contained_components,
790800
)?;
@@ -1158,6 +1168,12 @@ fn link_natively(
11581168
}
11591169
}
11601170

1171+
if should_archive {
1172+
let mut ab = archive_builder_builder.new_archive_builder(sess);
1173+
ab.add_file(temp_filename);
1174+
ab.build(out_filename);
1175+
}
1176+
11611177
Ok(())
11621178
}
11631179

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fs::File;
55
use std::io::Write;
66
use std::path::Path;
77

8+
use itertools::Itertools;
89
use object::write::{self, StandardSegment, Symbol, SymbolSection};
910
use object::{
1011
Architecture, BinaryFormat, Endianness, FileFlags, Object, ObjectSection, ObjectSymbol,
@@ -21,6 +22,7 @@ use rustc_middle::bug;
2122
use rustc_session::Session;
2223
use rustc_span::sym;
2324
use rustc_target::spec::{RelocModel, Target, ef_avr_arch};
25+
use tracing::debug;
2426

2527
use super::apple;
2628

@@ -53,6 +55,7 @@ fn load_metadata_with(
5355

5456
impl MetadataLoader for DefaultMetadataLoader {
5557
fn get_rlib_metadata(&self, target: &Target, path: &Path) -> Result<OwnedSlice, String> {
58+
debug!("getting rlib metadata for {}", path.display());
5659
load_metadata_with(path, |data| {
5760
let archive = object::read::archive::ArchiveFile::parse(&*data)
5861
.map_err(|e| format!("failed to parse rlib '{}': {}", path.display(), e))?;
@@ -77,8 +80,26 @@ impl MetadataLoader for DefaultMetadataLoader {
7780
}
7881

7982
fn get_dylib_metadata(&self, target: &Target, path: &Path) -> Result<OwnedSlice, String> {
83+
debug!("getting dylib metadata for {}", path.display());
8084
if target.is_like_aix {
81-
load_metadata_with(path, |data| get_metadata_xcoff(path, data))
85+
load_metadata_with(path, |data| {
86+
let archive = object::read::archive::ArchiveFile::parse(&*data).map_err(|e| {
87+
format!("failed to parse aix dylib '{}': {}", path.display(), e)
88+
})?;
89+
90+
match archive.members().exactly_one() {
91+
Ok(lib) => {
92+
let lib = lib.map_err(|e| {
93+
format!("failed to parse aix dylib '{}': {}", path.display(), e)
94+
})?;
95+
let data = lib.data(data).map_err(|e| {
96+
format!("failed to parse aix dylib '{}': {}", path.display(), e)
97+
})?;
98+
get_metadata_xcoff(path, data)
99+
}
100+
Err(e) => Err(format!("failed to parse aix dylib '{}': {}", path.display(), e)),
101+
}
102+
})
82103
} else {
83104
load_metadata_with(path, |data| search_for_section(path, data, ".rustc"))
84105
}

compiler/rustc_driver_impl/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ driver_impl_rlink_rustc_version_mismatch = .rlink file was produced by rustc ver
2323
driver_impl_rlink_unable_to_read = failed to read rlink file: `{$err}`
2424
2525
driver_impl_rlink_wrong_file_type = The input does not look like a .rlink file
26+
27+
driver_impl_unstable_feature_usage = cannot dump feature usage metrics: {$error}

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use rustc_interface::{Linker, Queries, interface, passes};
5151
use rustc_lint::unerased_lint_store;
5252
use rustc_metadata::creader::MetadataLoader;
5353
use rustc_metadata::locator;
54+
use rustc_middle::ty::TyCtxt;
5455
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
5556
use rustc_session::config::{
5657
CG_OPTIONS, ErrorOutputType, Input, OutFileName, OutputType, UnstableOptions, Z_OPTIONS,
@@ -103,7 +104,7 @@ mod signal_handler {
103104

104105
use crate::session_diagnostics::{
105106
RLinkEmptyVersionNumber, RLinkEncodingVersionMismatch, RLinkRustcVersionMismatch,
106-
RLinkWrongFileType, RlinkCorruptFile, RlinkNotAFile, RlinkUnableToRead,
107+
RLinkWrongFileType, RlinkCorruptFile, RlinkNotAFile, RlinkUnableToRead, UnstableFeatureUsage,
107108
};
108109

109110
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
@@ -431,6 +432,10 @@ fn run_compiler(
431432
// Make sure name resolution and macro expansion is run.
432433
queries.global_ctxt()?.enter(|tcx| tcx.resolver_for_lowering());
433434

435+
if let Some(metrics_dir) = &sess.opts.unstable_opts.metrics_dir {
436+
queries.global_ctxt()?.enter(|tcxt| dump_feature_usage_metrics(tcxt, metrics_dir));
437+
}
438+
434439
if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
435440
return early_exit();
436441
}
@@ -475,6 +480,23 @@ fn run_compiler(
475480
})
476481
}
477482

483+
fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &PathBuf) {
484+
let output_filenames = tcxt.output_filenames(());
485+
let mut metrics_file_name = std::ffi::OsString::from("unstable_feature_usage_metrics-");
486+
let mut metrics_path = output_filenames.with_directory_and_extension(metrics_dir, "json");
487+
let metrics_file_stem =
488+
metrics_path.file_name().expect("there should be a valid default output filename");
489+
metrics_file_name.push(metrics_file_stem);
490+
metrics_path.pop();
491+
metrics_path.push(metrics_file_name);
492+
if let Err(error) = tcxt.features().dump_feature_usage_metrics(metrics_path) {
493+
// FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
494+
// default metrics" to only produce a warning when metrics are enabled by default and emit
495+
// an error only when the user manually enables metrics
496+
tcxt.dcx().emit_err(UnstableFeatureUsage { error });
497+
}
498+
}
499+
478500
// Extract output directory and file from matches.
479501
fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileName>) {
480502
let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o));

compiler/rustc_driver_impl/src/session_diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::error::Error;
2+
13
use rustc_macros::{Diagnostic, Subdiagnostic};
24

35
#[derive(Diagnostic)]
@@ -93,3 +95,9 @@ pub(crate) struct IceFlags {
9395
#[derive(Diagnostic)]
9496
#[diag(driver_impl_ice_exclude_cargo_defaults)]
9597
pub(crate) struct IceExcludeCargoDefaults;
98+
99+
#[derive(Diagnostic)]
100+
#[diag(driver_impl_unstable_feature_usage)]
101+
pub(crate) struct UnstableFeatureUsage {
102+
pub error: Box<dyn Error>,
103+
}

compiler/rustc_feature/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ edition = "2021"
77
# tidy-alphabetical-start
88
rustc_data_structures = { path = "../rustc_data_structures" }
99
rustc_span = { path = "../rustc_span" }
10+
serde = { version = "1.0.125", features = [ "derive" ] }
11+
serde_json = "1.0.59"
1012
# tidy-alphabetical-end

compiler/rustc_feature/src/unstable.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! List of the unstable feature gates.
22
3+
use std::path::PathBuf;
4+
35
use rustc_data_structures::fx::FxHashSet;
46
use rustc_span::Span;
57
use rustc_span::symbol::{Symbol, sym};
@@ -651,6 +653,54 @@ declare_features! (
651653
// -------------------------------------------------------------------------
652654
);
653655

656+
impl Features {
657+
pub fn dump_feature_usage_metrics(
658+
&self,
659+
metrics_path: PathBuf,
660+
) -> Result<(), Box<dyn std::error::Error>> {
661+
#[derive(serde::Serialize)]
662+
struct LibFeature {
663+
symbol: String,
664+
}
665+
666+
#[derive(serde::Serialize)]
667+
struct LangFeature {
668+
symbol: String,
669+
since: Option<String>,
670+
}
671+
672+
#[derive(serde::Serialize)]
673+
struct FeatureUsage {
674+
lib_features: Vec<LibFeature>,
675+
lang_features: Vec<LangFeature>,
676+
}
677+
678+
let metrics_file = std::fs::File::create(metrics_path)?;
679+
let metrics_file = std::io::BufWriter::new(metrics_file);
680+
681+
let lib_features = self
682+
.enabled_lib_features
683+
.iter()
684+
.map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
685+
.collect();
686+
687+
let lang_features = self
688+
.enabled_lang_features
689+
.iter()
690+
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
691+
symbol: gate_name.to_string(),
692+
since: stable_since.map(|since| since.to_string()),
693+
})
694+
.collect();
695+
696+
let feature_usage = FeatureUsage { lib_features, lang_features };
697+
698+
serde_json::to_writer(metrics_file, &feature_usage)?;
699+
700+
Ok(())
701+
}
702+
}
703+
654704
/// Some features are not allowed to be used together at the same time, if
655705
/// the two are present, produce an error.
656706
///

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_span::symbol::{Ident, kw, sym};
3131
use rustc_span::{
3232
DUMMY_SP, ErrorGuaranteed, ExpnKind, FileName, MacroKind, Span, Symbol, edit_distance,
3333
};
34+
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
3435
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedNote;
3536
use rustc_trait_selection::infer::InferCtxtExt;
3637
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
@@ -45,50 +46,6 @@ use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
4546
use crate::{Expectation, FnCtxt};
4647

4748
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
48-
fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
49-
let tcx = self.tcx;
50-
match ty.kind() {
51-
// Not all of these (e.g., unsafe fns) implement `FnOnce`,
52-
// so we look for these beforehand.
53-
// FIXME(async_closures): These don't impl `FnOnce` by default.
54-
ty::Closure(..) | ty::FnDef(..) | ty::FnPtr(..) => true,
55-
// If it's not a simple function, look for things which implement `FnOnce`.
56-
_ => {
57-
let Some(fn_once) = tcx.lang_items().fn_once_trait() else {
58-
return false;
59-
};
60-
61-
// This conditional prevents us from asking to call errors and unresolved types.
62-
// It might seem that we can use `predicate_must_hold_modulo_regions`,
63-
// but since a Dummy binder is used to fill in the FnOnce trait's arguments,
64-
// type resolution always gives a "maybe" here.
65-
if self.autoderef(span, ty).silence_errors().any(|(ty, _)| {
66-
info!("check deref {:?} error", ty);
67-
matches!(ty.kind(), ty::Error(_) | ty::Infer(_))
68-
}) {
69-
return false;
70-
}
71-
72-
self.autoderef(span, ty).silence_errors().any(|(ty, _)| {
73-
info!("check deref {:?} impl FnOnce", ty);
74-
self.probe(|_| {
75-
let trait_ref =
76-
ty::TraitRef::new(tcx, fn_once, [ty, self.next_ty_var(span)]);
77-
let poly_trait_ref = ty::Binder::dummy(trait_ref);
78-
let obligation = Obligation::misc(
79-
tcx,
80-
span,
81-
self.body_id,
82-
self.param_env,
83-
poly_trait_ref,
84-
);
85-
self.predicate_may_hold(&obligation)
86-
})
87-
})
88-
}
89-
}
90-
}
91-
9249
fn is_slice_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
9350
self.autoderef(span, ty)
9451
.silence_errors()
@@ -2367,12 +2324,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23672324
let is_accessible = field.vis.is_accessible_from(scope, tcx);
23682325

23692326
if is_accessible {
2370-
if self.is_fn_ty(field_ty, span) {
2327+
if let Some((what, _, _)) = self.extract_callable_info(field_ty) {
2328+
let what = match what {
2329+
DefIdOrName::DefId(def_id) => self.tcx.def_descr(def_id),
2330+
DefIdOrName::Name(what) => what,
2331+
};
23712332
let expr_span = expr.span.to(item_name.span);
23722333
err.multipart_suggestion(
23732334
format!(
2374-
"to call the function stored in `{item_name}`, \
2375-
surround the field access with parentheses",
2335+
"to call the {what} stored in `{item_name}`, \
2336+
surround the field access with parentheses",
23762337
),
23772338
vec![
23782339
(expr_span.shrink_to_lo(), '('.to_string()),

compiler/rustc_metadata/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9+
libc = "0.2"
910
libloading = "0.8.0"
1011
odht = { version = "0.3.1", features = ["nightly"] }
1112
rustc_abi = { path = "../rustc_abi" }

0 commit comments

Comments
 (0)