Skip to content

Commit

Permalink
Rollup merge of rust-lang#66905 - petrochenkov:rmplugin2, r=Centril
Browse files Browse the repository at this point in the history
rustc_plugin: Remove some remaining plugin features

- Plugin arguments (`#![plugin(my_plugin(args))]`) are no longer supported.
- Registering additional plugins from command line (`-Z extra-plugins=my_plugin`) is no longer supported, `-Z crate-attr=plugin(my_plugin)` can be used instead.
- Lint `plugin_as_library` is removed as mostly useless now, when plugins exist as a compatibility feature with greatly reduced functionality.
- Plugins registering additional LLVM passes (`Registry::register_llvm_pass`) are no longer supported, `-C                   passes=my_passes` can be used instead.

r? @Centril
  • Loading branch information
Centril authored Dec 2, 2019
2 parents dbe880e + e5944a5 commit 90ac082
Show file tree
Hide file tree
Showing 36 changed files with 141 additions and 405 deletions.
12 changes: 0 additions & 12 deletions src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,6 @@ warning: path statement with no effect
|
```

## plugin-as-library

This lint detects when compiler plugins are used as ordinary library in
non-plugin crate. Some example code that triggers this lint:

```rust,ignore
#![feature(plugin)]
#![plugin(macro_crate_test)]
extern crate macro_crate_test;
```

## private-in-public

This lint detects private items in public interfaces not caught by the old implementation. Some
Expand Down
7 changes: 1 addition & 6 deletions src/doc/unstable-book/src/language-features/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@ the crate attribute `#![plugin(...)]`. See the
`rustc_driver::plugin` documentation for more about the
mechanics of defining and loading a plugin.

If present, arguments passed as `#![plugin(foo(... args ...))]` are not
interpreted by rustc itself. They are provided to the plugin through the
`Registry`'s `args` method.

In the vast majority of cases, a plugin should *only* be used through
`#![plugin]` and not through an `extern crate` item. Linking a plugin would
pull in all of libsyntax and librustc as dependencies of your crate. This is
generally unwanted unless you are building another plugin. The
`plugin_as_library` lint checks these guidelines.
generally unwanted unless you are building another plugin.

