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

Chore: Add witness hint for enum_variant_added lint #1218

Merged

Conversation

GlitchlessCode
Copy link
Contributor

Adds a witness hint for the enum_variant_added lint.

Example

enum_variant_added outputs the following witness hint for the ./test_crates/enum_variant_added/ test.

match value { 
    enum_variant_added::EnumWithNewVariant::OldVariant => (),
    enum_variant_added::EnumWithNewVariant::OldStructVariant { .. } => (),
    enum_variant_added::EnumWithNewVariant::OldTupleVariant(..) => (),
}

This compiles on the old version, but not on the new due to the lack of exhaustiveness on the match cases. The lack of a catch-all case causes the addition of a new variant to cause a compilation error.

Commit Notes

  • Added witness hint for enum_variant_added
  • Added new parts to query for enum_variant_added to fetch relevant data for the witness
  • Update test crates to allow for more exhaustive witness format testing

Comments

Two questions and possible areas for bigger improvements:

  1. Is there a better way to combine baseline_variant_names and baseline_variant_kinds? They both form lists, but each list is separate from the other. Now, each should still always form the same length of list as the other, as they are tied to the same variant query, but if there is a way to combine/tuple them together, that would be good to know so I can make that adjustment.
  2. Is it okay to modify tests like I've done here? It doesn't change the final result of the test, it all runs the same, I just added some new variants to the tested enum so that I can test the witness printing unit-like, struct-like, and tuple-like enum variants.

+ Added witness hint for enum_variant_added
+ Added new parts to query for enum_variant_added to fetch relevant data for the witness
+ Update test crates to allow for more exhaustive witness format testing
@obi1kenobi
Copy link
Owner

Excellent work 💯

Comments

Two questions and possible areas for bigger improvements:

  1. Is there a better way to combine baseline_variant_names and baseline_variant_kinds? They both form lists, but each list is separate from the other. Now, each should still always form the same length of list as the other, as they are tied to the same variant query, but if there is a way to combine/tuple them together, that would be good to know so I can make that adjustment.

Unfortunately no, at the moment Trustfall only supports what you've used here. Combining the outputs as you describe is a feature on our wish list, but it's surprisingly tricky to design due to having many non-obvious edge cases.

If you might be interested in taking a crack at building that feature (and would be willing to dedicate 3-6 months to work up to it + 3-6 months to actually build and test it), I'd be very happy to support you in that. You definitely have the right combination of coding skill, attention to detail, and tenacity to figure tricky things out to pull it off! That means it will merely be very challenging to build, as opposed to being impossible :)

  1. Is it okay to modify tests like I've done here? It doesn't change the final result of the test, it all runs the same, I just added some new variants to the tested enum so that I can test the witness printing unit-like, struct-like, and tuple-like enum variants.

Yes! Good call on noticing that the test coverage was insufficient and taking the initiative to improve it. I love to see it!

@obi1kenobi obi1kenobi merged commit aeccda8 into obi1kenobi:main Mar 24, 2025
31 of 32 checks passed
@GlitchlessCode GlitchlessCode deleted the enum_variant_added-witness branch March 25, 2025 03:05
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