Skip to content

Commit eb2226b

Browse files
committed
Auto merge of #85296 - bjorn3:plugin_cleanup, r=petrochenkov
Plugin interface cleanup The first commit performs two uncontroversial cleanups. The second commit removes `#[plugin_registrar]` and instead requires you to export a `__rustc_plugin_registrar` function, this will require a change to servo's script_plugins (cc `@jdm)`
2 parents 25d3e14 + a501308 commit eb2226b

35 files changed

+287
-556
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-8
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
375375
}
376376

377377
ast::ItemKind::Fn(..) => {
378-
if self.sess.contains_name(&i.attrs[..], sym::plugin_registrar) {
379-
gate_feature_post!(
380-
&self,
381-
plugin_registrar,
382-
i.span,
383-
"compiler plugins are experimental and possibly buggy"
384-
);
385-
}
386378
if self.sess.contains_name(&i.attrs[..], sym::start) {
387379
gate_feature_post!(
388380
&self,

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

-4
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
137137
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
138138
}
139139

140-
if let Some(id) = tcx.plugin_registrar_fn(()) {
141-
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
142-
}
143-
144140
reachable_non_generics
145141
}
146142

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ declare_features! (
281281
// feature-group-start: actual feature gates
282282
// -------------------------------------------------------------------------
283283

284-
/// Allows using `#[plugin_registrar]` on functions.
285-
(active, plugin_registrar, "1.0.0", Some(29597), None),
286-
287284
/// Allows using `#![plugin(myplugin)]`.
288285
(active, plugin, "1.0.0", Some(29597), None),
289286

compiler/rustc_feature/src/builtin_attrs.rs

-12
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
291291
),
292292

293293
// Plugins:
294-
(
295-
sym::plugin_registrar, Normal, template!(Word),
296-
Gated(
297-
Stability::Deprecated(
298-
"https://github.com/rust-lang/rust/pull/64675",
299-
Some("may be removed in a future compiler version"),
300-
),
301-
sym::plugin_registrar,
302-
"compiler plugins are deprecated",
303-
cfg_fn!(plugin_registrar)
304-
)
305-
),
306294
(
307295
sym::plugin, CrateLevel, template!(List: "name"),
308296
Gated(

compiler/rustc_feature/src/removed.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ declare_features! (
136136
(removed, main, "1.53.0", Some(29634), None, None),
137137
(removed, pub_macro_rules, "1.53.0", Some(78855), None,
138138
Some("removed due to being incomplete, in particular it does not work across crates")),
139-
/// Allows the definition of `const` functions with some advanced features.
139+
/// Allows the definition of `const` functions with some advanced features.
140140
(removed, const_fn, "1.54.0", Some(57563), None,
141141
Some("split into finer-grained feature gates")),
142+
/// Allows using `#[plugin_registrar]` on functions.
143+
(removed, plugin_registrar, "1.54.0", Some(29597), None,
144+
Some("a __rustc_plugin_registrar symbol must now be defined instead")),
142145

143146
/// Allows `#[doc(include = "some-file")]`.
144147
(removed, external_doc, "1.54.0", Some(44732), None,

compiler/rustc_interface/src/passes.rs

-3
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,6 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
741741
let providers = &mut Providers::default();
742742
providers.analysis = analysis;
743743
proc_macro_decls::provide(providers);
744-
plugin::build::provide(providers);
745744
rustc_middle::hir::provide(providers);
746745
mir::provide(providers);
747746
mir_build::provide(providers);
@@ -856,8 +855,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
856855
{
857856
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
858857

859-
sess.time("looking_for_plugin_registrar", || tcx.ensure().plugin_registrar_fn(()));
860-
861858
sess.time("looking_for_derive_registrar", || {
862859
tcx.ensure().proc_macro_decls_static(())
863860
});

compiler/rustc_metadata/src/locator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ use rustc_session::config::{self, CrateType};
226226
use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch};
227227
use rustc_session::search_paths::PathKind;
228228
use rustc_session::utils::CanonicalizedPath;
229-
use rustc_session::{Session, StableCrateId};
229+
use rustc_session::Session;
230230
use rustc_span::symbol::{sym, Symbol};
231231
use rustc_span::Span;
232232
use rustc_target::spec::{Target, TargetTriple};
@@ -787,7 +787,7 @@ pub fn find_plugin_registrar(
787787
metadata_loader: &dyn MetadataLoader,
788788
span: Span,
789789
name: Symbol,
790-
) -> (PathBuf, StableCrateId) {
790+
) -> PathBuf {
791791
match find_plugin_registrar_impl(sess, metadata_loader, name) {
792792
Ok(res) => res,
793793
// `core` is always available if we got as far as loading plugins.
@@ -799,7 +799,7 @@ fn find_plugin_registrar_impl<'a>(
799799
sess: &'a Session,
800800
metadata_loader: &dyn MetadataLoader,
801801
name: Symbol,
802-
) -> Result<(PathBuf, StableCrateId), CrateError> {
802+
) -> Result<PathBuf, CrateError> {
803803
info!("find plugin registrar `{}`", name);
804804
let mut locator = CrateLocator::new(
805805
sess,
@@ -816,7 +816,7 @@ fn find_plugin_registrar_impl<'a>(
816816

817817
match locator.maybe_load_library_crate()? {
818818
Some(library) => match library.source.dylib {
819-
Some(dylib) => Ok((dylib.0, library.metadata.get_root().stable_crate_id())),
819+
Some(dylib) => Ok(dylib.0),
820820
None => Err(CrateError::NonDylibPlugin(name)),
821821
},
822822
None => Err(locator.into_error()),

compiler/rustc_middle/src/query/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,6 @@ rustc_queries! {
12521252
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
12531253
desc { "looking up the entry function of a crate" }
12541254
}
1255-
query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
1256-
desc { "looking up the plugin registrar for a crate" }
1257-
}
12581255
query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
12591256
desc { "looking up the derive registrar for a crate" }
12601257
}

compiler/rustc_plugin_impl/src/build.rs

-57
This file was deleted.

compiler/rustc_plugin_impl/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use rustc_lint::LintStore;
1414

15-
pub mod build;
1615
pub mod load;
1716

1817
/// Structure used to register plugins.

compiler/rustc_plugin_impl/src/load.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,13 @@ fn load_plugin(
5555
metadata_loader: &dyn MetadataLoader,
5656
ident: Ident,
5757
) {
58-
let (lib, disambiguator) =
59-
locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name);
60-
let symbol = sess.generate_plugin_registrar_symbol(disambiguator);
61-
let fun = dylink_registrar(sess, ident.span, lib, symbol);
58+
let lib = locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name);
59+
let fun = dylink_registrar(sess, ident.span, lib);
6260
plugins.push(fun);
6361
}
6462

6563
// Dynamically link a registrar function into the compiler process.
66-
fn dylink_registrar(
67-
sess: &Session,
68-
span: Span,
69-
path: PathBuf,
70-
symbol: String,
71-
) -> PluginRegistrarFn {
64+
fn dylink_registrar(sess: &Session, span: Span, path: PathBuf) -> PluginRegistrarFn {
7265
use rustc_metadata::dynamic_lib::DynamicLibrary;
7366

7467
// Make sure the path contains a / or the linker will search for it.
@@ -83,15 +76,15 @@ fn dylink_registrar(
8376
};
8477

8578
unsafe {
86-
let registrar = match lib.symbol(&symbol) {
79+
let registrar = match lib.symbol("__rustc_plugin_registrar") {
8780
Ok(registrar) => mem::transmute::<*mut u8, PluginRegistrarFn>(registrar),
8881
// again fatal if we can't register macros
8982
Err(err) => sess.span_fatal(span, &err),
9083
};
9184

9285
// Intentionally leak the dynamic library. We can't ever unload it
9386
// since the library can make things that will live arbitrarily long
94-
// (e.g., an @-box cycle or a thread).
87+
// (e.g., an Rc cycle or a thread).
9588
mem::forget(lib);
9689

9790
registrar

compiler/rustc_session/src/session.rs

-6
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,6 @@ impl Session {
792792
)
793793
}
794794

795-
/// Returns the symbol name for the registrar function,
796-
/// given the crate `Svh` and the function `DefIndex`.
797-
pub fn generate_plugin_registrar_symbol(&self, stable_crate_id: StableCrateId) -> String {
798-
format!("__rustc_plugin_registrar_{:08x}__", stable_crate_id.to_u64())
799-
}
800-
801795
pub fn generate_proc_macro_decls_symbol(&self, stable_crate_id: StableCrateId) -> String {
802796
format!("__rustc_proc_macro_decls_{:08x}__", stable_crate_id.to_u64())
803797
}

compiler/rustc_symbol_mangling/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ fn compute_symbol_name(
164164

165165
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
166166
let is_foreign = if let Some(def_id) = def_id.as_local() {
167-
if tcx.plugin_registrar_fn(()) == Some(def_id) {
168-
let stable_crate_id = tcx.sess.local_stable_crate_id();
169-
return tcx.sess.generate_plugin_registrar_symbol(stable_crate_id);
170-
}
171167
if tcx.proc_macro_decls_static(()) == Some(def_id) {
172168
let stable_crate_id = tcx.sess.local_stable_crate_id();
173169
return tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id);

src/doc/unstable-book/src/language-features/plugin-registrar.md

-13
This file was deleted.

src/doc/unstable-book/src/language-features/plugin.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ The tracking issue for this feature is: [#29597]
66

77

88
This feature is part of "compiler plugins." It will often be used with the
9-
[`plugin_registrar`] and `rustc_private` features.
10-
11-
[`plugin_registrar`]: plugin-registrar.md
9+
`rustc_private` feature.
1210

1311
------------------------
1412

@@ -39,7 +37,6 @@ additional checks for code style, safety, etc. Now let's write a plugin
3937
that warns about any item named `lintme`.
4038

4139
```rust,ignore (requires-stage-2)
42-
#![feature(plugin_registrar)]
4340
#![feature(box_syntax, rustc_private)]
4441
4542
extern crate rustc_ast;
@@ -68,8 +65,8 @@ impl EarlyLintPass for Pass {
6865
}
6966
}
7067
71-
#[plugin_registrar]
72-
pub fn plugin_registrar(reg: &mut Registry) {
68+
#[no_mangle]
69+
fn __rustc_plugin_registrar(reg: &mut Registry) {
7370
reg.lint_store.register_lints(&[&TEST_LINT]);
7471
reg.lint_store.register_early_pass(|| box Pass);
7572
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// force-host
22

3-
#![feature(plugin_registrar)]
43
#![feature(rustc_private)]
54

65
extern crate rustc_driver;
76
use rustc_driver::plugin::Registry;
87

9-
#[plugin_registrar]
10-
pub fn plugin_registrar(_: &mut Registry) {}
8+
#[no_mangle]
9+
fn __rustc_plugin_registrar(_: &mut Registry) {}

src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#![feature(box_syntax, plugin, plugin_registrar, rustc_private)]
1+
#![feature(box_syntax, plugin, rustc_private)]
22
#![crate_type = "dylib"]
33

44
extern crate rustc_ast_pretty;
55
extern crate rustc_driver;
66
extern crate rustc_hir;
7-
#[macro_use]
87
extern crate rustc_lint;
98
#[macro_use]
109
extern crate rustc_session;
@@ -16,11 +15,11 @@ use rustc_driver::plugin::Registry;
1615
use rustc_hir as hir;
1716
use rustc_hir::intravisit;
1817
use rustc_hir::Node;
19-
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
18+
use rustc_lint::{LateContext, LateLintPass, LintContext};
2019
use rustc_span::source_map;
2120

22-
#[plugin_registrar]
23-
pub fn plugin_registrar(reg: &mut Registry) {
21+
#[no_mangle]
22+
fn __rustc_plugin_registrar(reg: &mut Registry) {
2423
reg.lint_store.register_lints(&[&MISSING_ALLOWED_ATTR]);
2524
reg.lint_store.register_late_pass(|| box MissingAllowedAttrPass);
2625
}

src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// force-host
22

3-
#![feature(plugin_registrar, rustc_private)]
3+
#![feature(rustc_private)]
44
#![feature(box_syntax)]
55

66
extern crate rustc_driver;
@@ -64,8 +64,8 @@ fake_lint_pass! {
6464
Symbol::intern("crate_grey"), Symbol::intern("crate_green")
6565
}
6666

67-
#[plugin_registrar]
68-
pub fn plugin_registrar(reg: &mut Registry) {
67+
#[no_mangle]
68+
fn __rustc_plugin_registrar(reg: &mut Registry) {
6969
reg.lint_store.register_lints(&[
7070
&CRATE_NOT_OKAY,
7171
&CRATE_NOT_RED,

src/test/ui-fulldeps/auxiliary/lint-for-crate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// force-host
22

3-
#![feature(plugin_registrar, rustc_private)]
3+
#![feature(rustc_private)]
44
#![feature(box_syntax)]
55

66
extern crate rustc_driver;
@@ -38,8 +38,8 @@ impl<'tcx> LateLintPass<'tcx> for Pass {
3838
}
3939
}
4040

41-
#[plugin_registrar]
42-
pub fn plugin_registrar(reg: &mut Registry) {
41+
#[no_mangle]
42+
fn __rustc_plugin_registrar(reg: &mut Registry) {
4343
reg.lint_store.register_lints(&[&CRATE_NOT_OKAY]);
4444
reg.lint_store.register_late_pass(|| box Pass);
4545
}

0 commit comments

Comments
 (0)