Skip to content

Commit 7d8ebe3

Browse files
committed
Auto merge of #151852 - Zalathar:rollup-jdJCcDh, r=Zalathar
Rollup of 5 pull requests Successful merges: - #151777 ( Reduce generics use in the query system.) - #151808 (Document a safety condition for `TypedArena::alloc_raw_slice`) - #151811 (Fix false positive in unused_parens caused by break) - #151817 (Fix missing syntax context in lifetime hygiene debug output) - #151844 (rustc-dev-guide subtree update)
2 parents ef2657c + 5b54208 commit 7d8ebe3

File tree

80 files changed

+1308
-1063
lines changed

Some content is hidden

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

80 files changed

+1308
-1063
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,22 @@ impl<T> TypedArena<T> {
172172
available_bytes >= additional_bytes
173173
}
174174

175+
/// Allocates storage for `len >= 1` values in this arena, and returns a
176+
/// raw pointer to the first value's storage.
177+
///
178+
/// # Safety
179+
///
180+
/// Caller must initialize each of the `len` slots to a droppable value
181+
/// before the arena is dropped.
182+
///
183+
/// In practice, this typically means that the caller must be able to
184+
/// raw-copy `len` already-initialized values into the slice without any
185+
/// possibility of panicking.
186+
///
187+
/// FIXME(Zalathar): This is *very* fragile; perhaps we need a different
188+
/// approach to arena-allocating slices of droppable values.
175189
#[inline]
176-
fn alloc_raw_slice(&self, len: usize) -> *mut T {
190+
unsafe fn alloc_raw_slice(&self, len: usize) -> *mut T {
177191
assert!(size_of::<T>() != 0);
178192
assert!(len != 0);
179193

@@ -208,7 +222,7 @@ impl<T> TypedArena<T> {
208222
&self,
209223
iter: impl IntoIterator<Item = Result<T, E>>,
210224
) -> Result<&mut [T], E> {
211-
// Despite the similarlty with `DroplessArena`, we cannot reuse their fast case. The reason
225+
// Despite the similarity with `DroplessArena`, we cannot reuse their fast case. The reason
212226
// is subtle: these arenas are reentrant. In other words, `iter` may very well be holding a
213227
// reference to `self` and adding elements to the arena during iteration.
214228
//
@@ -229,9 +243,15 @@ impl<T> TypedArena<T> {
229243
}
230244
// Move the content to the arena by copying and then forgetting it.
231245
let len = vec.len();
232-
let start_ptr = self.alloc_raw_slice(len);
246+
247+
// SAFETY: After allocating raw storage for exactly `len` values, we
248+
// must fully initialize the storage without panicking, and we must
249+
// also prevent the stale values in the vec from being dropped.
233250
Ok(unsafe {
251+
let start_ptr = self.alloc_raw_slice(len);
252+
// Initialize the newly-allocated storage without panicking.
234253
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
254+
// Prevent the stale values in the vec from being dropped.
235255
vec.set_len(0);
236256
slice::from_raw_parts_mut(start_ptr, len)
237257
})
@@ -584,7 +604,7 @@ impl DroplessArena {
584604
&self,
585605
iter: impl IntoIterator<Item = Result<T, E>>,
586606
) -> Result<&mut [T], E> {
587-
// Despite the similarlty with `alloc_from_iter`, we cannot reuse their fast case, as we
607+
// Despite the similarity with `alloc_from_iter`, we cannot reuse their fast case, as we
588608
// cannot know the minimum length of the iterator in this case.
589609
assert!(size_of::<T>() != 0);
590610

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,8 @@ impl<'a> State<'a> {
19611961
}
19621962

19631963
fn print_lifetime(&mut self, lifetime: ast::Lifetime) {
1964-
self.print_name(lifetime.ident.name)
1964+
self.word(lifetime.ident.name.to_string());
1965+
self.ann_post(lifetime.ident)
19651966
}
19661967

19671968
fn print_lifetime_bounds(&mut self, bounds: &ast::GenericBounds) {

compiler/rustc_lint/src/unused.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,10 @@ trait UnusedDelimLint {
805805

806806
ExprKind::Break(_label, None) => return false,
807807
ExprKind::Break(_label, Some(break_expr)) => {
808-
return matches!(break_expr.kind, ExprKind::Block(..));
808+
// `if (break 'label i) { ... }` removing parens would make `i { ... }`
809+
// be parsed as a struct literal, so keep parentheses if the break value
810+
// ends with a path (which could be mistaken for a struct name).
811+
return matches!(break_expr.kind, ExprKind::Block(..) | ExprKind::Path(..));
809812
}
810813

811814
ExprKind::Range(_lhs, Some(rhs), _limits) => {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use rustc_index::IndexVec;
8888
use rustc_lint_defs::LintId;
8989
use rustc_macros::rustc_queries;
9090
use rustc_query_system::ich::StableHashingContext;
91-
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
91+
use rustc_query_system::query::{QueryMode, QueryState};
9292
use rustc_session::Limits;
9393
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
9494
use rustc_session::cstore::{

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ macro_rules! define_callbacks {
440440
#[derive(Default)]
441441
pub struct QueryStates<'tcx> {
442442
$(
443-
pub $name: QueryState<$($K)*, QueryStackDeferred<'tcx>>,
443+
pub $name: QueryState<'tcx, $($K)*>,
444444
)*
445445
}
446446

compiler/rustc_query_impl/src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_query_system::dep_graph::SerializedDepNodeIndex;
2121
use rustc_query_system::ich::StableHashingContext;
2222
use rustc_query_system::query::{
2323
CycleError, CycleErrorHandling, HashResult, QueryCache, QueryDispatcher, QueryMap, QueryMode,
24-
QueryStackDeferred, QueryState, get_query_incr, get_query_non_incr,
24+
QueryState, get_query_incr, get_query_non_incr,
2525
};
2626
use rustc_span::{ErrorGuaranteed, Span};
2727

@@ -66,7 +66,7 @@ impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDA
6666

6767
// This is `impl QueryDispatcher for SemiDynamicQueryDispatcher`.
6868
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool>
69-
QueryDispatcher for SemiDynamicQueryDispatcher<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
69+
QueryDispatcher<'tcx> for SemiDynamicQueryDispatcher<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
7070
where
7171
for<'a> C::Key: HashStable<StableHashingContext<'a>>,
7272
{
@@ -86,10 +86,7 @@ where
8686
}
8787

8888
#[inline(always)]
89-
fn query_state<'a>(
90-
self,
91-
qcx: QueryCtxt<'tcx>,
92-
) -> &'a QueryState<Self::Key, QueryStackDeferred<'tcx>>
89+
fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<'tcx, Self::Key>
9390
where
9491
QueryCtxt<'tcx>: 'a,
9592
{
@@ -98,7 +95,7 @@ where
9895
unsafe {
9996
&*(&qcx.tcx.query_system.states as *const QueryStates<'tcx>)
10097
.byte_add(self.vtable.query_state)
101-
.cast::<QueryState<Self::Key, QueryStackDeferred<'tcx>>>()
98+
.cast::<QueryState<'tcx, Self::Key>>()
10299
}
103100
}
104101

@@ -211,13 +208,15 @@ where
211208
/// on the type `rustc_query_impl::query_impl::$name::QueryType`.
212209
trait QueryDispatcherUnerased<'tcx> {
213210
type UnerasedValue;
214-
type Dispatcher: QueryDispatcher<Qcx = QueryCtxt<'tcx>>;
211+
type Dispatcher: QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>;
215212

216213
const NAME: &'static &'static str;
217214

218215
fn query_dispatcher(tcx: TyCtxt<'tcx>) -> Self::Dispatcher;
219216

220-
fn restore_val(value: <Self::Dispatcher as QueryDispatcher>::Value) -> Self::UnerasedValue;
217+
fn restore_val(
218+
value: <Self::Dispatcher as QueryDispatcher<'tcx>>::Value,
219+
) -> Self::UnerasedValue;
221220
}
222221

223222
pub fn query_system<'a>(

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6060
}
6161
}
6262

63-
impl<'tcx> QueryContext for QueryCtxt<'tcx> {
64-
type QueryInfo = QueryStackDeferred<'tcx>;
65-
63+
impl<'tcx> QueryContext<'tcx> for QueryCtxt<'tcx> {
6664
#[inline]
6765
fn jobserver_proxy(&self) -> &Proxy {
6866
&self.tcx.jobserver_proxy
@@ -93,10 +91,7 @@ impl<'tcx> QueryContext for QueryCtxt<'tcx> {
9391
/// Prefer passing `false` to `require_complete` to avoid potential deadlocks,
9492
/// especially when called from within a deadlock handler, unless a
9593
/// complete map is needed and no deadlock is possible at this call site.
96-
fn collect_active_jobs(
97-
self,
98-
require_complete: bool,
99-
) -> Result<QueryMap<QueryStackDeferred<'tcx>>, QueryMap<QueryStackDeferred<'tcx>>> {
94+
fn collect_active_jobs(self, require_complete: bool) -> Result<QueryMap<'tcx>, QueryMap<'tcx>> {
10095
let mut jobs = QueryMap::default();
10196
let mut complete = true;
10297

@@ -322,7 +317,7 @@ macro_rules! should_ever_cache_on_disk {
322317
};
323318
}
324319

325-
fn create_query_frame_extra<'tcx, K: Key + Copy + 'tcx>(
320+
fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>(
326321
(tcx, key, kind, name, do_describe): (
327322
TyCtxt<'tcx>,
328323
K,
@@ -373,18 +368,16 @@ pub(crate) fn create_query_frame<
373368
) -> QueryStackFrame<QueryStackDeferred<'tcx>> {
374369
let def_id = key.key_as_def_id();
375370

376-
let hash = || {
377-
tcx.with_stable_hashing_context(|mut hcx| {
378-
let mut hasher = StableHasher::new();
379-
kind.as_usize().hash_stable(&mut hcx, &mut hasher);
380-
key.hash_stable(&mut hcx, &mut hasher);
381-
hasher.finish::<Hash64>()
382-
})
383-
};
371+
let hash = tcx.with_stable_hashing_context(|mut hcx| {
372+
let mut hasher = StableHasher::new();
373+
kind.as_usize().hash_stable(&mut hcx, &mut hasher);
374+
key.hash_stable(&mut hcx, &mut hasher);
375+
hasher.finish::<Hash64>()
376+
});
384377
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();
385378

386379
let info =
387-
QueryStackDeferred::new((tcx, key, kind, name, do_describe), create_query_frame_extra);
380+
QueryStackDeferred::new((tcx, key, kind, name, do_describe), mk_query_stack_frame_extra);
388381

389382
QueryStackFrame::new(info, kind, hash, def_id, def_id_for_ty_in_cycle)
390383
}
@@ -417,7 +410,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
417410
}
418411

419412
pub(crate) fn query_key_hash_verify<'tcx>(
420-
query: impl QueryDispatcher<Qcx = QueryCtxt<'tcx>>,
413+
query: impl QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>,
421414
qcx: QueryCtxt<'tcx>,
422415
) {
423416
let _timer = qcx.tcx.prof.generic_activity_with_arg("query_key_hash_verify_for", query.name());
@@ -445,7 +438,7 @@ pub(crate) fn query_key_hash_verify<'tcx>(
445438

446439
fn try_load_from_on_disk_cache<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode)
447440
where
448-
Q: QueryDispatcher<Qcx = QueryCtxt<'tcx>>,
441+
Q: QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>,
449442
{
450443
debug_assert!(tcx.dep_graph.is_green(&dep_node));
451444

@@ -491,7 +484,7 @@ where
491484

492485
fn force_from_dep_node<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool
493486
where
494-
Q: QueryDispatcher<Qcx = QueryCtxt<'tcx>>,
487+
Q: QueryDispatcher<'tcx, Qcx = QueryCtxt<'tcx>>,
495488
{
496489
// We must avoid ever having to call `force_from_dep_node()` for a
497490
// `DepNode::codegen_unit`:
@@ -734,14 +727,14 @@ macro_rules! define_queries {
734727
}
735728

736729
#[inline(always)]
737-
fn restore_val(value: <Self::Dispatcher as QueryDispatcher>::Value) -> Self::UnerasedValue {
730+
fn restore_val(value: <Self::Dispatcher as QueryDispatcher<'tcx>>::Value) -> Self::UnerasedValue {
738731
erase::restore_val::<queries::$name::Value<'tcx>>(value)
739732
}
740733
}
741734

742735
pub(crate) fn collect_active_jobs<'tcx>(
743736
tcx: TyCtxt<'tcx>,
744-
qmap: &mut QueryMap<QueryStackDeferred<'tcx>>,
737+
qmap: &mut QueryMap<'tcx>,
745738
require_complete: bool,
746739
) -> Option<()> {
747740
let make_query = |tcx, key| {
@@ -825,7 +818,7 @@ macro_rules! define_queries {
825818
// These arrays are used for iteration and can't be indexed by `DepKind`.
826819

827820
const COLLECT_ACTIVE_JOBS: &[
828-
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<QueryStackDeferred<'tcx>>, bool) -> Option<()>
821+
for<'tcx> fn(TyCtxt<'tcx>, &mut QueryMap<'tcx>, bool) -> Option<()>
829822
] =
830823
&[$(query_impl::$name::collect_active_jobs),*];
831824

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,11 @@ impl<D: Deps> DepGraph<D> {
519519
/// This encodes a diagnostic by creating a node with an unique index and associating
520520
/// `diagnostic` with it, for use in the next session.
521521
#[inline]
522-
pub fn record_diagnostic<Qcx: QueryContext>(&self, qcx: Qcx, diagnostic: &DiagInner) {
522+
pub fn record_diagnostic<'tcx, Qcx: QueryContext<'tcx>>(
523+
&self,
524+
qcx: Qcx,
525+
diagnostic: &DiagInner,
526+
) {
523527
if let Some(ref data) = self.data {
524528
D::read_deps(|task_deps| match task_deps {
525529
TaskDepsRef::EvalAlways | TaskDepsRef::Ignore => return,
@@ -532,7 +536,7 @@ impl<D: Deps> DepGraph<D> {
532536
/// This forces a diagnostic node green by running its side effect. `prev_index` would
533537
/// refer to a node created used `encode_diagnostic` in the previous session.
534538
#[inline]
535-
pub fn force_diagnostic_node<Qcx: QueryContext>(
539+
pub fn force_diagnostic_node<'tcx, Qcx: QueryContext<'tcx>>(
536540
&self,
537541
qcx: Qcx,
538542
prev_index: SerializedDepNodeIndex,
@@ -669,7 +673,7 @@ impl<D: Deps> DepGraphData<D> {
669673
/// This encodes a diagnostic by creating a node with an unique index and associating
670674
/// `diagnostic` with it, for use in the next session.
671675
#[inline]
672-
fn encode_diagnostic<Qcx: QueryContext>(
676+
fn encode_diagnostic<'tcx, Qcx: QueryContext<'tcx>>(
673677
&self,
674678
qcx: Qcx,
675679
diagnostic: &DiagInner,
@@ -693,7 +697,7 @@ impl<D: Deps> DepGraphData<D> {
693697
/// This forces a diagnostic node green by running its side effect. `prev_index` would
694698
/// refer to a node created used `encode_diagnostic` in the previous session.
695699
#[inline]
696-
fn force_diagnostic_node<Qcx: QueryContext>(
700+
fn force_diagnostic_node<'tcx, Qcx: QueryContext<'tcx>>(
697701
&self,
698702
qcx: Qcx,
699703
prev_index: SerializedDepNodeIndex,
@@ -843,7 +847,7 @@ impl<D: Deps> DepGraph<D> {
843847
DepNodeColor::Unknown
844848
}
845849

846-
pub fn try_mark_green<Qcx: QueryContext<Deps = D>>(
850+
pub fn try_mark_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
847851
&self,
848852
qcx: Qcx,
849853
dep_node: &DepNode,
@@ -858,7 +862,7 @@ impl<D: Deps> DepGraphData<D> {
858862
/// A node will have an index, when it's already been marked green, or when we can mark it
859863
/// green. This function will mark the current task as a reader of the specified node, when
860864
/// a node index can be found for that node.
861-
pub(crate) fn try_mark_green<Qcx: QueryContext<Deps = D>>(
865+
pub(crate) fn try_mark_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
862866
&self,
863867
qcx: Qcx,
864868
dep_node: &DepNode,
@@ -883,7 +887,7 @@ impl<D: Deps> DepGraphData<D> {
883887
}
884888

885889
#[instrument(skip(self, qcx, parent_dep_node_index, frame), level = "debug")]
886-
fn try_mark_parent_green<Qcx: QueryContext<Deps = D>>(
890+
fn try_mark_parent_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
887891
&self,
888892
qcx: Qcx,
889893
parent_dep_node_index: SerializedDepNodeIndex,
@@ -973,7 +977,7 @@ impl<D: Deps> DepGraphData<D> {
973977

974978
/// Try to mark a dep-node which existed in the previous compilation session as green.
975979
#[instrument(skip(self, qcx, prev_dep_node_index, frame), level = "debug")]
976-
fn try_mark_previous_green<Qcx: QueryContext<Deps = D>>(
980+
fn try_mark_previous_green<'tcx, Qcx: QueryContext<'tcx, Deps = D>>(
977981
&self,
978982
qcx: Qcx,
979983
prev_dep_node_index: SerializedDepNodeIndex,

0 commit comments

Comments
 (0)