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

Better error messages for derives #400

Merged
merged 5 commits into from
Jan 5, 2025
Merged

Conversation

shahn
Copy link
Contributor

@shahn shahn commented Jan 4, 2025

I added error span reporting to the derive macros. While doing so, I was worried about degrading performance, so I added a benchmark. To my surprise, performance improved between 2% and 20% for each of my individual benches. Benches are auto-generated from the rasn code base, by simply parsing all structs and enums which are using derives.

I also added a fuzz test for the derives, to help see if I missed any panics which would definitely not lead to good errors.

Please see which of the commits in this PR you want to take, because only the last one is about the better error messages. I am also happy to provide individual PRs if you think this would make sense. It is probably not useful to just squash all these into a single merge commit, as that removes the ability to reproduce the benchmark.

@shahn shahn force-pushed the derive_errors branch 3 times, most recently from b3b3704 to b9bc87d Compare January 4, 2025 17:27
@shahn shahn marked this pull request as draft January 4, 2025 17:46
@XAMPPRocky
Copy link
Collaborator

Thank you for your PR!

@shahn
Copy link
Contributor Author

shahn commented Jan 5, 2025

I am still working on this, there are some remaining instances of bad error messages left which I am weeding out.

This helps in benchmarking/profiling, because it removes the overhead of
repeatedly parsing the inputs.
shahn added 3 commits January 5, 2025 14:07
This is helpful for finding panics inside the derive macro, which always
lead to subpar error messages.

To use this with cargo-afl, you might go about it like this:

// Use extra fuzzing crate, not part of workspace
cd fuzzing

// To build
cargo afl build --release

// To start fuzzing. -a restricts the input to ascii, -G limits the
// input size to 512 bytes. Larger mostly just tests the TokenStream
// machinery. Leave out both options for slower but more thorough scan
cargo afl fuzz -i derive_in -x dict/derive.dict -a text -G 512 -o path_to_output_dir target/release/derive

// To reproduce a crash
cargo afl run --bin derive < path_to_output_dir/default/crashes/...
@shahn shahn marked this pull request as ready for review January 5, 2025 14:28
@shahn
Copy link
Contributor Author

shahn commented Jan 5, 2025

Should be fine now :)

@XAMPPRocky XAMPPRocky merged commit 11a2f38 into librasn:main Jan 5, 2025
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants