From e3865a9ffc36611645c64ef3fd059d5f01f18bfb Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 13 Jul 2023 01:55:50 +0200 Subject: [PATCH] feat: merge alloy-rs/ruint (ruint2) --- .github/CODEOWNERS | 7 +- .github/ISSUE_TEMPLATE/FEATURE-FORM.yml | 30 +- .github/ISSUE_TEMPLATE/config.yml | 5 - .github/ISSUE_TEMPLATE/question.md | 13 + .github/PULL_REQUEST_TEMPLATE.md | 1 + .github/dependabot.yml | 10 + .github/scripts/issue_tracker.py | 308 ++++++++++++++++++ .github/workflows/ci.yml | 75 ++--- .github/workflows/issue_tracker.yml | 27 ++ CHANGELOG.md | 15 +- Cargo.toml | 8 +- README.md | 44 +-- crates/ruint-macro/Cargo.toml | 4 +- crates/ruint-macro/README.md | 10 +- crates/ruint-macro/src/lib.rs | 2 +- crates/ruint-macro/tests/parse_mixed.rs | 4 +- crates/ruint/Cargo.toml | 8 +- crates/ruint/benches/bench.rs | 2 +- .../benches/algorithms/div/reciprocal.rs | 2 +- .../benches/benches/algorithms/div/small.rs | 2 +- .../ruint/benches/benches/algorithms/gcd.rs | 2 +- .../ruint/benches/benches/algorithms/mul.rs | 2 +- crates/ruint/src/algorithms/mul.rs | 2 +- crates/ruint/src/const_for.rs | 6 +- crates/ruint/src/from.rs | 12 +- crates/ruint/src/gcd.rs | 2 +- crates/ruint/src/lib.rs | 3 +- crates/ruint/src/log.rs | 2 +- crates/ruint/src/modular.rs | 2 +- crates/ruint/src/mul.rs | 4 +- crates/ruint/src/pow.rs | 6 +- crates/ruint/src/root.rs | 2 +- crates/ruint/src/special.rs | 6 +- crates/ruint/src/support/serde.rs | 4 +- 34 files changed, 499 insertions(+), 133 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/question.md create mode 100644 .github/dependabot.yml create mode 100644 .github/scripts/issue_tracker.py create mode 100644 .github/workflows/issue_tracker.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 10b0b9b..6f0dea5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,6 @@ -* @danipopes @prestwich +# General code +* @recmo +* @prestwich + +# CI +.github @recmo diff --git a/.github/ISSUE_TEMPLATE/FEATURE-FORM.yml b/.github/ISSUE_TEMPLATE/FEATURE-FORM.yml index b61e4a6..6a32b48 100644 --- a/.github/ISSUE_TEMPLATE/FEATURE-FORM.yml +++ b/.github/ISSUE_TEMPLATE/FEATURE-FORM.yml @@ -3,17 +3,19 @@ description: Suggest a feature labels: ["enhancement"] title: "[Feature] " body: - - type: markdown - attributes: - value: | - Please ensure that the feature has not already been requested in the issue tracker. - - type: textarea - attributes: - label: Describe the feature you would like - description: Please also describe your goals for the feature. What problems it solves, how it would be used, etc. - validations: - required: true - - type: textarea - attributes: - label: Additional context - description: Add any other context to the feature (like screenshots, resources) + - type: markdown + attributes: + value: | + Please ensure that the feature has not already been requested in the issue tracker. + - type: textarea + attributes: + label: Describe the feature you would like + description: + Please also describe your goals for the feature. What problems it solves, how it would + be used, etc. + validations: + required: true + - type: textarea + attributes: + label: Additional context + description: Add any other context to the feature (like screenshots, resources) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index bbfbdcc..0000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -blank_issues_enabled: true -contact_links: - - name: Support - url: https://t.me/ethers_rs - about: This issue tracker is only for bugs and feature requests. Support is available on Telegram! diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 0000000..70fa9d4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,13 @@ +--- +name: Question +about: Please use the discussions tab for questions +title: '' +labels: '' +assignees: '' +--- + +Please post your question as a discussion here: + + + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 51e6e84..ded054e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -28,3 +28,4 @@ the code change. - [ ] Added Tests - [ ] Added Documentation - [ ] Breaking changes +- [ ] Updated CHANGELOG.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0722170 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/scripts/issue_tracker.py b/.github/scripts/issue_tracker.py new file mode 100644 index 0000000..6764e9c --- /dev/null +++ b/.github/scripts/issue_tracker.py @@ -0,0 +1,308 @@ +#!/usr/bin/env python3 + +# TODO: The git blame is wrong. It seems to take the last commit instead. + +import glob +import json +import os +import re +import sys +from datetime import date + +import numpy as np + +# pip3 install PyGithub numpy +from github import Github + +# Only actually change things on master +# TODO: Make this a command line or env option +DRY_RUN = os.environ["DRY_RUN"] != "false" +print("DRY_RUN =", DRY_RUN) + +# Git current commit id +commit_hash = None +with os.popen("git rev-parse HEAD") as process: + commit_hash = process.read().strip() +print("Commit hash:", commit_hash) + +# Connect to the GitHub repo +gh = Github(os.environ["GITHUB_TOKEN"]) +repo = gh.get_repo(os.environ["REPO_NAME"]) +print("Connected to", repo) + +# GitHub labels for issues +labels = { + "TODO": ["tracker", "to do"], + "FEATURE": ["tracker", "feature"], + "REFACTOR": ["tracker", "refactor"], + "OPT": ["tracker", "optimize"], + "HACK": ["tracker", "hack"], +} + +# GitHub users for emails +users = { + "": "recmo", + "": "prestwich", +} + +# Translation from labels to PyGitHub `Label`s +repo_labels = {l.name: l for l in repo.get_labels()} + +# Translate users ot PyGitHub `User`s +users = {k: gh.get_user(v) for k, v in users.items()} + +# Collect existing tracker issues +open_issues = [] +issue_body_json = re.compile("^$", re.MULTILINE) +for gh_issue in repo.get_issues(): + if repo_labels["tracker"] in gh_issue.labels: + issue = json.loads(issue_body_json.search(gh_issue.body).group(1)) + issue["github"] = gh_issue + open_issues += [issue] +print("Found", len(open_issues), "tracked issues on GitHub.") + +# Number of lines to give before and after the TODO comment. +CONTEXT_LINES = 5 + +# Rust like todos. For *.{rs} +rust_todo = re.compile(r"//\W*(TODO|HACK|OPT|FEATURE|REFACTOR)\W*(.*)$") +rust_continuation = re.compile(r"//\W*(?!(TODO|HACK|OPT|FEATURE|REFACTOR))(.*)$") +rust_todo_macro = re.compile(r"\btodo!\((.*)\)") + +# Shell like todos. For *.{sh, yml, toml, py, Dockerfile, editorconfig, gitignore} +# TODO: `# TODO: {message}` + +# Markdown like todos. For *.{md} +# TODO: `` + +# Markdown todo lists. +# TODO: `* [] {message}` + + +def git_blame(filename, line): + # Git line numbers start at one + command = "git blame {filename} --line-porcelain -L {line},{line}".format( + filename=filename, line=line + 1 + ) + with os.popen(command) as process: + lines = process.readlines() + result = dict() + result["commit-hash"] = lines[0].split(" ")[0] + for line in lines[1:-1]: + line = line.replace("\n", "") + if " " in line: + [key, value] = line.split(" ", 1) + result[key] = value + result["author-time"] = int(result["author-time"]) + result["committer-time"] = int(result["committer-time"]) + return result + + +def get_context(filename, start, end): + with open(filename, "r") as file: + lines = file.readlines() + start = max(0, start) + end = min(end, len(lines)) + return "".join(lines[start:end]) + + +def prep_filename(filename): + if filename.startswith("src/"): + filename = filename[4:] + if filename.endswith(".rs"): + filename = filename[:-3] + return f"`{filename}`: " + + +def issues_from_file(filename): + with open(filename, "r") as file: + line_number = 0 + issue = None + kind = None + issue_line = 0 + for line in file: + match = rust_todo.search(line) + continuation = rust_continuation.search(line) + if match: + issue = match.group(2) + kind = match.group(1) + issue_line = line_number + elif issue and continuation: + issue += "\n" + continuation.group(2) + elif issue: + result = git_blame(filename, issue_line) + context = get_context( + filename, issue_line - CONTEXT_LINES, line_number + CONTEXT_LINES + ) + result["filename"] = filename + result["line"] = issue_line + result["line_end"] = line_number + result["kind"] = kind + result["issue"] = issue + result["head"] = prep_filename(filename) + issue.split("\n")[0] + result["context"] = context + result["repo"] = repo.full_name + result["branch-hash"] = commit_hash + yield result + issue = None + kind = None + issue_line = 0 + else: + match = rust_todo_macro.search(line) + if match: + issue = match.group(1) + if issue == "": + issue = "todo!()" + kind = "TODO" + issue_line = line_number + result = git_blame(filename, issue_line) + context = get_context( + filename, + issue_line - CONTEXT_LINES, + line_number + CONTEXT_LINES, + ) + result["filename"] = filename + result["line"] = issue_line + result["line_end"] = line_number + result["kind"] = kind + result["issue"] = issue + result["head"] = prep_filename(filename) + issue.split("\n")[0] + result["context"] = context + result["repo"] = repo.full_name + result["branch-hash"] = commit_hash + yield result + line_number += 1 + + +def issues_from_glob(pattern): + for filename in glob.iglob(pattern, recursive=True): + for issue in issues_from_file(filename): + yield issue + + +def render(issue): + issue = issue.copy() + issue.pop("open-issue-index", None) + issue["json"] = json.dumps(issue) + issue["github-handle"] = users[issue["author-mail"]].login + issue["author-time-pretty"] = date.fromtimestamp(issue["author-time"]).isoformat() + issue["commit-hash-short"] = issue["commit-hash"][0:7] + issue["line-one"] = issue["line"] + 1 + return dict( + title="{head}".format(**issue), + body=""" +*On {author-time-pretty} @{github-handle} wrote in [`{commit-hash-short}`](https://github.com/{repo}/commit/{commit-hash}) “{summary}”:* + +{issue} + +```rust +{context} +``` +*From [`{filename}:{line-one}`](https://github.com/{repo}/blob/{branch-hash}/{filename}#L{line-one})* + + +""".strip().format( + **issue + ), + assignee=users[issue["author-mail"]], + labels=labels[issue["kind"]] + (["blocked"] if "blocked" in issue else []), + ) + + +def create_issue(source_issue): + print("Creating issue...") + r = render(source_issue) + r["labels"] = [repo_labels[l] for l in r["labels"]] + if not DRY_RUN: + gh_issue = repo.create_issue(**r) + print("Created issue", gh_issue.number) + + +def update_issue(github_issue, source_issue): + # We update headline, body and labels + gh = github_issue["github"] + r = render(source_issue) + if ( + gh.title == r["title"] + and github_issue["issue"] == source_issue["issue"] + and set([l.name for l in gh.labels]) == set(r["labels"]) + ): + # Issue up to date + return + # NOTE: We don't update if the body changed because this changes with each + # commit hash. It is a good check to add if the json structure or the + # render function is modified. + print("Updating issue", github_issue["github"].number) + if not DRY_RUN: + gh.edit(**r) + + +def close_issue(github_issue): + print("Closing issue", github_issue["github"].number) + gh = github_issue["github"] + if not DRY_RUN: + gh.edit(state="closed") + + +# Collect source issues +source_issues = list(issues_from_glob("**/*.rs")) +print("Found", len(source_issues), "issues in source.") + +# Match source issues with open issues +print("Issue closeness matrix") +closeness = np.zeros((len(open_issues), len(source_issues))) +for i in range(len(open_issues)): + open_issue = open_issues[i] + for j in range(len(source_issues)): + source_issue = source_issues[j] + score = 0 + if open_issue["head"] == source_issue["head"]: + # Three point if the head matches + score += 3 + if ( + open_issue["filename"] == source_issue["filename"] + and open_issue["line"] == source_issue["line"] + ): + # Three points if location matches + score += 3 + if open_issue["commit-hash"] == source_issue["commit-hash"]: + # Two points if commit-hash matches + score += 2 + closeness[i, j] = score + sys.stdout.write(str(score) + " ") + sys.stdout.flush() + sys.stdout.write("\n") + +# Greedy match up pairs by highest scores first +min_score = 2.5 +if len(source_issues) > 0 and len(open_issues) > 0: + while True: + # Pick a highest score + (i, j) = np.unravel_index(np.argmax(closeness), closeness.shape) + + # If the score is less than the minimum required we are done + if closeness[i, j] <= min_score: + break + + # Remove pair from matrix + closeness[i, :] = 0.0 + closeness[:, j] = 0.0 + + # Pair up issues + open_issues[i]["source-issue-index"] = j + source_issues[j]["open-issue-index"] = i + +# Process issues +for issue in open_issues: + if "source-issue-index" in issue: + # TODO: Update github issue + update_issue(issue, source_issues[issue["source-issue-index"]]) + else: + # Close issue + close_issue(issue) +for issue in source_issues: + if "open-issue-index" in issue: + # already handles above + pass + else: + create_issue(issue) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abc0e5d..2a503f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,47 +47,40 @@ jobs: --depth 1 \ --all-targets - # codecov: - # # See - # name: Coverage - # runs-on: ubuntu-latest - # timeout-minutes: 30 - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 - # - name: Install rust - # uses: dtolnay/rust-toolchain@master - # with: - # toolchain: nightly - # components: llvm-tools-preview - # - name: Cache build - # uses: Swatinem/rust-cache@v1 - # with: - # key: cache-v1 - # - name: Install cargo-llvm-cov - # uses: taiki-e/install-action@cargo-llvm-cov - # - name: Build with code coverage - # run: | - # cargo llvm-cov --no-report --locked --workspace --all-features --all-targets -- --help - # cargo llvm-cov --no-report --locked --workspace --all-features --doc -- --help - # - name: Generate code coverage - # env: - # # Covered tests are slower, so reduce the test load. (We also shouldn't - # # depend too much on case generation for coverage). - # PROPTEST_CASES: 5 - # run: | - # # Generate profiles, but do not merge them - # cargo llvm-cov --no-report --locked --workspace --all-features --all-targets -- --nocapture - # cargo llvm-cov --no-report --locked --workspace --all-features --doc -- --nocapture - # - name: Merge profiles - # run: cargo llvm-cov --no-run --lcov --output-path lcov.info - # - name: Submit to codecov.io - # uses: codecov/codecov-action@v3.1.1 - # with: - # token: ${{ secrets.CODECOV_TOKEN }} # Optional for public repos - # files: lcov.info - # fail_ci_if_error: true - # verbose: true + codecov: + # See + name: Coverage + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: llvm-tools-preview + - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@cargo-llvm-cov + - name: Build with code coverage + run: | + cargo llvm-cov --no-report --locked --workspace --all-features --all-targets -- --help + cargo llvm-cov --no-report --locked --workspace --all-features --doc -- --help + - name: Generate code coverage + env: + # Covered tests are slower, so reduce the test load. (We also shouldn't + # depend too much on case generation for coverage). + PROPTEST_CASES: 5 + run: | + # Generate profiles, but do not merge them + cargo llvm-cov --no-report --locked --workspace --all-features --all-targets -- --nocapture + cargo llvm-cov --no-report --locked --workspace --all-features --doc -- --nocapture + - name: Merge profiles + run: cargo llvm-cov --no-run --lcov --output-path lcov.info + - name: Submit to codecov.io + uses: codecov/codecov-action@v3.1.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} # Optional for public repos + files: lcov.info + fail_ci_if_error: true + verbose: true clippy: name: clippy diff --git a/.github/workflows/issue_tracker.yml b/.github/workflows/issue_tracker.yml new file mode 100644 index 0000000..a4b70a8 --- /dev/null +++ b/.github/workflows/issue_tracker.yml @@ -0,0 +1,27 @@ +name: Issue Tracker + +on: + push: + branches: [main] + +jobs: + issue-tracker: + name: Issue Tracker + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Cache Python dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: issue_tracker-${{ hashFiles('.github/workflows/issue_tracker.yml') }} + restore-keys: issue_tracker- + - name: Install Python dependencies + run: pip install PyGithub numpy + - name: Update issues + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO_NAME: ${{ github.repository }} + DRY_RUN: false + run: .github/scripts/issue_tracker.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dabf5a..7eb309e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Support for [`alloy-rlp`](https://github.com/alloy-rs/rlp) + ### Changed - Make `serde::Deserialize` impl more permissive - Use Ethereum `Quantity` encoding for serde serialization when human-readable - Fix error in `from_base_be` that allowed instantiation of overflowing `Uint`. -- Updated `ark` to `0.4`, `fastrlp` to `0.3` and `pyo3` to `0.18`. +- Updated `ark` to `0.4`, `fastrlp` to `0.3`, `pyo3` to `0.18`, and `sqlx-core` to `0.7`. +- Improved `fastrlp` perfomance +- Improved `proptest` performance +- Made `support` module and its modules public +- Made more `algorithm` functions public + +### Removed + +- Automatic detection of nightly features. Enable them instead with the `nightly` cargo feature. +- Dependency on `derive_more` ### Fixed diff --git a/Cargo.toml b/Cargo.toml index af24ee3..0b4d2b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,9 @@ edition = "2021" rust-version = "1.65" authors = ["Remco Bloemen ", "Alloy Contributors"] license = "MIT" -homepage = "https://github.com/alloy-rs/core" -repository = "https://github.com/alloy-rs/core" +homepage = "https://github.com/recmo/uint" +repository = "https://github.com/recmo/uint" [workspace.dependencies] -ruint2 = { version = "1.9.0", path = "crates/ruint" } -ruint2-macro = { version = "1.0.3", path = "crates/ruint-macro" } +ruint = { version = "1.9.0", path = "crates/ruint" } +ruint-macro = { version = "1.0.3", path = "crates/ruint-macro" } diff --git a/README.md b/README.md index f080cd9..ff66c49 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ # Rust `uint` crate using const-generics -[![crates.io](https://buildstats.info/crate/ruint)](https://crates.io/crates/ruint2) -[![docs.rs](https://img.shields.io/docsrs/ruint)](https://docs.rs/ruint2) -[![MIT License](https://img.shields.io/github/license/alloy-rs/uint)](https://github.com/alloy-rs/uint/blob/main/LICENSE) -[![dependency status](https://deps.rs/repo/github/alloy-rs/uint/status.svg)](https://deps.rs/repo/github/alloy-rs/uint) -[![codecov](https://codecov.io/gh/alloy-rs/uint/branch/main/graph/badge.svg?token=WBPZ9U4TTO)](https://codecov.io/gh/alloy-rs/uint) -[![CI](https://github.com/alloy-rs/uint/actions/workflows/ci.yml/badge.svg)](https://github.com/alloy-rs/uint/actions/workflows/ci.yml) +[![crates.io](https://buildstats.info/crate/ruint)](https://crates.io/crates/ruint) +[![docs.rs](https://img.shields.io/docsrs/ruint)](https://docs.rs/ruint) +[![MIT License](https://img.shields.io/github/license/recmo/uint)](https://github.com/recmo/uint/blob/main/LICENSE) +[![dependency status](https://deps.rs/repo/github/recmo/uint/status.svg)](https://deps.rs/repo/github/recmo/uint) +[![codecov](https://codecov.io/gh/recmo/uint/branch/main/graph/badge.svg?token=WBPZ9U4TTO)](https://codecov.io/gh/recmo/uint) +[![CI](https://github.com/recmo/uint/actions/workflows/ci.yml/badge.svg)](https://github.com/recmo/uint/actions/workflows/ci.yml) Implements [`Uint`], the ring of numbers modulo $2^{\mathsf{BITS}}$. It requires two generic arguments: the number of bits and the number of 64-bit 'limbs' required to store those bits. ```rust -# use ruint2::Uint; +# use ruint::Uint; let answer: Uint<256, 4> = Uint::from(42); ``` @@ -26,15 +26,15 @@ A more convenient method on stable is to use the [`uint!`] macro, which construc [`Uint`] for you. ```rust -# use ruint2::{Uint, uint}; +# use ruint::{Uint, uint}; let answer = uint!(42_U256); ``` You can also use one of the pre-computed type [`aliases`]: ```rust -# use ruint2::Uint; -use ruint2::aliases::*; +# use ruint::Uint; +use ruint::aliases::*; let answer: U256 = Uint::from(42); ``` @@ -42,7 +42,7 @@ let answer: U256 = Uint::from(42); You can of course also create your own type alias if you need a funny size: ```rust -# use ruint2::Uint; +# use ruint::Uint; type U1337 = Uint<1337, 21>; let answer: U1337 = Uint::from(42); @@ -57,8 +57,8 @@ without `generic_const_exprs` support (Rust issue [#76560][r76560]). [r76560]: https://github.com/rust-lang/rust/issues/76560 ```rust -# #[cfg(all(has_generic_const_exprs, feature = "generic_const_exprs"))] { -use ruint2::nightly::Uint; +# #[cfg(feature = "generic_const_exprs")] { +use ruint::nightly::Uint; let answer: Uint<256> = Uint::<256>::from(42); # } @@ -73,7 +73,7 @@ these nightly features are stabilized. ## Examples ```rust -use ruint2::Uint; +use ruint::Uint; let a: Uint<256, 4> = Uint::from(0xf00f_u64); let b: Uint<256, 4> = Uint::from(42_u64); @@ -89,7 +89,7 @@ supported using their prefixes `0x`, `0b` and `0o`. Literals can have underscores `_` added for readability. ```rust -# use ruint2::uint; +# use ruint::uint; let cow = uint!(0xc85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4_U256); ``` @@ -97,7 +97,7 @@ In fact, this macro recurses down the parse tree, so you can apply it to entire source files: ```rust -# use ruint2::uint; +# use ruint::uint; uint!{ let a = 42_U256; @@ -192,9 +192,9 @@ RUSTDOCFLAGS="-Z unstable-options --show-coverage" cargo doc --workspace --all- --- -[![lines of code](https://img.shields.io/tokei/lines/github/alloy-rs/uint)](https://github.com/alloy-rs/uint) -[![GitHub contributors](https://img.shields.io/github/contributors/alloy-rs/uint)](https://github.com/alloy-rs/uint/graphs/contributors) -[![GitHub issues](https://img.shields.io/github/issues/alloy-rs/uint)](https://github.com/alloy-rs/uint/issues) -[![GitHub pull requests](https://img.shields.io/github/issues-pr/alloy-rs/uint?label=PRs)](https://github.com/alloy-rs/uint/pulls) -[![GitHub Repo stars](https://img.shields.io/github/stars/alloy-rs/uint)](https://star-history.com/#alloy-rs/uint&Date) -[![crates.io](https://img.shields.io/crates/d/ruint2)](https://crates.io/crates/ruint2) +[![lines of code](https://img.shields.io/tokei/lines/github/recmo/uint)](https://github.com/recmo/uint) +[![GitHub contributors](https://img.shields.io/github/contributors/recmo/uint)](https://github.com/recmo/uint/graphs/contributors) +[![GitHub issues](https://img.shields.io/github/issues/recmo/uint)](https://github.com/recmo/uint/issues) +[![GitHub pull requests](https://img.shields.io/github/issues-pr/recmo/uint?label=PRs)](https://github.com/recmo/uint/pulls) +[![GitHub Repo stars](https://img.shields.io/github/stars/recmo/uint)](https://star-history.com/#recmo/uint&Date) +[![crates.io](https://img.shields.io/crates/d/ruint)](https://crates.io/crates/ruint) diff --git a/crates/ruint-macro/Cargo.toml b/crates/ruint-macro/Cargo.toml index f175a84..e969feb 100644 --- a/crates/ruint-macro/Cargo.toml +++ b/crates/ruint-macro/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ruint2-macro" +name = "ruint-macro" description = "The `uint!` macro for `Uint` literals" version = "1.0.3" keywords = ["uint", "macro"] @@ -19,4 +19,4 @@ proc-macro = true tag = false [dev-dependencies] -ruint2.workspace = true +ruint.workspace = true diff --git a/crates/ruint-macro/README.md b/crates/ruint-macro/README.md index 79cad5e..da2adc5 100644 --- a/crates/ruint-macro/README.md +++ b/crates/ruint-macro/README.md @@ -11,13 +11,13 @@ Within the [`uint!`] macro arguments, you can write [`Uint`] and [`Bits`] litera To use it simply import it in scope: ```rust -use ruint2::uint; +use ruint::uint; ``` Now constants can be created in decimal, hex, binary and even octal: ```rust -# use ruint2::uint; +# use ruint::uint; let avogadro = uint!(602_214_076_000_000_000_000_000_U256); let cow_key = uint!(0xee79b5f6e221356af78cf4c36f4f7885a11b67dfcc81c34d80249947330c0f82_U256); let bender = uint!(0b1010011010_U10); @@ -26,7 +26,7 @@ let bender = uint!(0b1010011010_U10); The [`uint!`] macro recurses through the parse tree, so the above can equivalently be written ```rust -# use ruint2::uint; +# use ruint::uint; uint!{ let avogadro = 602_214_076_000_000_000_000_000_U256; let cow_key = 0xee79b5f6e221356af78cf4c36f4f7885a11b67dfcc81c34d80249947330c0f82_U256; @@ -37,7 +37,7 @@ let bender = 0b1010011010_U10; This latter form is particularly useful for lookup tables: ```rust -# use ruint2::{Uint, uint}; +# use ruint::{Uint, uint}; const PRIMES: [Uint<128, 2>; 3] = uint!([ 170141183460469231731687303715884105757_U128, 170141183460469231731687303715884105773_U128, @@ -49,7 +49,7 @@ The macro will throw a compile time error if you try to create a constant that does not fit the type: ```rust,compile_fail -# use ruint2::uint; +# use ruint::uint; # uint!{ let sparta = 300_U8; # } diff --git a/crates/ruint-macro/src/lib.rs b/crates/ruint-macro/src/lib.rs index 7789d27..f061449 100644 --- a/crates/ruint-macro/src/lib.rs +++ b/crates/ruint-macro/src/lib.rs @@ -46,7 +46,7 @@ fn construct(base_type: LiteralBaseType, bits: usize, limbs: &[u64]) -> TokenStr } let limbs_str = limbs_str.trim_end_matches(", "); let limbs = (bits + 63) / 64; - let source = format!("::ruint2::{base_type}::<{bits}, {limbs}>::from_limbs([{limbs_str}])"); + let source = format!("::ruint::{base_type}::<{bits}, {limbs}>::from_limbs([{limbs_str}])"); TokenStream::from_str(&source).unwrap() } diff --git a/crates/ruint-macro/tests/parse_mixed.rs b/crates/ruint-macro/tests/parse_mixed.rs index 4a069e6..01556e8 100644 --- a/crates/ruint-macro/tests/parse_mixed.rs +++ b/crates/ruint-macro/tests/parse_mixed.rs @@ -1,5 +1,5 @@ -use ruint2::aliases::{B256, U256}; -use ruint2_macro::uint; +use ruint::aliases::{B256, U256}; +use ruint_macro::uint; #[test] fn test_non_literal() { diff --git a/crates/ruint/Cargo.toml b/crates/ruint/Cargo.toml index 858e95e..6f12cf6 100644 --- a/crates/ruint/Cargo.toml +++ b/crates/ruint/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ruint2" +name = "ruint" description = "Unsigned integer type with const-generic bit length" version = "1.9.0" keywords = ["uint"] @@ -23,12 +23,12 @@ harness = false path = "benches/bench.rs" [dependencies] -ruint2-macro.workspace = true +ruint-macro.workspace = true thiserror = "1.0" # support -alloy-rlp = { version = "0", optional = true } +alloy-rlp = { version = "0.3", optional = true } arbitrary = { version = "1", optional = true } ark-ff = { version = "0.4", optional = true } bn-rs = { version = "0.2", optional = true } @@ -53,7 +53,7 @@ postgres-types = { version = "0.2", optional = true } sqlx-core = { version = "0.7", optional = true } [dev-dependencies] -ruint2 = { workspace = true, features = ["arbitrary", "proptest"] } +ruint = { workspace = true, features = ["arbitrary", "proptest"] } criterion = "0.5" rand = "0.8" diff --git a/crates/ruint/benches/bench.rs b/crates/ruint/benches/bench.rs index 9d93ccb..a11ebdd 100644 --- a/crates/ruint/benches/bench.rs +++ b/crates/ruint/benches/bench.rs @@ -8,7 +8,7 @@ mod prelude { test_runner::TestRunner, }; pub use rand::prelude::*; - pub use ruint2::{const_for, nlimbs, uint, Bits, Uint, UintTryFrom, UintTryTo}; + pub use ruint::{const_for, nlimbs, uint, Bits, Uint, UintTryFrom, UintTryTo}; pub use std::hint::black_box; } diff --git a/crates/ruint/benches/benches/algorithms/div/reciprocal.rs b/crates/ruint/benches/benches/algorithms/div/reciprocal.rs index b534ccd..67a1594 100644 --- a/crates/ruint/benches/benches/algorithms/div/reciprocal.rs +++ b/crates/ruint/benches/benches/algorithms/div/reciprocal.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use ruint2::algorithms::div::*; +use ruint::algorithms::div::*; pub fn group(criterion: &mut Criterion) { bench_reciprocal_ref(criterion); diff --git a/crates/ruint/benches/benches/algorithms/div/small.rs b/crates/ruint/benches/benches/algorithms/div/small.rs index a296936..5023354 100644 --- a/crates/ruint/benches/benches/algorithms/div/small.rs +++ b/crates/ruint/benches/benches/algorithms/div/small.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use ruint2::algorithms::div::*; +use ruint::algorithms::div::*; pub fn group(criterion: &mut Criterion) { bench_div_2x1_ref(criterion); diff --git a/crates/ruint/benches/benches/algorithms/gcd.rs b/crates/ruint/benches/benches/algorithms/gcd.rs index 52d7494..7477831 100644 --- a/crates/ruint/benches/benches/algorithms/gcd.rs +++ b/crates/ruint/benches/benches/algorithms/gcd.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use ruint2::algorithms::LehmerMatrix as Matrix; +use ruint::algorithms::LehmerMatrix as Matrix; use std::cmp::{max, min}; pub fn group(criterion: &mut Criterion) { diff --git a/crates/ruint/benches/benches/algorithms/mul.rs b/crates/ruint/benches/benches/algorithms/mul.rs index 348469e..1352a18 100644 --- a/crates/ruint/benches/benches/algorithms/mul.rs +++ b/crates/ruint/benches/benches/algorithms/mul.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use ruint2::algorithms::addmul_n; +use ruint::algorithms::addmul_n; pub fn group(criterion: &mut Criterion) { bench_addmul_nnn(criterion); diff --git a/crates/ruint/src/algorithms/mul.rs b/crates/ruint/src/algorithms/mul.rs index 60026b0..1d6770e 100644 --- a/crates/ruint/src/algorithms/mul.rs +++ b/crates/ruint/src/algorithms/mul.rs @@ -55,7 +55,7 @@ pub fn addmul_ref(result: &mut [u64], a: &[u64], b: &[u64]) -> bool { /// # Examples /// /// ``` -/// # use ruint2::algorithms::addmul; +/// # use ruint::algorithms::addmul; /// let mut result = [0]; /// let overflow = addmul(&mut result, &[3], &[4]); /// assert_eq!(overflow, false); diff --git a/crates/ruint/src/const_for.rs b/crates/ruint/src/const_for.rs index f70b033..f157177 100644 --- a/crates/ruint/src/const_for.rs +++ b/crates/ruint/src/const_for.rs @@ -3,7 +3,7 @@ /// Repeats a block of code with different values assigned to a constant. /// /// ```rust -/// # use ruint2::{const_for, nlimbs, Uint}; +/// # use ruint::{const_for, nlimbs, Uint}; /// const_for!(BITS in [0, 10, 100] { /// const LIMBS: usize = nlimbs(BITS); /// println!("{:?}", Uint::::MAX); @@ -13,7 +13,7 @@ /// is equivalent to /// /// ```rust -/// # use ruint2::{const_for, Uint}; +/// # use ruint::{const_for, Uint}; /// println!("{:?}", Uint::<0, 0>::MAX); /// println!("{:?}", Uint::<10, 1>::MAX); /// println!("{:?}", Uint::<100, 2>::MAX); @@ -32,7 +32,7 @@ /// /// ```rust /// # use proptest::prelude::*; -/// # use ruint2::{const_for, nlimbs, Uint}; +/// # use ruint::{const_for, nlimbs, Uint}; /// const_for!(BITS in SIZES { /// const LIMBS: usize = nlimbs(BITS); /// proptest!(|(value: Uint)| { diff --git a/crates/ruint/src/from.rs b/crates/ruint/src/from.rs index 0c1d84a..216a8d3 100644 --- a/crates/ruint/src/from.rs +++ b/crates/ruint/src/from.rs @@ -89,7 +89,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(U8::from(142_u16), 142_U8); /// assert_eq!(U64::from(0x7014b4c2d1f2_U256), 0x7014b4c2d1f2_U64); @@ -117,7 +117,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(U8::saturating_from(300_u16), 255_U8); /// assert_eq!(U8::saturating_from(-10_i16), 0_U8); @@ -145,7 +145,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(U8::wrapping_from(300_u16), 44_U8); /// assert_eq!(U8::wrapping_from(-10_i16), 246_U8); @@ -171,7 +171,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(300_U12.to::(), 300_i16); /// assert_eq!(300_U12.to::(), 300_U256); @@ -190,7 +190,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(300_U12.wrapping_to::(), 44_i8); /// assert_eq!(255_U32.wrapping_to::(), -1_i8); @@ -210,7 +210,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(300_U12.saturating_to::(), 300_i16); /// assert_eq!(255_U32.saturating_to::(), 127); diff --git a/crates/ruint/src/gcd.rs b/crates/ruint/src/gcd.rs index 9fdcce5..6716774 100644 --- a/crates/ruint/src/gcd.rs +++ b/crates/ruint/src/gcd.rs @@ -6,7 +6,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint! { /// assert_eq!(0_U128.gcd(0_U128), 0_U128); /// # } diff --git a/crates/ruint/src/lib.rs b/crates/ruint/src/lib.rs index b6b50cb..22d6582 100644 --- a/crates/ruint/src/lib.rs +++ b/crates/ruint/src/lib.rs @@ -22,7 +22,6 @@ // Workaround for proc-macro `uint!` in this crate. // See extern crate self as ruint; -extern crate self as ruint2; #[macro_use] mod macros; @@ -62,7 +61,7 @@ pub use self::{ }; #[doc(inline)] -pub use ruint2_macro::uint; +pub use ruint_macro::uint; #[cfg(feature = "generic_const_exprs")] pub mod nightly { diff --git a/crates/ruint/src/log.rs b/crates/ruint/src/log.rs index 1733a86..784ab01 100644 --- a/crates/ruint/src/log.rs +++ b/crates/ruint/src/log.rs @@ -95,7 +95,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(0_U64.approx_log2(), f64::NEG_INFINITY); /// assert_eq!(1_U64.approx_log2(), 0.0); diff --git a/crates/ruint/src/modular.rs b/crates/ruint/src/modular.rs index f562aee..eea5260 100644 --- a/crates/ruint/src/modular.rs +++ b/crates/ruint/src/modular.rs @@ -133,7 +133,7 @@ impl Uint { /// computed using [`inv_ring`](Self::inv_ring) from `U64`. /// /// ``` - /// # use ruint2::{uint, Uint, aliases::*}; + /// # use ruint::{uint, Uint, aliases::*}; /// # uint!{ /// # let modulus = 21888242871839275222246405745257275088548364400416034343698204186575808495617_U256; /// let inv = U64::wrapping_from(modulus).inv_ring().unwrap().wrapping_neg().to(); diff --git a/crates/ruint/src/mul.rs b/crates/ruint/src/mul.rs index b17b83d..f33d206 100644 --- a/crates/ruint/src/mul.rs +++ b/crates/ruint/src/mul.rs @@ -26,7 +26,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint}; + /// # use ruint::{Uint, uint}; /// # uint!{ /// assert_eq!(1_U1.overflowing_mul(1_U1), (1_U1, false)); /// assert_eq!( @@ -119,7 +119,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint}; + /// # use ruint::{Uint, uint}; /// # uint!{ /// assert_eq!(0_U0.widening_mul(0_U0), 0_U0); /// assert_eq!(1_U1.widening_mul(1_U1), 1_U2); diff --git a/crates/ruint/src/pow.rs b/crates/ruint/src/pow.rs index 165c326..62cbb56 100644 --- a/crates/ruint/src/pow.rs +++ b/crates/ruint/src/pow.rs @@ -12,7 +12,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint}; + /// # use ruint::{Uint, uint}; /// # uint!{ /// assert_eq!( /// 36_U64.overflowing_pow(12_U64), @@ -31,7 +31,7 @@ impl Uint { /// ``` /// Small cases: /// ``` - /// # use ruint2::{Uint, uint}; + /// # use ruint::{Uint, uint}; /// # uint!{ /// assert_eq!(0_U0.overflowing_pow(0_U0), (0_U0, false)); /// assert_eq!(0_U1.overflowing_pow(0_U1), (1_U1, false)); @@ -106,7 +106,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(U64::approx_pow2(-2.0), Some(0_U64)); /// assert_eq!(U64::approx_pow2(-1.0), Some(1_U64)); diff --git a/crates/ruint/src/root.rs b/crates/ruint/src/root.rs index 52503ff..5c0006e 100644 --- a/crates/ruint/src/root.rs +++ b/crates/ruint/src/root.rs @@ -15,7 +15,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::*}; + /// # use ruint::{Uint, uint, aliases::*}; /// # uint!{ /// assert_eq!(0_U64.root(2), 0_U64); /// assert_eq!(1_U64.root(63), 1_U64); diff --git a/crates/ruint/src/special.rs b/crates/ruint/src/special.rs index 59e7658..22fb538 100644 --- a/crates/ruint/src/special.rs +++ b/crates/ruint/src/special.rs @@ -40,7 +40,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::U64}; + /// # use ruint::{Uint, uint, aliases::U64}; /// # uint!{ /// assert_eq!(0_U64.checked_next_power_of_two(), Some(1_U64)); /// assert_eq!(1_U64.checked_next_power_of_two(), Some(1_U64)); @@ -83,7 +83,7 @@ impl Uint { /// # Examples /// /// ``` - /// # use ruint2::{Uint, uint, aliases::U64}; + /// # use ruint::{Uint, uint, aliases::U64}; /// # uint!{ /// assert_eq!(16_U64.checked_next_multiple_of(8_U64), Some(16_U64)); /// assert_eq!(23_U64.checked_next_multiple_of(8_U64), Some(24_U64)); @@ -93,7 +93,7 @@ impl Uint { /// ``` /// /// ``` - /// # use ruint2::{Uint, uint}; + /// # use ruint::{Uint, uint}; /// # uint!{ /// assert_eq!(0_U0.checked_next_multiple_of(0_U0), None); /// assert_eq!(0_U1.checked_next_multiple_of(0_U1), None); diff --git a/crates/ruint/src/support/serde.rs b/crates/ruint/src/support/serde.rs index 961d73e..d9a2751 100644 --- a/crates/ruint/src/support/serde.rs +++ b/crates/ruint/src/support/serde.rs @@ -200,7 +200,7 @@ mod tests { "0b1" ]"#; let numbers: Vec> = serde_json::from_str(jason).unwrap(); - ruint2_macro::uint! { + ruint_macro::uint! { assert_eq!(numbers, vec![1_U1, 1_U1, 1_U1, 1_U1]); } @@ -211,7 +211,7 @@ mod tests { "0b" ]"#; let numbers: Vec> = serde_json::from_str(jason).unwrap(); - ruint2_macro::uint! { + ruint_macro::uint! { assert_eq!(numbers, vec![0_U1, 0_U1, 0_U1, 0_U1]); } }