-
Notifications
You must be signed in to change notification settings - Fork 53
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
Rework modifyAll for Scala 3 #82
Conversation
quicklens/src/test/scala/com/softwaremill/quicklens/RepeatedModifyAllTest.scala
Show resolved
Hide resolved
I didn't read the code (just skimmed), but if you can make it work, I'll be of course happy to merge :) The main challenge will be grouping the fields by common modification path prefix, so that the combined copies are done when possible. So when you have |
I think that it's ready now. Added tests for all edge cases I could think of. An interesting example to demonstrate the order of modification: case class Cons(head: Int, tail: Option[Cons])
val sth = Cons(1, Some(Cons(2, None)))
sth.modifyAll(_.tail, _.tail.each.tail).using { x =>
println(x)
x
} The above code will print: Some(Cons(2,None))
None but the following code: sth.modifyAll(_.tail.each.tail, _.tail).using { x =>
println(x)
x
} Will output: None
Some(Cons(2,None)) This demonstrates the following rule:
One potential improvement for the future would be that comparing the equivalence/equality of function delegates is a non-trivial problem. In our case, it implies that for now, calls to e.g. |
Indeed, an impressive test suite - thanks! :) |
1 similar comment
Indeed, an impressive test suite - thanks! :) |
This PRa attempts to rework the way
modifyAll
method is generated in Scala 3.ATM a call like
bob.modifyAll(_.age, _.height).setTo(1)
is equivalent to
and generates
The bytecode from this method is suboptimal.
The proposed approach relies on compressing all paths into a paths tree and generating code from that.
This allows to generate the following code for the given example:
For example, for an invocation of the
modifyAll
fromRepeatedModifyAllTest
in an emptyMain
class, the bytecode sizes are:This PR is a draft since it is not very polished and needs a lot more tests.
Though I would like to know your opinion about it first. cc @adamw