Giter VIP home page Giter VIP logo

redpen's Introduction

Red Pen ๏ธโŒ๐Ÿ–Š

redpen is a linter for Rust code.

Goals

The aim of this tool is to:

  • have its own custom sets of lints independent of clippy to allow for different defaults
  • work as a test bed for internal rustc API stabilization
  • act as a buffer between lints written for this tool and that internal API by providing its own API for compiler internals so that changing rustc API internals don't require regularly rewriting lints (this work has not yet been started)
  • be quick to compile as part of CI so that projects can write project specific lints

Implemented lints

Currently, only two lints have been written

  • a simple lint that operates as a "negative trait check", that complains if a type parameter of an annotated type is used with a specific type
  • a much more useful assertion that the annotated fn will not transitively call panic

Meaning of the name

The tool is named after the writing instrument a teacher would use to mark mistakes in your paper. rustc is a strict teacher. redpen is a very strict teacher.

Installation and usage

There are two ways of using this tool. If you are only interested in using existing lints, you can install through cargo with cargo +nightly-2024-05-06 install redpen-linter. After that you can invoke redpen as if you were invoking cargo check. You must ensure that the appropriate Rust 1.72 compiler is installed with rustup toolchain add nightly-2024-05-06, as redpen is tightly coupled with a specific compiler version's internal APIs. Additionally, you must also add the following to your Cargo.toml in the [dependencies] section:

[dependencies]
cargo-redpen-shim = { version = "0.1", package = "redpen" }

This is necessary so that when running regular cargo commands, like cargo build, the custom linting annotations will be picked up as valid item attributes and not fail your build.

If you want to keep your own set of lints, then you'll have to keep your own working copy of the different redpen components.

Clone this repository and run cargo install:

export LD_LIBRARY_PATH=$(rustup run nightly-2024-05-06 bash -c "echo \$LD_LIBRARY_PATH")
git clone https://github.com/estebank/redpen.git
cd redpen
cargo install --path .

Note that redpen is pinned to a Rust version so it is likely that running cargo install --git will not work as it will not use the rust-toolchain file in the repository.

If you're adding new lints, you will also want to provide your own redpen proc-macro crate.

What it looks like

Given a src/main.rs with the following contents:

#[redpen::disallow(T = "Pineapple")]
struct Pizza<T>(T);

struct Pineapple;

#[allow(dead_code)]
type Alias = Pizza<Pineapple>;

impl Pineapple {
    fn foo(&self) {
        panic!("foo");
    }
}

#[redpen::dont_panic]
fn bar() {
    Pineapple.foo();
    let mut v = vec![1];
    v.swap_remove(0);
    v[1];
    panic!("asdf");
}

fn main() {
    bar();
    let _ = Pizza(Pineapple);
}

Executing redpen will produce the following output:

$ redpen
   Compiling pizza v0.1.0 (/home/gh-estebank/pizza)
error: `bar` can panic
  --> src/main.rs:16:1
   |
15 | #[redpen::dont_panic]
   | --------------------- the function can't panic due to this annotation
