Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible builder extension and type signature API #145

Merged
merged 119 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
ff213e8
Initial attempt
Veetaha Sep 19, 2024
76e3b6b
Smallfixes
Veetaha Sep 20, 2024
39ef481
Fix in TS
Veetaha Sep 20, 2024
a3a08e7
Brand new approach
Veetaha Sep 21, 2024
60bf268
Next iteration
Veetaha Sep 21, 2024
01ce57a
Fix lints
Veetaha Sep 21, 2024
8e12077
Better error messages
Veetaha Sep 21, 2024
3d3c823
Update tests and reduce the types in PhantomData
Veetaha Sep 22, 2024
525052e
Improve error messages in derives
Veetaha Sep 22, 2024
1f2208c
Add builder_mod overrides
Veetaha Sep 22, 2024
bedc8f1
cargo fmt
Veetaha Sep 22, 2024
7e7e73d
improve visibility syntax
Veetaha Sep 22, 2024
c917ad8
Add visibility overrides for all items, make the builder state trait …
Veetaha Sep 22, 2024
0359055
Rearrange error message
Veetaha Sep 22, 2024
1974c1a
Fix cfg attrs with doc comments
Veetaha Sep 22, 2024
eb13c35
Renamings, add `NamedMemberState<Name>` trait
Veetaha Sep 24, 2024
a1ddac5
`Option<T>` approach
Veetaha Sep 24, 2024
6dc1aa1
Refactor, add `mutable` members support
Veetaha Sep 24, 2024
71bb4a9
Update the tag line in crate description
Veetaha Sep 25, 2024
1ee0c3c
Fix grammar
Veetaha Sep 25, 2024
a2e2f00
Undo visibility syntax change
Veetaha Sep 25, 2024
f8d08b5
Update builder derives
Veetaha Sep 25, 2024
3c7a257
Fix warnings
Veetaha Sep 25, 2024
c0e51a0
Rename `mutable` -> `overwritable`
Veetaha Sep 28, 2024
dc29b69
start_fn visibility inherits builder_type vis by default
Veetaha Sep 28, 2024
b0d3380
Try vendor IsSet/UnsetTraits
Veetaha Sep 28, 2024
9de917d
Rename `builder_mod -> state_mod`, cleanup
Veetaha Sep 28, 2024
4563abc
Add `IsComplete` trait
Veetaha Sep 30, 2024
6141e55
Add `msrv-1-79-0` feature
Veetaha Oct 1, 2024
d872ebf
Small fix
Veetaha Oct 1, 2024
56ac346
Rename TokenStream2 -> TokenStream
Veetaha Oct 1, 2024
98cb5cc
Add some more things to the prelude
Veetaha Oct 1, 2024
af42d02
Fix whitespace
Veetaha Oct 1, 2024
319ca12
Commit initial v3 design
Veetaha Oct 1, 2024
2c43aa3
Add setters config
Veetaha Oct 2, 2024
64956eb
cargo fmt
Veetaha Oct 2, 2024
71c427c
Rename setter -> setters
Veetaha Oct 2, 2024
8516558
Refactor
Veetaha Oct 2, 2024
6f689e7
Test with parsing error
Veetaha Oct 2, 2024
38de96b
Refactoring and `transparent` attribute
Veetaha Oct 3, 2024
446ece0
Better error reporting
Veetaha Oct 3, 2024
e5d8652
Test and fix `#[builder(transparent)]`
Veetaha Oct 3, 2024
60f8830
Improve tests, fix `transparent` + `default`
Veetaha Oct 3, 2024
73976a8
More validations
Veetaha Oct 3, 2024
41029d7
Initial `with` impl
Veetaha Oct 3, 2024
ce7d01b
More fixes for `with`
Veetaha Oct 3, 2024
768c7b3
cargo fmt
Veetaha Oct 3, 2024
06c2f8b
More tests and fixes for `with`
Veetaha Oct 3, 2024
197c674
More tests
Veetaha Oct 3, 2024
e1265c8
Fixes for Visibility::into_equivalent_in_child_module
Veetaha Oct 3, 2024
28d4fd6
More tests for setters attr
Veetaha Oct 4, 2024
fc0e71f
Add `StateExt` trait indirection and make `AllUnset` a struct to impr…
Veetaha Oct 4, 2024
cc48c18
Add tests for `overwritable`
Veetaha Oct 4, 2024
c610490
Add comment
Veetaha Oct 4, 2024
6cbdcde
The great rename and identifier fixes
Veetaha Oct 4, 2024
a342462
Fix mentions of the old `#[builder]` syntax in the "Fallible builders…
Veetaha Oct 5, 2024
1275d48
Add a workaround for RA/proc_macro2 bugs on invalid punct
Veetaha Oct 5, 2024
41038eb
Setters configs compile :D
Veetaha Oct 8, 2024
e36efb0
Use table formatting
Veetaha Oct 8, 2024
62b2b5d
Update tests
Veetaha Oct 8, 2024
7bbed4e
Render defaults
Veetaha Oct 8, 2024
d552ae2
More docs improvements
Veetaha Oct 9, 2024
48f6b29
Remove unnecessary `move`
Veetaha Oct 10, 2024
8441369
Optimize state compile perf
Veetaha Oct 11, 2024
b9a1e9e
Move `IsSet`/`IsUnset` under a `builder_state` module to avoid flaggi…
Veetaha Oct 11, 2024
6472fc9
Add logo and favicon to rustdoc
Veetaha Oct 11, 2024
0301591
Render `Optional` in a box for optional member's docs
Veetaha Oct 11, 2024
67bc4cf
Some initial tests for `#[builder(setters)]` and reject attributes wi…
Veetaha Oct 11, 2024
7cab13c
Some more tests
Veetaha Oct 11, 2024
b5fd452
Fix validation
Veetaha Oct 11, 2024
fe288e8
Update test snapshot
Veetaha Oct 11, 2024
f53988a
Some fixes
Veetaha Oct 11, 2024
2516bab
Some refactoring and more tests
Veetaha Oct 12, 2024
9a6c6c2
Reorder items in the `bon` crate
Veetaha Oct 12, 2024
21ba789
Add more tests. This is when I recognized how much it kills the compi…
Veetaha Oct 12, 2024
49df1d5
Use structs as states
Veetaha Oct 12, 2024
ae640fe
Simplify
Veetaha Oct 12, 2024
1430ee5
Simplify sealing and remove unused `#[diagnostic::on_unimplemented]`
Veetaha Oct 12, 2024
6d6453a
Rename
Veetaha Oct 12, 2024
a4d3a84
Move `finish_fn` into a dedicated module
Veetaha Oct 12, 2024
763b7f4
Remove `transition_type_state_fn`
Veetaha Oct 12, 2024
d27cc7c
Randomize private field names
Veetaha Oct 12, 2024
fd0fa8d
Small fixes
Veetaha Oct 13, 2024
cf1db15
More tests for `builder(setters)`
Veetaha Oct 13, 2024
9d5dbf2
Add tests for `#[builder(setters(docs, vis))]`
Veetaha Oct 13, 2024
ef8d09e
Prevent name collisions
Veetaha Oct 13, 2024
7bdf004
Autoresolve name conflicts
Veetaha Oct 13, 2024
1e5924c
Add tests for builder state name conflicts
Veetaha Oct 14, 2024
1d53e5c
More tests
Veetaha Oct 14, 2024
b690c64
cargo fmt
Veetaha Oct 14, 2024
90509cc
Update trybuild
Veetaha Oct 14, 2024
d9d62c0
Install `rust-src` for trybuild tests
Veetaha Oct 14, 2024
3b161be
Clean up docs
Veetaha Oct 14, 2024
256e3a4
Fix lints from nightly
Veetaha Oct 14, 2024
d27aa43
Remove noise from codegen snapshot tests
Veetaha Oct 14, 2024
0edb305
Fix feature name
Veetaha Oct 14, 2024
cea27b2
Fix unstable jobs
Veetaha Oct 14, 2024
23014ff
Add `miri` tests
Veetaha Oct 15, 2024
dec1709
Fix miri nightly toolchain version
Veetaha Oct 15, 2024
4946c0b
Fix miri
Veetaha Oct 15, 2024
cb77974
Fix
Veetaha Oct 15, 2024
a708936
Initial compilation benchmarks
Veetaha Oct 16, 2024
78fe9b5
More benches
Veetaha Oct 16, 2024
a0b4f4a
Run benches
Veetaha Oct 16, 2024
6f70a82
Fix dead_code warning
Veetaha Oct 16, 2024
596dea7
t
Veetaha Oct 16, 2024
2ceeb6b
Fix tests
Veetaha Oct 17, 2024
90fb884
Fix CI
Veetaha Oct 17, 2024
6acf3f8
Self-review part1
Veetaha Oct 17, 2024
9175a5c
Refactor items params parsing
Veetaha Oct 17, 2024
3e5d9cd
Add bounds config for builder derives
Veetaha Oct 17, 2024
45038ac
Better docs
Veetaha Oct 18, 2024
fab59f3
Self-review part 2
Veetaha Oct 19, 2024
db8dcd2
Self-review part 3
Veetaha Oct 19, 2024
6a10020
Self-review part 4
Veetaha Oct 19, 2024
be13024
Self-revie part 5
Veetaha Oct 19, 2024
24996e0
Self-review part 6
Veetaha Oct 19, 2024
c47a2e6
Self-review part 7
Veetaha Oct 20, 2024
7e9709e
Self-review part 8
Veetaha Oct 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:

