Skip to content

Commit 4c0f500

Browse files
committed
Auto merge of rust-lang#109547 - matthiaskrgr:rollup-zczqgdk, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#108629 (rustdoc: add support for type filters in arguments and generics) - rust-lang#108924 (panic_immediate_abort requires abort as a panic strategy) - rust-lang#108961 (Refine error spans for const args in hir typeck) - rust-lang#108986 (sync LVI tests) - rust-lang#109142 (Add block-based mutex unlocking example) - rust-lang#109368 (fix typo in the creation of OpenOption for RustyHermit) - rust-lang#109493 (Return nested obligations from canonical response var unification) - rust-lang#109515 (Add AixLinker to support linking on AIX) - rust-lang#109536 (resolve: Rename some cstore methods to match queries and add comments) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cf073ec + 4d21d30 commit 4c0f500

Some content is hidden

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

48 files changed

+718
-290
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+174
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ pub fn get_linker<'a>(
133133
LinkerFlavor::Unix(Cc::No) if sess.target.os == "l4re" => {
134134
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>
135135
}
136+
LinkerFlavor::Unix(Cc::No) if sess.target.os == "aix" => {
137+
Box::new(AixLinker::new(cmd, sess)) as Box<dyn Linker>
138+
}
136139
LinkerFlavor::WasmLld(Cc::No) => Box::new(WasmLd::new(cmd, sess)) as Box<dyn Linker>,
137140
LinkerFlavor::Gnu(cc, _)
138141
| LinkerFlavor::Darwin(cc, _)
@@ -1474,6 +1477,177 @@ impl<'a> L4Bender<'a> {
14741477
}
14751478
}
14761479

