Skip to content

Commit aea9f0a

Browse files
committed
Auto merge of #57607 - Centril:rollup, r=Centril
Rollup of 8 pull requests Successful merges: - #57043 (Fix poor worst case performance of set intersection) - #57480 (Clean up and fix a bug in query plumbing) - #57481 (provide suggestion for invalid boolean cast) - #57540 (Modify some parser diagnostics to continue evaluating beyond the parser) - #57570 (Querify local `plugin_registrar_fn` and `proc_macro_decls_static`) - #57572 (Unaccept `extern_in_paths`) - #57585 (Recover from item trailing semicolon) - #57589 (Add a debug_assert to Vec::set_len) Failed merges: r? @ghost
2 parents 03acbd7 + 8a62e39 commit aea9f0a

File tree

94 files changed

+715
-496
lines changed

Some content is hidden

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

94 files changed

+715
-496
lines changed

src/doc/unstable-book/src/language-features/extern-in-paths.md

-40
This file was deleted.

src/liballoc/vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ impl<T> Vec<T> {
819819
#[inline]
820820
#[stable(feature = "rust1", since = "1.0.0")]
821821
pub unsafe fn set_len(&mut self, new_len: usize) {
822+
debug_assert!(new_len <= self.capacity());
823+
822824
self.len = new_len;
823825
}
824826

src/librustc/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub enum ExternCrateSource {
140140
),
141141
// Crate is loaded by `use`.
142142
Use,
143-
/// Crate is implicitly loaded by an absolute or an `extern::` path.
143+
/// Crate is implicitly loaded by an absolute path.
144144
Path,
145145
}
146146

src/librustc/session/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ pub struct Session {
6969
pub parse_sess: ParseSess,
7070
/// For a library crate, this is always none
7171
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
72-
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
73-
pub proc_macro_decls_static: Once<Option<ast::NodeId>>,
7472
pub sysroot: PathBuf,
7573
/// The name of the root source file of the crate, in the local file system.
7674
/// `None` means that there is no source file.
@@ -1177,8 +1175,6 @@ pub fn build_session_(
11771175
parse_sess: p_s,
11781176
// For a library crate, this is always none
11791177
entry_fn: Once::new(),
1180-
plugin_registrar_fn: Once::new(),
1181-
proc_macro_decls_static: Once::new(),
11821178
sysroot,
11831179
local_crate_source_file,
11841180
working_dir,

src/librustc/ty/query/plumbing.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
402402
// expensive for some DepKinds.
403403
if !self.dep_graph.is_fully_enabled() {
404404
let null_dep_node = DepNode::new_no_params(::dep_graph::DepKind::Null);
405-
return self.force_query_with_job::<Q>(key, job, null_dep_node).map(|(v, _)| v);
405+
return Ok(self.force_query_with_job::<Q>(key, job, null_dep_node).0);
406406
}
407407

408408
let dep_node = Q::to_dep_node(self, &key);
@@ -436,20 +436,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
436436

437437
if !dep_node.kind.is_input() {
438438
if let Some(dep_node_index) = self.try_mark_green_and_read(&dep_node) {
439-
return self.load_from_disk_and_cache_in_memory::<Q>(key,
440-
job,
441-
dep_node_index,
442-
&dep_node)
439+
return Ok(self.load_from_disk_and_cache_in_memory::<Q>(
440+
key,
441+
job,
442+
dep_node_index,
443+
&dep_node
444+
))
443445
}
444446
}
445447

446-
match self.force_query_with_job::<Q>(key, job, dep_node) {
447-
Ok((result, dep_node_index)) => {
448-
self.dep_graph.read_index(dep_node_index);
449-
Ok(result)
450-
}
451-
Err(e) => Err(e)
452-
}
448+
let (result, dep_node_index) = self.force_query_with_job::<Q>(key, job, dep_node);
449+
self.dep_graph.read_index(dep_node_index);
450+
Ok(result)
453451
}
454452

455453
fn load_from_disk_and_cache_in_memory<Q: QueryDescription<'gcx>>(
@@ -458,7 +456,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
458456
job: JobOwner<'a, 'gcx, Q>,
459457
dep_node_index: DepNodeIndex,
460458
dep_node: &DepNode
461-
) -> Result<Q::Value, Box<CycleError<'gcx>>>
459+
) -> Q::Value
462460
{
463461
// Note this function can be called concurrently from the same query
464462
// We must ensure that this is handled correctly
@@ -523,7 +521,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
523521

524522
job.complete(&result, dep_node_index);
525523

526-
Ok(result)
524+
result
527525
}
528526