16 | fn bar() {
   | ^^^^^^^^ this function can panic
17 |     Pineapple.foo();
   |               --- panic can occur here
18 |     let mut v = vec![1];
19 |     v.swap_remove(0);
   |       ----------- panic can occur here
20 |     v[1];
   |     ---- panic can occur here
21 |     panic!("asdf");
   |     -------------- panic can occur here
   |
   = note: `#[deny(redpen::dont_panic)]` on by default

error: type parameter `T` in `Pizza` can't be `Pineapple`
 --> src/main.rs:7:20
  |
7 | type Alias = Pizza<Pineapple>;
  |                    ^^^^^^^^^
  |
  = note: `#[deny(redpen::disallow)]` on by default

error: type parameter `T` in `Pizza` can't be `Pineapple`
  --> src/main.rs:26:13
   |
26 |     let _ = Pizza(Pineapple);
   |             ^^^^^^^^^^^^^^^^ this expression is of type `Pizza<Pineapple>`

    Finished dev [unoptimized + debuginfo] target(s) in 0.02s

How it works

This linter is implemented as a rustc_driver, effectively a different entry point to the regular rustc implementation. It links against the pre-built rustc_* components, so you're only compiling a very small amount of code, keeping its builds quite fast.

redpen_wrapper is a very small CLI tool that is meant to act as a passthrough between cargo and rustc. It is invoked through RUST_WRAPPER=redpen_wrapper cargo build. This allows us to use rustc to build a given crate, and only once this is done, execute redpen to execute the lints and collect metadata necessary for cross-crate analysis (like the panic!() reachability lint).

cargo-redpen is a small CLI that invokes cargo build with the appropriate environement variables. It executes:

export LD_LIBRARY_PATH=$(rustup run nightly-2024-05-06 bash -c "echo \$LD_LIBRARY_PATH")

RUSTC_WRAPPER=$PATH_TO/redpen_wrapper \
RUSTC_BOOTSTRAP=1 \
cargo +nightly-2024-05-06 build \
-Zbuild-std \
--target x86_64-unknown-linux-gnu # haven't tried in other platforms, experiment replacing this for your case

Ancestry notice

This linter was initially based of off the Rust-on-Linux linter klint, which in turn leverages the rustc codebase.

redpen's People

Contributors

estebank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

redpen's Issues

ReachabilityCheck with traits?

I was looking into adding a check to ensure no allocations happens and at least the naive approch with using ReachabilityCheck does not seem to work. It does not seem to catch any of trait methods such as Allocator or GlobalAllocator. And the only way I have gotten it to work is to name all the functions that does allocations. Which I am not sure is feasibly.

The source for my naive lint as far:

use crate::attribute::RedpenAttribute;
use crate::reachability_check::{Config, ReachabilityCheck};
use rustc_lint::Lint;
use rustc_session::{declare_tool_lint, impl_lint_pass};

pub struct DontAllocate;

impl Config for DontAllocate {
    fn new() -> DontAllocate {
        DontAllocate
    }

    fn lint(&self) -> &'static Lint {
        ALLOCS
    }

    fn is_relevant_leaf(&self, path: &str) -> bool {
        [
            "alloc::alloc::alloc",
            "alloc::alloc::alloc_zeroed",
            "alloc::alloc::dealloc",
            "alloc::alloc::realloc",

            // Traits
            // These does not seem to work?
            "alloc::alloc::GlobalAlloc::alloc",
            "alloc::alloc::GlobalAlloc::dealloc",
            "alloc::alloc::GlobalAlloc::alloc_zeroed",
            "alloc::alloc::GlobalAlloc::realloc",
            "alloc::alloc::Allocator::allocate",
            "alloc::alloc::Allocator::deallocate",
            "alloc::alloc::Allocator::allocate_zeroed",
            "alloc::alloc::Allocator::grow",
            "alloc::alloc::Allocator::grow_zeroed",
            "alloc::alloc::Allocator::shrink",

            "std::alloc::alloc",
            "std::alloc::alloc_zeroed",
            "std::alloc::dealloc",
            "std::alloc::realloc",

            // Traits
            // These does not seem to work?
            "std::alloc::GlobalAlloc::alloc",
            "std::alloc::GlobalAlloc::dealloc",
            "std::alloc::GlobalAlloc::alloc_zeroed",
            "std::alloc::GlobalAlloc::realloc",
            "std::alloc::Allocator::allocate",
            "std::alloc::Allocator::deallocate",
            "std::alloc::Allocator::allocate_zeroed",
            "std::alloc::Allocator::grow",
            "std::alloc::Allocator::grow_zeroed",
            "std::alloc::Allocator::shrink",

            "alloc::alloc::__rust_alloc",
            "alloc::alloc::__rust_alloc_zeroed",
            "alloc::alloc::__rust_realloc",
            "alloc::alloc::__rust_dealloc",

            "std::alloc::__rust_alloc",
            "std::alloc::__rust_alloc_zeroed",
            "std::alloc::__rust_realloc",
            "std::alloc::__rust_dealloc",
            
            "alloc::string::String::try_reserve",
            "alloc::string::String::try_reserve_exact",

            "std::string::String::try_reserve",
            "std::string::String::try_reserve_exact",

            "alloc::vec::Vec::try_reserve",
            "alloc::vec::Vec::try_reserve_exact",

            "std::vec::Vec::try_reserve",
            "std::vec::Vec::try_reserve_exact",

            "alloc::raw_vec::RawVec::try_reserve",
            "alloc::raw_vec::RawVec::try_reserve_exact",
        ]
        .contains(&path)
    }

    fn is_disabled_scope(&self, attr: &RedpenAttribute) -> bool {
        matches!(attr, RedpenAttribute::WontAllocate)
    }
    fn affected_description(&self) -> &'static str {
        "can allocate"
    }
}