1480+
/// Linker for AIX.
1481+
pub struct AixLinker<'a> {
1482+
cmd: Command,
1483+
sess: &'a Session,
1484+
hinted_static: bool,
1485+
}
1486+
1487+
impl<'a> AixLinker<'a> {
1488+
pub fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
1489+
AixLinker { cmd: cmd, sess: sess, hinted_static: false }
1490+
}
1491+
1492+
fn hint_static(&mut self) {
1493+
if !self.hinted_static {
1494+
self.cmd.arg("-bstatic");
1495+
self.hinted_static = true;
1496+
}
1497+
}
1498+
1499+
fn hint_dynamic(&mut self) {
1500+
if self.hinted_static {
1501+
self.cmd.arg("-bdynamic");
1502+
self.hinted_static = false;
1503+
}
1504+
}
1505+
1506+
fn build_dylib(&mut self, _out_filename: &Path) {
1507+
self.cmd.arg("-bM:SRE");
1508+
self.cmd.arg("-bnoentry");
1509+
// FIXME: Use CreateExportList utility to create export list
1510+
// and remove -bexpfull.
1511+
self.cmd.arg("-bexpfull");
1512+
}
1513+
}
1514+
1515+
impl<'a> Linker for AixLinker<'a> {
1516+
fn link_dylib(&mut self, lib: &str, _verbatim: bool, _as_needed: bool) {
1517+
self.hint_dynamic();
1518+
self.cmd.arg(format!("-l{}", lib));
1519+
}
1520+
1521+
fn link_staticlib(&mut self, lib: &str, _verbatim: bool) {
1522+
self.hint_static();
1523+
self.cmd.arg(format!("-l{}", lib));
1524+
}
1525+
1526+
fn link_rlib(&mut self, lib: &Path) {
1527+
self.hint_static();
1528+
self.cmd.arg(lib);
1529+
}
1530+
1531+
fn include_path(&mut self, path: &Path) {
1532+
self.cmd.arg("-L").arg(path);
1533+
}
1534+
1535+
fn framework_path(&mut self, _: &Path) {
1536+
bug!("frameworks are not supported on AIX");
1537+
}
1538+
1539+
fn output_filename(&mut self, path: &Path) {
1540+
self.cmd.arg("-o").arg(path);
1541+
}
1542+
1543+
fn add_object(&mut self, path: &Path) {
1544+
self.cmd.arg(path);
1545+
}
1546+
1547+
fn full_relro(&mut self) {}
1548+
1549+
fn partial_relro(&mut self) {}
1550+
1551+
fn no_relro(&mut self) {}
1552+
1553+
fn cmd(&mut self) -> &mut Command {
1554+
&mut self.cmd
1555+
}
1556+
1557+
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
1558+
match output_kind {
1559+
LinkOutputKind::DynamicDylib => {
1560+
self.hint_dynamic();
1561+
self.build_dylib(out_filename);
1562+
}
1563+
LinkOutputKind::StaticDylib => {
1564+
self.hint_static();
1565+
self.build_dylib(out_filename);
1566+
}
1567+
_ => {}
1568+
}
1569+
}
1570+
1571+
fn link_rust_dylib(&mut self, lib: &str, _: &Path) {
1572+
self.hint_dynamic();
1573+
self.cmd.arg(format!("-l{}", lib));
1574+
}
1575+
1576+
fn link_framework(&mut self, _framework: &str, _as_needed: bool) {
1577+
bug!("frameworks not supported on AIX");
1578+
}
1579+
1580+
fn link_whole_staticlib(&mut self, lib: &str, verbatim: bool, search_path: &[PathBuf]) {
1581+
self.hint_static();
1582+
let lib = find_native_static_library(lib, verbatim, search_path, &self.sess);
1583+
self.cmd.arg(format!("-bkeepfile:{}", lib.to_str().unwrap()));
1584+
}
1585+
1586+
fn link_whole_rlib(&mut self, lib: &Path) {
1587+
self.hint_static();
1588+
self.cmd.arg(format!("-bkeepfile:{}", lib.to_str().unwrap()));
1589+
}
1590+
1591+
fn gc_sections(&mut self, _keep_metadata: bool) {
1592+
self.cmd.arg("-bgc");
1593+
}
1594+
1595+
fn no_gc_sections(&mut self) {
1596+
self.cmd.arg("-bnogc");
1597+
}
1598+
1599+
fn optimize(&mut self) {}
1600+
1601+
fn pgo_gen(&mut self) {}
1602+
1603+
fn control_flow_guard(&mut self) {}
1604+
1605+
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
1606+
match strip {
1607+
Strip::None => {}
1608+
// FIXME: -s strips the symbol table, line number information
1609+
// and relocation information.
1610+
Strip::Debuginfo | Strip::Symbols => {
1611+
self.cmd.arg("-s");
1612+
}
1613+
}
1614+
}
1615+
1616+
fn no_crt_objects(&mut self) {}
1617+
1618+
fn no_default_libraries(&mut self) {}
1619+
1620+
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
1621+
let path = tmpdir.join("list.exp");
1622+
let res: io::Result<()> = try {
1623+
let mut f = BufWriter::new(File::create(&path)?);
1624+
// TODO: use llvm-nm to generate export list.
1625+
for symbol in symbols {
1626+
debug!(" _{}", symbol);
1627+
writeln!(f, " {}", symbol)?;
1628+
}
1629+
};
1630+
if let Err(e) = res {
1631+
self.sess.fatal(&format!("failed to write export file: {}", e));
1632+
}
1633+
self.cmd.arg(format!("-bE:{}", path.to_str().unwrap()));
1634+
}
1635+
1636+
fn subsystem(&mut self, _subsystem: &str) {}
1637+
1638+
fn reset_per_library_state(&mut self) {
1639+
self.hint_dynamic();
1640+
}
1641+
1642+
fn linker_plugin_lto(&mut self) {}
1643+
1644+
fn add_eh_frame_header(&mut self) {}
1645+
1646+
fn add_no_exec(&mut self) {}
1647+
1648+
fn add_as_needed(&mut self) {}
1649+
}
1650+
14771651
fn for_each_exported_symbols_include_dep<'tcx>(
14781652
tcx: TyCtxt<'tcx>,
14791653
crate_type: CrateType,

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+28-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::def::Res;
44
use rustc_hir::def_id::DefId;
55
use rustc_infer::traits::ObligationCauseCode;
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
7-
use rustc_span::{self, Span};
7+
use rustc_span::{self, symbol::kw, Span};
88
use rustc_trait_selection::traits;
99