529527
#[inline(never)]
@@ -563,7 +561,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
563561
key: Q::Key,
564562
job: JobOwner<'_, 'gcx, Q>,
565563
dep_node: DepNode)
566-
-> Result<(Q::Value, DepNodeIndex), Box<CycleError<'gcx>>> {
564+
-> (Q::Value, DepNodeIndex) {
567565
// If the following assertion triggers, it can have two reasons:
568566
// 1. Something is wrong with DepNode creation, either here or
569567
// in DepGraph::try_mark_green()
@@ -610,7 +608,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
610608

611609
job.complete(&result, dep_node_index);
612610

613-
Ok((result, dep_node_index))
611+
(result, dep_node_index)
614612
}
615613

616614
/// Ensure that either this query has all green inputs or been executed.
@@ -657,11 +655,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
657655
// Ensure that only one of them runs the query
658656
let job = match JobOwner::try_get(self, span, &key) {
659657
TryGetJob::NotYetStarted(job) => job,
660-
TryGetJob::JobCompleted(_) => return,
658+
TryGetJob::JobCompleted(result) => {
659+
if let Err(e) = result {
660+
self.report_cycle(e).emit();
661+
}
662+
return
663+
}
661664
};
662-
if let Err(e) = self.force_query_with_job::<Q>(key, job, dep_node) {
663-
self.report_cycle(e).emit();
664-
}
665+
self.force_query_with_job::<Q>(key, job, dep_node);
665666
}
666667

667668
pub(super) fn try_get_query<Q: QueryDescription<'gcx>>(

src/librustc_codegen_ssa/back/symbol_export.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,12 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
147147
})
148148
.collect();
149149

