-
Notifications
You must be signed in to change notification settings - Fork 395
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
Convert lambda functions into concrete classes to allow compatibility with Scala 2.11/2.12 #357
Conversation
Codecov Report
@@ Coverage Diff @@
## master #357 +/- ##
=========================================
- Coverage 86.82% 83.42% -3.4%
=========================================
Files 336 336
Lines 10865 10865
Branches 568 587 +19
=========================================
- Hits 9433 9064 -369
- Misses 1432 1801 +369
Continue to review full report at Codecov.
|
Imagine we move all lambdas to a companion object like this:
Still whenever try to inspect But, given that we a priori know where are stored all lambdas for that class we could easily inspect our Then during the serialization we would simply use our map to replace compiler generated names with class.property references. Because it would use run-time reflections the mapping would be always correct. Finally the solution would work for both scala 2.11/2.12 and would be future proof with our macro. |
@wsuchy Sorry, I dont understand what exactly are you suggesting? what's wrong with the solution I propose in this PR? |
@tovbinm Eventually we don't want our users to have to create manually their lambda functions as concrete classes and we know there is a solution (like the one I described). Although your changes apply only to the internal code we will end up having two ways of dealing with lambdas. Also, modifying the code where you have to write functions manually isn't the greatest experience. This is the reason I proposed to use macro for generating these instead. |
I think our macros would offer exactly the generation of concrete classes as proposed in this PR (since concrete classes are the most straightforward way to handle lambda functions in all scenarios possible, unless Scala decides to change their FunctionX interface of course, which is unlikely). |
Unfortunately you don't have types present at macro evaluation time so you can't populate type params here: |
Anonymous lambdas are much more difficult to debug and comprehend that simple classes, therefore I tend to assume that if simple macros spent work then we will have to write a compiler plugin if we decide to do so. |
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.
A few questions:
- How do you (or any of us) know that you found all the functions you need to change? Is this something that breaks with 2.12 and as long as it works, then you're good?
- All lambdas need to live in their own classes now? I'm assuming the same holds for extract functions and others (eg. like in automl)?
|
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
Related issues
Follows up on PR #274 and lands the foundation to support Scala 2.12 #332
Scala 2.12 generates different class names for lambdas than Scala 2.1. Example:
To maintain forward compatibility of models (so one won’t need to retrain models and would be able to load them in Scala 2.11/2.12) we would like to convert all the lambdas into concrete classes.
Describe the proposed solution
Changing all the lambdas with concrete classes.
Describe alternatives you've considered
NA