Skip to content

Commit

Permalink
Remove support for compiler plugins.
Browse files Browse the repository at this point in the history
They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in
  `compiler/rustc_driver_impl/src/lib.rs` and
  `compiler/rustc_lint/src/context.rs`. External lints are now called
  "loaded" lints, rather than "plugins" to avoid confusion with the old
  plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in
  `tests/ui-fulldeps/plugin/`.

Closes #29597.
  • Loading branch information
nnethercote committed Oct 4, 2023
1 parent 36aab8d commit 0fcfd98
Show file tree
Hide file tree
Showing 101 changed files with 57 additions and 1,692 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3666,7 +3666,6 @@ dependencies = [
"rustc_monomorphize",
"rustc_parse",
"rustc_passes",
"rustc_plugin_impl",
"rustc_privacy",
"rustc_query_system",
"rustc_resolve",
Expand Down Expand Up @@ -3956,7 +3955,6 @@ dependencies = [
"rustc_monomorphize",
"rustc_parse",
"rustc_passes",
"rustc_plugin_impl",
"rustc_privacy",
"rustc_query_impl",
"rustc_query_system",
Expand Down Expand Up @@ -4266,21 +4264,6 @@ dependencies = [
"tracing",
]

[[package]]
name = "rustc_plugin_impl"
version = "0.0.0"
dependencies = [
"libloading 0.7.4",
"rustc_ast",
"rustc_errors",
"rustc_fluent_macro",
"rustc_lint",
"rustc_macros",
"rustc_metadata",
"rustc_session",
"rustc_span",
]

[[package]]
name = "rustc_privacy"
version = "0.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ rm -r tests/run-make/split-debuginfo # same
rm -r tests/run-make/symbols-include-type-name # --emit=asm not supported
rm -r tests/run-make/target-specs # i686 not supported by Cranelift
rm -r tests/run-make/mismatching-target-triples # same
rm -r tests/run-make/use-extern-for-plugins # same

# requires LTO
rm -r tests/run-make/cdylib
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rustc_hir_pretty = { path = "../rustc_hir_pretty" }
rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_parse = { path = "../rustc_parse" }
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
rustc_session = { path = "../rustc_session" }
rustc_error_codes = { path = "../rustc_error_codes" }
Expand Down
45 changes: 21 additions & 24 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#[macro_use]
extern crate tracing;

pub extern crate rustc_plugin_impl as plugin;

use rustc_ast as ast;
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_data_structures::profiling::{
Expand Down Expand Up @@ -129,7 +127,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_monomorphize::DEFAULT_LOCALE_RESOURCE,
rustc_parse::DEFAULT_LOCALE_RESOURCE,
rustc_passes::DEFAULT_LOCALE_RESOURCE,
rustc_plugin_impl::DEFAULT_LOCALE_RESOURCE,
rustc_privacy::DEFAULT_LOCALE_RESOURCE,
rustc_query_system::DEFAULT_LOCALE_RESOURCE,
rustc_resolve::DEFAULT_LOCALE_RESOURCE,
Expand Down Expand Up @@ -970,16 +967,14 @@ the command line flag directly.
}

/// Write to stdout lint command options, together with a list of all available lints
pub fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_plugins: bool) {
pub fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_lints: bool) {
safe_println!(
"
Available lint options:
-W <foo> Warn about <foo>
-A <foo> \
Allow <foo>
-A <foo> Allow <foo>
-D <foo> Deny <foo>
-F <foo> Forbid <foo> \
(deny <foo> and all attempts to override)
-F <foo> Forbid <foo> (deny <foo> and all attempts to override)
"
);
Expand All @@ -998,18 +993,18 @@ Available lint options:
lints
}

let (plugin, builtin): (Vec<_>, _) =
lint_store.get_lints().iter().cloned().partition(|&lint| lint.is_plugin);
let plugin = sort_lints(sess, plugin);
let (loaded, builtin): (Vec<_>, _) =
lint_store.get_lints().iter().cloned().partition(|&lint| lint.is_loaded);
let loaded = sort_lints(sess, loaded);
let builtin = sort_lints(sess, builtin);

let (plugin_groups, builtin_groups): (Vec<_>, _) =
let (loaded_groups, builtin_groups): (Vec<_>, _) =
lint_store.get_lint_groups().partition(|&(.., p)| p);
let plugin_groups = sort_lint_groups(plugin_groups);
let loaded_groups = sort_lint_groups(loaded_groups);
let builtin_groups = sort_lint_groups(builtin_groups);

let max_name_len =
plugin.iter().chain(&builtin).map(|&s| s.name.chars().count()).max().unwrap_or(0);
loaded.iter().chain(&builtin).map(|&s| s.name.chars().count()).max().unwrap_or(0);
let padded = |x: &str| {
let mut s = " ".repeat(max_name_len - x.chars().count());
s.push_str(x);
Expand Down Expand Up @@ -1037,7 +1032,7 @@ Available lint options:

let max_name_len = max(
"warnings".len(),
plugin_groups
loaded_groups
.iter()
.chain(&builtin_groups)
.map(|&(s, _)| s.chars().count())
Expand Down Expand Up @@ -1075,20 +1070,22 @@ Available lint options:

print_lint_groups(builtin_groups, true);

match (loaded_plugins, plugin.len(), plugin_groups.len()) {
match (loaded_lints, loaded.len(), loaded_groups.len()) {
(false, 0, _) | (false, _, 0) => {
safe_println!("Lint tools like Clippy can provide additional lints and lint groups.");
safe_println!("Lint tools like Clippy can load additional lints and lint groups.");
}
(false, ..) => panic!("didn't load additional lints but got them anyway!"),
(true, 0, 0) => {
safe_println!("This crate does not load any additional lints or lint groups.")
}
(false, ..) => panic!("didn't load lint plugins but got them anyway!"),
(true, 0, 0) => safe_println!("This crate does not load any lint plugins or lint groups."),
(true, l, g) => {
if l > 0 {
safe_println!("Lint checks provided by plugins loaded by this crate:\n");
print_lints(plugin);
safe_println!("Lint checks loaded by this crate:\n");
print_lints(loaded);
}
if g > 0 {
safe_println!("Lint groups provided by plugins loaded by this crate:\n");
print_lint_groups(plugin_groups, false);
safe_println!("Lint groups loaded by this crate:\n");
print_lint_groups(loaded_groups, false);
}
}
}
Expand All @@ -1105,7 +1102,7 @@ pub fn describe_flag_categories(handler: &EarlyErrorHandler, matches: &Matches)
rustc_errors::FatalError.raise();
}

// Don't handle -W help here, because we might first load plugins.
// Don't handle -W help here, because we might first load additional lints.
let debug_flags = matches.opt_strs("Z");
if debug_flags.iter().any(|x| *x == "help") {
describe_debug_flags();
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0457.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#### Note: this error code is no longer emitted by the compiler`

Plugin `..` only found in rlib format, but must be available in dylib format.

Erroneous code example:
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_error_codes/src/error_codes/E0463.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
A plugin/crate was declared but cannot be found.
A crate was declared but cannot be found.

Erroneous code example:

```compile_fail,E0463
#![feature(plugin)]
#![plugin(cookie_monster)] // error: can't find crate for `cookie_monster`
extern crate cake_is_a_lie; // error: can't find crate for `cake_is_a_lie`
extern crate foo; // error: can't find crate
```

You need to link your code to the relevant crate in order to be able to use it
(through Cargo or the `-L` option of rustc example). Plugins are crates as
well, and you link to them the same way.
(through Cargo or the `-L` option of rustc, for example).

## Common causes

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0498.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

The `plugin` attribute was malformed.

Erroneous code example:

```compile_fail,E0498
```ignore (E0498 is no longer emitted)
#![feature(plugin)]
#![plugin(foo(args))] // error: invalid argument
#![plugin(bar="test")] // error: invalid argument
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,6 @@ declare_features! (
(active, object_safe_for_dispatch, "1.40.0", Some(43561), None),
/// Allows using `#[optimize(X)]`.
(active, optimize_attribute, "1.34.0", Some(54882), None),
/// Allows using `#![plugin(myplugin)]`.
(active, plugin, "1.0.0", Some(29597), None),
/// Allows exhaustive integer pattern matching on `usize` and `isize`.
(active, precise_pointer_size_matching, "1.32.0", Some(56354), None),
/// Allows macro attributes on expressions, statements and non-inline modules.
Expand Down
18 changes: 0 additions & 18 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,24 +417,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
naked_functions, experimental!(naked)
),

// Plugins:
BuiltinAttribute {
name: sym::plugin,
only_local: false,
type_: CrateLevel,
template: template!(List: "name"),
duplicates: DuplicatesOk,
gate: Gated(
Stability::Deprecated(
"https://github.com/rust-lang/rust/pull/64675",
Some("may be removed in a future compiler version"),
),
sym::plugin,
"compiler plugins are deprecated",
cfg_fn!(plugin)
),
},

// Testing:
gated!(
test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, custom_test_frameworks,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ declare_features! (
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
(removed, panic_implementation, "1.28.0", Some(44489), None,
Some("subsumed by `#[panic_handler]`")),
/// Allows using `#![plugin(myplugin)]`.
(removed, plugin, "1.74.0", Some(29597), None, // njn: version?
Some("plugins are no longer supported")),
/// Allows using `#[plugin_registrar]` on functions.
(removed, plugin_registrar, "1.54.0", Some(29597), None,
Some("a __rustc_plugin_registrar symbol must now be defined instead")),
Some("plugins are no longer supported")),
(removed, proc_macro_expr, "1.27.0", Some(54727), None,
Some("subsumed by `#![feature(proc_macro_hygiene)]`")),
(removed, proc_macro_gen, "1.27.0", Some(54727), None,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ rustc_hir_analysis = { path = "../rustc_hir_analysis" }
rustc_hir_typeck = { path = "../rustc_hir_typeck" }
rustc_lint = { path = "../rustc_lint" }
rustc_errors = { path = "../rustc_errors" }
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
rustc_privacy = { path = "../rustc_privacy" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_query_impl = { path = "../rustc_query_impl" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub struct Config {
pub parse_sess_created: Option<Box<dyn FnOnce(&mut ParseSess) + Send>>,

/// This is a callback from the driver that is called when we're registering lints;
/// it is called during plugin registration when we have the LintStore in a non-shared state.
/// it is called during lint loading when we have the LintStore in a non-shared state.
///
/// Note that if you find a Some here you probably want to call that function in the new
/// function being registered.
Expand Down
16 changes: 1 addition & 15 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ use rustc_middle::util::Providers;
use rustc_mir_build as mir_build;
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str, validate_attr};
use rustc_passes::{self, abi_test, hir_stats, layout_test};
use rustc_plugin_impl as plugin;
use rustc_resolve::Resolver;
use rustc_session::code_stats::VTableSizeInfo;
use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
use rustc_session::cstore::{MetadataLoader, Untracked};
use rustc_session::cstore::Untracked;
use rustc_session::output::filename_for_input;
use rustc_session::search_paths::PathKind;
use rustc_session::{Limit, Session};
Expand Down Expand Up @@ -75,25 +74,12 @@ fn count_nodes(krate: &ast::Crate) -> usize {

pub(crate) fn create_lint_store(
sess: &Session,
metadata_loader: &dyn MetadataLoader,
register_lints: Option<impl Fn(&Session, &mut LintStore)>,
pre_configured_attrs: &[ast::Attribute],
) -> LintStore {
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
if let Some(register_lints) = register_lints {
register_lints(sess, &mut lint_store);
}

let registrars = sess.time("plugin_loading", || {
plugin::load::load_plugins(sess, metadata_loader, pre_configured_attrs)
});
sess.time("plugin_registration", || {
let mut registry = plugin::Registry { lint_store: &mut lint_store };
for registrar in registrars {
registrar(&mut registry);
}
});

lint_store
}

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@ impl<'tcx> Queries<'tcx> {
);
let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?;

let lint_store = Lrc::new(passes::create_lint_store(
sess,
&*self.codegen_backend().metadata_loader(),
self.compiler.register_lints.as_deref(),
&pre_configured_attrs,
));
let lint_store =
Lrc::new(passes::create_lint_store(sess, self.compiler.register_lints.as_deref()));
let cstore = FreezeLock::new(Box::new(CStore::new(
self.codegen_backend().metadata_loader(),
stable_crate_id,
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct LintAlias {

struct LintGroup {
lint_ids: Vec<LintId>,
from_plugin: bool,
is_loaded: bool,
depr: Option<LintAlias>,
}

Expand Down Expand Up @@ -160,9 +160,7 @@ impl LintStore {
// Don't display deprecated lint groups.
depr.is_none()
})
.map(|(k, LintGroup { lint_ids, from_plugin, .. })| {
(*k, lint_ids.clone(), *from_plugin)
})
.map(|(k, LintGroup { lint_ids, is_loaded, .. })| (*k, lint_ids.clone(), *is_loaded))
}

pub fn register_early_pass(
Expand Down Expand Up @@ -221,7 +219,7 @@ impl LintStore {
.entry(edition.lint_name())
.or_insert(LintGroup {
lint_ids: vec![],
from_plugin: lint.is_plugin,
is_loaded: lint.is_loaded,
depr: None,
})
.lint_ids
Expand All @@ -234,7 +232,7 @@ impl LintStore {
.entry("future_incompatible")
.or_insert(LintGroup {
lint_ids: vec![],
from_plugin: lint.is_plugin,
is_loaded: lint.is_loaded,
depr: None,
})
.lint_ids
Expand All @@ -249,29 +247,29 @@ impl LintStore {
alias,
LintGroup {
lint_ids: vec![],
from_plugin: false,
is_loaded: false,
depr: Some(LintAlias { name: lint_name, silent: true }),
},
);
}

pub fn register_group(
&mut self,
from_plugin: bool,
is_loaded: bool,
name: &'static str,
deprecated_name: Option<&'static str>,
to: Vec<LintId>,
) {
let new = self
.lint_groups
.insert(name, LintGroup { lint_ids: to, from_plugin, depr: None })
.insert(name, LintGroup { lint_ids: to, is_loaded, depr: None })
.is_none();
if let Some(deprecated) = deprecated_name {
self.lint_groups.insert(
deprecated,
LintGroup {
lint_ids: vec![],
from_plugin,
is_loaded,
depr: Some(LintAlias { name, silent: false }),
},
);
Expand Down
Loading

0 comments on commit 0fcfd98

Please sign in to comment.