The usual practice is to put compiler plugins in their own crate, separate from
any `macro_rules!` macros or ordinary Rust code meant to be used by consumers
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ use rustc_error_codes::*;
/// This is basically the subset of `Context` that we can
/// build early in the compile pipeline.
pub struct LintStore {
/// Registered lints. The bool is true if the lint was
/// added by a plugin.
/// Registered lints.
lints: Vec<&'static Lint>,

/// Constructor functions for each variety of lint pass.
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,8 +1364,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"enable queries of the dependency graph for regression testing"),
no_analysis: bool = (false, parse_bool, [UNTRACKED],
"parse and expand the source, but run no analysis"),
extra_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
"load extra plugins"),
unstable_options: bool = (false, parse_bool, [UNTRACKED],
"adds unstable command line options to rustc interface"),
force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub struct Session {
/// (sub)diagnostics that have been set once, but should not be set again,
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
pub crate_types: Once<Vec<config::CrateType>>,
/// The `crate_disambiguator` is constructed out of all the `-C metadata`
/// arguments passed to the compiler. Its value together with the crate-name
Expand Down Expand Up @@ -1149,7 +1148,6 @@ fn build_session_(
local_crate_source_file,
working_dir,
one_time_diagnostics: Default::default(),
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
crate_types: Once::new(),
crate_disambiguator: Once::new(),
features: Once::new(),
Expand Down
14 changes: 0 additions & 14 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,6 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,

add_sanitizer_passes(config, &mut extra_passes);

for pass_name in &cgcx.plugin_passes {
if let Some(pass) = find_pass(pass_name) {
extra_passes.push(pass);
} else {
diag_handler.err(&format!("a plugin asked for LLVM pass \
`{}` but LLVM does not \
recognize it", pass_name));
}

if pass_name == "name-anon-globals" {
have_name_anon_globals_pass = true;
}
}

// Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
// to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
// we'll get errors in LLVM.
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
pub total_cgus: usize,
// Handler to use for diagnostics produced during codegen.
pub diag_emitter: SharedEmitter,
// LLVM passes added by plugins.
pub plugin_passes: Vec<String>,
// LLVM optimizations for which we want to print remarks.
pub remark: Passes,
// Worker thread number
Expand Down Expand Up @@ -1028,7 +1026,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
time_passes: sess.time_extended(),
prof: sess.prof.clone(),
exported_symbols,
plugin_passes: sess.plugin_llvm_passes.borrow().clone(),
remark: sess.opts.cg.remark.clone(),
worker: 0,
incr_comp_session_dir: sess.incr_comp_session_dir_opt().map(|r| r.clone()),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_feature/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
)
),
(
sym::plugin, CrateLevel, template!(List: "name|name(args)"),
sym::plugin, CrateLevel, template!(List: "name"),
Gated(
Stability::Deprecated(
"https://github.com/rust-lang/rust/pull/64675",
Expand Down
27 changes: 7 additions & 20 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use rustc_mir as mir;
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
use rustc_passes::{self, ast_validation, hir_stats, layout_test};
use rustc_plugin_impl as plugin;
use rustc_plugin_impl::registry::Registry;
use rustc_privacy;
use rustc_resolve::{Resolver, ResolverArenas};
use rustc_traits;
Expand Down Expand Up @@ -106,8 +105,7 @@ declare_box_region_type!(
(&mut Resolver<'_>) -> (Result<ast::Crate>, ResolverOutputs)
);

/// Runs the "early phases" of the compiler: initial `cfg` processing,
/// loading compiler plugins (including those from `addl_plugins`),
/// Runs the "early phases" of the compiler: initial `cfg` processing, loading compiler plugins,
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
/// harness if one is to be provided, injection of a dependency on the
/// standard library and prelude, and name resolution.
Expand Down Expand Up @@ -209,33 +207,22 @@ pub fn register_plugins<'a>(
middle::recursion_limit::update_limits(sess, &krate);
});

let registrars = time(sess, "plugin loading", || {
plugin::load::load_plugins(
sess,
metadata_loader,
&krate,
Some(sess.opts.debugging_opts.extra_plugins.clone()),
)
});

let mut lint_store = rustc_lint::new_lint_store(
sess.opts.debugging_opts.no_interleave_lints,
sess.unstable_options(),
);
register_lints(&sess, &mut lint_store);

(register_lints)(&sess, &mut lint_store);

let mut registry = Registry::new(sess, &mut lint_store, krate.span);

let registrars = time(sess, "plugin loading", || {
plugin::load::load_plugins(sess, metadata_loader, &krate)
});
time(sess, "plugin registration", || {
let mut registry = plugin::Registry { lint_store: &mut lint_store };
for registrar in registrars {
registry.args_hidden = Some(registrar.args);
(registrar.fun)(&mut registry);
registrar(&mut registry);
}
});

*sess.plugin_llvm_passes.borrow_mut() = registry.llvm_passes;

Ok((krate, Lrc::new(lint_store)))
}

Expand Down
4 changes: 0 additions & 4 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,6 @@ fn test_debugging_options_tracking_hash() {
opts.debugging_opts.continue_parse_after_error = true;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.extra_plugins = vec![String::from("plugin1"), String::from("plugin2")];
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.force_overflow_checks = Some(true);
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
Expand Down
42 changes: 1 addition & 41 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use std::fmt::Write;

use rustc::hir::def::{Res, DefKind};
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::hir::def_id::DefId;
use rustc::ty::{self, Ty, TyCtxt, layout::VariantIdx};
use rustc::{lint, util};
use rustc::lint::FutureIncompatibleInfo;
Expand Down Expand Up @@ -800,45 +800,6 @@ impl EarlyLintPass for UnusedDocComment {
}
}

declare_lint! {
PLUGIN_AS_LIBRARY,
Warn,
"compiler plugin used as ordinary library in non-plugin crate"
}

declare_lint_pass!(PluginAsLibrary => [PLUGIN_AS_LIBRARY]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item) {
if cx.tcx.plugin_registrar_fn(LOCAL_CRATE).is_some() {
// We're compiling a plugin; it's fine to link other plugins.
return;
}

match it.kind {
hir::ItemKind::ExternCrate(..) => (),
_ => return,
};

let def_id = cx.tcx.hir().local_def_id(it.hir_id);
let prfn = match cx.tcx.extern_mod_stmt_cnum(def_id) {
Some(cnum) => cx.tcx.plugin_registrar_fn(cnum),
None => {
// Probably means we aren't linking the crate for some reason.
//
// Not sure if / when this could happen.
return;
}
};

if prfn.is_some() {
cx.span_lint(PLUGIN_AS_LIBRARY,
it.span,
"compiler plugin used as an ordinary library");
}
}
}

declare_lint! {
NO_MANGLE_CONST_ITEMS,
Deny,
Expand Down Expand Up @@ -1268,7 +1229,6 @@ declare_lint_pass!(
MISSING_DEBUG_IMPLEMENTATIONS,
ANONYMOUS_PARAMETERS,
UNUSED_DOC_COMMENTS,
PLUGIN_AS_LIBRARY,
NO_MANGLE_CONST_ITEMS,
NO_MANGLE_GENERIC_ITEMS,
MUTABLE_TRANSMUTES,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ macro_rules! late_lint_mod_passes {
// Depends on types used in type definitions
MissingCopyImplementations: MissingCopyImplementations,

PluginAsLibrary: PluginAsLibrary,

// Depends on referenced function signatures in expressions
MutableTransmutes: MutableTransmutes,

Expand Down Expand Up @@ -350,6 +348,7 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) {
"converted into hard error, see https://github.com/rust-lang/rust/issues/35896");
store.register_removed("nested_impl_trait",
"converted into hard error, see https://github.com/rust-lang/rust/issues/59014");
store.register_removed("plugin_as_library", "plugins have been deprecated and retired");
}

fn register_internals(store: &mut lint::LintStore) {
Expand Down
16 changes: 11 additions & 5 deletions src/librustc_plugin_impl/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@

#![feature(nll)]

#![recursion_limit="256"]
use rustc::lint::LintStore;

pub use registry::Registry;

pub mod registry;
pub mod load;
pub mod build;
pub mod load;

/// Structure used to register plugins.
///
/// A plugin registrar function takes an `&mut Registry` and should call
/// methods to register its plugins.
pub struct Registry<'a> {
/// The `LintStore` allows plugins to register new lints.
pub lint_store: &'a mut LintStore,
}
Loading

0 comments on commit 90ac082

Please sign in to comment.