A Rust compiler plugin and support library to annotate overflow behavior

Overview

overflower

Build Status Current Version

This project contains a compiler plugin and supporting library to allow the programmer to annotate their code to declare how integer overflows should be dealt with.

Usage

Note: This needs a nightly compiler both for the compiler plugin and the supporting library, as the latter makes use of specialization, which is unstable for now.

To use it, you need the following in your Cargo.toml:

[dependencies]
overflower = "0.9"

You may also make it an optional dependency (overflower = { version = "0.4.6", optional = true }).

Next, in your crate root, you need to add:

#![feature(plugin)]
#![plugin(overflower)]

extern crate overflower_support;

// Now you can annotate items (up to and including the whole crate)
#[overflow(panic)]
fn panic_on_overflow() { .. }

#[overflow(wrap)]
fn like_you_just_dont_care() { .. }

#[overflow(saturate)]
fn too_much_sunlight() {
    #[overflow(default)]
    fn but_use_standard_ops_here() { .. }
    ..
}

In case of an optional dependency, you'd add the following instead:

#![cfg_attr(feature="overflower", feature(plugin))]
#![cfg_attr(feature="overflower", plugin(overflower))]

#[cfg(feature="overflower")
extern crate overflower_support;

// as well as the following instead of e.g. `#[overflow(wrap)]`
#[cfg_attr(feature="overflower", overflow(wrap))];

This is a bit of a work in progress, but most things should already be usable.

License: Apache 2.0

Comments
  • overflower 0.1.5 build faild with nightly 02/20 (unresolved import)

    overflower 0.1.5 build faild with nightly 02/20 (unresolved import)

    Following the readme, it generated several unresolved import. When I replaced the source code of overflower-0.1.5/src/lib.rs with the lib.rs, the errors disappears.

        Updating registry `https://github.com/rust-lang/crates.io-index`
     Downloading overflower v0.1.5
     Downloading overflower_support v0.1.5
       Compiling overflower_support v0.1.5
       Compiling overflower v0.1.5
    error[E0432]: unresolved import `syntax::ext::expand::expand_expr`
      --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:15:27
       |
    15 | use syntax::ext::expand::{expand_expr, expand_item};
       |                           ^^^^^^^^^^^ no `expand_expr` in `ext::expand`
    
    error[E0432]: unresolved import `syntax::ext::expand::expand_item`
      --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:15:40
       |
    15 | use syntax::ext::expand::{expand_expr, expand_item};
       |                                        ^^^^^^^^^^^ no `expand_item` in `ext::expand`
    
    error[E0532]: expected tuple struct/variant, found unit variant `MetaItemKind::Word`
       --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:188:20
        |
    188 |             if let MetaItemKind::Word(ref w) = l[0].node {
        |                    ^^^^^^^^^^^^^^^^^^ not a tuple struct/variant
    
    error[E0425]: cannot find function `intern` in module `token`
       --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:211:35
        |
    211 |     reg.register_syntax_extension(token::intern("overflow"),
        |                                   ^^^^^^^^^^^^^ not found in `token`
    
    error: no field `global` on type `&syntax::ast::Path`
       --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:177:7
        |
    177 |     p.global && segs.len() == 3 && any_of(&segs[0], &["std", "core"]) &&
        |       ^^^^^^
    
    error[E0308]: mismatched types
       --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:174:40
        |
    174 |         options.iter().any(|o| name == *o)
        |                                        ^^ expected struct `syntax::symbol::InternedString`, found &str
        |
        = note: expected type `syntax::symbol::InternedString`
                   found type `&str`
    
    error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
       --> /home/huang/.cargo/registry/src/github.com-1ecc6299db9ec823/overflower-0.1.5/src/lib.rs:183:12
        |
    183 |     if let MetaItemKind::List(ref s, ref l) = mi.node {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 field, found 2
    
    error: aborting due to 3 previous errors
    
    error: Could not compile `overflower`.
    
    
    1. In readme, you suggested adding a extern crate overflower_support;, however the compiler would fail due to
    error[E0463]: can't find crate for `overflower_support`
     --> src/main.rs:4:1
      |
    4 | extern crate overflower_support;
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
    
    error: aborting due to previous error
    

    This issue can be solved by deleting this statements.

    opened by qorost 3
  • Expand recursively

    Expand recursively

    Currently this code:

    #[overflow(wrap)]
    fn main() {
        let i = 1u8 - 1 - 2;
    }
    

    expands to:

    fn main() { 
        let i = 1u8 - 1.sub_wrap(2);
    }
    

    This is because in tag_method the receiver is noop-folded.

    With this change:

    diff --git i/src/lib.rs w/src/lib.rs
    index 7af31b6..cff4b10 100644
    --- i/src/lib.rs
    +++ w/src/lib.rs
    @@ -102,7 +102,7 @@ impl<'a, 'cx> Folder for Overflower<'a, 'cx> {
     }
    
     fn tag_method(o: &mut Overflower, name: &str, receiver: P<Expr>, args: Vec<P<Expr>>) -> P<Expr> {
    -    let rec = receiver.map(|r| fold::noop_fold_expr(r, o));
    +    let rec = receiver.map(|r| o.fold_expr(P(r)).unwrap());
         let fn_name = o.cx.ident_of(&format!("{}_{}", name, o.mode));
         let args_expanded = args.into_iter().map(|a| a.map(|e| fold::noop_fold_expr(e, o))).collect();
         o.cx.expr_method_call(DUMMY_SP, rec, fn_name, args_expanded)
    

    it is correctly expanded:

    fn main() { 
        let i = 1u8.sub_wrap(1).sub_wrap(2); 
    }
    

    The args are folded using the same noop_fold_expr as well, not sure if that needs to be changed (at least it still compiles and tests are green). I did not submit a PR (yet), because I just unwrap. Do we need proper error handling there? Is it possible this fails at all?

    opened by badboy 3
  • Update quote requirement from 0.6.9 to 1.0.2

    Update quote requirement from 0.6.9 to 1.0.2

    Updates the requirements on quote to permit the latest version.

    Release notes

    Sourced from quote's releases.

    1.0.2

    • Fix missing token if there is a star adjacent to repetition (#130)
    Commits
    • 727436c Release 1.0.2
    • 53f65a5 Merge pull request #131 from dtolnay/star
    • bce8f54 Fix potential skipped star after repetitions
    • 3179b09 Add regression test for issue 130
    • 40b9852 Merge pull request #128 from mystor/format_ident_examples
    • 35ec183 Encourage format_ident over Ident::new()
    • c6a5958 Add format_ident example from lib.rs to the README
    • 78f551d Release 1.0.1
    • 40f0213 Update to 1.0 in readme and links
    • 97d4571 Release 1.0.0
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)

    Finally, you can contact us by mentioning @dependabot.

    dependencies 
    opened by dependabot-preview[bot] 1
  • Update quote requirement from 0.6.9 to 1.0.0

    Update quote requirement from 0.6.9 to 1.0.0

    Updates the requirements on quote to permit the latest version.

    Release notes

    Sourced from quote's releases.

    1.0.0

    This release fixes some longstanding limitations of the quote! macro, bringing quote better in line with the patterns that macro authors are used to from working with macro_rules.


    Duplicate interpolations in a repetition

    In past versions of quote, interpolating the same variable multiple times inside of one repeating block was not allowed.

    For example if we had an iterator of local variable names and wanted the generated code to do a clone of each one, that wouldn't compile:

    error[E0416]: identifier `var` is bound more than once in the same pattern
     --> src/main.rs:7:27
      |
    7 |         #( let #var = #var.clone(); )*
      |                        ^^^ used in a pattern more than once
    

    Macros usually worked around this by having the same sequence of interpolated values named two different things:

    // old workaround 1
    let var = input.fields.iter().map(|field| &field.ident);
    let var2 = var.clone();
    
    quote! {
        #( let #var = #var2.clone(); )*
    }
    

    or by giving up on repetitions and doing more of the work within the iterator chain:

    // old workaround 2
    let var_clones = input
        .fields
        .iter()
        .map(|field| {
            let var = &field.ident;
            quote! {
                let #var = #var.clone();
            }
        });
    
    quote! {
        #(#var_clones)*
    }
    
    ... (truncated)
    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Note: This repo was added to Dependabot recently, so you'll receive a maximum of 5 PRs for your first few update runs. Once an update run creates fewer than 5 PRs we'll remove that limit.

    You can always request more updates by clicking Bump now in your Dependabot dashboard.

    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)

    Finally, you can contact us by mentioning @dependabot.

    dependencies 
    opened by dependabot-preview[bot] 1
  • {Add, Sub, Mul, Div}-Assign fail to compile

    {Add, Sub, Mul, Div}-Assign fail to compile

    Example code:

    #![feature(plugin)]
    #![plugin(overflower)]
    
    extern crate overflower_support;
    
    #[overflow(wrap)]
    fn it_doesnt_work() {
        let mut a = 0;
        a += 1;
        a -= 1;
        a *= 1;
        a /= 1;
    }
    

    Example error:

       Compiling overflower_support v0.1.5
       Compiling overflower v0.4.0
       Compiling mycrate v0.1.0 (file:///...)
    error[E0433]: failed to resolve. Could not find `Add_assignWrap` in `overflower_support`
     --> src/lib.rs:9:4
      |
    9 |     a += 1;
      |       ^^ Could not find `Add_assignWrap` in `overflower_support`
    
    error[E0433]: failed to resolve. Could not find `Sub_assignWrap` in `overflower_support`
      --> src/lib.rs:10:4
       |
    10 |    a -= 1;
       |      ^^ Could not find `Sub_assignWrap` in `overflower_support`
    
    error[E0433]: failed to resolve. Could not find `Mul_assignWrap` in `overflower_support`
      --> src/lib.rs:11:4
       |
    11 |    a *= 1;
       |      ^^ Could not find `Mul_assignWrap` in `overflower_support`
    
    error[E0433]: failed to resolve. Could not find `Div_assignWrap` in `overflower_support`
      --> src/lib.rs:12:4
       |
    12 |    a /= 1;
       |      ^^ Could not find `Div_assignWrap` in `overflower_support`
    
    error: aborting due to previous error(s)
    
    error: Could not compile `mycrate`.
    
    To learn more, run the command again with --verbose.
    
    opened by FliegendeWurst 1
  • Rustup + version bump

    Rustup + version bump

    This is just an intermittent solution until I get to use the new procedural-attr-macro interface (but that'll need some more rewriting). It doesn't do the right thing with regards to spans, but should otherwise work OK.

    opened by llogiq 1
  • Deal with .abs()

    Deal with .abs()

    This is a problem, because I don't want to do type inference. However, Unified Function Call Syntax (UFCS) to the rescue. We can ask users to use std::*::abs(_) (or core::*::abs(_)) instead and replace the calls directly.

    We may even write a lint to check on items with an #[overflow(_)] attribute if there's some .abs() method call on an integer and suggest the appropriate UFCS call.

    opened by llogiq 1
  • Upgrade to GitHub-native Dependabot

    Upgrade to GitHub-native Dependabot

    Dependabot Preview will be shut down on August 3rd, 2021. In order to keep getting Dependabot updates, please merge this PR and migrate to GitHub-native Dependabot before then.

    Dependabot has been fully integrated into GitHub, so you no longer have to install and manage a separate app. This pull request migrates your configuration from Dependabot.com to a config file, using the new syntax. When merged, we'll swap out dependabot-preview (me) for a new dependabot app, and you'll be all set!

    With this change, you'll now use the Dependabot page in GitHub, rather than the Dependabot dashboard, to monitor your version updates, and you'll configure Dependabot through the new config file rather than a UI.

    If you've got any questions or feedback for us, please let us know by creating an issue in the dependabot/dependabot-core repository.

    Learn more about migrating to GitHub-native Dependabot

    Please note that regular @dependabot commands do not work on this pull request.

    dependencies 
    opened by dependabot-preview[bot] 0
  • Update quickcheck requirement from 0.9 to 1.0

    Update quickcheck requirement from 0.9 to 1.0

    Updates the requirements on quickcheck to permit the latest version.

    Commits
    • 40ebcc6 1.0.1
    • 74d0c60 deps: trim 'rand' dependencies
    • 9dfcf7f release: more preparation for 1.0 release
    • 480a879 release: prepare for 1.0 release
    • c773663 semver: add note on compatibility
    • d44b417 style: tweak formatting of top-level comment
    • 282f146 msrv: bump to 1.46.0 and specify policy
    • 467f272 deps: update env_logger
    • 319145d deps: upgrade rand to 0.8
    • d286e4d rand: remove rand as a public dependency
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
    dependencies 
    opened by dependabot-preview[bot] 0
  • Remove travis cache

    Remove travis cache

    The lastest travis build failed because thte cache has grown so large that there's no chance it would get unpacked in 10 minutes.

    Quite frankly, your project is small and hardly needs any cache at all, just remove it.

    opened by CreepySkeleton 0
  • Overflower 0.9

    Overflower 0.9

    This changes the whole crate structure so you can now directly use overflower::overflow if you so desire. Also there's now a way to use overflower on stable Rust, but you will have to implement the overflower traits for all your types you use within #[overflow(..)]-annotated code that has arithmetic operations. The new overflower::impls!(..) macro lets you do that quite easily.

    opened by llogiq 0
  • DONT_PANIC?

    DONT_PANIC?

    I wonder if overflower should have a mode that avoids panics distinct from wrap/saturate to do whatever on overflow (e.g. return 0) but avoid panic.

    The rationale is that even with wrap (and as of yet saturate), division/remainder can panic when dividing by zero. I don't want to have different semantics from the original wrapping methods, and saturate is more complex and likely slower.

    opened by llogiq 2
Owner
null
Lightweight p2p library. Support build robust stable connection on p2p/distributed network.

Chamomile Build a robust stable connection on p2p network features Support build a robust stable connection between two peers on the p2p network. Supp

CympleTech 94 Jan 6, 2023
Jex Compiler Server - Server that runs Jex code

Server that compiles and runs Jex code.

furetur 3 Nov 18, 2021
Hammerspoon plugin and API to interact with Yabai socket directly

Yabai.spoon NOTE: no longer using it or intending to maintain it see #2. Yabai.spoon is lua 5.4 library to interact with yabai socket directly within

null 2 May 17, 2022
Barebones egui_baseview vst2 plugin with basic parameter control

egui_baseview_test_vst2 Based on baseview_test_vst2 Barebones baseview/egui_baseview vst2 plugin. It implements an egui ui for the vst gain effect exa

null 16 Dec 18, 2022
Barebones imgui_baseview vst2 plugin with basic parameter control

imgui_baseview_test_vst2 Based on baseview_test_vst2 Barebones baseview/imgui_baseview vst2 plugin. It implements a imgui-rs ui for the vst gain effec

null 3 Nov 16, 2021
A WireGuard UWP VPN plugin.

WireGuard UWP A Universal Windows Platform (UWP) VPN Plug-in for WireGuard® written in Rust. Windows provides a plug-in based model for adding 3rd-par

Luqman Aden 92 Dec 13, 2022
A mini-CI as a Zellij plugin

About This Zellij plugin is a "mini-ci". It allows you to specify commands that will run in parallel, keeping track of completed commands and their ex

Aram Drevekenin 10 Jun 22, 2023
UDP proxy with Proxy Protocol and mmproxy support

udppp UDP proxy with Proxy Protocol and mmproxy support. Features Async Support Proxy Protocol V2 SOCKET preserve client IP addresses in L7 proxies(mm

b23r0 10 Dec 18, 2022
A high performence Socks5 proxy server with bind/reverse support implementation by Rust.

rsocx A high performence Socks5 proxy server with bind/reverse support implementation by Rust Features Async-std No unsafe code Single executable Linu

b23r0 259 Jan 6, 2023
Interactive bind/reverse PTY shell with Windows&Linux support implementation by Rust.

Cliws Lightweight interactive bind/reverse PTY shell with Windows&Linux support implementation by Rust. Features WebSocket Full pty support: VIM, SSH,

b23r0 215 Dec 3, 2021
A rust implementation of websock/socket proxy. Support noVNC

websockify-rs: WebSockets support for any application/server This is a rust implement of the websockify-js, which is part of the noVNC project. At the

null 3 Jan 10, 2023
Many modbus devices support only one or very few clients

Modbus TCP proxy Many modbus devices support only one or very few clients. This proxy acts as a bridge between the client and the modbus device. It ca

Tiago Coutinho 6 Aug 10, 2022
Asynchronous Linux SocketCAN - Broadcast Manager support (BCM) with tokio

tokio-socketcan-bcm The Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in k

Marcel 4 Nov 8, 2022
The gRPC library for Rust built on C Core library and futures

gRPC-rs gRPC-rs is a Rust wrapper of gRPC Core. gRPC is a high performance, open source universal RPC framework that puts mobile and HTTP/2 first. Sta

TiKV Project 1.6k Jan 7, 2023
A µTP (Micro/uTorrent Transport Library) library implemented in Rust

rust-utp A Micro Transport Protocol library implemented in Rust. API documentation Overview The Micro Transport Protocol is a reliable transport proto

Ricardo Martins 134 Dec 11, 2022
A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems.

x-server-stats A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems. x-server(in x-serv

Pratyaksh 11 Oct 17, 2022
A BitTorrent V1 engine library for Rust (and currently Linux)

cratetorrent Cratetorrent is a Rust crate implementing the BitTorrent version 1 protocol. It can be used as a library and also provides a simple examp

null 401 Dec 28, 2022
Rust library for A-law and μ-law (mu-law) audio encoding.

law-encoder ⚖️️‍️law-encoder??‍⚖ is a Rust library for A-law and μ-law (mu-law) audio encoding. These encoding schemes are defined in ITU-T standards

Beric Bearnson 5 Feb 7, 2024
Library + CLI-Tool to measure the TTFB (time to first byte) of HTTP requests. Additionally, this crate measures the times of DNS lookup, TCP connect and TLS handshake.

TTFB: CLI + Lib to Measure the TTFB of HTTP/1.1 Requests Similar to the network tab in Google Chrome or Mozilla Firefox, this crate helps you find the

Philipp Schuster 24 Dec 1, 2022