jobs:
# Sanity-check that benchmarks work
benchmarks:
runtime-benchmarks:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -41,7 +41,16 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1

- run: sudo apt-get install -y valgrind
- run: ./benchmarks/run.sh ${{ matrix.benchmark }}
- run: cd ./benchmarks/runtime && ./run.sh ${{ matrix.benchmark }}

compilation-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: ./scripts/install/hyperfine.sh

- run: cd ./benchmarks/compilation && ./run.sh

cargo-lock:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -75,13 +84,21 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# rust-src is required to make sure compile errors on CI are rendered
# the same as locally. The `rust-src` component is installed by default
# locally, and with its presence compile error messages can show snippets
# of rust standard library code.
components: rust-src

- run: cargo clippy --all-features --all-targets --locked

- run: cargo test --locked --all-features --all-targets
- run: cargo test --locked --all-features --doc
- run: cd bon && cargo test --locked --no-default-features --features=
- run: cd bon && cargo test --locked --no-default-features --features=alloc
- run: cd bon && cargo test --locked --no-default-features --features=implied-bounds
- run: cd bon && cargo test --locked --no-default-features --features=alloc,implied-bounds

test-msrv:
runs-on: ${{ matrix.os }}-latest
Expand Down Expand Up @@ -119,13 +136,28 @@ jobs:
toolchain: ${{ matrix.toolchain }}
components: clippy

- run: cargo +${{ matrix.toolchain }} clippy --all-features --all-targets --locked
- run: |
cargo +${{ matrix.toolchain }} clippy --all-features --all-targets --locked \
-- \
--allow edition-2024-expr-fragment-specifier \
--allow impl-trait-overcaptures

cargo-miri:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-10-14
components: miri

- run: |
cargo miri test --locked --all-features --all-targets \
--workspace --exclude runtime-benchmarks
env:
# There is no need for us to stick with the edition 2021 meaning for
# the `expr` fragment in macro rules.
RUSTFLAGS: >-
--deny warnings
--allow unknown-lints
--allow edition-2024-expr-fragment-specifier
--allow impl-trait-overcaptures

Expand Down
114 changes: 98 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[workspace]
members = ["benchmarks", "bon", "bon-cli", "bon-macros", "e2e-tests"]
members = [
"benchmarks/compilation",
"benchmarks/compilation/codegen",
"benchmarks/runtime",
"bon",
"bon-cli",
"bon-macros",
"e2e-tests",
]
resolver = "2"

# This config is used for the benchmarks
Expand Down Expand Up @@ -130,8 +138,7 @@ wildcard_dependencies = "warn"
zero_sized_map_values = "warn"

# Priorities are used not because we override lints from these lint groups
# but just to order them in order from the less noisy to the more noisy in
# the output
# but just to order them from the less noisy to the more noisy in the output
nursery = { level = "warn", priority = -2 }
pedantic = { level = "warn", priority = -1 }

Expand Down Expand Up @@ -176,5 +183,5 @@ rust_2024_compatibility = { level = "warn", priority = 1 }
# [workspace.lints.rust]
# must_not_suspend = "warn"
# rust_2024_incompatible_pat = "warn"
# lossy_provenance_casts = "warn"
# fuzzy_provenance_casts = "warn"
# lossy_provenance_casts = "warn"
# fuzzy_provenance_casts = "warn"
28 changes: 28 additions & 0 deletions benchmarks/compilation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "compilation-benchmarks"

publish = false

description = """
Crate for benchmarking of the compilation time of code generated by
proc-macros in the `bon` crate and other alternatives.
"""

edition = "2021"
version = "0.1.0"

[dependencies]
bon = { path = "../../bon", optional = true }
cfg-if = "1.0"
derive_builder = { version = "0.20", optional = true }
typed-builder = { version = "0.20", optional = true }

[lints]
workspace = true

[features]
bon-overwritable = ["bon"]
default = []

structs_100_fields_10 = []
structs_10_fields_50 = []
25 changes: 25 additions & 0 deletions benchmarks/compilation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Benchmarks

This is a collection of compilation time benchmarks for the code generated by `bon` crate and some other alternative builder macro crates.

## Dependencies

If you'd like to run the benchmarks yourself, first you need to install the following:

- [`hyperfine`](https://github.com/sharkdp/hyperfine) CLI

If you are on Linux, just run the following commands to install the dependencies:

```bash
./scripts/install/hyperfine.sh
```

## Running the benchmarks

Once you have all the [dependencies](#dependencies) installed you can run the selected benchmark from this directory like this:

```bash
./run.sh {benchmark_name}
```

The `{benchmark_name}` corresponds to the modules in this crate.
16 changes: 16 additions & 0 deletions benchmarks/compilation/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "compilation-benchmarks-codegen"

publish = false

description = """
Generates code for the compilation benchmarks.
"""

edition = "2021"
version = "0.1.0"

[dependencies]
anyhow = "1.0"
proc-macro2 = "1.0"
quote = "1.0"
Loading
Loading