ruff/crates
Charlie Marsh 93b5d8a0fb
Implement our own small-integer optimization (#7584)
## Summary

This is a follow-up to #7469 that attempts to achieve similar gains, but
without introducing malachite. Instead, this PR removes the `BigInt`
type altogether, instead opting for a simple enum that allows us to
store small integers directly and only allocate for values greater than
`i64`:

```rust
/// A Python integer literal. Represents both small (fits in an `i64`) and large integers.
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Int(Number);

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Number {
    /// A "small" number that can be represented as an `i64`.
    Small(i64),
    /// A "large" number that cannot be represented as an `i64`.
    Big(Box<str>),
}

impl std::fmt::Display for Number {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Number::Small(value) => write!(f, "{value}"),
            Number::Big(value) => write!(f, "{value}"),
        }
    }
}
```

We typically don't care about numbers greater than `isize` -- our only
uses are comparisons against small constants (like `1`, `2`, `3`, etc.),
so there's no real loss of information, except in one or two rules where
we're now a little more conservative (with the worst-case being that we
don't flag, e.g., an `itertools.pairwise` that uses an extremely large
value for the slice start constant). For simplicity, a few diagnostics
now show a dedicated message when they see integers that are out of the
supported range (e.g., `outdated-version-block`).

An additional benefit here is that we get to remove a few dependencies,
especially `num-bigint`.

## Test Plan

`cargo test`
2023-09-25 15:13:21 +00:00
..
flake8_to_ruff Bump version to v0.0.291 (#7606) 2023-09-22 13:25:37 -04:00
ruff_benchmark Introduce LinterSettings 2023-09-20 17:02:34 +02:00
ruff_cache Introduce FormatterSettings (#7545) 2023-09-21 08:01:24 +02:00
ruff_cli Bump version to v0.0.291 (#7606) 2023-09-22 13:25:37 -04:00
ruff_dev Support option group documentation (#7593) 2023-09-22 16:31:52 +00:00
ruff_diagnostics Create ruff_notebook crate (#7039) 2023-09-01 13:56:44 +00:00
ruff_formatter Add most formatter options to ruff.toml / pyproject.toml (#7566) 2023-09-22 15:47:57 +00:00
ruff_index Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
ruff_linter Implement our own small-integer optimization (#7584) 2023-09-25 15:13:21 +00:00
ruff_macros Support option group documentation (#7593) 2023-09-22 16:31:52 +00:00
ruff_notebook chore: Upgrade pyproject-toml crate (#7335) 2023-09-13 17:55:03 +02:00
ruff_python_ast Implement our own small-integer optimization (#7584) 2023-09-25 15:13:21 +00:00
ruff_python_codegen Remove Int wrapper type from parser (#7577) 2023-09-21 17:01:44 +00:00
ruff_python_formatter Treat form feed as whitespace in SimpleTokenizer (#7626) 2023-09-25 14:34:59 +00:00
ruff_python_index Remove triple-quoted string ranges computation (#7476) 2023-09-18 20:57:49 +05:30
ruff_python_literal Implement our own small-integer optimization (#7584) 2023-09-25 15:13:21 +00:00
ruff_python_parser Implement our own small-integer optimization (#7584) 2023-09-25 15:13:21 +00:00
ruff_python_resolver Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_semantic Implement our own small-integer optimization (#7584) 2023-09-25 15:13:21 +00:00
ruff_python_stdlib Use u8 to represent version segments (#7578) 2023-09-21 14:24:51 -04:00
ruff_python_trivia Treat form feed as whitespace in SimpleTokenizer (#7626) 2023-09-25 14:34:59 +00:00
ruff_shrinking Bump shlex from 1.1.0 to 1.2.0 (#7381) 2023-09-14 09:40:05 -05:00
ruff_source_file Skip BOM when inserting start-of-file imports (#7622) 2023-09-23 19:36:50 +00:00
ruff_text_size Unify line size settings between ruff and the formatter (#6873) 2023-08-28 06:44:56 +00:00
ruff_wasm Add most formatter options to ruff.toml / pyproject.toml (#7566) 2023-09-22 15:47:57 +00:00
ruff_workspace Fix line ending doc typo (#7611) 2023-09-22 20:16:41 +00:00