-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Make VAVr
Java 8 & 9 compatible
#2105
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2105 +/- ##
========================================
Coverage 97.5% 97.5%
Complexity 5202 5202
========================================
Files 92 92
Lines 11944 11944
Branches 1576 1576
========================================
Hits 11646 11646
Misses 148 148
Partials 150 150
Continue to review full report at Codecov.
|
VAVr
compilable under both Java 8 & 9VAVr
Java 8 & 9 compatible
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.
Hi, great - many thanks!
It would be cool to have jdk8 & jdk9 travis-ci builds. We could accomplish it by adding jdk9 to the .travis.yml.
See https://docs.travis-ci.com/user/languages/java/#Testing-Against-Multiple-JDKs
@@ -32,6 +32,7 @@ We use these goals frequently to keep the dependencies and plugins up-to-date: | |||
<description>Vavr (formerly called Javaslang) is an object-functional language extension to Java 8+.</description> | |||
<modules> | |||
<module>vavr</module> | |||
<module>vavr-benchmark</module> |
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.
Does a Java 9 build require now this module? Just asking...
I ask myself if now a jar is released for vavr-benchmark, too (i.e. to maven central).
Is the benchmark profile then still needed?
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.
It's in a separate commit, because it's obviously not strictly related :)
It should be part of the project so that it is compile-time checked. I will disable the deployment, it's a valid concern.
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.
Checked it, since it has tests only, there's nothing to deploy.
The benchmark
profile has a run config also, so it still has its purpose - though we can remove the duplicate modules
part, thanks for the note! :)
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 had to test this module for Java 9 compatibility also, that's why I modified this part also)
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.
The benchmarks should not be part of the main build, even if it is a minimal benchmark.
If there are assertions/checks, they should be moved to the vavr core unit tests.
Benchmarks are about measuring. The only valid case to run them as part of the tests would be that we break the build if the performance decreases. But that is (currently) not possible.
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.
The benchmarks aren't run during the build. Not even the assertions. just the compilation.
They are just part of the project, to make sure any refactoring is propagated there also.
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 see, that's cool.
public static <T> Lazy<Seq<T>> sequence(Iterable<? extends Lazy<? extends T>> values) { | ||
Objects.requireNonNull(values, "values is null"); | ||
return Lazy.of(() -> Vector.ofAll(values).map(Lazy::get)); | ||
return Lazy.of(() -> Vector.ofAll(values).map(lazy -> lazy.get())); |
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.
Does a java 9 build not compile with the method reference?
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.
Yeah, it's weird :/
We should probably open a bug for the JDK
and for Idea
try { | ||
cons = clazz.getDeclaredConstructor(); | ||
final Constructor<?> cons = clazz.getDeclaredConstructor(); |
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.
👍🏼
// types are inferred correctly! | ||
final Some<Number> head = x; | ||
final List<Option<Number>> tail = xs; | ||
return head + "::" + tail; |
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 would keep the block. It was intended to make the types explicitly visible (even if vars are not used).
The difference to (Some<Number> x, List<Option<Number>> xs) -> x + "::" + xs)
is that we have List<Option<Number>> tail = xs
. I.e. we show which general type is inferred by Match.
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.
Yeah, except that it's not working in Java 9
, different types are inferred for some reason.
If I specify it explicitly, as done here, it's working.
Not sure how to fix it otherwise.
The JDK 9 additional build is a very good idea, let me do that quickly :) |
@@ -315,17 +315,12 @@ public void shouldDecomposeListOfTuple3() { | |||
assertThat(actual).isEqualTo("(begin, 10, 4.5)::List((middle, 11, 0.0), (end, 12, 1.2))"); | |||
} | |||
|
|||
@SuppressWarnings("UnnecessaryLocalVariable") | |||
@Test | |||
public void shouldDecomposeListWithNonEmptyTail() { | |||
final List<Option<Number>> intOptionList = List.of(Option.some(1), Option.some(2.0)); |
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.
The problem is, this isn't an intOptionList
, it's a numberOptionList
@@ -318,12 +319,12 @@ public void shouldDecomposeListOfTuple3() { | |||
@SuppressWarnings("UnnecessaryLocalVariable") | |||
@Test | |||
public void shouldDecomposeListWithNonEmptyTail() { | |||
final List<Option<Number>> intOptionList = List.of(Option.some(1), Option.some(2.0)); | |||
final String actual = Match(intOptionList).of( | |||
final List<Option<? extends Number>> numberOptionList = List.of(Option.some(1), Option.some(2.0)); |
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 because of the added ? extends
the build currently breaks. Does it not compile with jdk9 otherwise?
Another fix could be List.<Option<Number>> of(Option.some(1), Option.some(2.0));
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.
Dunno, man, this seems to randomly pass or fail on JDK 9
. There's a wedding I should attend, instead I'm debugging this :p
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.
Go to the medding, wan - eh I mean wedding, man. We can do this later :)
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.
darn ... could you take a look, it's hopeless (it just passed locally ...)?
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.
Yes, will do that later today! Currently I'm in the middle of splitting #2093 in to smaller PRs. After that (and after going to german election)...
@@ -253,6 +254,8 @@ We use these goals frequently to keep the dependencies and plugins up-to-date: | |||
<arg>-Xlint:all</arg> | |||
<!-- Workaround for JDK bug https://bugs.openjdk.java.net/browse/JDK-6999068 --> | |||
<arg>-Xlint:-processing</arg> | |||
<!-- Enable Java 9 compilation with 1.8 compatibility --> | |||
<arg>-Xlint:-options</arg> |
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.
Where do we use the options? Is it the implicit <target>${java.version}</target>
?
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.
this is needed because java.version
is always 8
, even if the selected JDK is 9. The JDK cannot compile to another bytecode version, giving a warning. This disables the warning, since we're only checking the build, not producing any artifacts.
<java.version>1.8</java.version>
Case($Cons($Some($(1)), $Cons($Some($(2.0)), $())), (x, xs) -> { | ||
final List<Option<Number>> numberOptionList = List.of(Option.some(1), Option.some(2.0)); | ||
final String actual = Match(numberOptionList).of( | ||
Case($Cons($Some($(1)), $Cons($Some($(2.0)), $())), (Some<Number> x, List<Option<Number>> xs) -> { |
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.
@danieldietrich, it only compiles on Java 9
if we explicitly specify the types here. Is that still ok?
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.
Many thanks, this change looks great!
Just realized that the build is broken for jdk9 (you told me already). It does not matter - I will fix that tomorrow. Thx! |
related to: