Skip to content

Commit 0e0328c

Browse files
committed
Auto merge of #63482 - Centril:rollup-iyakgmg, r=Centril
Rollup of 10 pull requests Successful merges: - #62108 (Use sharded maps for queries) - #63297 (Improve pointer offset method docs) - #63306 (Adapt AddRetag for shallow retagging) - #63406 (Suggest using a qualified path in patterns with inconsistent bindings) - #63431 (Revert "Simplify MIR generation for logical ops") - #63449 (resolve: Remove remaining special cases from built-in macros) - #63461 (docs: add stdlib env::var(_os) panic) - #63473 (Regression test for #56870) - #63474 (Add tests for issue #53598 and #57700) - #63480 (Fixes #63477) Failed merges: r? @ghost
2 parents 72f8043 + a7496fb commit 0e0328c

30 files changed

+534
-203
lines changed

src/libcore/ptr/mod.rs

+128-34
Large diffs are not rendered by default.

src/librustc/ty/query/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::util::profiling::ProfileCategory;
1111
use std::borrow::Cow;
1212
use std::hash::Hash;
1313
use std::fmt::Debug;
14-
use rustc_data_structures::sync::Lock;
14+
use rustc_data_structures::sharded::Sharded;
1515
use rustc_data_structures::fingerprint::Fingerprint;
1616
use crate::ich::StableHashingContext;
1717

@@ -34,7 +34,7 @@ pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
3434
fn query(key: Self::Key) -> Query<'tcx>;
3535

3636
// Don't use this method to access query results, instead use the methods on TyCtxt
37-
fn query_cache<'a>(tcx: TyCtxt<'tcx>) -> &'a Lock<QueryCache<'tcx, Self>>;
37+
fn query_cache<'a>(tcx: TyCtxt<'tcx>) -> &'a Sharded<QueryCache<'tcx, Self>>;
3838

3939
fn to_dep_node(tcx: TyCtxt<'tcx>, key: &Self::Key) -> DepNode;
4040

src/librustc/ty/query/on_disk_cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,9 @@ where
10621062
::std::any::type_name::<Q>());
10631063