declare_tool_lint! {
    pub redpen::ALLOCS,
    Allow,
    "The marked function cannot transitively allocate"
}

impl_lint_pass!(ReachabilityCheck<'_, DontAllocate> => [ALLOCS]);

pub type AllocFreedom<'a> = ReachabilityCheck<'a, DontAllocate>;

Can't build redpen

After running cargo +nightly-2023-09-04 install redpen-linter, it gives the following output

    Updating crates.io index
  Installing redpen-linter v0.2.0
    Updating crates.io index
   Compiling home v0.5.5
   Compiling redpen-linter v0.2.0
error[E0463]: can't find crate for `rustc_ast`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:11:1
   |
11 | extern crate rustc_ast;
   | ^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_data_structures`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:12:1
   |
12 | extern crate rustc_data_structures;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_driver`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:13:1
   |
13 | extern crate rustc_driver;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_errors`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:14:1
   |
14 | extern crate rustc_errors;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_hir`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:15:1
   |
15 | extern crate rustc_hir;
   | ^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_hir_typeck`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:16:1
   |
16 | extern crate rustc_hir_typeck;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_index`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:17:1
   |
17 | extern crate rustc_index;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_infer`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:18:1
   |
18 | extern crate rustc_infer;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_interface`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:19:1
   |
19 | extern crate rustc_interface;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_lint`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:20:1
   |
20 | extern crate rustc_lint;
   | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_macros`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:21:1
   |
21 | extern crate rustc_macros;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_middle`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:22:1
   |
22 | extern crate rustc_middle;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_mir_dataflow`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:23:1
   |
23 | extern crate rustc_mir_dataflow;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_monomorphize`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:24:1
   |
24 | extern crate rustc_monomorphize;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_serialize`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:25:1
   |
25 | extern crate rustc_serialize;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_session`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:26:1
   |
26 | extern crate rustc_session;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_span`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:27:1
   |
27 | extern crate rustc_span;
   | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_symbol_mangling`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:28:1
   |
28 | extern crate rustc_symbol_mangling;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_target`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:29:1
   |
29 | extern crate rustc_target;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `rustc_trait_selection`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:30:1
   |
30 | extern crate rustc_trait_selection;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

error[E0463]: can't find crate for `tracing`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:33:1
   |
33 | extern crate tracing;
   | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: cannot determine resolution for the macro `declare_tool_lint`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/disallow.rs:18:1
   |
18 | declare_tool_lint! {
   | ^^^^^^^^^^^^^^^^^
   |
   = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the macro `impl_lint_pass`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/disallow.rs:24:1
   |
24 | impl_lint_pass!(Disallow<'_> => [DISALLOW]);
   | ^^^^^^^^^^^^^^
   |
   = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the macro `declare_tool_lint`
   --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/panic_freedom.rs:154:1
    |
154 | declare_tool_lint! {
    | ^^^^^^^^^^^^^^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the macro `impl_lint_pass`
   --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/panic_freedom.rs:160:1
    |
160 | impl_lint_pass!(DontPanic<'_> => [DONT_PANIC]);
    | ^^^^^^^^^^^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports

error[E0425]: cannot find value `INCORRECT_ATTRIBUTE` in the crate root
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/attribute.rs:62:20
   |
62 |             crate::INCORRECT_ATTRIBUTE,
   |                    ^^^^^^^^^^^^^^^^^^^ not found in the crate root

error[E0425]: cannot find value `INCORRECT_ATTRIBUTE` in the crate root
   --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/attribute.rs:266:24
    |
266 |                 crate::INCORRECT_ATTRIBUTE,
    |                        ^^^^^^^^^^^^^^^^^^^ not found in the crate root

error[E0425]: cannot find value `INCORRECT_ATTRIBUTE` in the crate root
   --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/attribute.rs:282:28
    |
282 |                     crate::INCORRECT_ATTRIBUTE,
    |                            ^^^^^^^^^^^^^^^^^^^ not found in the crate root

error[E0425]: cannot find value `DISALLOW` in this scope
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/disallow.rs:92:33
   |
92 | ...                   DISALLOW,
   |                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `DISALLOW` in this scope
   --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/disallow.rs:153:29
    |
153 | ...                   DISALLOW,
    |                       ^^^^^^^^ not found in this scope

error[E0425]: cannot find value `DONT_PANIC` in this scope
   --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/panic_freedom.rs:426:21
    |
426 |                     DONT_PANIC,
    |                     ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `INCORRECT_ATTRIBUTE` in this scope
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:90:18
   |
90 |                 &INCORRECT_ATTRIBUTE,
   |                  ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `DISALLOW` in module `disallow`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:91:28
   |
91 |                 &disallow::DISALLOW,
   |                            ^^^^^^^^ not found in `disallow`

error[E0425]: cannot find value `DONT_PANIC` in module `panic_freedom`
  --> /home/polly/.cargo/registry/src/index.crates.io-6f17d22bba15001f/redpen-linter-0.2.0/src/main.rs:92:33
   |
92 |                 &panic_freedom::DONT_PANIC,
   |                                 ^^^^^^^^^^ not found in `panic_freedom`

`unknown tool name \`redpen\` in scoped lint` when invoking `redpen`

I'm unable to successfully run Redpen 0.3.0. I think there's a bug in either redpen or redpen_wrapper, but it's also possible that this is user error.

Reproduction steps: Install Redpen using cargo +nightly-2023-11-01 install redpen-linter, and create a project with the following sources:

Cargo.toml:

[package]
name = "redpen_test"
version = "0.1.0"
edition = "2021"

rust-toolchain.toml:

[toolchain]
channel = "nightly-2023-11-01"

src/lib.rs:

//#![feature(register_tool)]
//#![register_tool(redpen)]
#[deny(redpen::panics)]
pub fn redpen_test() {
    panic!("Explicit panic that should make redpen error.");
}

When I invoke redpen, I get:

jrvanwhy@jrvanwhy:~/playground$ redpen
[... Cargo compiling dependency crates snipped ...]
   Compiling redpen_test v0.1.0 (/home/jrvanwhy/playground)
error[E0710]: unknown tool name `redpen` found in scoped lint: `redpen::panics`
 --> src/lib.rs:3:8
  |
3 | #[deny(redpen::panics)]
  |        ^^^^^^
  |
  = help: add `#![register_tool(redpen)]` to the crate root

For more information about this error, try `rustc --explain E0710`.
    Finished dev [unoptimized + debuginfo] target(s) in 26.11s

If I uncomment the #![feature(register_tool)] and #![register_tool(redpen)] lines, I get:

jrvanwhy@jrvanwhy:~/playground$ redpen
   Compiling redpen_test v0.1.0 (/home/jrvanwhy/playground)
error: tool `redpen` was already registered
 --> <crate attribute>:1:15
  |
1 | register_tool(redpen)
  |               ^^^^^^
  |
 ::: src/lib.rs:2:18
  |
2 | #![register_tool(redpen)]
  |                  ------ already registered here

error[E0636]: the feature `register_tool` has already been declared
 --> <crate attribute>:1:9
  |
1 | feature(register_tool)
  |         ^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0636`.
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s

Evaluate Profile-Guided Optimization (PGO) and LLVM BOLT

Hi!

I did a lot of Profile-Guided Optimization (PGO) benchmarks recently on different kinds of software (including many compilers and compiler-like projects like Clang, Rustc, Clangd, clang-tidy, etc.) - all currently available results are located at https://github.com/zamazan4ik/awesome-pgo . According to the tests, PGO usually helps a lot for compiler-like workloads. That's why I think testing PGO would be a good idea for Redpen.

I can suggest to do the following things:

  • Evaluate PGO on Redpen
  • If it benefits Redpen - add a note to the Redpen documentation about building with PGO. In this case, users and maintainers who build their own Redpen binaries will be aware of PGO as an additional way to optimize the project
  • Optimize provided by Redpen project binaries on the CI (like it's already done for other projects like Rustc), if any
  • After that, I suggest trying to apply LLVM BOLT as an additional post-PGO step. Rustc already does it on some platforms

For the Rust projects, I suggest PGO optimizing with cargo-pgo.

I understand that the project is in the early stages of development. So just consider the issue just an idea for the possible future improvements.

Indexing operations are not accurate on whether they panic

rustc doesn't mark the internal APIs that it uses to determine the appropriate trait used by an indexing operation as public. For now, the dont_panic lint always treats indexing as a potentially panicking operation as a stop-gap.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.