Skip to content

Commit c6861df

Browse files
committed
Auto merge of #101592 - compiler-errors:rollup-d2fya7z, r=compiler-errors
Rollup of 7 pull requests Successful merges: - #101423 (Fix hermit warnings) - #101499 (Introduce lowering_arena to avoid creating AST nodes on the fly) - #101530 (llvm-wrapper: adapt for LLVM API changes) - #101554 (rustdoc: remove unused CSS `#implementations-list > h3 > span.in-band`) - #101580 (rustdoc: remove unused CSS `div.impl-items > div`) - #101584 (rustdoc: remove no-op CSS `#settings-menu { padding: 0 }`) - #101587 (Make `Debug` impl for `Term` useful) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1120c5e + e43cf3d commit c6861df

File tree

8 files changed

+60
-39
lines changed

8 files changed

+60
-39
lines changed

compiler/rustc_ast_lowering/src/item.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::errors::{InvalidAbi, MisplacedRelaxTraitBound};
22
use super::ResolverAstLoweringExt;
3-
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
3+
use super::{Arena, AstOwner, ImplTraitContext, ImplTraitPosition};
44
use super::{FnDeclKind, LoweringContext, ParamMode};
55

66
use rustc_ast::ptr::P;
@@ -25,6 +25,7 @@ use std::iter;
2525
pub(super) struct ItemLowerer<'a, 'hir> {
2626
pub(super) tcx: TyCtxt<'hir>,
2727
pub(super) resolver: &'a mut ResolverAstLowering,
28+
pub(super) ast_arena: &'a Arena<'static>,
2829
pub(super) ast_index: &'a IndexVec<LocalDefId, AstOwner<'a>>,
2930
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
3031
}
@@ -60,6 +61,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6061
tcx: self.tcx,
6162
resolver: self.resolver,
6263
arena: self.tcx.hir_arena,
64+
ast_arena: self.ast_arena,
6365

6466
// HirId handling.
6567
bodies: Vec::new(),

compiler/rustc_ast_lowering/src/lib.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern crate tracing;
4444

4545
use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
4646

47+
use rustc_arena::declare_arena;
4748
use rustc_ast::ptr::P;
4849
use rustc_ast::visit;
4950
use rustc_ast::{self as ast, *};
@@ -95,6 +96,13 @@ struct LoweringContext<'a, 'hir> {
9596
/// Used to allocate HIR nodes.
9697
arena: &'hir hir::Arena<'hir>,
9798

99+
/// Used to allocate temporary AST nodes for use during lowering.
100+
/// This allows us to create "fake" AST -- these nodes can sometimes
101+
/// be allocated on the stack, but other times we need them to live longer
102+
/// than the current stack frame, so they can be collected into vectors
103+
/// and things like that.
104+
ast_arena: &'a Arena<'static>,
105+
98106
/// Bodies inside the owner being lowered.
99107
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
100108
/// Attributes inside the owner being lowered.
@@ -140,6 +148,15 @@ struct LoweringContext<'a, 'hir> {
140148
generics_def_id_map: Vec<FxHashMap<LocalDefId, LocalDefId>>,
141149
}
142150

151+
declare_arena!([
152+
[] tys: rustc_ast::Ty,
153+
[] aba: rustc_ast::AngleBracketedArgs,
154+
[] ptr: rustc_ast::PolyTraitRef,
155+
// This _marker field is needed because `declare_arena` creates `Arena<'tcx>` and we need to
156+
// use `'tcx`. If we don't have this we get a compile error.
157+
[] _marker: std::marker::PhantomData<&'tcx ()>,
158+
]);
159+
143160
trait ResolverAstLoweringExt {
144161
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
145162
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
@@ -401,10 +418,13 @@ pub fn lower_to_hir<'hir>(tcx: TyCtxt<'hir>, (): ()) -> hir::Crate<'hir> {
401418
tcx.definitions_untracked().def_index_count(),
402419
);
403420

421+
let ast_arena = Arena::default();
422+
404423
for def_id in ast_index.indices() {
405424
item::ItemLowerer {
406425
tcx,
407426
resolver: &mut resolver,
427+
ast_arena: &ast_arena,
408428
ast_index: &ast_index,
409429
owners: &mut owners,
410430
}
@@ -974,12 +994,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
974994
}
975995
GenericArgs::Parenthesized(ref data) => {
976996
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
977-
self.lower_angle_bracketed_parameter_data(
978-
&data.as_angle_bracketed_args(),
979-
ParamMode::Explicit,
980-
itctx,
981-
)
982-
.0
997+
let aba = self.ast_arena.aba.alloc(data.as_angle_bracketed_args());
998+
self.lower_angle_bracketed_parameter_data(aba, ParamMode::Explicit, itctx).0
983999
}
9841000
};
9851001
gen_args_ctor.into_generic_args(self)
@@ -1048,15 +1064,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10481064

