Skip to content

Alternatives to rustc_plugin::registry for (Servo’s) custom lints? #62868

Closed
@SimonSapin

Description

Continuing from #62727 (comment):

Servo’s memory safety unfortunately still depends on a custom lint that checks that GC pointers on the stack are properly rooted: https://github.com/servo/servo/tree/cef98d2e5179/components/script_plugins
I would love to find another solution, this plugin is regularly giving us headaches. But until we do, if the plugin API is removed Servo will be unable to upgrade and will be stuck on an old Rust Nightly.

So there has been no movement since last time we discussed this. That's unfortunate. At some point however, I think it stops being reasonable for rustc to indefinitely maintain the plugin interface solely for the benefit of servo. What would it take to get rid of your reliance on this?

It would take building an alternative.

This thread is to discuss what alternative mechanisms already exist or could be added.

Requirements

  • Having custom attributes in source code (e.g. on struct definitions), ignored without warning by rustc.

    Currently we rely on rustc_plugin::registry::Registry::register_attribute.

    My reading of Tracking issue: RFC 2103 - attributes for tools #44690 is that the rustfmt:: and clippy:: attribute namespaces are hard-coded for now, and that the RFC-proposed mechanism for registering more such namespaces / tools is not implemented yet.

    Edit: This is now taken care of by #![register_tool]: Tracking issue for #![register_tool] #66079

  • The ability to write custom “lints”: arbitrary code that analyses a given crate and can reject it based on:

    • Access to everything in a crate: type definitions, expressions and sub-expressions
    • Access to span information, to report the location of an error when there is one
    • Access to full type information. For example in let x = foo.bar(); the lint wants to find out whether the struct definition for the concrete type of x has one of the previously mentioned custom attributes, even if bar is a trait method that returns an associated type.
  • The lint only runs for selected crates. Or at least it has access to the crate name (and can exit early based on its own allow-list.)

  • Running the lint after (or during) a normal cargo build -p script (where script is the crate being linted) does not require recompiling dependencies, nor duplicating much of Cargo’s logic.

    As far as I understand, resolving types requires metadata for dependency crates. It’s fine if the lint runs separately from rustc, but reverse-engineering Cargo to find out which of multiple libfoo*.rlib with different hashes in their name is the correct one would be fragile.

  • Using Rust Nightly through rustup.

    Many years ago Servo had custom builds of rustc. It was a pain.

Nice to have

  • Access to rustc’s mechanism for emitting nicely-formatted diagnostics (not just access to line and column numbers)

  • Running the lint after either cargo build or cargo check does not require recompiling/rechecking dependencies. Consider allowing reuse of metadata between cargo check and cargo build cargo#3501 may be relevant.

    • The lint being part of normal compilation / checking is ideal.
  • Reducing reliance on rustc-internal APIs that change often would be nice, to help reduce the frequency of PRs like this: Upgrade to rustc 1.38.0-nightly (273f42b59 2019-07-21) servo/servo#23822. (We’re averaging at 20 days between Nightly upgrades in the last year, mostly because of this.)

    I do realize this is in contradiction with many of the other points.

    • Would it be crazy for RLS to have a non-interactive mode where it dumps everything it knows about a crate into a giant JSON file?

@jdm, @Manishearth, @nox: anything to add?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-pluginsArea: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.htmlC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions