Skip to content
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

Merged
merged 5 commits into from
Sep 25, 2017
Merged

Make VAVr Java 8 & 9 compatible #2105

merged 5 commits into from
Sep 25, 2017

Conversation

@codecov-io
Copy link

codecov-io commented Sep 23, 2017

Codecov Report

Merging #2105 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ Complexity Δ
vavr/src/main/java/io/vavr/Lazy.java 100% <100%> (ø) 34 <1> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8cb9ca...3aa7ad0. Read the comment docs.

@l0rinc l0rinc changed the title Make VAVr compilable under both Java 8 & 9 Make VAVr Java 8 & 9 compatible Sep 23, 2017
Copy link
Contributor

@danieldietrich danieldietrich left a 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>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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! :)

Copy link
Contributor Author

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)

Copy link
Contributor

@danieldietrich danieldietrich Sep 24, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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()));
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@l0rinc
Copy link
Contributor Author

l0rinc commented Sep 24, 2017

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));
Copy link
Contributor Author

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));
Copy link
Contributor

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));

Copy link
Contributor Author

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

Copy link
Contributor

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 :)

Copy link
Contributor Author

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 ...)?

Copy link
Contributor

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>
Copy link
Contributor

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>?

Copy link
Contributor Author

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) -> {
Copy link
Contributor Author

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?

Copy link
Contributor

@danieldietrich danieldietrich left a 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!

@danieldietrich danieldietrich merged commit 44a23e7 into vavr-io:master Sep 25, 2017
@danieldietrich
Copy link
Contributor

Just realized that the build is broken for jdk9 (you told me already). It does not matter - I will fix that tomorrow. Thx!

@l0rinc l0rinc deleted the Java9 branch September 26, 2017 09:02
ruslansennov pushed a commit that referenced this pull request Oct 27, 2017
* Fix Java 9 warnings

* Enable code generation on Java 9

* Update the rest of the build dependencies

* Enable the `vavr-benchmark` module

* Add Java 9 as an alternative Travis build
danieldietrich pushed a commit that referenced this pull request Nov 23, 2017
* Fix Java 9 warnings

* Enable code generation on Java 9

* Update the rest of the build dependencies

* Enable the `vavr-benchmark` module

* Add Java 9 as an alternative Travis build
danieldietrich pushed a commit that referenced this pull request Jan 13, 2019
* Fix Java 9 warnings

* Enable code generation on Java 9

* Update the rest of the build dependencies

* Enable the `vavr-benchmark` module

* Add Java 9 as an alternative Travis build
danieldietrich pushed a commit that referenced this pull request Jan 13, 2019
* Fix Java 9 warnings

* Enable code generation on Java 9

* Update the rest of the build dependencies

* Enable the `vavr-benchmark` module

* Add Java 9 as an alternative Travis build
danieldietrich pushed a commit that referenced this pull request Jan 16, 2019
* Fix Java 9 warnings

* Enable code generation on Java 9

* Update the rest of the build dependencies

* Enable the `vavr-benchmark` module

* Add Java 9 as an alternative Travis build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants