-
Notifications
You must be signed in to change notification settings - Fork 33
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
Relax %parse-param
bounds from Copy
to Clone
#471
Conversation
Huh, that is easier than I expected! That now makes me wonder if we can/should pass |
Passing it in as This requires a couple of tricks higher ranked trait bounds (HRTB's) The major concept lifetime-wise is that the lifetime of the parameter is less than the lifetime of the function the parameter gets passed to, and thus the functions closure cannot capture it, once the compiler knows that it is implied that once the function returns the reference that was passed is no longer referenced, and thus unique ownership is retained. On top of this, there is a lot of "pattern matching/codegen stuff" which is made hard by any needs for explicit lifetimes, and separation of the types from the references, the syntactical side here can actually be a bit of a pain too because of the differences between pattern matching in rust expressions and rust parameter lists. It is definitely possible, I've gotten it working, but IIRC it was fairly syntactically wonky/mediocre |
Ah, so what you're saying is that |
I think i'm saying slightly less than that, it is tricky, but I don't think it is that messy, but it is a break in compatibility maybe But it is possible that syntactically the arguments to |
Right. I don't remember what we changed here, either. |
Sounds good to me, I'll try and work on examples/docs/tests soon. |
So, curiously I haven't been able to make a backwards incompatible test like I thought, The theory that I am working under is that in the generated code the So within the generated code we know that So unless I am mistaken and there is something weirder going on, it seems like you can actually rely on types being copy within the actions even though the library/parse algorithm can only rely on the weaker
|
That is a good point -- I hadn't even thought about that! So, dumb question: does that mean we need any bounds at all? Can we just pass through an arbitrary type |
I'm certain that this is not the case (exactly for the references multiple rules reason given). So only through that mechanism can we call each individual action from parse_actions only knowing the generic bounds of |
FWIW, here is kind of minimization of what is going on here, in the following
|
So with the |
(With the caveat that I haven't fully tested it), the answer should definitely be no we shouldn't have any problem.
To actually get rid of the
Does that help answer your questions? |
Thanks for the pointers!
Sounds good to me :) |
Sorry it took me a while to get the rest done, Some notes:
|
lrpar/examples/mut_param/Cargo.toml
Outdated
[package] | ||
name = "mut_param" | ||
version = "0.1.0" | ||
authors = ["Laurence Tratt <http://tratt.net/laurie/>"] |
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 think your name should go here!
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.
Should be resolved in bf4ada3.
lrpar/examples/mut_param/Cargo.toml
Outdated
@@ -0,0 +1,20 @@ | |||
[package] | |||
name = "mut_param" |
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.
We could call this clone_param
maybe?
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.
Should be resolved in bf4ada3.
I think this is ready for squashing? |
bf4ada3
to
c15507a
Compare
Squashed, I had considered keeping separate commits for the example, but it all seemed short enough that just doing one commit didn't seem unjustifiable. |
Apologies, didn't realize it was still marked as draft. |
Please squash. |
207a291
to
1007f13
Compare
Squashed. |
In the recent discussion in #404 the @ltratt brought up the idea of relaxing the
Copy
bounds toClone
.Here is a quick attempt at an implementation of that, it seems a lot simpler than I expected.
Marking as draft for the following reasons:
.clone()
. However none of this appears to be exercised by the testsuite currently.Copy
bounds therein.Rc<RefCell<..>>
.