10491065
self.with_dyn_type_scope(false, |this| {
10501066
let node_id = this.next_node_id();
1051-
let ty = this.lower_ty(
1052-
&Ty {
1053-
id: node_id,
1054-
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1055-
span: this.lower_span(constraint.span),
1056-
tokens: None,
1057-
},
1058-
itctx,
1059-
);
1067+
let ty = this.ast_arena.tys.alloc(Ty {
1068+
id: node_id,
1069+
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1070+
span: this.lower_span(constraint.span),
1071+
tokens: None,
1072+
});
1073+
let ty = this.lower_ty(ty, itctx);
10601074

10611075
hir::TypeBindingKind::Equality { term: ty.into() }
10621076
})
@@ -1192,12 +1206,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11921206
&& let Res::Def(DefKind::Trait | DefKind::TraitAlias, _) = partial_res.base_res()
11931207
{
11941208
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1209+
let poly_trait_ref = this.ast_arena.ptr.alloc(PolyTraitRef {
1210+
bound_generic_params: vec![],
1211+
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1212+
span: t.span
1213+
});
11951214
let bound = this.lower_poly_trait_ref(
1196-
&PolyTraitRef {
1197-
bound_generic_params: vec![],
1198-
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1199-
span: t.span
1200-
},
1215+
poly_trait_ref,
12011216
itctx,
12021217
);
12031218
let bounds = this.arena.alloc_from_iter([bound]);

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,14 @@ LLVMRustOptimizeWithNewPassManager(
936936
/*CompileKernel=*/false);
937937
OptimizerLastEPCallbacks.push_back(
938938
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
939-
#if LLVM_VERSION_GE(14, 0)
939+
#if LLVM_VERSION_GE(14, 0) && LLVM_VERSION_LT(16, 0)
940940
MPM.addPass(ModuleMemorySanitizerPass(Options));
941941
#else
942942
MPM.addPass(MemorySanitizerPass(Options));
943943
#endif
944+
#if LLVM_VERSION_LT(16, 0)
944945
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
946+
#endif
945947
}
946948
);
947949
}
@@ -972,7 +974,11 @@ LLVMRustOptimizeWithNewPassManager(
972974
/*UseAfterScope=*/true,
973975
AsanDetectStackUseAfterReturnMode::Runtime,
974976
};
977+
#if LLVM_VERSION_LT(16, 0)
975978
MPM.addPass(ModuleAddressSanitizerPass(opts));
979+
#else
980+
MPM.addPass(AddressSanitizerPass(opts));
981+
#endif
976982
#else
977983
MPM.addPass(ModuleAddressSanitizerPass(
978984
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));

compiler/rustc_middle/src/ty/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -915,12 +915,25 @@ pub struct CoercePredicate<'tcx> {
915915
}
916916
pub type PolyCoercePredicate<'tcx> = ty::Binder<'tcx, CoercePredicate<'tcx>>;
917917

918-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
918+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
919919
pub struct Term<'tcx> {
920920
ptr: NonZeroUsize,
921921
marker: PhantomData<(Ty<'tcx>, Const<'tcx>)>,
922922
}
923923

924+
impl Debug for Term<'_> {
925+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
926+
let data = if let Some(ty) = self.ty() {
927+
format!("Term::Ty({:?})", ty)
928+
} else if let Some(ct) = self.ct() {
929+
format!("Term::Ct({:?})", ct)
930+
} else {
931+
unreachable!()
932+
};
933+
f.write_str(&data)
934+
}
935+
}
936+
924937
impl<'tcx> From<Ty<'tcx>> for Term<'tcx> {
925938
fn from(ty: Ty<'tcx>) -> Self {
926939
TermKind::Ty(ty).pack()

library/std/src/sys/hermit/mutex.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::cell::UnsafeCell;
22
use crate::collections::VecDeque;
33
use crate::hint;
44
use crate::ops::{Deref, DerefMut, Drop};
5-
use crate::ptr;
65
use crate::sync::atomic::{AtomicUsize, Ordering};
76
use crate::sys::hermit::abi;
87

library/std/src/sys/hermit/net.rs

-2
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,4 @@ pub mod netc {
487487

488488
#[derive(Copy, Clone)]
489489
pub struct sockaddr {}
490-
491-
pub type socklen_t = usize;
492490
}

library/std/src/sys/hermit/rwlock.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::cell::UnsafeCell;
22
use crate::sys::locks::{MovableCondvar, Mutex};
3-
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
43

54
pub struct RwLock {
65
lock: Mutex,

src/librustdoc/html/static/css/rustdoc.css

+1-12
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ h4.code-header {
197197
position: relative;
198198
}
199199

200-
div.impl-items > div {
201-
padding-left: 0;
202-
}
203-
204200
h1, h2, h3, h4, h5, h6,
205201
.sidebar,
206202
.mobile-topbar,
@@ -212,7 +208,6 @@ a.source,
212208
span.since,
213209
#source-sidebar, #sidebar-toggle,
214210
details.rustdoc-toggle > summary::before,
215-
div.impl-items > div:not(.docblock):not(.item-info),
216211
.content ul.crate a.crate,
217212
a.srclink,
218213
#help-button > button,
@@ -1449,9 +1444,7 @@ pre.rust {
14491444
border-radius: 2px;
14501445
cursor: pointer;
14511446
}
1452-
#settings-menu {
1453-
padding: 0;
1454-
}
1447+
14551448
#settings-menu > a, #help-button > button {
14561449
padding: 5px;
14571450
height: 100%;
@@ -1528,10 +1521,6 @@ kbd {
15281521
cursor: default;
15291522
}
15301523

1531-
#implementations-list > h3 > span.in-band {
1532-
width: 100%;
1533-
}
1534-
15351524
#main-content > ul {
15361525
padding-left: 10px;
15371526
}

0 commit comments

Comments
 (0)