-
Notifications
You must be signed in to change notification settings - Fork 38
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
Deriver: share fuel between mutual generators #195
Conversation
Great, thanks! 🙂 👍 Is it correctly understood that
If so, would it make sense to unify the last two, so that any kind of recursive variant needing fuel (mutually recursive or not) always derives a pair of generators
|
yes
Yes it is! I did not want to break to much code regarding this particular fix. However, if we agree on the fix I can do this as well :) I will ping you when it's done. |
Done @jmid The rule is now:
The idea behind the second point is: share the size indicator in each sub-type. There was also a fix in these commits: type 'a tree = Leaf of 'a | Node of 'a tree * 'a tree
type int_tree = int tree
(* generator for int_tree before the fix: *)
let gen_int_tree = gen_tree
(* generator for int_tree after the fix: *)
let gen_int_tree gen_tree QCheck.Gen.int The parameters were ignored. |
Could I ask you to rebase? (it would be nice to have a green light from CI before merging, now that it's working again) 🙏 |
93c9f02
to
d0c0b1e
Compare
If the CI pass and you agree on the generated code, I think we can merge this @jmid. |
I quickly found bugs writing these tests. They are not yet related to this specific PR I let you decide whether I should add those tests in this PR, or if we merge and I come up with a follow-up PR. (I first wrote the deriver for |
OK, makes sense. It probably makes most sense to submit those tests (and fixes) as a separate PR. First: Sorry for leaving this hanging for some time... 😬 I took a quick look and found that there's now two copies of (what looks like) identical copies of qcheck/src/ppx_deriving_qcheck/ppx_deriving_qcheck.ml Lines 43 to 47 in d0c0b1e
qcheck/src/ppx_deriving_qcheck/ppx_deriving_qcheck.ml Lines 461 to 465 in d0c0b1e
It indicates that it would be worth it to take an extra clean-up pass over the code. Unrelated: The comments with I was a bit confused by the order of the code: First some basic helpers, some There's already a tests for recursive types (tree, expr), for two-level (expr-value), and truly mutually recursive types (tree-forest), so you've done a great effort there already. If you feel like putting the plugin to the test, I just remembered this one Finally: I'm super happy with this deriving plugin (I started using it myself to avoid writing this boilerplate) - so thanks for your effort! 🙏 |
It does not surprise me, my rebase was suspicious.
and, yes!
Yes it is not ideal, I will restructure the code before this MR's changes, with more documentation obviously :). Even though, the commits in this MR are not really great: I introduced a signifcant change in d1edc6f, which I generalize in a7cb9b6 and lead to several removals from previous commit. I think with the testing suite we have for the deriver, it could be a good thing to restart from scratch to produce a more sustainable code (I had trouble to read my own code during the rebase).
I'll have a look, sounds like a solid test |
I have not used |
69aa567
to
e5823ac
Compare
It was a global mutable state to remember recursive functions and facilitate at several locations whether the type was recursive or not. However, I removed the global state for a variable moved around in f6d55c6. |
Remove the |
let gens = List.map (gen_from_type_declaration ~loc ~env) xs in | ||
mutually_recursive_gens ~loc gens | ||
let typ_names = List.map (fun x -> x.ptype_name.txt) xs in | ||
let env = { curr_type = ""; rec_types = []; curr_types = typ_names } in |
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.
curr_type = ""
surprised me a bit at first.
In a sense it moves the "absence of curr_type
representation from None
to ""
.
However, we no longer have a ref
- and here the absence is only local to derive_gen
.
Any reader can thus convince him/her/themself that curr_type
will be updated to be
non-empty just a few lines below (l.465) before being used.
I therefore think it is fine 👍 (and definitely better than the ref!)
I know this is intended as a tongue-in-cheek remark 😅 ...but just to be clear: |
Just to repeat: I think the outcome of these iterations is clearer, simpler, and shorter. |
I also believe that, do not worry :) |
Great. I think this shaped out very nicely - thanks for your effort! 😀 I'll let the CI go green before merging (which also gives @c-cube a brief window to comment/object/celebrate...) |
Rebased the history - thanks a lot for the review! |
Follow-up PR with those tests: #208 |
Fixes #188
Now mutual recursive generators share the size fuel (or indicator w/e).
Are you ok with that fix @jmid ?
Also in ba96a95 I removed the use of
frequency
when the list contains one element only.