-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add lifetime parameter to Arbitrary trait. Remove shrinking functionality. Implement Arbitrary for &str. #63
Conversation
@Manishearth @fitzgen thoughts on this so far? should we create a separate crate for the shrinking behavior? |
I think we should have a pre-1.0 release before going 1.0 fwiw. But we can name the branch whatever |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the shrinking code is worth maintaining? AFAIK, no one is using it at all. It isn't used with cargo fuzz
, so someone would have to be implementing their own fuzzing engine or driver to use it, which AFAIK, no one is doing. As the person who wrote the shrinking code initially, I'd like to hear someone else champion it and articulate why we should keep it around.
In any case, if we keep it, then we should name the trait Shrink
instead of Shrinkable
, the same way std::iter::Extend
is not named Extendable
.
Finally, we should also add a impl<'a> Arbitrary<'a> for &'a str
implementation, now that it's possible.
Also: thanks for driving this work @frewsxcv! :) |
I'm not using the shrinking code, and not planning to use it. Just moved the code to a separate module in case someone did have a use for it! But if none of us do, then yeah let's just get rid of it |
to anyone in the future who wants the shrinking code: https://gist.github.com/frewsxcv/390976eb39c7e2a065c0b2d2731a3eb3 |
currently trying to figure out what the right behavior should be for the new lifetime when deriving |
Do you mean the actual name of the lifetime we emit in the generated code? The only way I can imagine running into issues is if the type requires multiple type parameters, but in such a case I don't think our derive can support such types anyways, because we wouldn't know what to do with any extra lifetimes. But I'm also not a master macrologist, so I'm not 100% sure here... |
This is ready for review! I will add a |
08e939d
to
4e8410f
Compare
Squashed |
4e8410f
to
7548ee8
Compare
In the latest force push, I renamed our derive codegen to generate a lifetime named |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Can we also have a type with a lifetime parameter that we derive Arbitrary
for in the tests/derive.rs
file?
With that, I think we can release a 1.0-rc1.
Oh I just remembered the other thing we can do: try and grab their existing lifetime from their type and use that instead of coming up with our own and replacing theirs. Sort of something like |
I think you're right, we do want to be smarter about lifetimes than just using a new one. In particular, I created this struct for a test: #[derive(Arbitrary, Debug)]
struct Lifetime<'a, 'b> {
alpha: &'a str,
beta: &'b str,
} This results in an error as currently implemented: The fix here is to replace: impl<'a, 'b, 'arbitrary> arbitrary::Arbitrary<'arbitrary> for Lifetime<'a, 'b> With: impl<'a, 'b, 'arbitrary: 'a + 'b> arbitrary::Arbitrary<'arbitrary> for Lifetime<'a, 'b> So that our lifetime is guaranteed to last as long as the existing lifetimes |
Also good idea to add a test :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
A couple inline suggestions, just little things.
With this merged, I think we can release 1.0.0-rc1, unless I'm overlooking something. @Manishearth @nagisa anything you can think of holding us back from a 1.0.0-rc1 release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm modulo nick's comments
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
1.0.0-rc1 has been published! |
Fixes #43
Note: This merges into a new branch
staging-1.0
where we can put our changes prepping for a 1.0 releaseTo-do:
Shrinkable
Cow
lifetime