Giter Site home page Giter Site logo

Comments (6)

avdv avatar avdv commented on May 26, 2024 1

You do have Instant implementation of your own :) avdv/scalals@main/native/src/main/scala/javatime.scala#L7

Oh really? I totally forgot about that... 😆

Thank you @keynmol !

from scala-native.

WojciechMazur avatar WojciechMazur commented on May 26, 2024

Scala Native does not emit any Bytecode or Tasty for javalib (Java standard library) so it cannot affect compilation of Java methods. It seems like an issue in the compiler / setup, but I cannot reproduce it. Instant. ofEpochSecond has two variants long and long,long, both of this are present in all JDK distributions between JDK 8 and 21.

I think that these kind of issues can only exist when there is some Bytecode for symbols defined in JDK but coming from the Scala code (eg. library dependenices, custom JDK definitions) - a that point we might get duplicated definitions for some types/methods in the compiler which might affect compilation.
I'll start with checking the dependencyTree in sbt to check the classpath and check which dependencies can introduce duplicates. I'm aware that scala-java-time defines java.time.Instant, but I'm not aware how their artifacts are published

from scala-native.

avdv avatar avdv commented on May 26, 2024

Thank you for the quick response, @WojciechMazur!

I tried to create a minimal reproducer and started with sbt new scala-native/scala-native.g8.

Basically I hit the same problem (with scala-native 0.4.16).

And even linking this simple program:

λ cat src/main/scala/Main.scala 
import java.time.Instant

object Main {
  def main(args: Array[String]): Unit =
    println(Instant.ofEpochSecond(12345345L))
}

leads to this error:

[info] welcome to sbt 1.9.4 (N/A Java 19.0.2)
[info] loading settings for project scala-native-seed-project-build from plugins.sbt ...
[info] loading project definition from /home/claudio/code/scalals/repro-1/scala-native-seed-project/project
[info] loading settings for project scala-native-seed-project from build.sbt ...
[info] set current project to scala-native-seed-project (in build file:/home/claudio/code/scalals/repro-1/scala-native-seed-project/)
[info] sbt server started at local:///home/claudio/.sbt/1.0/server/7a16653207cb96270333/sock
[info] started sbt server
sbt:scala-native-seed-project> run
[info] compiling 1 Scala source to /home/claudio/code/scalals/repro-1/scala-native-seed-project/target/scala-3.3.3/classes ...
[warn] Found a call to not defined static method Member(Top(java.time.Instant),D13ofEpochSecondjL17java.time.InstantEo). Static methods are generated since Scala Native 0.4.3, report this bug in the Scala Native issues. Call defined at file:/home/claudio/code/scalals/repro-1/scala-native-seed-project/src/main/scala/Main.scala:5:34
[error] Found 2 missing definitions while linking
[error] Not found Top(java.time.Instant)
[error] 	at file:/home/claudio/code/scalals/repro-1/scala-native-seed-project/src/main/scala/Main.scala:4
[error] Not found Member(Top(java.time.Instant),D13ofEpochSecondjL17java.time.InstantEo)
[error] 	at file:/home/claudio/code/scalals/repro-1/scala-native-seed-project/src/main/scala/Main.scala:4
[error] 	at file:/home/claudio/code/scalals/repro-1/scala-native-seed-project/src/main/scala/Main.scala:5
[error] Undefined definitions found in reachability phase
[error] (Compile / nativeLink) Undefined definitions found in reachability phase
[error] Total time: 25 s, completed Mar 20, 2024, 9:00:08 PM

🤔

from scala-native.

keynmol avatar keynmol commented on May 26, 2024

@avdv The java.time.* classes in general are not implemented in either Scala.js or Scala Native, given their size, complexity, and the need to handle lots of locales.

For that, you should add a dependency to a pure Scala implementation of those, such as https://github.com/cquiroz/scala-java-time

For example, here's your code in Scala CLI with this dependency:

//> using platform scala-native
//> using dep io.github.cquiroz::scala-java-time::2.5.0

import java.time.Instant

object Main {
  def main(args: Array[String]): Unit =
    println(Instant.ofEpochSecond(12345345L))
}

And it works fine:

> scli run .
Compiling project (Scala 3.3.1, Scala Native 0.4.17)
Compiled project (Scala 3.3.1, Scala Native 0.4.17)
[info] Linking (1193 ms)
[info] Checking intermediate code (quick) (88 ms)
[info] Discovered 1329 classes and 8939 methods
[info] Optimizing (debug mode) (1196 ms)
[info] Generating intermediate code (1133 ms)
[info] Produced 10 files
[info] Compiling to native code (1832 ms)
[info] Linking with [pthread, dl]
[info] Total (6797 ms)
1970-05-23T21:15:45Z

When that library is published for Scala Native 0.5.x (final release), you'll be able to use it in your project using SN 0.5.x

from scala-native.

avdv avatar avdv commented on May 26, 2024

@avdv The java.time.* classes in general are not implemented in either Scala.js or Scala Native, given their size, complexity, and the need to handle lots of locales.

Oh really ? I use java.time.Instant for quite some time now in my project (https://github.com/avdv/scalals) and as far as I can tell I don't use any external library...

from scala-native.

keynmol avatar keynmol commented on May 26, 2024

You do have Instant implementation of your own :) https://github.com/avdv/scalals/blob/main/native/src/main/scala/javatime.scala#L7

from scala-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.