1010
use std::ops::ControlFlow;
@@ -25,17 +25,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2525

2626
let generics = self.tcx.generics_of(def_id);
2727
let predicate_substs = match unsubstituted_pred.kind().skip_binder() {
28-
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => pred.trait_ref.substs,
29-
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => pred.projection_ty.substs,
30-
_ => ty::List::empty(),
28+
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => pred.trait_ref.substs.to_vec(),
29+
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
30+
pred.projection_ty.substs.to_vec()
31+
}
32+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(arg, ty)) => {
33+
vec![ty.into(), arg.into()]
34+
}
35+
ty::PredicateKind::ConstEvaluatable(e) => vec![e.into()],
36+
_ => return false,
3137
};
3238

33-
let find_param_matching = |matches: &dyn Fn(&ty::ParamTy) -> bool| {
34-
predicate_substs.types().find_map(|ty| {
35-
ty.walk().find_map(|arg| {
39+
let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| {
40+
predicate_substs.iter().find_map(|arg| {
41+
arg.walk().find_map(|arg| {
3642
if let ty::GenericArgKind::Type(ty) = arg.unpack()
37-
&& let ty::Param(param_ty) = ty.kind()
38-
&& matches(param_ty)
43+
&& let ty::Param(param_ty) = *ty.kind()
44+
&& matches(ty::ParamTerm::Ty(param_ty))
45+
{
46+
Some(arg)
47+
} else if let ty::GenericArgKind::Const(ct) = arg.unpack()
48+
&& let ty::ConstKind::Param(param_ct) = ct.kind()
49+
&& matches(ty::ParamTerm::Const(param_ct))
3950
{
4051
Some(arg)
4152
} else {
@@ -47,21 +58,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4758

4859
// Prefer generics that are local to the fn item, since these are likely
4960
// to be the cause of the unsatisfied predicate.
50-
let mut param_to_point_at = find_param_matching(&|param_ty| {
51-
self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) == def_id
61+
let mut param_to_point_at = find_param_matching(&|param_term| {
62+
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) == def_id
5263
});
5364
// Fall back to generic that isn't local to the fn item. This will come
5465
// from a trait or impl, for example.
55-
let mut fallback_param_to_point_at = find_param_matching(&|param_ty| {
56-
self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) != def_id
57-
&& param_ty.name != rustc_span::symbol::kw::SelfUpper
66+
let mut fallback_param_to_point_at = find_param_matching(&|param_term| {
67+
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) != def_id
68+
&& !matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper)
5869
});
5970
// Finally, the `Self` parameter is possibly the reason that the predicate
6071
// is unsatisfied. This is less likely to be true for methods, because
6172
// method probe means that we already kinda check that the predicates due
6273
// to the `Self` type are true.
63-
let mut self_param_to_point_at =
64-
find_param_matching(&|param_ty| param_ty.name == rustc_span::symbol::kw::SelfUpper);
74+
let mut self_param_to_point_at = find_param_matching(
75+
&|param_term| matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper),
76+
);
6577

6678
// Finally, for ambiguity-related errors, we actually want to look
6779
// for a parameter that is the source of the inference type left
@@ -225,14 +237,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
225237
.own_substs(ty::InternalSubsts::identity_for_item(self.tcx, def_id));
226238
let Some((index, _)) = own_substs
227239
.iter()
228-
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
229240
.enumerate()
230241
.find(|(_, arg)| **arg == param_to_point_at) else { return false };
231242
let Some(arg) = segment
232243
.args()
233244
.args
234245
.iter()
235-
.filter(|arg| matches!(arg, hir::GenericArg::Type(_)))
236246
.nth(index) else { return false; };
237247
error.obligation.cause.span = arg
238248
.span()

compiler/rustc_metadata/src/rmeta/decoder.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1041,13 +1041,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10411041
self.root.tables.optimized_mir.get(self, id).is_some()
10421042
}
10431043

1044-
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
1045-
match self.def_kind(id) {
1046-
DefKind::Mod | DefKind::Enum | DefKind::Trait => self.get_expn_that_defined(id, sess),
1047-
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
1048-
}
1049-
}
1050-
10511044
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
10521045
self.root
10531046
.tables

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
490490
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
491491
},
492492
crates: |tcx, ()| {
493+
// The list of loaded crates is now frozen in query cache,
494+
// so make sure cstore is not mutably accessed from here on.
495+
tcx.untracked().cstore.leak();
493496
tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum))
494497
},
495498
..*providers
@@ -537,16 +540,16 @@ impl CStore {
537540
)
538541
}
539542

540-
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
543+
pub fn def_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
541544
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
542545
}
543546

544-
pub fn def_kind(&self, def: DefId) -> DefKind {
547+
pub fn def_kind_untracked(&self, def: DefId) -> DefKind {
545548
self.get_crate_data(def.krate).def_kind(def.index)
546549
}
547550

548-
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
549-
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
551+
pub fn expn_that_defined_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
552+
self.get_crate_data(def_id.krate).get_expn_that_defined(def_id.index, sess)
550553
}
551554

552555
/// Only public-facing way to traverse all the definitions in a non-local crate.

compiler/rustc_middle/src/ty/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,21 @@ impl<'tcx> TermKind<'tcx> {
10511051
}
10521052
}
10531053

1054+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
1055+
pub enum ParamTerm {
1056+
Ty(ParamTy),
1057+
Const(ParamConst),
1058+
}
1059+
1060+
impl ParamTerm {
1061+
pub fn index(self) -> usize {
1062+
match self {
1063+
ParamTerm::Ty(ty) => ty.index as usize,
1064+
ParamTerm::Const(ct) => ct.index as usize,
1065+
}
1066+
}
1067+
}
1068+
10541069
/// This kind of predicate has no *direct* correspondent in the
10551070
/// syntax, but it roughly corresponds to the syntactic forms:
10561071
///

compiler/rustc_resolve/src/build_reduced_graph.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
114114
}
115115