150-
if let Some(id) = *tcx.sess.proc_macro_decls_static.get() {
151-
let def_id = tcx.hir().local_def_id(id);
152-
reachable_non_generics.insert(def_id, SymbolExportLevel::C);
150+
if let Some(id) = tcx.proc_macro_decls_static(LOCAL_CRATE) {
151+
reachable_non_generics.insert(id, SymbolExportLevel::C);
153152
}
154153

155-
if let Some(id) = *tcx.sess.plugin_registrar_fn.get() {
156-
let def_id = tcx.hir().local_def_id(id);
157-
reachable_non_generics.insert(def_id, SymbolExportLevel::C);
154+
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) {
155+
reachable_non_generics.insert(id, SymbolExportLevel::C);
158156
}
159157

160158
Lrc::new(reachable_non_generics)

src/librustc_codegen_utils/symbol_names.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
242242

243243
let node_id = tcx.hir().as_local_node_id(def_id);
244244

245-
if let Some(id) = node_id {
246-
if *tcx.sess.plugin_registrar_fn.get() == Some(id) {
245+
if def_id.is_local() {
246+
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
247247
let disambiguator = tcx.sess.local_crate_disambiguator();
248248
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
249249
}
250-
if *tcx.sess.proc_macro_decls_static.get() == Some(id) {
250+
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
251251
let disambiguator = tcx.sess.local_crate_disambiguator();
252252
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
253253
}

src/librustc_driver/driver.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ where
11581158
}
11591159

11601160
pub fn default_provide(providers: &mut ty::query::Providers) {
1161+
proc_macro_decls::provide(providers);
1162+
plugin::build::provide(providers);
11611163
hir::provide(providers);
11621164
borrowck::provide(providers);
11631165
mir::provide(providers);
@@ -1212,13 +1214,6 @@ where
12121214
middle::entry::find_entry_point(sess, &hir_map, name)
12131215
});
12141216

1215-
sess.plugin_registrar_fn
1216-
.set(time(sess, "looking for plugin registrar", || {
1217-
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
1218-
}));
1219-
sess.proc_macro_decls_static
1220-
.set(proc_macro_decls::find(&hir_map));
1221-
12221217
let mut local_providers = ty::query::Providers::default();
12231218
default_provide(&mut local_providers);
12241219
codegen_backend.provide(&mut local_providers);
@@ -1248,6 +1243,14 @@ where
12481243
// tcx available.
12491244
time(sess, "dep graph tcx init", || rustc_incremental::dep_graph_tcx_init(tcx));
12501245

1246+
time(sess, "looking for plugin registrar", || {
1247+
plugin::build::find_plugin_registrar(tcx)
1248+
});
1249+
1250+
time(sess, "looking for derive registrar", || {
1251+
proc_macro_decls::find(tcx)
1252+
});
1253+
12511254
time(sess, "loop checking", || loops::check_crate(tcx));
12521255

12531256
time(sess, "attribute checking", || {

src/librustc_driver/proc_macro_decls.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
use rustc::hir::itemlikevisit::ItemLikeVisitor;
2-
use rustc::hir::map::Map;
2+
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
33
use rustc::hir;
4+
use rustc::ty::TyCtxt;
5+
use rustc::ty::query::Providers;
46
use syntax::ast;
57
use syntax::attr;
68

7-
pub fn find(hir_map: &Map) -> Option<ast::NodeId> {
8-
let krate = hir_map.krate();
9+
pub fn find<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> {
10+
tcx.proc_macro_decls_static(LOCAL_CRATE)
11+
}
12+
13+
fn proc_macro_decls_static<'tcx>(
14+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
15+
cnum: CrateNum,
16+
) -> Option<DefId> {
17+
assert_eq!(cnum, LOCAL_CRATE);
918

1019
let mut finder = Finder { decls: None };
11-
krate.visit_all_item_likes(&mut finder);
12-
finder.decls
20+
tcx.hir().krate().visit_all_item_likes(&mut finder);
21+
22+
finder.decls.map(|id| tcx.hir().local_def_id(id))
1323
}
1424

1525
struct Finder {
@@ -30,3 +40,9 @@ impl<'v> ItemLikeVisitor<'v> for Finder {
3040
}
3141
}
3242

43+
pub(crate) fn provide(providers: &mut Providers<'_>) {
44+
*providers = Providers {
45+
proc_macro_decls_static,
46+
..*providers
47+
};
48+
}

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! a `pub fn new()`.
2020
2121
use rustc::hir::def::Def;
22-
use rustc::hir::def_id::DefId;
22+
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
2323
use rustc::ty::{self, Ty};
2424
use hir::Node;
2525
use util::nodemap::NodeSet;
@@ -860,7 +860,7 @@ impl LintPass for PluginAsLibrary {
860860

861861
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
862862
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
863-
if cx.sess().plugin_registrar_fn.get().is_some() {
863+
if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() {
864864
// We're compiling a plugin; it's fine to link other plugins.
865865
return;
866866
}

src/librustc_metadata/encoder.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
482482
has_global_allocator: has_global_allocator,
483483
has_panic_handler: has_panic_handler,
484484
has_default_lib_allocator: has_default_lib_allocator,
485-
plugin_registrar_fn: tcx.sess
486-
.plugin_registrar_fn
487-
.get()
488-
.map(|id| tcx.hir().local_def_id(id).index),
485+
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
489486
proc_macro_decls_static: if is_proc_macro {
490-
let id = tcx.sess.proc_macro_decls_static.get().unwrap();
491-
Some(tcx.hir().local_def_id(id).index)
487+
let id = tcx.proc_macro_decls_static(LOCAL_CRATE).unwrap();
488+
Some(id.index)
492489
} else {
493490
None
494491
},

src/librustc_plugin/build.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
33
use syntax::ast;
44
use syntax::attr;
5-
use errors;
65
use syntax_pos::Span;
7-
use rustc::hir::map::Map;
86
use rustc::hir::itemlikevisit::ItemLikeVisitor;
97
use rustc::hir;
8+
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
9+
use rustc::ty::TyCtxt;
10+
use rustc::ty::query::Providers;
1011

1112
struct RegistrarFinder {
1213
registrars: Vec<(ast::NodeId, Span)> ,
@@ -30,21 +31,27 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder {
3031
}
3132

3233
/// Find the function marked with `#[plugin_registrar]`, if any.
33-
pub fn find_plugin_registrar(diagnostic: &errors::Handler,
34-
hir_map: &Map)
35-
-> Option<ast::NodeId> {
36-
let krate = hir_map.krate();
34+
pub fn find_plugin_registrar<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> {
35+
tcx.plugin_registrar_fn(LOCAL_CRATE)
36+
}
37+
38+
fn plugin_registrar_fn<'tcx>(
39+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
40+
cnum: CrateNum,
41+
) -> Option<DefId> {
42+
assert_eq!(cnum, LOCAL_CRATE);
3743

3844
let mut finder = RegistrarFinder { registrars: Vec::new() };
39-
krate.visit_all_item_likes(&mut finder);
45+
tcx.hir().krate().visit_all_item_likes(&mut finder);
4046

4147
match finder.registrars.len() {
4248
0 => None,
4349
1 => {
4450
let (node_id, _) = finder.registrars.pop().unwrap();
45-
Some(node_id)
51+
Some(tcx.hir().local_def_id(node_id))
4652
},
4753
_ => {
54+
let diagnostic = tcx.sess.diagnostic();
4855
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
4956
for &(_, span) in &finder.registrars {
5057
e.span_note(span, "one is here");
@@ -55,3 +62,11 @@ pub fn find_plugin_registrar(diagnostic: &errors::Handler,
5562
}
5663
}
5764
}
65+
66+
67+
pub fn provide(providers: &mut Providers<'_>) {
68+
*providers = Providers {
69+
plugin_registrar_fn,
70+
..*providers
71+
};
72+
}

0 commit comments

Comments
 (0)