10641064
time_ext(tcx.sess.time_extended(), Some(tcx.sess), desc, || {
1065-
let map = Q::query_cache(tcx).borrow();
1066-
assert!(map.active.is_empty());
1067-
for (key, entry) in map.results.iter() {
1065+
let shards = Q::query_cache(tcx).lock_shards();
1066+
assert!(shards.iter().all(|shard| shard.active.is_empty()));
1067+
for (key, entry) in shards.iter().flat_map(|shard| shard.results.iter()) {
10681068
if Q::cache_on_disk(tcx, key.clone(), Some(&entry.value)) {
10691069
let dep_node = SerializedDepNodeIndex::new(entry.index.index());
10701070

src/librustc/ty/query/plumbing.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use errors::Diagnostic;
1717
use errors::FatalError;
1818
use rustc_data_structures::fx::{FxHashMap};
1919
use rustc_data_structures::sync::{Lrc, Lock};
20+
use rustc_data_structures::sharded::Sharded;
2021
use rustc_data_structures::thin_vec::ThinVec;
2122
#[cfg(not(parallel_compiler))]
2223
use rustc_data_structures::cold_path;
@@ -90,7 +91,7 @@ macro_rules! profq_query_msg {
9091
/// A type representing the responsibility to execute the job in the `job` field.
9192
/// This will poison the relevant query if dropped.
9293
pub(super) struct JobOwner<'a, 'tcx, Q: QueryDescription<'tcx>> {
93-
cache: &'a Lock<QueryCache<'tcx, Q>>,
94+
cache: &'a Sharded<QueryCache<'tcx, Q>>,
9495
key: Q::Key,
9596
job: Lrc<QueryJob<'tcx>>,
9697
}
@@ -107,7 +108,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
107108
pub(super) fn try_get(tcx: TyCtxt<'tcx>, span: Span, key: &Q::Key) -> TryGetJob<'a, 'tcx, Q> {
108109
let cache = Q::query_cache(tcx);
109110
loop {
110-
let mut lock = cache.borrow_mut();
111+
let mut lock = cache.get_shard_by_value(key).lock();
111112
if let Some(value) = lock.results.get(key) {
112113
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
113114
tcx.sess.profiler(|p| p.record_query_hit(Q::NAME));
@@ -191,7 +192,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
191192

192193
let value = QueryValue::new(result.clone(), dep_node_index);
193194
{
194-
let mut lock = cache.borrow_mut();
195+
let mut lock = cache.get_shard_by_value(&key).lock();
195196
lock.active.remove(&key);
196197
lock.results.insert(key, value);
197198
}
@@ -215,7 +216,8 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> Drop for JobOwner<'a, 'tcx, Q> {
215216
#[cold]
216217
fn drop(&mut self) {
217218
// Poison the query so jobs waiting on it panic
218-
self.cache.borrow_mut().active.insert(self.key.clone(), QueryResult::Poisoned);
219+
let shard = self.cache.get_shard_by_value(&self.key);
220+
shard.lock().active.insert(self.key.clone(), QueryResult::Poisoned);
219221
// Also signal the completion of the job, so waiters
220222
// will continue execution
221223
self.job.signal_complete();
@@ -708,7 +710,7 @@ macro_rules! define_queries_inner {
708710
use std::mem;
709711
#[cfg(parallel_compiler)]
710712
use ty::query::job::QueryResult;
711-
use rustc_data_structures::sync::Lock;
713+
use rustc_data_structures::sharded::Sharded;
712714
use crate::{
713715
rustc_data_structures::stable_hasher::HashStable,
714716
rustc_data_structures::stable_hasher::StableHasherResult,
@@ -740,18 +742,17 @@ macro_rules! define_queries_inner {
740742
pub fn collect_active_jobs(&self) -> Vec<Lrc<QueryJob<$tcx>>> {
741743
let mut jobs = Vec::new();
742744

743-
// We use try_lock here since we are only called from the
745+
// We use try_lock_shards here since we are only called from the
744746
// deadlock handler, and this shouldn't be locked.
745747
$(
746-
jobs.extend(
747-
self.$name.try_lock().unwrap().active.values().filter_map(|v|
748-
if let QueryResult::Started(ref job) = *v {
749-
Some(job.clone())
750-
} else {
751-
None
752-
}
753-
)
754-
);
748+
let shards = self.$name.try_lock_shards().unwrap();
749+
jobs.extend(shards.iter().flat_map(|shard| shard.active.values().filter_map(|v|
750+
if let QueryResult::Started(ref job) = *v {
751+
Some(job.clone())
752+
} else {
753+
None
754+
}
755+
)));
755756
)*
756757

757758
jobs
@@ -773,26 +774,27 @@ macro_rules! define_queries_inner {
773774

774775
fn stats<'tcx, Q: QueryConfig<'tcx>>(
775776
name: &'static str,
776-
map: &QueryCache<'tcx, Q>
777+
map: &Sharded<QueryCache<'tcx, Q>>,
777778
) -> QueryStats {
779+
let map = map.lock_shards();
778780
QueryStats {
779781
name,
780782
#[cfg(debug_assertions)]
781-
cache_hits: map.cache_hits,
783+
cache_hits: map.iter().map(|shard| shard.cache_hits).sum(),
782784
#[cfg(not(debug_assertions))]
783785
cache_hits: 0,
784786
key_size: mem::size_of::<Q::Key>(),
785787
key_type: type_name::<Q::Key>(),
786788
value_size: mem::size_of::<Q::Value>(),
787789
value_type: type_name::<Q::Value>(),
788-
entry_count: map.results.len(),
790+
entry_count: map.iter().map(|shard| shard.results.len()).sum(),
789791
}
790792
}
791793

792794
$(
793795
queries.push(stats::<queries::$name<'_>>(
794796
stringify!($name),
795-
&*self.$name.lock()
797+
&self.$name,
796798
));
797799
)*
798800

@@ -967,7 +969,7 @@ macro_rules! define_queries_inner {
967969
}
968970

969971
#[inline(always)]
970-
fn query_cache<'a>(tcx: TyCtxt<$tcx>) -> &'a Lock<QueryCache<$tcx, Self>> {
972+
fn query_cache<'a>(tcx: TyCtxt<$tcx>) -> &'a Sharded<QueryCache<$tcx, Self>> {
971973
&tcx.queries.$name
972974
}
973975

@@ -1099,7 +1101,7 @@ macro_rules! define_queries_struct {
10991101
providers: IndexVec<CrateNum, Providers<$tcx>>,
11001102
fallback_extern_providers: Box<Providers<$tcx>>,
11011103

1102-
$($(#[$attr])* $name: Lock<QueryCache<$tcx, queries::$name<$tcx>>>,)*
1104+
$($(#[$attr])* $name: Sharded<QueryCache<$tcx, queries::$name<$tcx>>>,)*
11031105
}
11041106
};
11051107
}

src/librustc_mir/build/expr/into.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -79,59 +79,66 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7979
ExprKind::LogicalOp { op, lhs, rhs } => {
8080
// And:
8181
//
82-
// [block: If(lhs)] -true-> [else_block: dest = (rhs)]
83-
// | (false)
84-
// [shortcurcuit_block: dest = false]
82+
// [block: If(lhs)] -true-> [else_block: If(rhs)] -true-> [true_block]
83+
// | | (false)
84+
// +----------false-----------+------------------> [false_block]
8585
//
8686
// Or:
8787
//
88-
// [block: If(lhs)] -false-> [else_block: dest = (rhs)]
89-
// | (true)
90-
// [shortcurcuit_block: dest = true]
88+
// [block: If(lhs)] -false-> [else_block: If(rhs)] -true-> [true_block]
89+
// | (true) | (false)
90+
// [true_block] [false_block]
9191

92-
let (shortcircuit_block, mut else_block, join_block) = (
92+
let (true_block, false_block, mut else_block, join_block) = (
93+
this.cfg.start_new_block(),
9394
this.cfg.start_new_block(),
9495
this.cfg.start_new_block(),
9596
this.cfg.start_new_block(),
9697
);
9798

9899
let lhs = unpack!(block = this.as_local_operand(block, lhs));
99100
let blocks = match op {
100-
LogicalOp::And => (else_block, shortcircuit_block),
101-
LogicalOp::Or => (shortcircuit_block, else_block),
101+
LogicalOp::And => (else_block, false_block),
102+
LogicalOp::Or => (true_block, else_block),
102103
};
103104
let term = TerminatorKind::if_(this.hir.tcx(), lhs, blocks.0, blocks.1);
104105
this.cfg.terminate(block, source_info, term);
105106

107+
let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
108+
let term = TerminatorKind::if_(this.hir.tcx(), rhs, true_block, false_block);
109+
this.cfg.terminate(else_block, source_info, term);
110+
106111
this.cfg.push_assign_constant(
107-
shortcircuit_block,
112+
true_block,
108113
source_info,
109114
destination,
110115
Constant {
111116
span: expr_span,
112117
ty: this.hir.bool_ty(),
113118
user_ty: None,
114-
literal: match op {
115-
LogicalOp::And => this.hir.false_literal(),
116-
LogicalOp::Or => this.hir.true_literal(),
117-
},
119+
literal: this.hir.true_literal(),
118120
},
119121
);
120-
this.cfg.terminate(
121-
shortcircuit_block,
122+
123+
this.cfg.push_assign_constant(
124+
false_block,
122125
source_info,
123-
TerminatorKind::Goto { target: join_block },
126+
destination,
127+
Constant {
128+
span: expr_span,
129+
ty: this.hir.bool_ty(),
130+
user_ty: None,
131+
literal: this.hir.false_literal(),
132+
},
124133
);
125134

126-
let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
127-
this.cfg.push_assign(
128-
else_block,
135+
this.cfg.terminate(
136+
true_block,
129137
source_info,
130-
destination,
131-
Rvalue::Use(rhs),
138+
TerminatorKind::Goto { target: join_block },
132139
);
133140
this.cfg.terminate(
134-
else_block,
141+
false_block,
135142
source_info,
136143
TerminatorKind::Goto { target: join_block },
137144
);

src/librustc_mir/transform/add_retag.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ fn is_stable(
4242
}
4343
}
4444

45-
/// Determine whether this type may have a reference in it, recursing below compound types but
46-
/// not below references.
47-
fn may_have_reference<'tcx>(ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
45+
/// Determine whether this type may be a reference (or box), and thus needs retagging.
46+
fn may_be_reference<'tcx>(ty: Ty<'tcx>) -> bool {
4847
match ty.sty {
4948
// Primitive types that are not references
5049
ty::Bool | ty::Char |
@@ -55,15 +54,12 @@ fn may_have_reference<'tcx>(ty: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> bool {
5554
// References
5655
ty::Ref(..) => true,
5756
ty::Adt(..) if ty.is_box() => true,
58-
// Compound types
59-
ty::Array(ty, ..) | ty::Slice(ty) =>
60-
may_have_reference(ty, tcx),
61-
ty::Tuple(tys) =>
62-
tys.iter().any(|ty| may_have_reference(ty.expect_ty(), tcx)),
63-
ty::Adt(adt, substs) =>
64-
adt.variants.iter().any(|v| v.fields.iter().any(|f|
65-
may_have_reference(f.ty(tcx, substs), tcx)
66-
)),
57+
// Compound types are not references
58+
ty::Array(..) |
59+
ty::Slice(..) |
60+
ty::Tuple(..) |
61+
ty::Adt(..) =>
62+
false,
6763
// Conservative fallback
6864
_ => true,
6965
}
@@ -80,7 +76,7 @@ impl MirPass for AddRetag {
8076
// FIXME: Instead of giving up for unstable places, we should introduce
8177
// a temporary and retag on that.
8278
is_stable(place.as_ref())
83-
&& may_have_reference(place.ty(&*local_decls, tcx).ty, tcx)
79+
&& may_be_reference(place.ty(&*local_decls, tcx).ty)
8480
};
8581

8682
// PART 1

src/librustc_resolve/build_reduced_graph.rs

-7
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ impl<'a> Resolver<'a> {
126126
};
127127
if let Some(id) = self.definitions.as_local_node_id(def_id) {
128128
self.local_macro_def_scopes[&id]
129-
} else if self.is_builtin_macro(Some(def_id)) {
130-
self.injected_crate.unwrap_or(self.graph_root)
131129
} else {
132130
let module_def_id = ty::DefIdTree::parent(&*self, def_id).unwrap();
133131
self.get_module(module_def_id)
@@ -596,11 +594,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
596594
};
597595

598596
self.r.populate_module_if_necessary(module);
599-
if let Some(name) = self.r.session.parse_sess.injected_crate_name.try_get() {
600-
if name.as_str() == ident.name.as_str() {
601-
self.r.injected_crate = Some(module);
602-
}
603-
}
604597

605598
let used = self.process_legacy_macro_imports(item, module);
606599
let binding =

src/librustc_resolve/diagnostics.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use syntax_pos::{BytePos, Span, MultiSpan};
2020

2121
use crate::resolve_imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
2222
use crate::{path_names_to_string, KNOWN_TOOLS};
23-
use crate::{CrateLint, LegacyScope, Module, ModuleOrUniformRoot};
23+
use crate::{BindingError, CrateLint, LegacyScope, Module, ModuleOrUniformRoot};
2424
use crate::{PathResult, ParentScope, ResolutionError, Resolver, Scope, ScopeSet, Segment};
2525

2626
type Res = def::Res<ast::NodeId>;
@@ -207,21 +207,32 @@ impl<'a> Resolver<'a> {
207207
err
208208
}
209209
ResolutionError::VariableNotBoundInPattern(binding_error) => {
210-
let target_sp = binding_error.target.iter().cloned().collect::<Vec<_>>();
210+
let BindingError { name, target, origin, could_be_path } = binding_error;
211+
212+
let target_sp = target.iter().copied().collect::<Vec<_>>();
213+
let origin_sp = origin.iter().copied().collect::<Vec<_>>();
214+
211215
let msp = MultiSpan::from_spans(target_sp.clone());
212-
let msg = format!("variable `{}` is not bound in all patterns", binding_error.name);
216+
let msg = format!("variable `{}` is not bound in all patterns", name);
213217
let mut err = self.session.struct_span_err_with_code(
214218
msp,
215219
&msg,
216220
DiagnosticId::Error("E0408".into()),
217221
);
218222
for sp in target_sp {
219-
err.span_label(sp, format!("pattern doesn't bind `{}`", binding_error.name));
223+
err.span_label(sp, format!("pattern doesn't bind `{}`", name));
220224
}
221-
let origin_sp = binding_error.origin.iter().cloned();
222225
for sp in origin_sp {
223226
err.span_label(sp, "variable not in all patterns");
224227
}
228+
if *could_be_path {
229+
let help_msg = format!(
230+
"if you meant to match on a variant or a `const` item, consider \
231+
making the path in the pattern qualified: `?::{}`",
232+
name,
233+
);
234+
err.span_help(span, &help_msg);
235+
}
225236
err
226237
}
227238
ResolutionError::VariableBoundWithDifferentMode(variable_name,

0 commit comments

Comments
 (0)