116116
if !def_id.is_local() {
117-
let def_kind = self.cstore().def_kind(def_id);
117+
// Query `def_kind` is not used because query system overhead is too expensive here.
118+
let def_kind = self.cstore().def_kind_untracked(def_id);
118119
if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind {
119120
let parent = self
120121
.tcx
121122
.opt_parent(def_id)
122123
.map(|parent_id| self.get_nearest_non_block_module(parent_id));
123-
let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess);
124+
// Query `expn_that_defined` is not used because
125+
// hashing spans in its result is expensive.
126+
let expn_id = self.cstore().expn_that_defined_untracked(def_id, &self.tcx.sess);
124127
return Some(self.new_module(
125128
parent,
126129
ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)),
@@ -194,6 +197,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
194197
}
195198

196199
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
200+
// Query `module_children` is not used because hashing spans in its result is expensive.
197201
let children =
198202
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess));
199203
for child in children {

compiler/rustc_resolve/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18751875
fn def_span(&self, def_id: DefId) -> Span {
18761876
match def_id.as_local() {
18771877
Some(def_id) => self.tcx.source_span(def_id),
1878-
None => self.cstore().get_span_untracked(def_id, self.tcx.sess),
1878+
// Query `def_span` is not used because hashing its result span is expensive.
1879+
None => self.cstore().def_span_untracked(def_id, self.tcx.sess),
18791880
}
18801881
}
18811882

0 commit comments

Comments
 (0)