From 55b6543ec1d9da659c4b7be77f31103966a12959 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Sat, 14 Oct 2023 00:33:16 +0200 Subject: [PATCH 01/38] Towards 0.4.17 --- docs/conf.py | 4 ++-- nir/src/main/scala/scala/scalanative/nir/Versions.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 43deab6260..10807418b1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -69,9 +69,9 @@ def generateScalaNativeCurrentYear(): # built documents. # # The short X.Y version. -version = u'0.4.16' +version = u'0.4.17-SNAPSHOT' # The full version, including alpha/beta/rc tags. -release = u'0.4.16' +release = u'0.4.17-SNAPSHOT' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/nir/src/main/scala/scala/scalanative/nir/Versions.scala b/nir/src/main/scala/scala/scalanative/nir/Versions.scala index c575d80ff1..e69c7824c2 100644 --- a/nir/src/main/scala/scala/scalanative/nir/Versions.scala +++ b/nir/src/main/scala/scala/scalanative/nir/Versions.scala @@ -25,7 +25,7 @@ object Versions { final val revision: Int = 9 // a.k.a. MINOR version /* Current public release version of Scala Native. */ - final val current: String = "0.4.16" + final val current: String = "0.4.17-SNAPSHOT" final val currentBinaryVersion: String = binaryVersion(current) private object FullVersion { From 9bc2d71ff7dfcda0c72d86ff5f563109982023d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Mon, 16 Oct 2023 06:27:12 +0200 Subject: [PATCH 02/38] Fix C example in interop.rst (#3571) * Fix C comments in interop.rst Not sure why some of the comments were using `#` instead of `//`,I think it must have been an oversight. Now the syntax highlighting should look better and the example code can actually be copied and pasted. * Add missing stdio.h include * Fix addInts (cherry picked from commit 974a70a70a7f22a5458efb821d8211925d208b19) --- docs/user/interop.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/user/interop.rst b/docs/user/interop.rst index 52a5f20d90..55bf608949 100644 --- a/docs/user/interop.rst +++ b/docs/user/interop.rst @@ -189,26 +189,27 @@ You can also disable generation of library constructors by defining `-DSCALANATI .. code-block:: c - # libmylib.h + // libmylib.h int ScalaNativeInit(void); long addLongs(long, long); - int addInts(int, int); + int mylib_addInts(int, int); int mylib_current_count(); void mylib_set_counter(int); - # test.c + // test.c #include "libmylib.h" #include + #include int main(int argc, char** argv){ - # This function needs to be called before invoking any methods defined in Scala Native. - # Might be called automatically unless SCALANATIVE_NO_DYLIB_CTOR env variable is set. + // This function needs to be called before invoking any methods defined in Scala Native. + // Might be called automatically unless SCALANATIVE_NO_DYLIB_CTOR env variable is set. assert(ScalaNativeInit() == 0); addLongs(0L, 4L); mylib_addInts(4, 0); printf("Current count %d\n", mylib_current_count()); mylib_set_counter(42); - ... + // ... } Pointer types From 4d9564d8aa2f1b1d7bd314841debfda81b1ec168 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 19 Oct 2023 23:49:26 +0200 Subject: [PATCH 03/38] Simplifiy `FileDescriptor.valid()` Reset fileDescriptor on close, and check if fd.handle is invalid (#3578) (cherry picked from commit 83ed21cc28dc26ac81ed1798c0cd3453fe557546) --- .../main/scala/java/io/FileDescriptor.scala | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/javalib/src/main/scala/java/io/FileDescriptor.scala b/javalib/src/main/scala/java/io/FileDescriptor.scala index ba48fdb98e..9e569745e8 100644 --- a/javalib/src/main/scala/java/io/FileDescriptor.scala +++ b/javalib/src/main/scala/java/io/FileDescriptor.scala @@ -15,17 +15,13 @@ import scala.scalanative.windows.winnt.AccessRights._ import scala.scalanative.windows.{ConsoleApiExt, DWord} final class FileDescriptor private[java] ( - fileHandle: FileHandle, + private var fileHandle: FileHandle, readOnly: Boolean ) { - def this() = { - this( - fileHandle = - if (isWindows) FileHandle(INVALID_HANDLE_VALUE) - else FileHandle(-1), - readOnly = true - ) - } + def this() = this( + fileHandle = FileHandle.Invalid, + readOnly = true + ) // ScalaNative private construcors private[java] def this(fd: Int) = @@ -57,7 +53,6 @@ final class FileDescriptor private[java] ( this == FileDescriptor.in || this == FileDescriptor.out || this == FileDescriptor.err - } else fd <= 2 } @@ -75,20 +70,13 @@ final class FileDescriptor private[java] ( } } - def valid(): Boolean = - if (isWindows) { - val flags = stackalloc[DWord]() - handle != INVALID_HANDLE_VALUE && - GetHandleInformation(handle, flags) - } else { - // inspired by Apache Harmony including filedesc.c - fcntl.fcntl(fd, fcntl.F_GETFD, 0) != -1 - } + def valid(): Boolean = fileHandle != FileHandle.Invalid // Not in the Java API. Called by java.nio.channels.FileChannelImpl.scala private[java] def close(): Unit = { if (isWindows) CloseHandle(handle) else unistd.close(fd) + fileHandle = FileHandle.Invalid } } @@ -100,6 +88,10 @@ object FileDescriptor { private[java] object FileHandle { def apply(handle: Handle): FileHandle = handle.toLong def apply(unixFd: Int): FileHandle = unixFd.toLong + @alwaysinline + def Invalid = + if (isWindows) FileHandle(INVALID_HANDLE_VALUE) + else FileHandle(-1) } val in: FileDescriptor = { From c6cfbeea9c7e75b7140c367f455d914953937583 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 19 Oct 2023 23:49:49 +0200 Subject: [PATCH 04/38] Respect `java.lang.Clonable` trait and throw exception on clone when it's absent (#3579) (cherry picked from commit 77b2a52e49d4c1faa746d430cad9aa2bad66cfa8) --- .../main/scala/java/util/regex/Matcher.scala | 3 +- .../src/main/scala/java/lang/Object.scala | 19 +++++++---- .../javalib/lang/CloneableTest.scala | 33 +++++++++++++++++++ .../test/scala/scala/ObjectCloneTest.scala | 4 +-- 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CloneableTest.scala diff --git a/javalib/src/main/scala/java/util/regex/Matcher.scala b/javalib/src/main/scala/java/util/regex/Matcher.scala index 7a338d4919..ad712cabef 100644 --- a/javalib/src/main/scala/java/util/regex/Matcher.scala +++ b/javalib/src/main/scala/java/util/regex/Matcher.scala @@ -15,7 +15,8 @@ object Matcher { final class Matcher private[regex] ( var _pattern: Pattern, var _inputSequence: CharSequence -) extends MatchResult { +) extends MatchResult + with Cloneable { private val underlying = new rMatcher(_pattern.compiled, _inputSequence) diff --git a/nativelib/src/main/scala/java/lang/Object.scala b/nativelib/src/main/scala/java/lang/Object.scala index 44f83a9963..fc9aad8c63 100644 --- a/nativelib/src/main/scala/java/lang/Object.scala +++ b/nativelib/src/main/scala/java/lang/Object.scala @@ -53,13 +53,18 @@ class _Object { addr.toInt ^ (addr >> 32).toInt } - protected def __clone(): _Object = { - val cls = __getClass() - val size = cls.size.toULong - val clone = GC.alloc(cls.asInstanceOf[Class[_]], size) - val src = castObjectToRawPtr(this) - libc.memcpy(clone, src, size) - castRawPtrToObject(clone).asInstanceOf[_Object] + protected def __clone(): _Object = this match { + case _: Cloneable => + val cls = __getClass() + val size = cls.size.toULong + val clone = GC.alloc(cls.asInstanceOf[Class[_]], size) + val src = castObjectToRawPtr(this) + libc.memcpy(clone, src, size) + castRawPtrToObject(clone).asInstanceOf[_Object] + case _ => + throw new CloneNotSupportedException( + "Doesn't implement Cloneable interface!" + ) } protected def __finalize(): Unit = () diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CloneableTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CloneableTest.scala new file mode 100644 index 0000000000..3e8d968da2 --- /dev/null +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CloneableTest.scala @@ -0,0 +1,33 @@ +package org.scalanative.testsuite.javalib.lang + +import java.lang._ + +import org.junit.{Ignore, Test} +import org.junit.Assert._ + +class CloneableTest { + + class Foo(val x: Int, val y: String) { + override def clone(): Foo = super.clone().asInstanceOf[Foo] + } + class CloneableFoo(val x: Int, val y: String) extends Cloneable() { + override def clone(): CloneableFoo = + super.clone().asInstanceOf[CloneableFoo] + } + + @Test def isNotClonable(): Unit = { + assertThrows( + classOf[CloneNotSupportedException], + () => (new Foo(42, "*").clone()) + ) + } + + @Test def isClonable(): Unit = { + val instance = new CloneableFoo(42, "*") + val clone = instance.clone() + assertEquals(instance.getClass(), clone.getClass()) + assertEquals(instance.x, clone.x) + assertEquals(instance.y, clone.y) + assertNotSame(instance, clone) + } +} diff --git a/unit-tests/shared/src/test/scala/scala/ObjectCloneTest.scala b/unit-tests/shared/src/test/scala/scala/ObjectCloneTest.scala index 7dde1fa38e..3e4148d5f7 100644 --- a/unit-tests/shared/src/test/scala/scala/ObjectCloneTest.scala +++ b/unit-tests/shared/src/test/scala/scala/ObjectCloneTest.scala @@ -5,7 +5,7 @@ import org.junit.Assert._ class ObjectCloneTest { - case class I(var i: Int) { + case class I(var i: Int) extends Cloneable { def copy(): I = this.clone().asInstanceOf[I] } @@ -19,7 +19,7 @@ class ObjectCloneTest { assertTrue(clone.i == 123) } - case class Arr(val arr: Array[Int]) { + case class Arr(val arr: Array[Int]) extends Cloneable { def copy(): Arr = this.clone().asInstanceOf[Arr] } From 0d13873640b193b393275dfdefcbe0355977cbc0 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Fri, 17 Nov 2023 11:39:11 +0100 Subject: [PATCH 05/38] When generating top-level extern methods check its annotations for `link`/`define` (#3604) * When generating top-level extern methods check it's annonations for @link/@define * Port the change to Scala2 plugin to allow for marking with @link/@define only selected methods (cherry picked from commit a724248782ef6223400c56c9441f64a877424496) --- .../scalanative/nscplugin/NirGenStat.scala | 52 ++++++++---- .../scalanative/nscplugin/NirGenStat.scala | 48 +++++++---- .../linker/TopLevelExternsTest.scala | 42 ++++++++++ .../linker/MethodAttributesTest.scala | 80 +++++++++++++++++++ 4 files changed, 190 insertions(+), 32 deletions(-) create mode 100644 nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala create mode 100644 nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenStat.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenStat.scala index de10fc7936..e36203476d 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenStat.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenStat.scala @@ -856,24 +856,42 @@ trait NirGenStat[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => } } } - - def genMethodAttrs(sym: Symbol): Attrs = { - val inlineAttrs = - if (sym.isBridge || sym.hasFlag(ACCESSOR)) Seq(Attr.AlwaysInline) - else Nil - - val annotatedAttrs = - sym.annotations.map(_.symbol).collect { - case NoInlineClass => Attr.NoInline - case AlwaysInlineClass => Attr.AlwaysInline - case InlineClass => Attr.InlineHint - case StubClass => Attr.Stub - case NoOptimizeClass => Attr.NoOpt - case NoSpecializeClass => Attr.NoSpecialize + private def genMethodAttrs(sym: Symbol): nir.Attrs = { + val isExtern = sym.owner.isExternType + val attrs = Seq.newBuilder[nir.Attr] + + if (sym.isBridge || sym.hasFlag(ACCESSOR)) + attrs += nir.Attr.AlwaysInline + if (isExtern) + attrs += nir.Attr.Extern + + def requireLiteralStringAnnotation( + annotation: Annotation + ): Option[String] = + annotation.tree match { + case Apply(_, Seq(Literal(Constant(name: String)))) => Some(name) + case tree => + reporter.error( + tree.pos, + s"Invalid usage of ${annotation.symbol}, expected literal constant string argument, got ${tree}" + ) + None } - val externAttrs = if (sym.owner.isExternType) Seq(Attr.Extern) else Nil - - Attrs.fromSeq(inlineAttrs ++ annotatedAttrs ++ externAttrs) + sym.annotations.foreach { ann => + ann.symbol match { + case NoInlineClass => attrs += nir.Attr.NoInline + case AlwaysInlineClass => attrs += nir.Attr.AlwaysInline + case InlineClass => attrs += nir.Attr.InlineHint + case NoOptimizeClass => attrs += nir.Attr.NoOpt + case NoSpecializeClass => attrs += nir.Attr.NoSpecialize + case StubClass => attrs += nir.Attr.Stub + case LinkClass => + requireLiteralStringAnnotation(ann) + .foreach(attrs += nir.Attr.Link(_)) + case _ => () + } + } + nir.Attrs.fromSeq(attrs.result()) } def genMethodBody( diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala index 4ddc7502c0..de7df6e9cc 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala @@ -21,6 +21,7 @@ import scala.scalanative.util.unsupported import dotty.tools.FatalError import dotty.tools.dotc.report import dotty.tools.dotc.core.NameKinds +import dotty.tools.dotc.core.Annotations.Annotation trait NirGenStat(using Context) { self: NirCodeGen => @@ -238,22 +239,39 @@ trait NirGenStat(using Context) { } private def genMethodAttrs(sym: Symbol): nir.Attrs = { - val inlineAttrs = - if (sym.is(Bridge) || sym.is(Accessor)) Seq(Attr.AlwaysInline) - else Nil - - val annotatedAttrs = - sym.annotations.map(_.symbol.typeRef).collect { - case defnNir.NoInlineType => Attr.NoInline - case defnNir.AlwaysInlineType => Attr.AlwaysInline - case defnNir.InlineType => Attr.InlineHint - case defnNir.NoOptimizeType => Attr.NoOpt - case defnNir.NoSpecializeType => Attr.NoSpecialize - case defnNir.StubType => Attr.Stub + val isExtern = sym.owner.isExternType || sym.isExternType + val attrs = Seq.newBuilder[nir.Attr] + + if (sym.is(Bridge) || sym.is(Accessor)) + attrs += nir.Attr.AlwaysInline + if (isExtern) + attrs += nir.Attr.Extern + + def requireLiteralStringAnnotation(annotation: Annotation): Option[String] = + annotation.tree match { + case Apply(_, Seq(Literal(Constant(name: String)))) => Some(name) + case tree => + report.error( + s"Invalid usage of ${annotation.symbol.show}, expected literal constant string argument, got ${tree}", + tree.srcPos + ) + None } - val externAttrs = if (sym.owner.isExternType) Seq(Attr.Extern) else Nil - - Attrs.fromSeq(inlineAttrs ++ annotatedAttrs ++ externAttrs) + sym.annotations.foreach { ann => + ann.symbol match { + case defnNir.NoInlineClass => attrs += nir.Attr.NoInline + case defnNir.AlwaysInlineClass => attrs += nir.Attr.AlwaysInline + case defnNir.InlineClass => attrs += nir.Attr.InlineHint + case defnNir.NoOptimizeClass => attrs += nir.Attr.NoOpt + case defnNir.NoSpecializeClass => attrs += nir.Attr.NoSpecialize + case defnNir.StubClass => attrs += nir.Attr.Stub + case defnNir.LinkClass => + requireLiteralStringAnnotation(ann) + .foreach(attrs += nir.Attr.Link(_)) + case _ => () + } + } + nir.Attrs.fromSeq(attrs.result()) } protected val curExprBuffer = ScopedVar[ExprBuffer]() diff --git a/nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala b/nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala new file mode 100644 index 0000000000..252b276a3a --- /dev/null +++ b/nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala @@ -0,0 +1,42 @@ +package scala.scalanative +package linker + +import org.junit.Test +import org.junit.Assert._ + +class TopLevelExternsTest { + + @Test def topLevelExternAnnotations(): Unit = { + val PackageModule = nir.Global.Top("Main$package$") + val ExternFunctionSymbol = + PackageModule.member(nir.Sig.Extern("externFunction")) + + compileAndLoad( + "Main.scala" -> """ + |import scala.scalanative.unsafe.{link, define, extern} + |@extern + |@link("MyCustomLink") + |@define("MyCustomDefn") + |def externFunction(): Unit = extern + """.stripMargin + ) { defns => + defns + .find(_.name == ExternFunctionSymbol) + .orElse { fail("Not found extern function definition"); None } + .foreach { defn => + assertTrue("isExtern", defn.attrs.isExtern) + assertEquals( + "link", + Some(nir.Attr.Link("MyCustomLink")), + defn.attrs.links.headOption + ) + assertEquals( + "define", + Some(nir.Attr.Define("MyCustomDefn")), + defn.attrs.preprocessorDefinitions.headOption + ) + } + } + } + +} diff --git a/nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala b/nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala new file mode 100644 index 0000000000..ed2991e4fc --- /dev/null +++ b/nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala @@ -0,0 +1,80 @@ +package scala.scalanative +package linker + +import org.junit.Test +import org.junit.Assert._ + +class MethodAttributesTest { + + @Test def explicitLinkOrDefine(): Unit = { + compileAndLoad( + "Test.scala" -> + """ + |import scala.scalanative.unsafe.{extern, link, define} + |@link("common-lib") + |@define("common-define") + |@extern object Foo { + | @link("custom-lib") def withLink(): Int = extern + | @define("custom-define") def withDefine(): Int = extern + | def default(): Int = extern + |} + """.stripMargin + ) { defns => + val Module = nir.Global.Top("Foo$") + val WithLinkMethod = Module.member(nir.Sig.Extern("withLink")) + val WithDefineMethod = Module.member(nir.Sig.Extern("withDefine")) + val DefaultMethod = Module.member(nir.Sig.Extern("default")) + + val CommonLink = nir.Attr.Link("common-lib") + val CustomLink = nir.Attr.Link("custom-lib") + val CommonDefine = nir.Attr.Define("common-define") + val CustomDefine = nir.Attr.Define("custom-define") + + val expected = + Seq(Module, WithLinkMethod, WithDefineMethod, DefaultMethod) + val found = defns.filter { defn => + def checkLink(value: nir.Attr.Link, expected: Boolean) = assertEquals( + s"${defn.name} - ${value}", + expected, + defn.attrs.links.contains(value) + ) + def checkDefine(value: nir.Attr.Define, expected: Boolean) = + assertEquals( + s"${defn.name} - ${value}", + expected, + defn.attrs.preprocessorDefinitions.contains(value) + ) + + defn.name match { + case Module => + checkLink(CommonLink, true) + checkLink(CustomLink, false) + checkDefine(CommonDefine, true) + checkDefine(CustomDefine, false) + case WithLinkMethod => + checkLink(CommonLink, false) // defined in module + checkLink(CustomLink, true) + checkDefine(CommonDefine, false) // defined in module + checkDefine(CustomDefine, false) + case WithDefineMethod => + checkLink(CommonLink, false) // defined in module + checkLink(CustomLink, false) + checkDefine(CommonDefine, false) // defined in module + checkDefine(CustomDefine, true) + case DefaultMethod => + checkLink(CommonLink, false) // defined in module + checkLink(CustomLink, false) + checkDefine(CommonDefine, false) // defined in module + checkDefine(CustomDefine, false) + case _ => () + } + expected.contains(defn.name) + } + assertTrue( + s"not found some defns, ${found.map(_.name)}", + found.size == expected.size + ) + } + } + +} From 11d64105ea41b96f60badc3828a08326aea3ebeb Mon Sep 17 00:00:00 2001 From: Paul Thordarson Date: Tue, 21 Nov 2023 10:59:57 -0500 Subject: [PATCH 06/38] Fix typo on VEOL @name annotation in termios module (#3606) (cherry picked from commit f4b9078c6c96dade366518f037d8f47048d2a4f3) --- posixlib/src/main/scala/scala/scalanative/posix/termios.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posixlib/src/main/scala/scala/scalanative/posix/termios.scala b/posixlib/src/main/scala/scala/scalanative/posix/termios.scala index 587ca889a4..cb4f494eb7 100644 --- a/posixlib/src/main/scala/scala/scalanative/posix/termios.scala +++ b/posixlib/src/main/scala/scala/scalanative/posix/termios.scala @@ -58,7 +58,7 @@ object termios { @name("scalanative_termios_veof") def VEOF: CInt = extern - @name("scalanative_termios_veof") + @name("scalanative_termios_veol") def VEOL: CInt = extern @name("scalanative_termios_verase") def VERASE: CInt = extern From a8a3b5a1a0be8e66f19520ea77228a54494f93f9 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 5 Dec 2023 00:56:02 +0100 Subject: [PATCH 07/38] Try fix Windows CI, replace no longer existing Choco-Install script (#3615) (cherry picked from commit c2906c03b3bd4855dd76a7571f1e68ac53293a48) --- .github/actions/windows-setup-env/action.yml | 32 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/actions/windows-setup-env/action.yml b/.github/actions/windows-setup-env/action.yml index bb0dd50845..52f8f57a38 100644 --- a/.github/actions/windows-setup-env/action.yml +++ b/.github/actions/windows-setup-env/action.yml @@ -9,7 +9,7 @@ inputs: default: "8" llvm-version: description: "LLVM version to use" - default: "11.0.0" + default: "17.0.6" outputs: vcpkg-dir: description: "Directory containing installed libraries" @@ -48,6 +48,8 @@ runs: "VcpkgLibs=${env:VCPKG_INSTALLATION_ROOT}\installed\x64-windows-static" >> $env:GITHUB_OUTPUT if ("${{inputs.scala-version}}".StartsWith("2.")) { echo ("project-version=" + ("${{inputs.scala-version}}".Split(".")[0, 1] -join "_")) >> $env:GITHUB_ENV + } elseif ("${{inputs.scala-version}}".StartsWith("3-next")) { + echo ("project-version=3_next") >> $env:GITHUB_ENV } else { echo "project-version=3" >> $env:GITHUB_ENV } @@ -63,10 +65,34 @@ runs: key: ${{ runner.os }}-${{ inputs.scala-version }}-deps # Install LLVM in case if cache is missing - # Choco-Install is GH Actions wrappers around choco, which does retries - name: Install LLVM shell: pwsh - run: Choco-Install -PackageName llvm -ArgumentList "--version=${{ inputs.llvm-version }}", "--allow-downgrade", "--force" + run: | + $retryCount = 3 + $retryDelay = 5 # seconds + + function InstallLLVM { + Write-Host "Attempting to install LLVM (try $($retryCount + 1 - $global:retryAttempt) of $($retryCount + 1))..." + choco install llvm --version=${{ inputs.llvm-version }} --allow-downgrade --force + } + + # Attempt to install LLVM with retries + for ($global:retryAttempt = 1; $global:retryAttempt -le $retryCount; $global:retryAttempt++) { + try { + InstallLLVM + Write-Host "LLVM installation successful!" + break # Exit the loop if installation is successful + } catch { + Write-Host "Error installing LLVM: $_" + if ($global:retryAttempt -lt $retryCount) { + Write-Host "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } else { + Write-Host "Maximum retry attempts reached. Exiting." + exit 1 + } + } + } - name: Add LLVM on Path shell: pwsh From 9e0114893433cc97958cdf5fb9fe8190e78e21b9 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 6 Dec 2023 00:09:05 +0100 Subject: [PATCH 08/38] Exlcude internal part of stacktraces from JUnit errpr reports (#3617) (cherry picked from commit 6ea76bc64b673c17f0421f7c9f1f642331b33f8f) --- .../scala/scala/scalanative/junit/Reporter.scala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/junit-runtime/src/main/scala/scala/scalanative/junit/Reporter.scala b/junit-runtime/src/main/scala/scala/scalanative/junit/Reporter.scala index 3f347bcadd..047a115b98 100644 --- a/junit-runtime/src/main/scala/scala/scalanative/junit/Reporter.scala +++ b/junit-runtime/src/main/scala/scala/scalanative/junit/Reporter.scala @@ -160,18 +160,20 @@ private[junit] final class Reporter( else Ansi.filterAnsi(s) private def logTrace(t: Throwable): Unit = { - val trace = t.getStackTrace.dropWhile { p => - p.getFileName != null && { - p.getFileName.contains("StackTrace.scala") || - p.getFileName.contains("Throwables.scala") + val trace = t.getStackTrace + .dropWhile { p => + p.getClassName() != null && { + p.getClassName().startsWith("java.lang.StackTrace") || + p.getClassName().startsWith("java.lang.Throwable") + } } - } val testFileName = { if (settings.color) findTestFileName(trace) else null } val i = trace.indexWhere { p => - p.getFileName != null && p.getFileName.contains("JUnitExecuteTest.scala") + p.getClassName() != null && + p.getClassName().startsWith("scala.scalanative.junit.") } - 1 val m = if (i > 0) i else trace.length - 1 logStackTracePart(trace, m, trace.length - m - 1, t, testFileName) From 183b47a93ef4d6a4cff243ae2759c61ed6cc8d57 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 6 Dec 2023 01:23:43 +0100 Subject: [PATCH 09/38] Prevent crashes in `test-interface` (#3618) * Skip calling `done()` on crashed tests runner. Ensure to use the same `ExcecutionContext` in all parts of RPC * Remove colored error markers from signal handler stacktraces (cherry picked from commit e7e9788381e0cad03e81ff894697fd37f3ca84f7) --- .../scala/scalanative/testinterface/common/RPCCore.scala | 3 +++ .../scala/scalanative/testinterface/NativeRPC.scala | 9 ++++++--- .../scala/scala/scalanative/testinterface/TestMain.scala | 3 ++- .../testinterface/signalhandling/SignalConfig.scala | 4 ---- .../scala/scalanative/testinterface/ComRunner.scala | 4 ++-- .../testinterface/adapter/RunnerAdapter.scala | 8 ++++++-- .../scalanative/testinterface/adapter/TestAdapter.scala | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala b/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala index 39f4d934bc..f8c5aec971 100644 --- a/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala +++ b/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala @@ -115,6 +115,9 @@ private[testinterface] abstract class RPCCore()(implicit ec: ExecutionContext) { } } + /** Has connection channel been closed */ + private[testinterface] def isClosed: Boolean = closeReason != null + /** Subclass needs to implement message sending. */ protected def send(msg: String): Unit diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala index adb57d8e9e..9f3a4a5ef3 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala @@ -3,13 +3,16 @@ package scala.scalanative.testinterface import java.io.{DataInputStream, DataOutputStream, EOFException} import java.net.Socket import scala.annotation.tailrec -import scala.concurrent.ExecutionContext.Implicits.global +import scala.concurrent.ExecutionContext import scala.scalanative.testinterface.common.RPCCore import scala.util.{Failure, Success, Try} import java.nio.charset.StandardCharsets +import scala.scalanative.meta.LinktimeInfo /** Native RPC Core. */ -private[testinterface] class NativeRPC(clientSocket: Socket) extends RPCCore { +private[testinterface] class NativeRPC(clientSocket: Socket)(implicit + ec: ExecutionContext +) extends RPCCore { private lazy val inStream = new DataInputStream(clientSocket.getInputStream) private lazy val outStream = new DataOutputStream( clientSocket.getOutputStream @@ -34,7 +37,7 @@ private[testinterface] class NativeRPC(clientSocket: Socket) extends RPCCore { } else { val msg = Array.fill(msgLength)(inStream.readChar).mkString handleMessage(msg) - scalanative.runtime.loop() + if (!LinktimeInfo.isMultithreadingEnabled) scalanative.runtime.loop() loop() } } diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala index 24a3c305e1..4f3e405b8e 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala @@ -9,6 +9,7 @@ import signalhandling.SignalConfig import scalanative.posix.sys.socket._ import scalanative.posix.netinet.in import scalanative.posix.unistd +import scala.concurrent.ExecutionContext object TestMain { @@ -91,7 +92,7 @@ object TestMain { else getFreeBSDLoopbackAddr() val serverPort = args(0).toInt val clientSocket = new Socket(serverAddr, serverPort) - val nativeRPC = new NativeRPC(clientSocket) + val nativeRPC = new NativeRPC(clientSocket)(ExecutionContext.global) val bridge = new TestAdapterBridge(nativeRPC) bridge.start() diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/signalhandling/SignalConfig.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/signalhandling/SignalConfig.scala index c8bf69963b..b4d17c2c05 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/signalhandling/SignalConfig.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/signalhandling/SignalConfig.scala @@ -22,8 +22,6 @@ private[testinterface] object SignalConfig { * async-signal-safe methods the way POSIX does. */ private def asyncSafePrintStackTrace(sig: CInt): Unit = { - val errorTag = c"[\u001b[0;31merror\u001b[0;0m]" - def printError(str: CString): Unit = if (isWindows) { val written = stackalloc[DWord]() @@ -70,7 +68,6 @@ private[testinterface] object SignalConfig { } val stackTraceHeader: Ptr[CChar] = stackalloc[CChar](100.toUInt) - strcat(stackTraceHeader, errorTag) strcat(stackTraceHeader, c" Fatal signal ") strcat(stackTraceHeader, signalNumberStr) strcat(stackTraceHeader, c" caught\n") @@ -101,7 +98,6 @@ private[testinterface] object SignalConfig { val formattedSymbol: Ptr[CChar] = stackalloc[CChar](1100.toUInt) formattedSymbol(0) = 0.toByte - strcat(formattedSymbol, errorTag) strcat(formattedSymbol, c" at ") strcat(formattedSymbol, className) strcat(formattedSymbol, c".") diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala index 445acfa8a3..ee51011737 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala @@ -19,9 +19,9 @@ private[testinterface] class ComRunner( serverSocket: ServerSocket, logger: Logger, handleMessage: String => Unit -) extends AutoCloseable { +)(implicit ec: ExecutionContext) + extends AutoCloseable { import ComRunner._ - implicit val executionContext: ExecutionContext = ExecutionContext.global processRunner.future.onComplete { case Failure(exception) => forceClose(exception) diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/RunnerAdapter.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/RunnerAdapter.scala index 41cb3e394a..2caa49f5b4 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/RunnerAdapter.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/RunnerAdapter.scala @@ -4,6 +4,7 @@ package scala.scalanative.testinterface.adapter import sbt.testing._ import scala.collection.concurrent.TrieMap +import scala.concurrent.ExecutionContext import scala.scalanative.testinterface.adapter.TestAdapter.ManagedRunner import scala.scalanative.testinterface.common.{ FrameworkMessage, @@ -42,13 +43,16 @@ private final class RunnerAdapter private ( } def done(): String = synchronized { - val workers = this.workers.values.toList // .toList to make it strict. + // .toList to make it strict. + val workers = this.workers.values.filter(!_.com.isClosed).toList try { workers .map(_.mux.call(NativeEndpoints.done, runID)(())) .foreach(_.await()) - controller.mux.call(NativeEndpoints.done, runID)(()).await() + // RPC connection was closed, probaly due to native runner crash, skip sending fruitless command + if (controller.com.isClosed) "" + else controller.mux.call(NativeEndpoints.done, runID)(()).await() } finally { workers.foreach(_.mux.detach(JVMEndpoints.msgWorker, runID)) controller.mux.detach(JVMEndpoints.msgController, runID) diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala index cb84efe745..89ee7bf69c 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala @@ -74,7 +74,7 @@ final class TestAdapter(config: TestAdapter.Config) { * on an async operation to complete. */ private def reportFailure(cause: Throwable): Unit = { - val msg = "Failure in async execution. Aborting all test runs." + val msg = "Fatal failure in tests execution. Aborting all test runs." val error = new AssertionError(msg, cause) config.logger.error(msg) config.logger.trace(error) From aff391dfab23809a131f3395ec89897c4b0fcefe Mon Sep 17 00:00:00 2001 From: Michel Davit Date: Wed, 20 Dec 2023 15:46:30 +0100 Subject: [PATCH 10/38] bugfix: Skip addr memcmp if getifaddrs returns a null ifa_addr pointer (#3626) (cherry picked from commit ab04e1e0a9ce1d6508a3dd6db4e8c1bc88e731c3) --- .../scala/java/net/NetworkInterface.scala | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/javalib/src/main/scala/java/net/NetworkInterface.scala b/javalib/src/main/scala/java/net/NetworkInterface.scala index 3d16fc712e..ab33a4c65d 100644 --- a/javalib/src/main/scala/java/net/NetworkInterface.scala +++ b/javalib/src/main/scala/java/net/NetworkInterface.scala @@ -318,19 +318,22 @@ object NetworkInterface { private def unixGetByInetAddress(addr: InetAddress): NetworkInterface = { def found(addr: Array[Byte], addrLen: Int, sa: Ptr[sockaddr]): Boolean = { - val sa_family = sa.sa_family.toInt - if (sa_family == AF_INET6) { - if (addrLen != 16) false - else { - val sa6 = sa.asInstanceOf[Ptr[sockaddr_in6]] - val sin6Addr = sa6.sin6_addr.at1.at(0).asInstanceOf[Ptr[Byte]] - memcmp(addr.at(0), sin6Addr, addrLen.toUInt) == 0 - } - } else if (sa_family == AF_INET) { - val sa4 = sa.asInstanceOf[Ptr[sockaddr_in]] - val sin4Addr = sa4.sin_addr.at1.asInstanceOf[Ptr[Byte]] - memcmp(addr.at(0), sin4Addr, addrLen.toUInt) == 0 - } else false + if (sa == null) false + else { + val sa_family = sa.sa_family.toInt + if (sa_family == AF_INET6) { + if (addrLen != 16) false + else { + val sa6 = sa.asInstanceOf[Ptr[sockaddr_in6]] + val sin6Addr = sa6.sin6_addr.at1.at(0).asInstanceOf[Ptr[Byte]] + memcmp(addr.at(0), sin6Addr, addrLen.toUInt) == 0 + } + } else if (sa_family == AF_INET) { + val sa4 = sa.asInstanceOf[Ptr[sockaddr_in]] + val sin4Addr = sa4.sin_addr.at1.asInstanceOf[Ptr[Byte]] + memcmp(addr.at(0), sin4Addr, addrLen.toUInt) == 0 + } else false + } } @tailrec @@ -346,7 +349,7 @@ object NetworkInterface { findIfInetAddress( ipAddress, addrLen, - ifa.ifa_next.asInstanceOf[Ptr[ifaddrs]] + ifa.ifa_next ) } From 34726484ebd2079b65758a2a416c5b3965532f87 Mon Sep 17 00:00:00 2001 From: Michel Davit Date: Fri, 22 Dec 2023 01:32:04 +0100 Subject: [PATCH 11/38] bugfix: Mutate socket localAddr only on successful bind (#3627) (cherry picked from commit e9299b8f860d55d4f696b05c1ba3cf65ffb66342) --- javalib/src/main/scala/java/net/Socket.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/javalib/src/main/scala/java/net/Socket.scala b/javalib/src/main/scala/java/net/Socket.scala index 150ea46f70..c581809ed6 100644 --- a/javalib/src/main/scala/java/net/Socket.scala +++ b/javalib/src/main/scala/java/net/Socket.scala @@ -128,8 +128,7 @@ class Socket protected ( def bind(bindpoint: SocketAddress): Unit = { if (bindpoint != null && !bindpoint.isInstanceOf[InetSocketAddress]) { throw new IllegalArgumentException( - "Endpoint is of unsupported " + - "SocketAddress subclass" + "Endpoint SocketAddress subclass is not supported" ) } @@ -143,8 +142,8 @@ class Socket protected ( checkClosedAndCreate() + impl.bind(addr.getAddress, addr.getPort) this.localAddr = addr.getAddress - impl.bind(this.localAddr, addr.getPort) this.localPort = impl.localport bound = true } From 313e876f4c8aefdd6f36715fca6896a9645b0711 Mon Sep 17 00:00:00 2001 From: Alex Dupre Date: Fri, 22 Dec 2023 11:21:44 +0100 Subject: [PATCH 12/38] bugfix: Fix compilation on FreeBSD. (#3625) * Fix compilation on FreeBSD. * Explicitly error out on unsupported platforms. * Make the MAP_NORESERVE change specific for FreeBSD. * Fix the sed expression to run on FreeBSD, too. * Make the TestMain to run on all java versions on FreeBSD. * Update the documentation for FreeBSD. * Restore the ability to skip leading whitespaces in a more portable way. * Add a note about failing tests. (cherry picked from commit 963666dd25f9da99bbb1ec2e304caaa61d320320) --- docs/user/setup.rst | 17 +++-- scripts/scalafmt | 2 +- .../scalanative/testinterface/TestMain.scala | 66 +++++-------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/docs/user/setup.rst b/docs/user/setup.rst index f61addc016..5e71aee5c3 100644 --- a/docs/user/setup.rst +++ b/docs/user/setup.rst @@ -93,15 +93,24 @@ installation of Arch Linux. $ sudo dnf groupinstall "Development Tools" $ sudo dnf install gc-devel zlib-devel # both optional -**FreeBSD 12.2 and later** +**FreeBSD 12.4 and later** + +*Note 1:* Only AMD64 and ARM64 architectures are supported. + +*Note 2:* Sufficiently recent versions of llvm and zlib come with the +installation of FreeBSD. .. code-block:: shell - $ pkg install llvm10 $ pkg install boehm-gc # optional -*Note:* A version of zlib that is sufficiently recent comes with the -installation of FreeBSD. +*Note 3:* Using the boehm GC with multi-threaded binaries doesn't work +out-of-the-box yet. + +*Note 4:* A number of tests, primarily unit-tests, are known to fail +or not terminate on FreeBSD. It is believed that the code-under-test +is correct and that the defect is in the test itself. +Work is underway to fix these tests. **Nix/NixOS** diff --git a/scripts/scalafmt b/scripts/scalafmt index fdebe25dab..64dad5d983 100755 --- a/scripts/scalafmt +++ b/scripts/scalafmt @@ -3,7 +3,7 @@ set -e HERE="`dirname $0`" -VERSION=$(sed -nre "s#\s*version[^0-9]+([0-9.]+)#\1#p" $HERE/../.scalafmt.conf) +VERSION=$(sed -nre "s#[[:space:]]*version[^0-9]+([0-9.]+)#\1#p" $HERE/../.scalafmt.conf) COURSIER="$HERE/.coursier" SCALAFMT="$HERE/.scalafmt-$VERSION" diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala index 4f3e405b8e..574cfb0ffe 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala @@ -28,56 +28,26 @@ object TestMain { |""".stripMargin } - final val iPv4Loopback = "127.0.0.1" - final val iPv6Loopback = "::1" - - private def getFreeBSDLoopbackAddr(): String = { + private def setFreeBSDWorkaround(): Unit = { /* Standard out-of-the-box FreeBSD differs from Linux & macOS in - * not allowing IPv4 mapped IPv6 addresses, such as :FFFF:127.0.0.1 - * or ::ffff:7f00:1. These can be enabled by setting the line - * ipv6_ipv4mapping="YES" in /etc/rc.conf (and rebooting). + * not allowing IPv4-mapped IPv6 addresses, such as :FFFF:127.0.0.1 + * or ::ffff:7f00:1. * - * FreeBSD TestMain initial connections should succeed on both IPv4 - * and IPv6 systems without requiring arcane and non-standard system - * configuration. This method checks the protocol that Java connect() - * is likely used and returns the corresponding loopback address. - * Tests which use IPv4 addresses, either through hard-coding or - * bind resolution, on IPv6 systems will still fail. This allows to - * run the vast majority of tests which do not have this characteristic. + * Another difference is that Java versions >= 11 on FreeBSD set + * java.net.preferIPv4Stack=true by default, so the sbt server + * listens only on a tcp4 socket. * - * Networking is complex, especially on j-random systems: full of - * joy & lamentation. + * Even if IPv4-mapped IPv6 addresses can be enabled (via the + * net.inet6.ip6.v6only=0 sysctl and/or via the ipv6_ipv4mapping="YES" + * rc.conf variable) and sbt can be instructed to listen on an IPv6 + * socket (via the java.net.preferIPv4Stack=false system property), + * the easiest way to make TestMain to work on most FreeBSD machines, + * with different Java versions, is to set + * java.net.preferIPv4Stack=true in Scala Native, before the first + * Java network call, in order to always use an AF_INET IPv4 socket. */ - if (!LinktimeInfo.isFreeBSD) iPv4Loopback // should never happen - else { - // These are the effective imports - import scalanative.posix.sys.socket._ - import scalanative.posix.netinet.in - import scalanative.posix.unistd - - /* These are to get this code to compile on Windows. - * Including all of them is cargo cult programming. Someone - * more patient or more knowledgeable about Windows may - * be able to reduce the set. - */ - import scala.scalanative.windows._ - import scala.scalanative.windows.WinSocketApi._ - import scala.scalanative.windows.WinSocketApiExt._ - import scala.scalanative.windows.WinSocketApiOps._ - import scala.scalanative.windows.ErrorHandlingApi._ - - /* The keen observer will note that this scheme could be used - * for Linux and macOS. That change is not introduced at this time - * in order to preserve historical behavior. - */ - val sd = socket(AF_INET6, SOCK_STREAM, in.IPPROTO_TCP) - if (sd == -1) iPv4Loopback - else { - unistd.close(sd) - iPv6Loopback - } - } + System.setProperty("java.net.preferIPv4Stack", "true") } /** Main method of the test runner. */ @@ -87,11 +57,9 @@ object TestMain { throw new IllegalArgumentException("One argument expected") } - val serverAddr = - if (!LinktimeInfo.isFreeBSD) iPv4Loopback - else getFreeBSDLoopbackAddr() + if (LinktimeInfo.isFreeBSD) setFreeBSDWorkaround() val serverPort = args(0).toInt - val clientSocket = new Socket(serverAddr, serverPort) + val clientSocket = new Socket("127.0.0.1", serverPort) val nativeRPC = new NativeRPC(clientSocket)(ExecutionContext.global) val bridge = new TestAdapterBridge(nativeRPC) From c3c5adfcb4178b12139ac59566a03b57e114498b Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Mon, 1 Jan 2024 13:22:12 +0100 Subject: [PATCH 13/38] Make ArrayIndexOutBoundsExceptions compliant with JVM 8+ - inform about bounds in exception message (#3638) (cherry picked from commit 9ed8cb0fc269ff4d405e023822217004b4d16973) --- .../scala/scalanative/runtime/Arrays.scala | 26 +++++++++---------- .../scalanative/runtime/Arrays.scala.gyb | 10 +++---- .../scala/scalanative/runtime/package.scala | 6 +++++ .../scala/scalanative/codegen/Lower.scala | 21 ++++++++++----- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala b/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala index b816a16cd5..7b59a021bc 100644 --- a/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala +++ b/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala @@ -100,9 +100,9 @@ object Array { } else if (len < 0) { throw new ArrayIndexOutOfBoundsException("length is negative") } else if (fromPos < 0 || fromPos + len > from.length) { - throwOutOfBounds(fromPos) + throwOutOfBounds(fromPos, from.length) } else if (toPos < 0 || toPos + len > to.length) { - throwOutOfBounds(toPos) + throwOutOfBounds(toPos, to.length) } else if (len == 0) { () } else { @@ -145,9 +145,9 @@ object Array { } else if (len < 0) { throw new ArrayIndexOutOfBoundsException("length is negative") } else if (leftPos < 0 || leftPos + len > left.length) { - throwOutOfBounds(leftPos) + throwOutOfBounds(leftPos, left.length) } else if (rightPos < 0 || rightPos + len > right.length) { - throwOutOfBounds(rightPos) + throwOutOfBounds(rightPos, right.length) } else if (len == 0) { 0 } else { @@ -166,7 +166,7 @@ final class BooleanArray private () extends Array[Boolean] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -222,7 +222,7 @@ final class CharArray private () extends Array[Char] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -278,7 +278,7 @@ final class ByteArray private () extends Array[Byte] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -334,7 +334,7 @@ final class ShortArray private () extends Array[Short] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -390,7 +390,7 @@ final class IntArray private () extends Array[Int] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -446,7 +446,7 @@ final class LongArray private () extends Array[Long] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -502,7 +502,7 @@ final class FloatArray private () extends Array[Float] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -558,7 +558,7 @@ final class DoubleArray private () extends Array[Double] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } @@ -614,7 +614,7 @@ final class ObjectArray private () extends Array[Object] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } diff --git a/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala.gyb b/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala.gyb index 0c10614b43..96b95b2bcb 100644 --- a/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala.gyb +++ b/nativelib/src/main/scala/scala/scalanative/runtime/Arrays.scala.gyb @@ -101,9 +101,9 @@ object Array { } else if (len < 0) { throw new ArrayIndexOutOfBoundsException("length is negative") } else if (fromPos < 0 || fromPos + len > from.length) { - throwOutOfBounds(fromPos) + throwOutOfBounds(fromPos, from.length) } else if (toPos < 0 || toPos + len > to.length) { - throwOutOfBounds(toPos) + throwOutOfBounds(toPos, to.length) } else if (len == 0) { () } else { @@ -146,9 +146,9 @@ object Array { } else if (len < 0) { throw new ArrayIndexOutOfBoundsException("length is negative") } else if (leftPos < 0 || leftPos + len > left.length) { - throwOutOfBounds(leftPos) + throwOutOfBounds(leftPos, left.length) } else if (rightPos < 0 || rightPos + len > right.length) { - throwOutOfBounds(rightPos) + throwOutOfBounds(rightPos, right.length) } else if (len == 0) { 0 } else { @@ -183,7 +183,7 @@ final class ${T}Array private () extends Array[${T}] { @inline def atRaw(i: Int): RawPtr = if (i < 0 || i >= length) { - throwOutOfBounds(i) + throwOutOfBounds(i, length) } else { atRawUnsafe(i) } diff --git a/nativelib/src/main/scala/scala/scalanative/runtime/package.scala b/nativelib/src/main/scala/scala/scalanative/runtime/package.scala index 1fe10116b9..51de217259 100644 --- a/nativelib/src/main/scala/scala/scalanative/runtime/package.scala +++ b/nativelib/src/main/scala/scala/scalanative/runtime/package.scala @@ -83,6 +83,12 @@ package object runtime { @noinline def throwOutOfBounds(i: Int): Nothing = throw new ArrayIndexOutOfBoundsException(i.toString) + /** Called by the generated code in case of out of bounds on array access. */ + private[scalanative] def throwOutOfBounds(i: Int, length: Int): Nothing = + throw new ArrayIndexOutOfBoundsException( + s"Index $i out of bounds for length $length" + ) + /** Called by the generated code in case of missing method on reflective call. */ @noinline def throwNoSuchMethod(sig: String): Nothing = diff --git a/tools/src/main/scala/scala/scalanative/codegen/Lower.scala b/tools/src/main/scala/scala/scalanative/codegen/Lower.scala index 46084f463b..d22c0f6e28 100644 --- a/tools/src/main/scala/scala/scalanative/codegen/Lower.scala +++ b/tools/src/main/scala/scala/scalanative/codegen/Lower.scala @@ -319,12 +319,13 @@ object Lower { unwindHandler := slowPathUnwindHandler ) { val idx = Val.Local(fresh(), Type.Int) + val len = nir.Val.Local(fresh(), nir.Type.Int) - buf.label(slowPath, Seq(idx)) + buf.label(slowPath, Seq(idx, len)) buf.call( throwOutOfBoundsTy, throwOutOfBoundsVal, - Seq(Val.Null, idx), + Seq(Val.Null, idx, len), unwind ) buf.unreachable(Next.None) @@ -469,7 +470,7 @@ object Lower { val gt0 = comp(Comp.Sge, Type.Int, idx, zero, unwind) val ltLen = comp(Comp.Slt, Type.Int, idx, len, unwind) val inBounds = bin(Bin.And, Type.Bool, gt0, ltLen, unwind) - branch(inBounds, Next(inBoundsL), Next.Label(outOfBoundsL, Seq(idx))) + branch(inBounds, Next(inBoundsL), Next.Label(outOfBoundsL, Seq(idx, len))) label(inBoundsL) } @@ -1464,11 +1465,17 @@ object Lower { Val.Global(throwUndefined, Type.Ptr) val throwOutOfBoundsTy = - Type.Function(Seq(Type.Ptr, Type.Int), Type.Nothing) + nir.Type.Function( + Seq(nir.Type.Ptr, nir.Type.Int, nir.Type.Int), + nir.Type.Nothing + ) val throwOutOfBounds = - Global.Member( - Rt.Runtime.name, - Sig.Method("throwOutOfBounds", Seq(Type.Int, Type.Nothing)) + nir.Global.Member( + nir.Rt.Runtime.name, + nir.Sig.Method( + "throwOutOfBounds", + Seq(nir.Type.Int, nir.Type.Int, nir.Type.Nothing) + ) ) val throwOutOfBoundsVal = Val.Global(throwOutOfBounds, Type.Ptr) From e5e1d016b964015b4764714c5262dc4a9bd3ddfc Mon Sep 17 00:00:00 2001 From: LeeTibbert Date: Tue, 2 Jan 2024 03:49:29 -0500 Subject: [PATCH 14/38] Fix #3631: Regex now handles OR alternatives with more than two clauses (#3642) (cherry picked from commit d152d675cf096a2c199516c261fb6b1e616975b9) --- .../scala/scalanative/regex/Parser.scala | 7 ++++ .../scala/issues/RegexIssuesTest.scala | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 unit-tests/shared/src/test/scala-3/scala/issues/RegexIssuesTest.scala diff --git a/nativelib/src/main/scala/scala/scalanative/regex/Parser.scala b/nativelib/src/main/scala/scala/scalanative/regex/Parser.scala index 84afaccf4a..f613006972 100644 --- a/nativelib/src/main/scala/scala/scalanative/regex/Parser.scala +++ b/nativelib/src/main/scala/scala/scalanative/regex/Parser.scala @@ -705,6 +705,13 @@ class Parser(wholeRegexp: String, _flags: Int) { val old = re re = re.subs(0) this.reuse(old) + + /* Scala Native Issue #3631 + * This Scala Native port must follow the Java switch + * statement semantics used in the RE2J original code. + * That is, return the now shortened re if there is no explicit case. + */ + case _ => } re } else { diff --git a/unit-tests/shared/src/test/scala-3/scala/issues/RegexIssuesTest.scala b/unit-tests/shared/src/test/scala-3/scala/issues/RegexIssuesTest.scala new file mode 100644 index 0000000000..247846109c --- /dev/null +++ b/unit-tests/shared/src/test/scala-3/scala/issues/RegexIssuesTest.scala @@ -0,0 +1,33 @@ +package scala.issues + +import org.junit.Test +import org.junit.Assert._ + +class RegexIssuesTest: + + /* Issue 3631 describes a parse failue in a complicated regex. + * To increase confidence, the Test should stay as close as feasible + * to the original report. + * + * The complication is that Scala 2.12 regex class does not have + * the "matches" method used in the Issue. That method was introduced + * in Scala 2.13. + * + * To reduce duplication & confusion, this Test is run only on Scala 3. + * + * This test should be run on both Scala and JVM to ensure that the regex + * from the Issue continues to parse on the latter. + */ + + @Test def test_Issue3631(): Unit = { + // Use the full regex from the Issue, which is _not_ the minimal reproducer. + val pattern = "^(\\-|\\+)?(0\\.[0-9]+|[1-9][0-9]*\\.[0-9]+|[1-9][0-9]*|0)$" + val expected = "1" + + assertTrue( + s"regex '${pattern}' does not match '${expected}'", + pattern.r.matches(expected) + ) + } + +end RegexIssuesTest From dae39bbfe7fad34f32938fb51d50b35a193e9984 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 2 Jan 2024 14:32:53 +0100 Subject: [PATCH 15/38] improvement: In NIR codegen always use `nir.Type.Unit` for if return type if one of branches is unit type (#3644) (cherry picked from commit fff2bf0c37d5c8d45eee048672213ffab38cf91d) --- .../scala-2/scala/scalanative/nscplugin/NirGenExpr.scala | 6 +++++- .../scala-3/scala/scalanative/nscplugin/NirGenExpr.scala | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala index 7bc8af39ad..97c4c5b210 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala @@ -185,7 +185,11 @@ trait NirGenExpr[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => def genIf(tree: If): Val = { val If(cond, thenp, elsep) = tree - val retty = genType(tree.tpe) + def isUnitType(tpe: Type) = + defn.isUnitType(tpe) || tpe =:= defn.BoxedUnitTpe + val retty = + if (isUnitType(thenp.tpe) || isUnitType(elsep.tpe)) nir.Type.Unit + else genType(tree.tpe) genIf(retty, cond, thenp, elsep)(tree.pos) } diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala index 0df35da6f2..80bd716807 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala @@ -427,7 +427,11 @@ trait NirGenExpr(using Context) { def genIf(tree: If): Val = { given nir.Position = tree.span val If(cond, thenp, elsep) = tree - val retty = genType(tree.tpe) + def isUnitType(tpe: Type) = + tpe =:= defn.UnitType || defn.isBoxedUnitClass(tpe.sym) + val retty = + if (isUnitType(thenp.tpe) || isUnitType(elsep.tpe)) nir.Type.Unit + else genType(tree.tpe) genIf(retty, cond, thenp, elsep) } From 68256d3a957383800f84ad8b641b88752f414f92 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 17 Jan 2024 19:46:33 +0100 Subject: [PATCH 16/38] After rebase fixes --- .../scala/scalanative/nscplugin/NirGenExpr.scala | 2 +- .../scala/scalanative/nscplugin/NirGenExpr.scala | 2 +- .../scala/scalanative/nscplugin/NirGenStat.scala | 16 ++++++++-------- .../scalanative/testinterface/NativeRPC.scala | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala index 97c4c5b210..fd0b215f8f 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala @@ -186,7 +186,7 @@ trait NirGenExpr[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => def genIf(tree: If): Val = { val If(cond, thenp, elsep) = tree def isUnitType(tpe: Type) = - defn.isUnitType(tpe) || tpe =:= defn.BoxedUnitTpe + definitions.isUnitType(tpe) || tpe =:= definitions.BoxedUnitTpe val retty = if (isUnitType(thenp.tpe) || isUnitType(elsep.tpe)) nir.Type.Unit else genType(tree.tpe) diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala index 80bd716807..a1935baf38 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala @@ -427,7 +427,7 @@ trait NirGenExpr(using Context) { def genIf(tree: If): Val = { given nir.Position = tree.span val If(cond, thenp, elsep) = tree - def isUnitType(tpe: Type) = + def isUnitType(tpe: Types.Type) = tpe =:= defn.UnitType || defn.isBoxedUnitClass(tpe.sym) val retty = if (isUnitType(thenp.tpe) || isUnitType(elsep.tpe)) nir.Type.Unit diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala index de7df6e9cc..9b5c87f117 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala @@ -258,14 +258,14 @@ trait NirGenStat(using Context) { None } sym.annotations.foreach { ann => - ann.symbol match { - case defnNir.NoInlineClass => attrs += nir.Attr.NoInline - case defnNir.AlwaysInlineClass => attrs += nir.Attr.AlwaysInline - case defnNir.InlineClass => attrs += nir.Attr.InlineHint - case defnNir.NoOptimizeClass => attrs += nir.Attr.NoOpt - case defnNir.NoSpecializeClass => attrs += nir.Attr.NoSpecialize - case defnNir.StubClass => attrs += nir.Attr.Stub - case defnNir.LinkClass => + ann.symbol.typeRef match { + case defnNir.NoInlineType => attrs += nir.Attr.NoInline + case defnNir.AlwaysInlineType => attrs += nir.Attr.AlwaysInline + case defnNir.InlineType => attrs += nir.Attr.InlineHint + case defnNir.NoOptimizeType => attrs += nir.Attr.NoOpt + case defnNir.NoSpecializeType => attrs += nir.Attr.NoSpecialize + case defnNir.StubType => attrs += nir.Attr.Stub + case defnNir.LinkType => requireLiteralStringAnnotation(ann) .foreach(attrs += nir.Attr.Link(_)) case _ => () diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala index 9f3a4a5ef3..ff99bd1942 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala @@ -37,7 +37,7 @@ private[testinterface] class NativeRPC(clientSocket: Socket)(implicit } else { val msg = Array.fill(msgLength)(inStream.readChar).mkString handleMessage(msg) - if (!LinktimeInfo.isMultithreadingEnabled) scalanative.runtime.loop() + scalanative.runtime.loop() loop() } } From e496f3c68e227668f35149cf580e4b74505f3adc Mon Sep 17 00:00:00 2001 From: LeeTibbert Date: Fri, 5 Jan 2024 13:26:19 +0100 Subject: [PATCH 17/38] bugfix: Format IPv4-mapped IPv6 addresses as IPv6 (#3654) (cherry picked from commit 5279a63e45deec60d4a2da15e98eea9758f3fc2a) --- javalib/src/main/scala/java/net/InetAddress.scala | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/javalib/src/main/scala/java/net/InetAddress.scala b/javalib/src/main/scala/java/net/InetAddress.scala index edeaef3420..6a031b0762 100644 --- a/javalib/src/main/scala/java/net/InetAddress.scala +++ b/javalib/src/main/scala/java/net/InetAddress.scala @@ -90,13 +90,7 @@ class InetAddress protected (ipAddress: Array[Byte], originalHost: String) if (ipAddress.length == 4) { formatIn4Addr(arrayByteToPtrByte(ipAddress)) } else if (ipAddress.length == 16) { - if (isIPv4MappedAddress(arrayByteToPtrByte(ipAddress))) { - formatIn4Addr( - arrayByteToPtrByte(extractIP4Bytes(arrayByteToPtrByte(ipAddress))) - ) - } else { - Inet6Address.formatInet6Address(this.asInstanceOf[Inet6Address]) - } + Inet6Address.formatInet6Address(this.asInstanceOf[Inet6Address]) } else { "" } From d281a58fe312b43f9657b73261139112f084f393 Mon Sep 17 00:00:00 2001 From: LeeTibbert Date: Mon, 8 Jan 2024 05:41:21 -0500 Subject: [PATCH 18/38] Fix #3655: provide posixlib syslog method (#3656) (cherry picked from commit f1829aca124f22501d7ff8cd3669d6a5df1145cc) --- .../scala/scalanative/posix/syslog.scala | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala b/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala index 82f839b63e..b928819c94 100644 --- a/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala +++ b/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala @@ -1,18 +1,37 @@ package scala.scalanative + package posix import scalanative.unsafe._ +import scalanative.posix.stdio.va_list + +/* Open Group 2018 (X/Open System Interfaces (XSI) + * Reference: + * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/syslog.h.html + */ + +// XSI - all of syslog.scala is marked XSI + +/* Four methods are now marked "// Neither XSI nor POSIX, Why here?". + * Once understood, they should be marked deprecated. Once the depreciation + * period has expired they and their "glue" code should be deleted. + */ @extern object syslog { @name("scalanative_closelog") - def closelog(): Unit = extern + @blocking def closelog(): Unit = extern @name("scalanative_openlog") - def openlog(ident: CString, logopt: CInt, facility: CInt): Unit = extern + @blocking def openlog(ident: CString, logopt: CInt, facility: CInt): Unit = + extern @name("scalanative_setlogmask") - def setlogmask(maskpri: CInt): CInt = extern + @blocking def setlogmask(maskpri: CInt): CInt = extern + + // "glue" code is not used here so that implementation of va_list is simpler. + @blocking def syslog(priority: CInt, format: CString, vargs: Any*): Unit = + extern @name("scalanative_log_emerg") def LOG_EMERG: CInt = extern @@ -119,9 +138,11 @@ object syslog { @name("scalanative_log_local7") def LOG_LOCAL7: CInt = extern +// Neither XSI nor POSIX, Why here? @name("scalanative_log_nfacilities") def LOG_NFACILITIES: CInt = extern +// Neither XSI nor POSIX, Why here? @name("scalanative_log_facmask") def LOG_FACMASK: CInt = extern @@ -131,6 +152,7 @@ object syslog { @name("scalanative_log_mask") def LOG_MASK(pri: CInt): CInt = extern + // Neither XSI nor POSIX, Why here? @name("scalanative_log_upto") def LOG_UPTO(pri: CInt): CInt = extern @@ -149,6 +171,7 @@ object syslog { @name("scalanative_log_nowait") def LOG_NOWAIT: CInt = extern + // Neither XSI nor POSIX, Why here? @name("scalanative_log_perror") def LOG_PERROR: CInt = extern } From 8cee03061d433ef5696f0458937cb584e3ed78e9 Mon Sep 17 00:00:00 2001 From: LeeTibbert Date: Mon, 8 Jan 2024 06:33:40 -0500 Subject: [PATCH 19/38] refactor: Make java.net.Inet6Address constructor arguments more consistent (#3653) * Make java.net.Inet6Address constructor arguments more consistent * Remove commented out obsolete code * Keep constructor arguments private * Per review make constructors private[net]; remove unused constructor (cherry picked from commit 09eab396d903ac1964ce2f897650b053cf3f76a0) --- javalib/src/main/scala/java/net/Inet6Address.scala | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/javalib/src/main/scala/java/net/Inet6Address.scala b/javalib/src/main/scala/java/net/Inet6Address.scala index ffc076f022..eee0f87b67 100644 --- a/javalib/src/main/scala/java/net/Inet6Address.scala +++ b/javalib/src/main/scala/java/net/Inet6Address.scala @@ -10,20 +10,18 @@ import scala.scalanative.posix.net.ifOps._ import scala.scalanative.posix.stddef final class Inet6Address private ( - val ipAddress: Array[Byte], + ipAddress: Array[Byte], host: String, scopeId: Int, val zoneIdent: String ) extends InetAddress(ipAddress, host) { - def this(ipAddress: Array[Byte], host: String, scope: Int) = + private[net] def this(ipAddress: Array[Byte], host: String, scope: Int) = this(ipAddress, host, scope, "") - def this(ipAddress: Array[Byte], host: String) = + private[net] def this(ipAddress: Array[Byte], host: String) = this(ipAddress, host, 0) - def this(ipAddress: Array[Byte]) = this(ipAddress, null) - def getScopeId(): Int = scopeId override def isLinkLocalAddress(): Boolean = @@ -96,7 +94,7 @@ object Inet6Address { * Translate by hand as before but avoid non-local returns. */ - val ia6ByteArray = in6Addr.ipAddress + val ia6ByteArray = in6Addr.getAddress() val buffer = new StringBuilder() var isFirst = true From 1aed54ff867f8b83d9e18bcf18e94684234d11b4 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 9 Jan 2024 09:30:47 +0100 Subject: [PATCH 20/38] feature: Setup debug signal handlers in the TestMain only when requested (#3660) (cherry picked from commit 3422d3a85e5e37a1e8f8c393265d712fece07958) --- docs/user/testing.rst | 7 +++++++ .../scala/scalanative/testinterface/TestMain.scala | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/user/testing.rst b/docs/user/testing.rst index d5016287bf..d9456866c5 100644 --- a/docs/user/testing.rst +++ b/docs/user/testing.rst @@ -50,4 +50,11 @@ You may also use `testOnly` to run a particular test, for example: testOnly MyTest testOnly MyTest.superComplicatedTest +Debugging sygnals +----------------- +In case of problems with unexpected signals crashing the test (SIGSEGV, SIGBUS) +you can set the environment variable `SCALANATIVE_TEST_DEBUG_SIGNALS=1` to enable debug signal handlers +in the test runner. When enabled test runner would set up signal handlers printing stack trace for most of the available signals for a given platform. + + Continue to :ref:`profiling`. diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala index 574cfb0ffe..663e6b9a1d 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala @@ -57,6 +57,14 @@ object TestMain { throw new IllegalArgumentException("One argument expected") } + locally { + val shouldSetupSignalHandlers = sys.env + .get("SCALANATIVE_TEST_DEBUG_SIGNALS") + .exists(v => v.isEmpty() || v == "1") + if (shouldSetupSignalHandlers) + SignalConfig.setDefaultHandlers() + } + if (LinktimeInfo.isFreeBSD) setFreeBSDWorkaround() val serverPort = args(0).toInt val clientSocket = new Socket("127.0.0.1", serverPort) @@ -65,8 +73,6 @@ object TestMain { bridge.start() - SignalConfig.setDefaultHandlers() - val exitCode = nativeRPC.loop() sys.exit(exitCode) } From a48dfe8d341d21dd396352fd61025266fbb2b121 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 17 Jan 2024 20:16:30 +0100 Subject: [PATCH 21/38] fix: Allow to define multi-level exports refering finally to extern method (#3665) (cherry picked from commit e7a7fbed9dc4a581ae47f9e3f41d25b0734dbf04) --- .../nscplugin/PrepNativeInterop.scala | 51 ++++++++++-- .../linker/TopLevelExternsTest.scala | 42 ---------- .../linker/MethodAttributesTest.scala | 80 ------------------- .../scala/scalanative/posix/syslog.scala | 8 +- .../scala-3/scala/NativeCompilerTest.scala | 36 +++++++++ 5 files changed, 83 insertions(+), 134 deletions(-) delete mode 100644 nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala delete mode 100644 nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala index cee19ae276..755bfcadfa 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala @@ -57,11 +57,39 @@ class PrepNativeInterop extends PluginPhase { def isExported(using Context) = sym.hasAnnotation(defnNir.ExportedClass) || sym.hasAnnotation(defnNir.ExportAccessorsClass) + + /** `true` iff `sym` uses variadic arguments. */ + def usesVariadicArgs(using Context) = sym.paramInfo.stripPoly match { + case MethodTpe(_, paramTypes, _) => + paramTypes.exists(param => param.isRepeatedParam) + case t => t.isVarArgsMethod + } end extension + private val exportTargets = collection.mutable.Map.empty[Symbol, Symbol] + override def runOn( + units: List[CompilationUnit] + )(using Context): List[CompilationUnit] = { + // Collect information about exported method dependencies with run + val traverser = new TreeTraverser { + override def traverse(tree: Tree)(using Context): Unit = tree match { + case dd: DefDef => + val sym = dd.symbol + if sym.is(Exported) + then exportTargets.update(sym, dd.rhs.symbol) + case tree => traverseChildren(tree) + } + } + for unit <- units + do traverser.traverse(unit.tpdTree) + + // Execute standard run + try super.runOn(units) + finally exportTargets.clear() + } + override def transformDefDef(dd: DefDef)(using Context): Tree = { val sym = dd.symbol - lazy val rhsSym = dd.rhs.symbol // Set `@extern` annotation for top-level extern functions if (isTopLevelExtern(dd) && !sym.hasAnnotation(defnNir.ExternClass)) { sym.addAnnotation(defnNir.ExternClass) @@ -73,13 +101,8 @@ class PrepNativeInterop extends PluginPhase { else if sym.isExported then report.error("Exported method cannot be inlined", dd.srcPos) - def usesVariadicArgs = sym.paramInfo.stripPoly match { - case MethodTpe(paramNames, paramTypes, _) => - paramTypes.exists(param => param.isRepeatedParam) - case t => t.isVarArgsMethod - } - - if sym.is(Exported) && rhsSym.isExtern && usesVariadicArgs + lazy val exportTarget = finalExportTarget(dd.rhs.symbol) + if sym.is(Exported) && sym.usesVariadicArgs && exportTarget.isExtern then // Externs with varargs need to be called directly, replace proxy // with redifintion of extern method @@ -90,6 +113,18 @@ class PrepNativeInterop extends PluginPhase { else dd } + private def finalExportTarget(sym: Symbol): Symbol = { + var current = sym + while exportTargets + .get(current) + .match + case Some(target) if target ne NoSymbol => + current = target; true // continue search + case _ => false // final target found + do () + current + } + override def transformValDef(vd: ValDef)(using Context): Tree = { val enumsCtx = EnumerationsContext.get import enumsCtx._ diff --git a/nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala b/nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala deleted file mode 100644 index 252b276a3a..0000000000 --- a/nscplugin/src/test/scala-3/scala/scalanative/linker/TopLevelExternsTest.scala +++ /dev/null @@ -1,42 +0,0 @@ -package scala.scalanative -package linker - -import org.junit.Test -import org.junit.Assert._ - -class TopLevelExternsTest { - - @Test def topLevelExternAnnotations(): Unit = { - val PackageModule = nir.Global.Top("Main$package$") - val ExternFunctionSymbol = - PackageModule.member(nir.Sig.Extern("externFunction")) - - compileAndLoad( - "Main.scala" -> """ - |import scala.scalanative.unsafe.{link, define, extern} - |@extern - |@link("MyCustomLink") - |@define("MyCustomDefn") - |def externFunction(): Unit = extern - """.stripMargin - ) { defns => - defns - .find(_.name == ExternFunctionSymbol) - .orElse { fail("Not found extern function definition"); None } - .foreach { defn => - assertTrue("isExtern", defn.attrs.isExtern) - assertEquals( - "link", - Some(nir.Attr.Link("MyCustomLink")), - defn.attrs.links.headOption - ) - assertEquals( - "define", - Some(nir.Attr.Define("MyCustomDefn")), - defn.attrs.preprocessorDefinitions.headOption - ) - } - } - } - -} diff --git a/nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala b/nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala deleted file mode 100644 index ed2991e4fc..0000000000 --- a/nscplugin/src/test/scala/scala/scalanative/linker/MethodAttributesTest.scala +++ /dev/null @@ -1,80 +0,0 @@ -package scala.scalanative -package linker - -import org.junit.Test -import org.junit.Assert._ - -class MethodAttributesTest { - - @Test def explicitLinkOrDefine(): Unit = { - compileAndLoad( - "Test.scala" -> - """ - |import scala.scalanative.unsafe.{extern, link, define} - |@link("common-lib") - |@define("common-define") - |@extern object Foo { - | @link("custom-lib") def withLink(): Int = extern - | @define("custom-define") def withDefine(): Int = extern - | def default(): Int = extern - |} - """.stripMargin - ) { defns => - val Module = nir.Global.Top("Foo$") - val WithLinkMethod = Module.member(nir.Sig.Extern("withLink")) - val WithDefineMethod = Module.member(nir.Sig.Extern("withDefine")) - val DefaultMethod = Module.member(nir.Sig.Extern("default")) - - val CommonLink = nir.Attr.Link("common-lib") - val CustomLink = nir.Attr.Link("custom-lib") - val CommonDefine = nir.Attr.Define("common-define") - val CustomDefine = nir.Attr.Define("custom-define") - - val expected = - Seq(Module, WithLinkMethod, WithDefineMethod, DefaultMethod) - val found = defns.filter { defn => - def checkLink(value: nir.Attr.Link, expected: Boolean) = assertEquals( - s"${defn.name} - ${value}", - expected, - defn.attrs.links.contains(value) - ) - def checkDefine(value: nir.Attr.Define, expected: Boolean) = - assertEquals( - s"${defn.name} - ${value}", - expected, - defn.attrs.preprocessorDefinitions.contains(value) - ) - - defn.name match { - case Module => - checkLink(CommonLink, true) - checkLink(CustomLink, false) - checkDefine(CommonDefine, true) - checkDefine(CustomDefine, false) - case WithLinkMethod => - checkLink(CommonLink, false) // defined in module - checkLink(CustomLink, true) - checkDefine(CommonDefine, false) // defined in module - checkDefine(CustomDefine, false) - case WithDefineMethod => - checkLink(CommonLink, false) // defined in module - checkLink(CustomLink, false) - checkDefine(CommonDefine, false) // defined in module - checkDefine(CustomDefine, true) - case DefaultMethod => - checkLink(CommonLink, false) // defined in module - checkLink(CustomLink, false) - checkDefine(CommonDefine, false) // defined in module - checkDefine(CustomDefine, false) - case _ => () - } - expected.contains(defn.name) - } - assertTrue( - s"not found some defns, ${found.map(_.name)}", - found.size == expected.size - ) - } - } - -} diff --git a/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala b/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala index b928819c94..cb71952c6b 100644 --- a/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala +++ b/posixlib/src/main/scala/scala/scalanative/posix/syslog.scala @@ -20,17 +20,17 @@ import scalanative.posix.stdio.va_list @extern object syslog { @name("scalanative_closelog") - @blocking def closelog(): Unit = extern + def closelog(): Unit = extern @name("scalanative_openlog") - @blocking def openlog(ident: CString, logopt: CInt, facility: CInt): Unit = + def openlog(ident: CString, logopt: CInt, facility: CInt): Unit = extern @name("scalanative_setlogmask") - @blocking def setlogmask(maskpri: CInt): CInt = extern + def setlogmask(maskpri: CInt): CInt = extern // "glue" code is not used here so that implementation of va_list is simpler. - @blocking def syslog(priority: CInt, format: CString, vargs: Any*): Unit = + def syslog(priority: CInt, format: CString, vargs: Any*): Unit = extern @name("scalanative_log_emerg") diff --git a/tools/src/test/scala-3/scala/NativeCompilerTest.scala b/tools/src/test/scala-3/scala/NativeCompilerTest.scala index 67928365f3..bf411ff089 100644 --- a/tools/src/test/scala-3/scala/NativeCompilerTest.scala +++ b/tools/src/test/scala-3/scala/NativeCompilerTest.scala @@ -99,3 +99,39 @@ class NativeCompilerTest extends AnyFlatSpec: |}""".stripMargin ) } + + it should "issue3231 allow MultiLevel Export" in { + // Exporting extern function should work for recursive exports + compileAll( + "level_1.scala" -> s""" + |package issue.level1 + | + |import scala.scalanative.unsafe.extern + | + |@extern + |private[issue] object extern_functions: + | def test(bla: Int, args: Any*): Unit = extern + | + |export extern_functions.* // should comppile + | + """.stripMargin, + "level_2.scala" -> s""" + |package issue.level2 + | + |export _root_.issue.level1.test + | + """.stripMargin, + "level_3.scala" -> s""" + |package issue.level3 + | + |export _root_.issue.level2.test + | + """.stripMargin, + "level_4.scala" -> s""" + |package issue.level4 + | + |export _root_.issue.level3.test + | + """.stripMargin + ) + } From 0f67dae98b73bf44daaa529042b4a073b6bd4373 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 21 Dec 2023 14:46:18 +0100 Subject: [PATCH 22/38] Mitigate refactor of `dotty.tools.dotc.transform.SymUtils` Fix compilation of junitPlugin (cherry picked from commit 4cd803747bc12026e48108d18b23cb0d2c37b662) --- .../junit/plugin/JUnitDefinitions.scala | 5 +++-- .../plugin/ScalaNativeJUnitBootstrappers.scala | 3 +-- .../scalanative/nscplugin/CompilerCompat.scala | 15 +++++++++++++++ .../scalanative/nscplugin/GenNativeExports.scala | 2 +- .../scala/scalanative/nscplugin/NirGenExpr.scala | 2 +- .../scala/scalanative/nscplugin/NirGenName.scala | 4 ++-- .../scala/scalanative/nscplugin/NirGenStat.scala | 4 ++-- .../scala/scalanative/nscplugin/NirGenType.scala | 2 +- .../scala/scalanative/nscplugin/NirGenUtil.scala | 13 ++++++++++--- .../scalanative/nscplugin/NirPositions.scala | 5 +++-- .../scalanative/nscplugin/NirPrimitives.scala | 2 +- .../scalanative/nscplugin/PrepNativeInterop.scala | 6 +++--- project/Build.scala | 3 ++- project/ScalaVersions.scala | 3 ++- project/Settings.scala | 9 +++++++++ 15 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala diff --git a/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/JUnitDefinitions.scala b/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/JUnitDefinitions.scala index f769af1f54..366f89115f 100644 --- a/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/JUnitDefinitions.scala +++ b/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/JUnitDefinitions.scala @@ -7,10 +7,11 @@ import core.Contexts._ import core.Types._ import core.StdNames._ import scala.annotation.threadUnsafe +import scala.compiletime.uninitialized object JUnitDefinitions { - private var cached: JUnitDefinitions = _ - private var lastContext: Context = _ + private var cached: JUnitDefinitions = uninitialized + private var lastContext: Context = uninitialized def defnJUnit(using ctx: Context): JUnitDefinitions = { if (lastContext != ctx) { cached = JUnitDefinitions() diff --git a/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/ScalaNativeJUnitBootstrappers.scala b/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/ScalaNativeJUnitBootstrappers.scala index f2f478499e..cf3771582f 100644 --- a/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/ScalaNativeJUnitBootstrappers.scala +++ b/junit-plugin/src/main/scala-3/scala/scalanative/junit/plugin/ScalaNativeJUnitBootstrappers.scala @@ -90,8 +90,7 @@ class ScalaNativeJUnitBootstrappers extends PluginPhase { Synthetic, List(defn.ObjectType, junitdefn.BootstrapperType), newScope, - coord = testClass.span, - assocFile = testClass.assocFile + coord = testClass.span ).entered val classSym = moduleSym.moduleClass.asClass diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala new file mode 100644 index 0000000000..3562275b6e --- /dev/null +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala @@ -0,0 +1,15 @@ +package scala.scalanative.nscplugin + +object CompilerCompat { + + private object SymUtilsCompatDef: + val SymUtils = dotty.tools.dotc.core.Symbols + + private object SymUtilsCompatSelect: + import SymUtilsCompatDef._ + object Inner { + import dotty.tools.dotc.transform._ + val SymUtilsAlias = SymUtils + } + val SymUtilsCompat = SymUtilsCompatSelect.Inner.SymUtilsAlias +} diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/GenNativeExports.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/GenNativeExports.scala index aefbad369e..c0d1406f38 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/GenNativeExports.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/GenNativeExports.scala @@ -9,7 +9,7 @@ import core.Symbols._ import core.Flags._ import core.Annotations.* import dotty.tools.dotc.report -import dotty.tools.dotc.transform.SymUtils.* +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.* import scala.scalanative.nir import nir._ diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala index a1935baf38..a0e434aa17 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala @@ -22,9 +22,9 @@ import core._ import dotty.tools.FatalError import dotty.tools.dotc.report import dotty.tools.dotc.transform -import transform.SymUtils._ import transform.{ValueClasses, Erasure} import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.* import scala.collection.mutable import scala.scalanative.nir diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenName.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenName.scala index cf357d1480..354fa819b9 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenName.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenName.scala @@ -6,12 +6,12 @@ import core.Contexts._ import core.Symbols._ import core.Flags._ import core.StdNames._ -import dotty.tools.dotc.transform.SymUtils._ -import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.* import scalanative.util.unreachable import scala.scalanative.nir import scala.scalanative.nir._ import scala.language.implicitConversions +import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions trait NirGenName(using Context) { self: NirCodeGen => diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala index 9b5c87f117..870adf1b63 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenStat.scala @@ -10,7 +10,7 @@ import core.Constants._ import core.StdNames._ import core.Flags._ import core.Phases._ -import dotty.tools.dotc.transform.SymUtils._ +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat._ import scala.collection.mutable import scala.scalanative.nir @@ -576,7 +576,7 @@ trait NirGenStat(using Context) { def isInheritedField(f: Symbol) = classSym.directlyInheritedTraits.exists { - _.info.decls.exists(_ matches f.getter) + _.info.decls.exists(_.matches(f.getter)) } for f <- classSym.info.decls diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenType.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenType.scala index d3831e6954..5d6c909aa8 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenType.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenType.scala @@ -13,7 +13,7 @@ import core.StdNames._ import core.TypeErasure._ import dotty.tools.dotc.report import dotty.tools.dotc.typer.TyperPhase -import dotty.tools.dotc.transform.SymUtils._ +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.* import scala.scalanative.nir diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenUtil.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenUtil.scala index 0f4a4361d8..eccc99d78c 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenUtil.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenUtil.scala @@ -6,11 +6,18 @@ import dotty.tools.dotc.core import core.Symbols._ import core.Contexts._ import core.Types._ +import scala.scalanative.util.ScopedVar +import scalanative.util.ScopedVar.scoped +import scala.collection.mutable +import dotty.tools.dotc.core.Names.Name +import dotty.tools.dotc.report +import scala.scalanative.nir +import scala.compiletime.uninitialized import core.Flags._ import scalanative.util.unsupported -import scalanative.util.ScopedVar.scoped import scalanative.nir.Fresh import dotty.tools.dotc.core.Phases + trait NirGenUtil(using Context) { self: NirCodeGen => private lazy val materializeClassTagTypes: Map[Symbol, Symbol] = Map( @@ -166,8 +173,8 @@ trait NirGenUtil(using Context) { self: NirCodeGen => object NirGenUtil { class ContextCached[T](init: Context ?=> T) { - private var lastContext: Context = _ - private var cached: T = _ + private var lastContext: Context = uninitialized + private var cached: T = uninitialized def get(using Context): T = { if (lastContext != ctx) { diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala index f84c377217..1328ec3b71 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala @@ -7,6 +7,7 @@ import dotty.tools.dotc.util.{SourceFile, SourcePosition} import dotty.tools.dotc.util.Spans.Span import GenNIR.URIMap import scalanative.nir +import scala.compiletime.uninitialized class NirPositions(sourceURIMaps: List[GenNIR.URIMap])(using Context) { given fromSourcePosition: Conversion[SourcePosition, nir.Position] = { @@ -33,8 +34,8 @@ class NirPositions(sourceURIMaps: List[GenNIR.URIMap])(using Context) { private object conversionCache { import dotty.tools.dotc.util._ - private var lastDotcSource: SourceFile = _ - private var lastNIRSource: nir.Position.SourceFile = _ + private var lastDotcSource: SourceFile = uninitialized + private var lastNIRSource: nir.Position.SourceFile = uninitialized def toNIRSource(dotcSource: SourceFile): nir.Position.SourceFile = { if (dotcSource != lastDotcSource) { diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPrimitives.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPrimitives.scala index d9beb3e854..9c172e531f 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPrimitives.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPrimitives.scala @@ -125,7 +125,7 @@ class NirPrimitives(using ctx: Context) extends DottyPrimitives(ctx) { val primitives = MutableSymbolMap[Int]() def addPrimitive(s: Symbol, code: Int) = { - assert(!(primitives contains s), "Duplicate primitive " + s) + assert(!(primitives.contains(s)), "Duplicate primitive " + s) assert(s.exists, s"Empty symbol with code $code") primitives(s) = code } diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala index 755bfcadfa..d8ad3f78eb 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala @@ -4,7 +4,7 @@ import dotty.tools.dotc.plugins.PluginPhase import dotty.tools._ import dotc._ import dotc.ast.tpd._ -import dotc.transform.SymUtils._ +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.* import core.Contexts._ import core.Definitions import core.Names._ @@ -132,11 +132,11 @@ class PrepNativeInterop extends PluginPhase { vd match { case ValDef(_, tpt, ScalaEnumValue.NoName(optIntParam)) => val nrhs = scalaEnumValName(sym.owner.asClass, sym, optIntParam) - cpy.ValDef(vd)(tpt = transformAllDeep(tpt), nrhs) + cpy.ValDef(vd)(tpt = transformAllDeep(tpt), rhs = nrhs) case ValDef(_, tpt, ScalaEnumValue.NullName(optIntParam)) => val nrhs = scalaEnumValName(sym.owner.asClass, sym, optIntParam) - cpy.ValDef(vd)(tpt = transformAllDeep(tpt), nrhs) + cpy.ValDef(vd)(tpt = transformAllDeep(tpt), rhs = nrhs) case _ => // Set `@extern` annotation for top-level extern variables diff --git a/project/Build.scala b/project/Build.scala index 0757fda345..6eb8dff577 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -297,7 +297,8 @@ object Build { .settings( mavenPublishSettings, docsSettings, - libraryDependencies ++= Deps.NativeLib(scalaVersion.value) + libraryDependencies ++= Deps.NativeLib(scalaVersion.value), + scalacOptions ++= Settings.ignoredScalaDeprecations(scalaVersion.value) ) .withNativeCompilerPlugin diff --git a/project/ScalaVersions.scala b/project/ScalaVersions.scala index 1011dc1b8e..29b90cb3bc 100644 --- a/project/ScalaVersions.scala +++ b/project/ScalaVersions.scala @@ -23,7 +23,8 @@ object ScalaVersions { val crossScala3 = List( (0 to 3).map(v => s"3.1.$v"), (0 to 2).map(v => s"3.2.$v"), - (0 to 1).map(v => s"3.3.$v") + (0 to 1).map(v => s"3.3.$v"), + Seq("3.4.0-RC1") ).flatten // Version of Scala 3 standard library sources used for publishing diff --git a/project/Settings.scala b/project/Settings.scala index d261dfbdda..7b0e32b04b 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -594,6 +594,15 @@ object Settings { }, exportJars := true ) + lazy val commonJavalibSettings = Def.settings( + recompileAllOrNothingSettings, + noJavaReleaseSettings, // we don't emit classfiles + Compile / scalacOptions ++= scalaNativeCompilerOptions( + "genStaticForwardersForNonTopLevelObjects" + ), + NIROnlySettings, + scalacOptions ++= Settings.ignoredScalaDeprecations(scalaVersion.value), + ) // Calculates all prefixes of the current Scala version // (including the empty prefix) to construct Scala version depenent From 561ae7d0f604d29b4fb2a794267fe37b3268c1e2 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 21 Dec 2023 14:37:33 +0000 Subject: [PATCH 23/38] Fix scalalib overrides (cherry picked from commit c5774c7e932317ff999e2cb00e13dd776b497ace) --- .gitignore | 3 + .../scala/reflect/Selectable.scala.patch | 39 +++++ .../scala/reflect/Selectable.scala.patch | 39 +++++ .../scala/runtime/LazyVals.scala.patch | 0 .../scala/reflect/Selectable.scala2.patch | 39 +++++ .../scala/runtime/LazyVals.scala.patch | 158 ++++++++++++++++++ .../scala/reflect/Selectable.scala.patch | 18 +- .../scala/runtime/LazyVals.scala.patch | 10 +- scripts/scalalib-patch-tool.sc | 8 +- 9 files changed, 299 insertions(+), 15 deletions(-) create mode 100644 scalalib/overrides-3.1/scala/reflect/Selectable.scala.patch create mode 100644 scalalib/overrides-3.2/scala/reflect/Selectable.scala.patch rename scalalib/{overrides-3.2.2 => overrides-3.2}/scala/runtime/LazyVals.scala.patch (100%) create mode 100644 scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch create mode 100644 scalalib/overrides-3.3/scala/runtime/LazyVals.scala.patch diff --git a/.gitignore b/.gitignore index 33beedf109..f8f4a7721b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ bin/ .externalToolBuilders/ .cache* +# scala-cli +**/.scala-build + # metals **/.bloop/ /.metals/ diff --git a/scalalib/overrides-3.1/scala/reflect/Selectable.scala.patch b/scalalib/overrides-3.1/scala/reflect/Selectable.scala.patch new file mode 100644 index 0000000000..9fdb3442ae --- /dev/null +++ b/scalalib/overrides-3.1/scala/reflect/Selectable.scala.patch @@ -0,0 +1,39 @@ +--- 3.1.2/scala/reflect/Selectable.scala ++++ overrides-3/scala/reflect/Selectable.scala +@@ -16,16 +16,16 @@ + */ + protected def selectedValue: Any = this + ++ private def unreachable(methodName: String): Nothing = ++ throw new IllegalStateException( ++ "Reflection is not fully supported in Scala Native. " + ++ s"Call to method scala.reflect.Selectable.$methodName should have been " + ++ "replaced by Scala Native. Please report it to the Scala Native team." ++ ) ++ + // The Scala.js codegen relies on this method being final for correctness + /** Select member with given name */ +- final def selectDynamic(name: String): Any = +- val rcls = selectedValue.getClass +- try +- val fld = rcls.getField(name).nn +- ensureAccessible(fld) +- fld.get(selectedValue) +- catch case ex: NoSuchFieldException => +- applyDynamic(name)() ++ final def selectDynamic(name: String): Any = unreachable("selectDynamic") + + // The Scala.js codegen relies on this method being final for correctness + /** Select method and apply to arguments. +@@ -34,10 +34,7 @@ + * @param args The arguments to pass to the selected method + */ + final def applyDynamic(name: String, paramTypes: Class[_]*)(args: Any*): Any = +- val rcls = selectedValue.getClass +- val mth = rcls.getMethod(name, paramTypes: _*).nn +- ensureAccessible(mth) +- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]: _*) ++ unreachable("applyDynamic") + + object Selectable: + diff --git a/scalalib/overrides-3.2/scala/reflect/Selectable.scala.patch b/scalalib/overrides-3.2/scala/reflect/Selectable.scala.patch new file mode 100644 index 0000000000..9fdb3442ae --- /dev/null +++ b/scalalib/overrides-3.2/scala/reflect/Selectable.scala.patch @@ -0,0 +1,39 @@ +--- 3.1.2/scala/reflect/Selectable.scala ++++ overrides-3/scala/reflect/Selectable.scala +@@ -16,16 +16,16 @@ + */ + protected def selectedValue: Any = this + ++ private def unreachable(methodName: String): Nothing = ++ throw new IllegalStateException( ++ "Reflection is not fully supported in Scala Native. " + ++ s"Call to method scala.reflect.Selectable.$methodName should have been " + ++ "replaced by Scala Native. Please report it to the Scala Native team." ++ ) ++ + // The Scala.js codegen relies on this method being final for correctness + /** Select member with given name */ +- final def selectDynamic(name: String): Any = +- val rcls = selectedValue.getClass +- try +- val fld = rcls.getField(name).nn +- ensureAccessible(fld) +- fld.get(selectedValue) +- catch case ex: NoSuchFieldException => +- applyDynamic(name)() ++ final def selectDynamic(name: String): Any = unreachable("selectDynamic") + + // The Scala.js codegen relies on this method being final for correctness + /** Select method and apply to arguments. +@@ -34,10 +34,7 @@ + * @param args The arguments to pass to the selected method + */ + final def applyDynamic(name: String, paramTypes: Class[_]*)(args: Any*): Any = +- val rcls = selectedValue.getClass +- val mth = rcls.getMethod(name, paramTypes: _*).nn +- ensureAccessible(mth) +- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]: _*) ++ unreachable("applyDynamic") + + object Selectable: + diff --git a/scalalib/overrides-3.2.2/scala/runtime/LazyVals.scala.patch b/scalalib/overrides-3.2/scala/runtime/LazyVals.scala.patch similarity index 100% rename from scalalib/overrides-3.2.2/scala/runtime/LazyVals.scala.patch rename to scalalib/overrides-3.2/scala/runtime/LazyVals.scala.patch diff --git a/scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch b/scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch new file mode 100644 index 0000000000..9aa871e7b5 --- /dev/null +++ b/scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch @@ -0,0 +1,39 @@ +--- 3.4.0-RC1/scala/reflect/Selectable.scala ++++ overrides-3/scala/reflect/Selectable.scala +@@ -16,16 +16,17 @@ + */ + protected def selectedValue: Any = this + ++ private def unreachable(methodName: String): Nothing = ++ throw new IllegalStateException( ++ "Reflection is not fully supported in Scala Native. " + ++ s"Call to method scala.reflect.Selectable.$methodName should have been " + ++ "replaced by Scala Native. Please report it to the Scala Native team." ++ ) ++ + // The Scala.js codegen relies on this method being final for correctness + /** Select member with given name */ + final def selectDynamic(name: String): Any = +- val rcls = selectedValue.getClass +- try +- val fld = rcls.getField(NameTransformer.encode(name)).nn +- ensureAccessible(fld) +- fld.get(selectedValue) +- catch case ex: NoSuchFieldException => +- applyDynamic(name)() ++ unreachable("selectDynamic") + + // The Scala.js codegen relies on this method being final for correctness + /** Select method and apply to arguments. +@@ -34,10 +35,7 @@ + * @param args The arguments to pass to the selected method + */ + final def applyDynamic(name: String, paramTypes: Class[?]*)(args: Any*): Any = +- val rcls = selectedValue.getClass +- val mth = rcls.getMethod(NameTransformer.encode(name), paramTypes*).nn +- ensureAccessible(mth) +- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]*) ++ unreachable("applyDynamic") + + object Selectable: + diff --git a/scalalib/overrides-3.3/scala/runtime/LazyVals.scala.patch b/scalalib/overrides-3.3/scala/runtime/LazyVals.scala.patch new file mode 100644 index 0000000000..a6c24ca33c --- /dev/null +++ b/scalalib/overrides-3.3/scala/runtime/LazyVals.scala.patch @@ -0,0 +1,158 @@ +--- 3.3.0-RC4/scala/runtime/LazyVals.scala ++++ overrides-3/scala/runtime/LazyVals.scala +@@ -4,44 +4,13 @@ + + import scala.annotation.* + ++import scala.scalanative.runtime.* ++ + /** + * Helper methods used in thread-safe lazy vals. + */ + object LazyVals { +- @nowarn +- private[this] val unsafe: sun.misc.Unsafe = { +- def throwInitializationException() = +- throw new ExceptionInInitializerError( +- new IllegalStateException("Can't find instance of sun.misc.Unsafe") +- ) +- try +- val unsafeField = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe").nn +- if unsafeField.getType == classOf[sun.misc.Unsafe] then +- unsafeField.setAccessible(true) +- unsafeField.get(null).asInstanceOf[sun.misc.Unsafe] +- else +- throwInitializationException() +- catch case _: NoSuchFieldException => +- throwInitializationException() +- } +- +- private[this] val base: Int = { +- val processors = java.lang.Runtime.getRuntime.nn.availableProcessors() +- 8 * processors * processors +- } +- +- private[this] val monitors: Array[Object] = +- Array.tabulate(base)(_ => new Object) +- +- private def getMonitor(obj: Object, fieldId: Int = 0) = { +- var id = (java.lang.System.identityHashCode(obj) + fieldId) % base +- +- if (id < 0) id += base +- monitors(id) +- } +- + private final val LAZY_VAL_MASK = 3L +- private final val debug = false + + /* ------------- Start of public API ------------- */ + +@@ -70,94 +39,47 @@ + + def STATE(cur: Long, ord: Int): Long = { + val r = (cur >> (ord * BITS_PER_LAZY_VAL)) & LAZY_VAL_MASK +- if (debug) +- println(s"STATE($cur, $ord) = $r") + r + } + + def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int): Boolean = { +- if (debug) +- println(s"CAS($t, $offset, $e, $v, $ord)") +- val mask = ~(LAZY_VAL_MASK << ord * BITS_PER_LAZY_VAL) +- val n = (e & mask) | (v.toLong << (ord * BITS_PER_LAZY_VAL)) +- unsafe.compareAndSwapLong(t, offset, e, n) ++ unexpectedUsage() + } + + def objCAS(t: Object, offset: Long, exp: Object, n: Object): Boolean = { +- if (debug) +- println(s"objCAS($t, $exp, $n)") +- unsafe.compareAndSwapObject(t, offset, exp, n) ++ unexpectedUsage() + } + + def setFlag(t: Object, offset: Long, v: Int, ord: Int): Unit = { +- if (debug) +- println(s"setFlag($t, $offset, $v, $ord)") +- var retry = true +- while (retry) { +- val cur = get(t, offset) +- if (STATE(cur, ord) == 1) retry = !CAS(t, offset, cur, v, ord) +- else { +- // cur == 2, somebody is waiting on monitor +- if (CAS(t, offset, cur, v, ord)) { +- val monitor = getMonitor(t, ord) +- monitor.synchronized { +- monitor.notifyAll() +- } +- retry = false +- } +- } +- } ++ unexpectedUsage() + } + + def wait4Notification(t: Object, offset: Long, cur: Long, ord: Int): Unit = { +- if (debug) +- println(s"wait4Notification($t, $offset, $cur, $ord)") +- var retry = true +- while (retry) { +- val cur = get(t, offset) +- val state = STATE(cur, ord) +- if (state == 1) CAS(t, offset, cur, 2, ord) +- else if (state == 2) { +- val monitor = getMonitor(t, ord) +- monitor.synchronized { +- if (STATE(get(t, offset), ord) == 2) // make sure notification did not happen yet. +- monitor.wait() +- } +- } +- else retry = false +- } ++ unexpectedUsage() + } + + def get(t: Object, off: Long): Long = { +- if (debug) +- println(s"get($t, $off)") +- unsafe.getLongVolatile(t, off) ++ unexpectedUsage() + } + + // kept for backward compatibility + def getOffset(clz: Class[_], name: String): Long = { +- @nowarn +- val r = unsafe.objectFieldOffset(clz.getDeclaredField(name)) +- if (debug) +- println(s"getOffset($clz, $name) = $r") +- r ++ unexpectedUsage() + } + + def getStaticFieldOffset(field: java.lang.reflect.Field): Long = { +- @nowarn +- val r = unsafe.staticFieldOffset(field) +- if (debug) +- println(s"getStaticFieldOffset(${field.getDeclaringClass}, ${field.getName}) = $r") +- r ++ unexpectedUsage() + } + + def getOffsetStatic(field: java.lang.reflect.Field) = +- @nowarn +- val r = unsafe.objectFieldOffset(field) +- if (debug) +- println(s"getOffset(${field.getDeclaringClass}, ${field.getName}) = $r") +- r ++ unexpectedUsage() + ++ private def unexpectedUsage() = { ++ throw new IllegalStateException( ++ "Unexpected usage of scala.runtime.LazyVals method, " + ++ "in Scala Native lazy vals use overriden version of this class" ++ ) ++ } + + object Names { + final val state = "STATE" diff --git a/scalalib/overrides-3/scala/reflect/Selectable.scala.patch b/scalalib/overrides-3/scala/reflect/Selectable.scala.patch index 9fdb3442ae..9aa871e7b5 100644 --- a/scalalib/overrides-3/scala/reflect/Selectable.scala.patch +++ b/scalalib/overrides-3/scala/reflect/Selectable.scala.patch @@ -1,6 +1,6 @@ ---- 3.1.2/scala/reflect/Selectable.scala +--- 3.4.0-RC1/scala/reflect/Selectable.scala +++ overrides-3/scala/reflect/Selectable.scala -@@ -16,16 +16,16 @@ +@@ -16,16 +16,17 @@ */ protected def selectedValue: Any = this @@ -13,26 +13,26 @@ + // The Scala.js codegen relies on this method being final for correctness /** Select member with given name */ -- final def selectDynamic(name: String): Any = + final def selectDynamic(name: String): Any = - val rcls = selectedValue.getClass - try -- val fld = rcls.getField(name).nn +- val fld = rcls.getField(NameTransformer.encode(name)).nn - ensureAccessible(fld) - fld.get(selectedValue) - catch case ex: NoSuchFieldException => - applyDynamic(name)() -+ final def selectDynamic(name: String): Any = unreachable("selectDynamic") ++ unreachable("selectDynamic") // The Scala.js codegen relies on this method being final for correctness /** Select method and apply to arguments. -@@ -34,10 +34,7 @@ +@@ -34,10 +35,7 @@ * @param args The arguments to pass to the selected method */ - final def applyDynamic(name: String, paramTypes: Class[_]*)(args: Any*): Any = + final def applyDynamic(name: String, paramTypes: Class[?]*)(args: Any*): Any = - val rcls = selectedValue.getClass -- val mth = rcls.getMethod(name, paramTypes: _*).nn +- val mth = rcls.getMethod(NameTransformer.encode(name), paramTypes*).nn - ensureAccessible(mth) -- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]: _*) +- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]*) + unreachable("applyDynamic") object Selectable: diff --git a/scalalib/overrides-3/scala/runtime/LazyVals.scala.patch b/scalalib/overrides-3/scala/runtime/LazyVals.scala.patch index a6c24ca33c..4d4cf9efd5 100644 --- a/scalalib/overrides-3/scala/runtime/LazyVals.scala.patch +++ b/scalalib/overrides-3/scala/runtime/LazyVals.scala.patch @@ -1,4 +1,4 @@ ---- 3.3.0-RC4/scala/runtime/LazyVals.scala +--- 3.4.0-RC1/scala/runtime/LazyVals.scala +++ overrides-3/scala/runtime/LazyVals.scala @@ -4,44 +4,13 @@ @@ -12,7 +12,7 @@ object LazyVals { - @nowarn - private[this] val unsafe: sun.misc.Unsafe = { -- def throwInitializationException() = +- def throwInitializationException() = - throw new ExceptionInInitializerError( - new IllegalStateException("Can't find instance of sun.misc.Unsafe") - ) @@ -27,12 +27,12 @@ - throwInitializationException() - } - -- private[this] val base: Int = { +- private val base: Int = { - val processors = java.lang.Runtime.getRuntime.nn.availableProcessors() - 8 * processors * processors - } - -- private[this] val monitors: Array[Object] = +- private val monitors: Array[Object] = - Array.tabulate(base)(_ => new Object) - - private def getMonitor(obj: Object, fieldId: Int = 0) = { @@ -121,7 +121,7 @@ } // kept for backward compatibility - def getOffset(clz: Class[_], name: String): Long = { + def getOffset(clz: Class[?], name: String): Long = { - @nowarn - val r = unsafe.objectFieldOffset(clz.getDeclaredField(name)) - if (debug) diff --git a/scripts/scalalib-patch-tool.sc b/scripts/scalalib-patch-tool.sc index 01b6488aab..c8a73dc71f 100644 --- a/scripts/scalalib-patch-tool.sc +++ b/scripts/scalalib-patch-tool.sc @@ -201,7 +201,13 @@ def sourcesExistsOrFetch(scalaVersion: String, sourcesDir: os.Path)(implicit ) = { if (!exists(sourcesDir)) { println(s"Fetching Scala $scalaVersion sources") - os.proc("sbt", s"++ $scalaVersion", "scalalib/fetchScalaSource").call() + val suffix = scalaVersion match { + case s"2.12.${patch}" => "2_12" + case s"2.13.${patch}" => "2_13" + case s"3.${minor}.${patch}" => "3" + } + os.proc("sbt", s"++ $scalaVersion", s"scalalib${suffix}/fetchScalaSource") + .call() } assert(os.exists(sourcesDir), s"Sources at $sourcesDir missing") } From 55a919f339a56ec6e92e804c772a8a9fd9ff12ab Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 11 Jan 2024 16:23:37 +0100 Subject: [PATCH 24/38] Don't use 3.4.0-RC1 as default, allow to compiler plugin/scalalib tests (cherry picked from commit 1db2894e8bc94e679a18ceb8b93478c984067353) --- project/ScalaVersions.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project/ScalaVersions.scala b/project/ScalaVersions.scala index 29b90cb3bc..b2c0e229d9 100644 --- a/project/ScalaVersions.scala +++ b/project/ScalaVersions.scala @@ -22,9 +22,11 @@ object ScalaVersions { val crossScala213 = (4 to 12).map(v => s"2.13.$v") val crossScala3 = List( (0 to 3).map(v => s"3.1.$v"), + // Bug in compiler leads to errors in tests, don't use it as default until RC2 + Seq("3.4.0-RC1"), + (2 to 3).map(v => s"3.1.$v"), (0 to 2).map(v => s"3.2.$v"), - (0 to 1).map(v => s"3.3.$v"), - Seq("3.4.0-RC1") + (0 to 1).map(v => s"3.3.$v") ).flatten // Version of Scala 3 standard library sources used for publishing From e9e4c77c8438a8690b017682ddc79903649d23eb Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 21 Dec 2023 14:47:08 +0100 Subject: [PATCH 25/38] Handle new language deprecations in Scala 3.4.0 (cherry picked from commit 945fd738eb88f91782efb7d7ba39d77a799720f7) --- .../main/scala/scala/scalanative/nir/Rt.scala | 18 ++++++------ project/Build.scala | 19 +------------ project/Settings.scala | 28 ++++++++++++++++++- .../scala/scala/scalanative/util/Scope.scala | 2 +- .../scala/scalanative/util/ScopedVar.scala | 3 ++ 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/nir/src/main/scala/scala/scalanative/nir/Rt.scala b/nir/src/main/scala/scala/scalanative/nir/Rt.scala index 40183f1d16..cb797f71b2 100644 --- a/nir/src/main/scala/scala/scalanative/nir/Rt.scala +++ b/nir/src/main/scala/scala/scalanative/nir/Rt.scala @@ -40,17 +40,17 @@ object Rt { val ToRawPtrSig = Sig.Method("toRawPtr", Seq(BoxedPtr, Ptr)).mangled val ClassName = Class.name - val ClassIdName = ClassName member Sig.Field("id") - val ClassTraitIdName = ClassName member Sig.Field("traitId") - val ClassNameName = ClassName member Sig.Field("name") - val ClassSizeName = ClassName member Sig.Field("size") - val ClassIdRangeUntilName = ClassName member Sig.Field("idRangeUntil") + val ClassIdName = ClassName.member(Sig.Field("id")) + val ClassTraitIdName = ClassName.member(Sig.Field("traitId")) + val ClassNameName = ClassName.member(Sig.Field("name")) + val ClassSizeName = ClassName.member(Sig.Field("size")) + val ClassIdRangeUntilName = ClassName.member(Sig.Field("idRangeUntil")) val StringName = String.name - val StringValueName = StringName member Sig.Field("value") - val StringOffsetName = StringName member Sig.Field("offset") - val StringCountName = StringName member Sig.Field("count") - val StringCachedHashCodeName = StringName member Sig.Field("cachedHashCode") + val StringValueName = StringName.member(Sig.Field("value")) + val StringOffsetName = StringName.member(Sig.Field("offset")) + val StringCountName = StringName.member(Sig.Field("count")) + val StringCachedHashCodeName = StringName.member(Sig.Field("cachedHashCode")) val PrimitiveTypes: Seq[Global.Top] = Seq( "Byte", diff --git a/project/Build.scala b/project/Build.scala index 6eb8dff577..1328c28949 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -140,24 +140,7 @@ object Build { .settings( libraryDependencies ++= Deps.Tools(scalaVersion.value), Test / fork := true, - scalacOptions ++= { - val scala213StdLibDeprecations = Seq( - // In 2.13 lineStream_! was replaced with lazyList_!. - "method lineStream_!", - // OpenHashMap is used with value class parameter type, we cannot replace it with AnyRefMap or LongMap - // Should not be replaced with HashMap due to performance reasons. - "class|object OpenHashMap", - "class Stream", - "method retain in trait SetOps" - ).map(msg => s"-Wconf:cat=deprecation&msg=$msg:s") - CrossVersion - .partialVersion(scalaVersion.value) - .fold(Seq.empty[String]) { - case (2, 12) => Nil - case (2, 13) => scala213StdLibDeprecations - case (3, _) => scala213StdLibDeprecations - } - }, + // Running tests in parallel results in `FileSystemAlreadyExistsException` Test / parallelExecution := false ) diff --git a/project/Settings.scala b/project/Settings.scala index 7b0e32b04b..a16d851e81 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -555,9 +555,35 @@ object Settings { lazy val toolSettings: Seq[Setting[_]] = Def.settings( - javacOptions ++= Seq("-encoding", "utf8") + javacOptions ++= Seq("-encoding", "utf8"), + scalacOptions ++= ignoredScalaDeprecations(scalaVersion.value) ) + def ignoredScalaDeprecations(scalaVersion: String): Seq[String] = { + def scala213StdLibDeprecations = Seq( + // In 2.13 lineStream_! was replaced with lazyList_!. + "method lineStream_!", + // OpenHashMap is used with value class parameter type, we cannot replace it with AnyRefMap or LongMap + // Should not be replaced with HashMap due to performance reasons. + "class|object OpenHashMap", + "class Stream", + "method retain in trait SetOps" + ).map(msg => s"-Wconf:cat=deprecation&msg=$msg:s") + + def scala3Deprecations = Seq( + "`= _` has been deprecated", + "`_` is deprecated for wildcard arguments of types" + ).map(msg => s"-Wconf:msg=$msg:s") + + CrossVersion + .partialVersion(scalaVersion) + .fold(Seq.empty[String]) { + case (2, 12) => Nil + case (2, 13) => scala213StdLibDeprecations + case (3, _) => scala213StdLibDeprecations ++ scala3Deprecations + } + } + lazy val recompileAllOrNothingSettings = Def.settings( /* Recompile all sources when at least 1/10,000 of the source files have * changed, i.e., as soon as at least one source file changed. diff --git a/util/src/main/scala/scala/scalanative/util/Scope.scala b/util/src/main/scala/scala/scalanative/util/Scope.scala index 0a665d4075..2c73e92cfb 100644 --- a/util/src/main/scala/scala/scalanative/util/Scope.scala +++ b/util/src/main/scala/scala/scalanative/util/Scope.scala @@ -47,7 +47,7 @@ object Scope { private sealed class Impl extends Scope { type Resources = List[Resource] - private[this] val resources = new AtomicReference[Resources](Nil) + private val resources = new AtomicReference[Resources](Nil) def acquire(res: Resource): Unit = { resources.getAndUpdate { diff --git a/util/src/main/scala/scala/scalanative/util/ScopedVar.scala b/util/src/main/scala/scala/scalanative/util/ScopedVar.scala index 1153985e2b..4298b4391c 100644 --- a/util/src/main/scala/scala/scalanative/util/ScopedVar.scala +++ b/util/src/main/scala/scala/scalanative/util/ScopedVar.scala @@ -2,11 +2,13 @@ package scala.scalanative package util import language.implicitConversions +import scala.annotation.nowarn class ScopedVar[A] { import ScopedVar.Assignment private var init = false + @nowarn private var value: A = _ def get: A = if (!init) throw ScopedVar.Unitialized() else value @@ -38,6 +40,7 @@ object ScopedVar { implicit def toValue[T](scVar: ScopedVar[T]): T = scVar.get + @nowarn def scoped[T](ass: Assignment[_]*)(body: => T): T = { val stack = ass.map(_.push()) try body From 07cd776eb4584993bb0653452ccea9417d62fb1f Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 21 Dec 2023 15:04:08 +0100 Subject: [PATCH 26/38] Replace usage of deprecated `private[this]` with `private` (cherry picked from commit 4e7a21d831e19cdf9b9e810df08b171227440ec7) --- .../src/main/scala/java/util/Locale.scala | 4 +- .../java/nio/file/StandardCopyOption.scala | 2 +- .../java/nio/file/StandardOpenOption.scala | 2 +- .../file/attribute/PosixFilePermission.scala | 2 +- .../java/util/concurrent/TimeUnit.scala | 2 +- .../scala/java/io/BufferedInputStream.scala | 2 +- .../main/scala/java/io/BufferedReader.scala | 10 +-- javalib/src/main/scala/java/io/File.scala | 2 +- .../scala/java/io/InputStreamReader.scala | 12 ++-- .../main/scala/java/io/LineNumberReader.scala | 8 +-- .../scala/java/io/OutputStreamWriter.scala | 10 +-- .../src/main/scala/java/io/PrintStream.scala | 4 +- .../src/main/scala/java/io/PrintWriter.scala | 4 +- .../src/main/scala/java/io/StringReader.scala | 6 +- .../src/main/scala/java/lang/Character.scala | 70 +++++++++---------- javalib/src/main/scala/java/lang/String.scala | 2 +- .../src/main/scala/java/lang/Throwables.scala | 6 +- .../main/scala/java/lang/process/PipeIO.scala | 2 +- .../lang/process/ProcessBuilderImpl.scala | 2 +- .../java/lang/process/WindowsProcess.scala | 6 +- .../main/scala/java/lang/ref/Reference.scala | 2 +- .../src/main/scala/java/net/URLEncoder.scala | 4 +- .../scala/java/nio/MappedByteBufferImpl.scala | 2 +- .../java/nio/charset/CharsetDecoder.scala | 8 +-- .../java/nio/charset/CharsetEncoder.scala | 8 +-- .../main/scala/java/nio/file/AccessMode.scala | 2 +- .../PosixFileAttributeViewImpl.scala | 14 ++-- .../cert/CertificateEncodingException.scala | 4 +- .../src/main/scala/java/util/ArrayList.scala | 10 +-- .../main/scala/java/util/FormatterImpl.scala | 4 +- .../src/main/scala/java/util/HashMap.scala | 26 +++---- .../main/scala/java/util/LinkedHashMap.scala | 4 +- .../main/scala/java/util/PriorityQueue.scala | 18 ++--- .../main/scala/java/util/RedBlackTree.scala | 52 +++++++------- .../concurrent/atomic/AtomicInteger.scala | 2 +- .../util/concurrent/atomic/AtomicLong.scala | 2 +- .../scala/java/util/stream/Collector.scala | 2 +- .../scalanative/nio/fs/FileHelpers.scala | 2 +- .../scala/scala/scalanative/junit/Ansi.scala | 2 +- .../scala/scalanative/junit/JUnitTask.scala | 2 +- .../scalanative/runtime/MemoryPool.scala | 16 ++--- .../scala/scalanative/posix/sys/select.scala | 2 +- .../testinterface/common/RPCCore.scala | 8 +-- .../testinterface/common/RunMuxRPC.scala | 2 +- .../src/main/scala-2/sbt/testing/Status.scala | 2 +- .../testinterface/TestAdapterBridge.scala | 2 +- .../scalanative/testinterface/ComRunner.scala | 4 +- .../testinterface/NativeRunnerRPC.scala | 2 +- .../testinterface/ProcessRunner.scala | 6 +- .../testinterface/adapter/TestAdapter.scala | 8 +-- .../scala/issues/Scala3IssuesTest.scala | 2 +- .../javalib/io/InputStreamReaderTest.scala | 2 +- .../javalib/security/TimestampTest.scala | 2 +- .../javalib/util/AbstractCollectionTest.scala | 4 +- .../util/function/BiPredicateTest.scala | 2 +- .../javalib/util/function/FunctionTest.scala | 2 +- 56 files changed, 197 insertions(+), 197 deletions(-) diff --git a/javalib-ext-dummies/src/main/scala/java/util/Locale.scala b/javalib-ext-dummies/src/main/scala/java/util/Locale.scala index ec6d34e747..01d869199c 100644 --- a/javalib-ext-dummies/src/main/scala/java/util/Locale.scala +++ b/javalib-ext-dummies/src/main/scala/java/util/Locale.scala @@ -15,9 +15,9 @@ final class Locale( ) extends Serializable with Cloneable { - private[this] val language: String = languageRaw.toLowerCase() + private val language: String = languageRaw.toLowerCase() - private[this] val country: String = countryRaw.toUpperCase() + private val country: String = countryRaw.toUpperCase() if (language == null || country == null || variant == null) throw new NullPointerException() diff --git a/javalib/src/main/scala-2/java/nio/file/StandardCopyOption.scala b/javalib/src/main/scala-2/java/nio/file/StandardCopyOption.scala index 6face92119..068f477680 100644 --- a/javalib/src/main/scala-2/java/nio/file/StandardCopyOption.scala +++ b/javalib/src/main/scala-2/java/nio/file/StandardCopyOption.scala @@ -12,7 +12,7 @@ object StandardCopyOption { def values(): Array[StandardCopyOption] = _values.clone() - private[this] val _values = + private val _values = Array(REPLACE_EXISTING, COPY_ATTRIBUTES, ATOMIC_MOVE) } diff --git a/javalib/src/main/scala-2/java/nio/file/StandardOpenOption.scala b/javalib/src/main/scala-2/java/nio/file/StandardOpenOption.scala index 6c7f5b505c..8cdc197f6e 100644 --- a/javalib/src/main/scala-2/java/nio/file/StandardOpenOption.scala +++ b/javalib/src/main/scala-2/java/nio/file/StandardOpenOption.scala @@ -19,7 +19,7 @@ object StandardOpenOption { def values(): Array[StandardOpenOption] = _values.clone() - private[this] val _values = Array( + private val _values = Array( READ, WRITE, APPEND, diff --git a/javalib/src/main/scala-2/java/nio/file/attribute/PosixFilePermission.scala b/javalib/src/main/scala-2/java/nio/file/attribute/PosixFilePermission.scala index 210674aa98..4d9234e07c 100644 --- a/javalib/src/main/scala-2/java/nio/file/attribute/PosixFilePermission.scala +++ b/javalib/src/main/scala-2/java/nio/file/attribute/PosixFilePermission.scala @@ -17,7 +17,7 @@ object PosixFilePermission { def values: Array[PosixFilePermission] = _values.clone() - private[this] val _values = Array( + private val _values = Array( OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, diff --git a/javalib/src/main/scala-2/java/util/concurrent/TimeUnit.scala b/javalib/src/main/scala-2/java/util/concurrent/TimeUnit.scala index 646d24e255..563f548f4f 100644 --- a/javalib/src/main/scala-2/java/util/concurrent/TimeUnit.scala +++ b/javalib/src/main/scala-2/java/util/concurrent/TimeUnit.scala @@ -96,7 +96,7 @@ object TimeUnit { def toDays(a: Long): Long = a } - private[this] val _values: Array[TimeUnit] = + private val _values: Array[TimeUnit] = Array( NANOSECONDS, MICROSECONDS, diff --git a/javalib/src/main/scala/java/io/BufferedInputStream.scala b/javalib/src/main/scala/java/io/BufferedInputStream.scala index ee7401277c..ea3321ab23 100644 --- a/javalib/src/main/scala/java/io/BufferedInputStream.scala +++ b/javalib/src/main/scala/java/io/BufferedInputStream.scala @@ -28,7 +28,7 @@ class BufferedInputStream(_in: InputStream, initialSize: Int) */ protected[this] var count: Int = 0 - private[this] var closed: Boolean = false + private var closed: Boolean = false /** The maximum read ahead allowed after a call to the mark method before* * subsequent calls to the reset method fail. diff --git a/javalib/src/main/scala/java/io/BufferedReader.scala b/javalib/src/main/scala/java/io/BufferedReader.scala index 7ad3ed48a2..15f7779c70 100644 --- a/javalib/src/main/scala/java/io/BufferedReader.scala +++ b/javalib/src/main/scala/java/io/BufferedReader.scala @@ -10,17 +10,17 @@ class BufferedReader(in: Reader, sz: Int) extends Reader { def this(in: Reader) = this(in, 4096) - private[this] var buf = new Array[Char](sz) + private var buf = new Array[Char](sz) /** Last valid value in the buffer (exclusive) */ - private[this] var end = 0 + private var end = 0 /** Next position to read from buffer */ - private[this] var pos = 0 + private var pos = 0 - private[this] var closed = false + private var closed = false - private[this] var validMark = false + private var validMark = false override def close(): Unit = if (!closed) { in.close() diff --git a/javalib/src/main/scala/java/io/File.scala b/javalib/src/main/scala/java/io/File.scala index b20cfa1108..629dbe195a 100644 --- a/javalib/src/main/scala/java/io/File.scala +++ b/javalib/src/main/scala/java/io/File.scala @@ -624,7 +624,7 @@ class File(_path: String) extends Serializable with Comparable[File] { } } - private[this] def checkWindowsAccess( + private def checkWindowsAccess( access: windows.DWord )(implicit zone: Zone): Boolean = { // based on this article https://blog.aaronballman.com/2011/08/how-to-check-access-rights/ diff --git a/javalib/src/main/scala/java/io/InputStreamReader.scala b/javalib/src/main/scala/java/io/InputStreamReader.scala index d6e1d6eeb8..fc3683d905 100644 --- a/javalib/src/main/scala/java/io/InputStreamReader.scala +++ b/javalib/src/main/scala/java/io/InputStreamReader.scala @@ -6,27 +6,27 @@ import java.nio.charset._ import java.util.Objects class InputStreamReader( - private[this] var in: InputStream, - private[this] var decoder: CharsetDecoder + private var in: InputStream, + private var decoder: CharsetDecoder ) extends Reader { Objects.requireNonNull(in) Objects.requireNonNull(decoder) - private[this] var closed: Boolean = false + private var closed: Boolean = false /** Buffer in which to read bytes from the underlying input stream. * * Class invariant: contains bytes already read from `in` but not yet * decoded. */ - private[this] var inBuf: ByteBuffer = ByteBuffer.allocate(4096) + private var inBuf: ByteBuffer = ByteBuffer.allocate(4096) inBuf.limit(0) /** Tells whether the end of the underlying input stream has been reached. * Class invariant: if true, then `in.read()` has returned -1. */ - private[this] var endOfInput: Boolean = false + private var endOfInput: Boolean = false /** Buffer in which to decode bytes into chars. Usually, it is not used, * because we try to decode directly to the destination array. So as long as @@ -35,7 +35,7 @@ class InputStreamReader( * Class invariant: contains chars already decoded but not yet *read* by the * user of this instance. */ - private[this] var outBuf: CharBuffer = + private var outBuf: CharBuffer = InputStreamReader.CommonEmptyCharBuffer def this(in: InputStream, charset: Charset) = diff --git a/javalib/src/main/scala/java/io/LineNumberReader.scala b/javalib/src/main/scala/java/io/LineNumberReader.scala index ed7faf6ce9..be6dbf7a00 100644 --- a/javalib/src/main/scala/java/io/LineNumberReader.scala +++ b/javalib/src/main/scala/java/io/LineNumberReader.scala @@ -5,10 +5,10 @@ package java.io class LineNumberReader(in: Reader, sz: Int) extends BufferedReader(in, sz) { def this(in: Reader) = this(in, 4096) - private[this] var lineNumber: Int = 0 - private[this] var lastWasCR: Boolean = false - private[this] var markedLineNumber: Int = -1 - private[this] var markedLastWasCR: Boolean = false + private var lineNumber: Int = 0 + private var lastWasCR: Boolean = false + private var markedLineNumber: Int = -1 + private var markedLastWasCR: Boolean = false override def mark(readAheadLimit: Int): Unit = { super.mark(readAheadLimit) diff --git a/javalib/src/main/scala/java/io/OutputStreamWriter.scala b/javalib/src/main/scala/java/io/OutputStreamWriter.scala index ee2b179e7b..9de0be4121 100644 --- a/javalib/src/main/scala/java/io/OutputStreamWriter.scala +++ b/javalib/src/main/scala/java/io/OutputStreamWriter.scala @@ -6,27 +6,27 @@ import java.nio.charset._ import java.util.Objects class OutputStreamWriter( - private[this] var out: OutputStream, - private[this] var enc: CharsetEncoder + private var out: OutputStream, + private var enc: CharsetEncoder ) extends Writer { Objects.requireNonNull(out) Objects.requireNonNull(enc) - private[this] var closed: Boolean = false + private var closed: Boolean = false /** Incoming buffer: pending Chars that have been written to this instance of * OutputStreamWriter, but not yet encoded. Normally, this should always be * at most 1 Char, if it is a high surrogate which ended up alone at the end * of the input of a write(). */ - private[this] var inBuf: String = "" + private var inBuf: String = "" /** Outgoing buffer: Bytes that have been decoded (from `inBuf`), but not yet * written to the underlying output stream. The valid bytes are between 0 and * outBuf.position. */ - private[this] var outBuf: ByteBuffer = ByteBuffer.allocate(4096) + private var outBuf: ByteBuffer = ByteBuffer.allocate(4096) def this(out: OutputStream, cs: Charset) = { this( diff --git a/javalib/src/main/scala/java/io/PrintStream.scala b/javalib/src/main/scala/java/io/PrintStream.scala index 49356ff9de..6fc033a31c 100644 --- a/javalib/src/main/scala/java/io/PrintStream.scala +++ b/javalib/src/main/scala/java/io/PrintStream.scala @@ -224,7 +224,7 @@ class PrintStream private ( this } - @inline private[this] def trapIOExceptions(body: => Unit): Unit = { + @inline private def trapIOExceptions(body: => Unit): Unit = { try { body } catch { @@ -232,7 +232,7 @@ class PrintStream private ( } } - @inline private[this] def ensureOpenAndTrapIOExceptions( + @inline private def ensureOpenAndTrapIOExceptions( body: => Unit ): Unit = { if (closed) setError() diff --git a/javalib/src/main/scala/java/io/PrintWriter.scala b/javalib/src/main/scala/java/io/PrintWriter.scala index 8789b94209..b57b40a87d 100644 --- a/javalib/src/main/scala/java/io/PrintWriter.scala +++ b/javalib/src/main/scala/java/io/PrintWriter.scala @@ -160,7 +160,7 @@ class PrintWriter(protected[io] var out: Writer, autoFlush: Boolean) this } - @inline private[this] def trapIOExceptions(body: => Unit): Unit = { + @inline private def trapIOExceptions(body: => Unit): Unit = { try { body } catch { @@ -168,7 +168,7 @@ class PrintWriter(protected[io] var out: Writer, autoFlush: Boolean) } } - @inline private[this] def ensureOpenAndTrapIOExceptions( + @inline private def ensureOpenAndTrapIOExceptions( body: => Unit ): Unit = { if (closed) setError() diff --git a/javalib/src/main/scala/java/io/StringReader.scala b/javalib/src/main/scala/java/io/StringReader.scala index bb78cd2cfb..987790aaba 100644 --- a/javalib/src/main/scala/java/io/StringReader.scala +++ b/javalib/src/main/scala/java/io/StringReader.scala @@ -2,9 +2,9 @@ package java.io class StringReader(s: String) extends Reader { - private[this] var closed = false - private[this] var pos = 0 - private[this] var mark = 0 + private var closed = false + private var pos = 0 + private var mark = 0 override def close(): Unit = { closed = true diff --git a/javalib/src/main/scala/java/lang/Character.scala b/javalib/src/main/scala/java/lang/Character.scala index 17cef56d85..9adbb3f8bd 100644 --- a/javalib/src/main/scala/java/lang/Character.scala +++ b/javalib/src/main/scala/java/lang/Character.scala @@ -435,11 +435,11 @@ object Character { } @inline - private[this] def getTypeLT256(codePoint: Int): scala.Byte = + private def getTypeLT256(codePoint: Int): scala.Byte = charTypesFirst256(codePoint) // Ported from Scala.js, commit: ac38a148, dated: 2020-09-25 - private[this] def getTypeGE256(codePoint: Int): scala.Byte = { + private def getTypeGE256(codePoint: Int): scala.Byte = { charTypes( findIndexOfRange(charTypeIndices, codePoint, hasEmptyRanges = false) ) @@ -468,7 +468,7 @@ object Character { * digits 1 to 9, in order. Conversely, there are no other non-ASCII code * point mapping to digits from 0 to 9. */ - private[this] lazy val nonASCIIZeroDigitCodePoints: Array[Int] = { + private lazy val nonASCIIZeroDigitCodePoints: Array[Int] = { Array[Int](0x660, 0x6f0, 0x7c0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xbe6, 0xc66, 0xce6, 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x1090, 0x17e0, 0x1810, 0x1946, 0x19d0, 0x1a80, 0x1a90, 0x1b50, 0x1bb0, 0x1c40, 0x1c50, 0xa620, @@ -563,7 +563,7 @@ object Character { def isSpaceChar(codePoint: Int): scala.Boolean = isSpaceCharImpl(getType(codePoint)) - @inline private[this] def isSpaceCharImpl(tpe: Int): scala.Boolean = + @inline private def isSpaceCharImpl(tpe: Int): scala.Boolean = tpe == SPACE_SEPARATOR || tpe == LINE_SEPARATOR || tpe == PARAGRAPH_SEPARATOR // --- UTF-16 surrogate pairs handling --- @@ -601,7 +601,7 @@ object Character { isLowerCaseGE256(c) } - private[this] def isLowerCaseGE256(c: Int): scala.Boolean = { + private def isLowerCaseGE256(c: Int): scala.Boolean = { ('\u02B0' <= c && c <= '\u02B8') || ('\u02C0' <= c && c <= '\u02C1') || ('\u02E0' <= c && c <= '\u02E4') || c == '\u0345' || c == '\u037A' || ('\u1D2C' <= c && c <= '\u1D6A') || c == '\u1D78' || @@ -636,7 +636,7 @@ object Character { if (cp < 256) false else isTitleCaseImpl(getTypeGE256(cp)) - @inline private[this] def isTitleCaseImpl(tpe: Int): scala.Boolean = + @inline private def isTitleCaseImpl(tpe: Int): scala.Boolean = tpe == TITLECASE_LETTER def isDigit(c: scala.Char): scala.Boolean = @@ -646,7 +646,7 @@ object Character { if (cp < 256) '0' <= cp && cp <= '9' else isDigitImpl(getTypeGE256(cp)) - @inline private[this] def isDigitImpl(tpe: Int): scala.Boolean = + @inline private def isDigitImpl(tpe: Int): scala.Boolean = tpe == DECIMAL_DIGIT_NUMBER def isDefined(c: scala.Char): scala.Boolean = @@ -662,7 +662,7 @@ object Character { def isLetter(cp: Int): scala.Boolean = isLetterImpl(getType(cp)) - @inline private[this] def isLetterImpl(tpe: Int): scala.Boolean = { + @inline private def isLetterImpl(tpe: Int): scala.Boolean = { tpe == UPPERCASE_LETTER || tpe == LOWERCASE_LETTER || tpe == TITLECASE_LETTER || tpe == MODIFIER_LETTER || tpe == OTHER_LETTER } @@ -673,13 +673,13 @@ object Character { def isLetterOrDigit(cp: Int): scala.Boolean = isLetterOrDigitImpl(getType(cp)) - @inline private[this] def isLetterOrDigitImpl(tpe: Int): scala.Boolean = + @inline private def isLetterOrDigitImpl(tpe: Int): scala.Boolean = isDigitImpl(tpe) || isLetterImpl(tpe) def isJavaLetter(ch: scala.Char): scala.Boolean = isJavaLetterImpl(getType(ch)) - @inline private[this] def isJavaLetterImpl(tpe: Int): scala.Boolean = { + @inline private def isJavaLetterImpl(tpe: Int): scala.Boolean = { isLetterImpl(tpe) || tpe == LETTER_NUMBER || tpe == CURRENCY_SYMBOL || tpe == CONNECTOR_PUNCTUATION } @@ -687,7 +687,7 @@ object Character { def isJavaLetterOrDigit(ch: scala.Char): scala.Boolean = isJavaLetterOrDigitImpl(ch, getType(ch)) - @inline private[this] def isJavaLetterOrDigitImpl( + @inline private def isJavaLetterOrDigitImpl( codePoint: Int, tpe: Int ): scala.Boolean = { @@ -718,7 +718,7 @@ object Character { isJavaIdentifierStartImpl(getType(codePoint)) @inline - private[this] def isJavaIdentifierStartImpl(tpe: Int): scala.Boolean = { + private def isJavaIdentifierStartImpl(tpe: Int): scala.Boolean = { isLetterImpl(tpe) || tpe == LETTER_NUMBER || tpe == CURRENCY_SYMBOL || tpe == CONNECTOR_PUNCTUATION } @@ -729,7 +729,7 @@ object Character { def isJavaIdentifierPart(codePoint: Int): scala.Boolean = isJavaIdentifierPartImpl(codePoint, getType(codePoint)) - @inline private[this] def isJavaIdentifierPartImpl( + @inline private def isJavaIdentifierPartImpl( codePoint: Int, tpe: Int ): scala.Boolean = { @@ -746,7 +746,7 @@ object Character { isUnicodeIdentifierStartImpl(getType(codePoint)) @inline - private[this] def isUnicodeIdentifierStartImpl(tpe: Int): scala.Boolean = + private def isUnicodeIdentifierStartImpl(tpe: Int): scala.Boolean = isLetterImpl(tpe) || tpe == LETTER_NUMBER def isUnicodeIdentifierPart(ch: scala.Char): scala.Boolean = @@ -768,7 +768,7 @@ object Character { def isIdentifierIgnorable(codePoint: Int): scala.Boolean = isIdentifierIgnorableImpl(codePoint, getType(codePoint)) - @inline private[this] def isIdentifierIgnorableImpl( + @inline private def isIdentifierIgnorableImpl( codePoint: Int, tpe: Int ): scala.Boolean = { @@ -832,7 +832,7 @@ object Character { } } - @inline private[this] def toSurrogate( + @inline private def toSurrogate( codePoint: Int, dst: Array[Char], dstIndex: Int @@ -843,10 +843,10 @@ object Character { } // These both allow for the logic in toSurrogate to not change, the codepoint must be normalised first with -0x10000 - @inline private[this] def highSurrogateFromNormalised(cp: Int): Char = + @inline private def highSurrogateFromNormalised(cp: Int): Char = (0xd800 | ((cp >> 10) & 0x3ff)).toChar - @inline private[this] def lowSurrogateFromNormalised(cp: Int): Char = + @inline private def lowSurrogateFromNormalised(cp: Int): Char = (0xdc00 | (cp & 0x3ff)).toChar @inline def highSurrogate(codePoint: Int): Char = @@ -881,7 +881,7 @@ object Character { // format: off // Types of characters from 0 to 255 - private[this] lazy val charTypesFirst256 = Array[scala.Byte](15, 15, 15, 15, + private lazy val charTypesFirst256 = Array[scala.Byte](15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 12, 24, 24, 24, 26, 24, 24, 24, 21, 22, 24, 25, 24, 20, 24, 24, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 24, 24, 25, @@ -1066,10 +1066,10 @@ object Character { 182, 1, 4, 3, 62, 2, 4, 12, 24, 147, 70, 4, 11, 48, 70, 58, 116, 2188, 42711, 41, 4149, 11, 222, 16354, 542, 722403, 1, 30, 96, 128, 240, 65040, 65534, 2, 65534) - private[this] lazy val charTypeIndices = + private lazy val charTypeIndices = uncompressDeltas(charTypeIndicesDeltas) - private[this] lazy val charTypes = Array[scala.Byte](1, 2, 1, 2, 1, 2, + private lazy val charTypes = Array[scala.Byte](1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, @@ -1245,7 +1245,7 @@ object Character { 1, 1, 3, 5, 5, 3, 4, 1, 3, 5, 1, 1, 772, 4, 3, 2, 1, 2, 14, 2, 2, 10, 478, 10, 2, 8, 52797, 6, 5, 2, 162, 2, 18, 1, 1, 1, 28, 1, 1, 1, 29, 1, 1, 1, 1, 2, 1, 2, 55159, 1, 57, 1, 57, 1, 57, 1, 57, 1) - private[this] lazy val isMirroredIndices = + private lazy val isMirroredIndices = uncompressDeltas(isMirroredIndicesDeltas) private[lang] final val CombiningClassIsNone = 0 @@ -1308,7 +1308,7 @@ object Character { println(formatLargeArray(indicesDeltas.toArray, " ")) println(" )") */ - private[this] lazy val combiningClassNoneOrAboveOrOtherIndices: Array[Int] = { + private lazy val combiningClassNoneOrAboveOrOtherIndices: Array[Int] = { val deltas = Array( 768, 21, 40, 0, 8, 1, 0, 1, 3, 0, 3, 2, 1, 3, 4, 0, 1, 3, 0, 1, 7, 0, 13, 0, 275, 5, 0, 265, 0, 1, 0, 4, 1, 0, 3, 2, 0, 6, 6, 0, 2, 1, 0, 2, @@ -1361,7 +1361,7 @@ object Character { } // format: on - @noinline private[this] def uncompressDeltas( + @noinline private def uncompressDeltas( deltas: Array[Int] ): Array[Int] = { for (i <- 1 until deltas.length) @@ -1369,7 +1369,7 @@ object Character { deltas } - private[this] def findIndexOfRange( + private def findIndexOfRange( startOfRangesArray: Array[Int], value: Int, hasEmptyRanges: scala.Boolean @@ -1405,7 +1405,7 @@ object Character { // Refer to the following project for the transformation code. // https://github.com/ekrich/scala-unicode - private[this] lazy val lowerRanges = Array[scala.Int](97, 122, 181, 224, 246, + private lazy val lowerRanges = Array[scala.Int](97, 122, 181, 224, 246, 248, 254, 255, 257, 303, 305, 307, 311, 314, 328, 331, 375, 378, 382, 383, 384, 387, 389, 392, 396, 402, 405, 409, 410, 414, 417, 421, 424, 429, 432, 436, 438, 441, 445, 447, 453, 454, 456, 457, 459, 460, 462, 476, 477, 479, @@ -1429,7 +1429,7 @@ object Character { 65370, 66600, 66639, 66776, 66811, 68800, 68850, 71872, 71903, 93792, 93823, 125218, 125251) - private[this] lazy val lowerDeltas = Array[scala.Int](32, 32, -743, 32, 32, + private lazy val lowerDeltas = Array[scala.Int](32, 32, -743, 32, 32, 32, 32, -121, 1, 1, 232, 1, 1, 1, 1, 1, 1, 1, 1, 300, -195, 1, 1, 1, 1, 1, -97, 1, -163, -130, 1, 1, 1, 1, 1, 1, 1, 1, 1, -56, 1, 2, 1, 2, 1, 2, 1, 1, 79, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, -10815, -10815, 1, 1, 1, -10783, -10780, @@ -1447,7 +1447,7 @@ object Character { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -48, 1, 1, 1, 1, 1, 1, 1, 1, 928, 38864, 38864, 32, 32, 40, 40, 40, 40, 64, 64, 32, 32, 32, 32, 34, 34) - private[this] lazy val lowerSteps = Array[scala.Byte](0, 1, 0, 0, 1, 0, 1, 0, + private lazy val lowerSteps = Array[scala.Byte](0, 1, 0, 0, 1, 0, 1, 0, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 2, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1460,7 +1460,7 @@ object Character { 0, 1, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) - private[this] lazy val upperRanges = Array[scala.Int](65, 90, 192, 214, 216, + private lazy val upperRanges = Array[scala.Int](65, 90, 192, 214, 216, 222, 256, 302, 304, 306, 310, 313, 327, 330, 374, 376, 377, 381, 385, 386, 388, 390, 391, 393, 394, 395, 398, 399, 400, 401, 403, 404, 406, 407, 408, 412, 413, 415, 416, 420, 422, 423, 425, 428, 430, 431, 433, 434, 435, 437, @@ -1483,7 +1483,7 @@ object Character { 65338, 66560, 66599, 66736, 66771, 68736, 68786, 71840, 71871, 93760, 93791, 125184, 125217) - private[this] lazy val upperDeltas = Array[scala.Int](-32, -32, -32, -32, -32, + private lazy val upperDeltas = Array[scala.Int](-32, -32, -32, -32, -32, -32, -1, -1, 199, -1, -1, -1, -1, -1, -1, 121, -1, -1, -210, -1, -1, -206, -1, -205, -205, -1, -79, -202, -203, -1, -205, -207, -211, -209, -1, -211, -213, -214, -1, -1, -218, -1, -218, -1, -218, -1, -217, -217, -1, -1, -219, @@ -1502,7 +1502,7 @@ object Character { -1, -1, -32, -32, -40, -40, -40, -40, -64, -64, -32, -32, -32, -32, -34, -34) - private[this] lazy val upperSteps = Array[scala.Byte](0, 1, 0, 1, 0, 1, 0, 2, + private lazy val upperSteps = Array[scala.Byte](0, 1, 0, 1, 0, 1, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, @@ -1515,7 +1515,7 @@ object Character { 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) - private[this] object CaseUtil { + private object CaseUtil { lazy val a = lowerRanges(0) lazy val z = lowerRanges(1) lazy val A = upperRanges(0) @@ -1527,7 +1527,7 @@ object Character { def convert(codePoint: Int, delta: Int) = codePoint - delta } - private[this] def toCase( + private def toCase( codePoint: Int, asciiLow: Int, asciiHigh: Int, @@ -1616,7 +1616,7 @@ object Character { * } * ``` */ - private[this] lazy val caseIgnorableIndices: Array[Int] = { + private lazy val caseIgnorableIndices: Array[Int] = { val deltas: Array[Int] = Array(39, 1, 6, 1, 11, 1, 35, 1, 1, 1, 71, 1, 4, 1, 1, 1, 4, 1, 2, 2, 503, 192, 4, 2, 4, 1, 9, 2, 1, 1, 251, 7, 207, 1, 5, 1, 49, 45, 1, 1, 1, 2, 1, 2, 1, 1, 44, 1, 11, 6, 10, 11, 1, 1, 35, 1, 10, 21, @@ -1678,7 +1678,7 @@ object Character { * * For code used to generate deltas see `caseIgnorableIndices` comment. */ - private[this] lazy val casedIndices: Array[Int] = { + private lazy val casedIndices: Array[Int] = { val deltas: Array[Int] = Array(65, 26, 6, 26, 47, 1, 10, 1, 4, 1, 5, 23, 1, 31, 1, 195, 1, 4, 4, 208, 1, 36, 7, 2, 30, 5, 96, 1, 42, 4, 2, 2, 2, 4, 1, 1, 6, 1, 1, 3, 1, 1, 1, 20, 1, 83, 1, 139, 8, 166, 1, 38, 9, 41, 2839, 38, diff --git a/javalib/src/main/scala/java/lang/String.scala b/javalib/src/main/scala/java/lang/String.scala index 620a7625e6..d8116876b5 100644 --- a/javalib/src/main/scala/java/lang/String.scala +++ b/javalib/src/main/scala/java/lang/String.scala @@ -1246,7 +1246,7 @@ for (cp <- 0 to Character.MAX_CODE_POINT) { result } - private[this] final val REGEX_METACHARACTERS = ".$()[{^?*+\\" + private final val REGEX_METACHARACTERS = ".$()[{^?*+\\" @inline private def isRegexMeta(c: Char) = REGEX_METACHARACTERS.indexOf(c) >= 0 diff --git a/javalib/src/main/scala/java/lang/Throwables.scala b/javalib/src/main/scala/java/lang/Throwables.scala index 74ac7eb7e6..fb99b24436 100644 --- a/javalib/src/main/scala/java/lang/Throwables.scala +++ b/javalib/src/main/scala/java/lang/Throwables.scala @@ -61,7 +61,7 @@ private[lang] object StackTrace { class Throwable protected ( s: String, - private[this] var e: Throwable, + private var e: Throwable, enableSuppression: scala.Boolean, writableStackTrace: scala.Boolean ) extends Object @@ -76,14 +76,14 @@ class Throwable protected ( def this(e: Throwable) = this(if (e == null) null else e.toString, e) - private[this] var stackTrace: Array[StackTraceElement] = _ + private var stackTrace: Array[StackTraceElement] = _ if (writableStackTrace) fillInStackTrace() // We use an Array rather than, say, a List, so that Throwable does not // depend on the Scala collections. - private[this] var suppressed: Array[Throwable] = _ + private var suppressed: Array[Throwable] = _ final def addSuppressed(exception: Throwable): Unit = { if (exception eq null) { diff --git a/javalib/src/main/scala/java/lang/process/PipeIO.scala b/javalib/src/main/scala/java/lang/process/PipeIO.scala index a881cf6cd3..eb36194fa6 100644 --- a/javalib/src/main/scala/java/lang/process/PipeIO.scala +++ b/javalib/src/main/scala/java/lang/process/PipeIO.scala @@ -83,7 +83,7 @@ private[lang] object PipeIO { this.in = new ByteArrayInputStream(readBuf) } - private[this] var drained = false + private var drained = false private def availableFD() = { if (isWindows) { val availableTotal = stackalloc[DWord]() diff --git a/javalib/src/main/scala/java/lang/process/ProcessBuilderImpl.scala b/javalib/src/main/scala/java/lang/process/ProcessBuilderImpl.scala index 12d83319f8..a6de0a0d5f 100644 --- a/javalib/src/main/scala/java/lang/process/ProcessBuilderImpl.scala +++ b/javalib/src/main/scala/java/lang/process/ProcessBuilderImpl.scala @@ -114,7 +114,7 @@ private[lang] class ProcessBuilderImpl(private var _command: List[String]) { else process.UnixProcess(this) } - @inline private[this] def set(f: => Unit): ProcessBuilder = { + @inline private def set(f: => Unit): ProcessBuilder = { f this } diff --git a/javalib/src/main/scala/java/lang/process/WindowsProcess.scala b/javalib/src/main/scala/java/lang/process/WindowsProcess.scala index 2d00485027..b1def79aa3 100644 --- a/javalib/src/main/scala/java/lang/process/WindowsProcess.scala +++ b/javalib/src/main/scala/java/lang/process/WindowsProcess.scala @@ -88,12 +88,12 @@ private[lang] class WindowsProcess private ( (hasValidTimeout && hasFinished) } - private[this] val _inputStream = + private val _inputStream = PipeIO[PipeIO.Stream](this, outHandle, builder.redirectOutput()) - private[this] val _errorStream = + private val _errorStream = if (builder.redirectErrorStream()) PipeIO.InputPipeIO.nullStream else PipeIO[PipeIO.Stream](this, errHandle, builder.redirectError()) - private[this] val _outputStream = + private val _outputStream = PipeIO[OutputStream](this, inHandle, builder.redirectInput()) private def checkExitValue: Option[scala.Int] = { diff --git a/javalib/src/main/scala/java/lang/ref/Reference.scala b/javalib/src/main/scala/java/lang/ref/Reference.scala index dd6d96e852..46df07ce83 100644 --- a/javalib/src/main/scala/java/lang/ref/Reference.scala +++ b/javalib/src/main/scala/java/lang/ref/Reference.scala @@ -1,6 +1,6 @@ package java.lang.ref -abstract class Reference[T](private[this] var referent: T) { +abstract class Reference[T](private var referent: T) { def get(): T = referent def clear(): Unit = referent = null.asInstanceOf[T] def isEnqueued(): Boolean = false diff --git a/javalib/src/main/scala/java/net/URLEncoder.scala b/javalib/src/main/scala/java/net/URLEncoder.scala index 1ced350290..f1820c465a 100644 --- a/javalib/src/main/scala/java/net/URLEncoder.scala +++ b/javalib/src/main/scala/java/net/URLEncoder.scala @@ -5,7 +5,7 @@ package java.net import scala.annotation.tailrec object URLEncoder { - private[this] val digits = "0123456789ABCDEF".toCharArray + private val digits = "0123456789ABCDEF".toCharArray def encode(s: String, enc: String): String = { if (s == null || enc == null) { @@ -44,7 +44,7 @@ object URLEncoder { buf.toString } - private[this] def convert( + private def convert( s: String, buf: java.lang.StringBuilder, enc: String diff --git a/javalib/src/main/scala/java/nio/MappedByteBufferImpl.scala b/javalib/src/main/scala/java/nio/MappedByteBufferImpl.scala index 3c5e511abf..f8f9c3434e 100644 --- a/javalib/src/main/scala/java/nio/MappedByteBufferImpl.scala +++ b/javalib/src/main/scala/java/nio/MappedByteBufferImpl.scala @@ -42,7 +42,7 @@ private class MappedByteBufferImpl( private def genBuffer = GenBuffer[ByteBuffer](this) private def genMappedBuffer = GenMappedBuffer[ByteBuffer](this) - private[this] implicit def newMappedByteBuffer + private implicit def newMappedByteBuffer : GenMappedBuffer.NewMappedBuffer[ByteBuffer, Byte] = MappedByteBufferImpl.NewMappedByteBuffer diff --git a/javalib/src/main/scala/java/nio/charset/CharsetDecoder.scala b/javalib/src/main/scala/java/nio/charset/CharsetDecoder.scala index 79c36bbdd5..57077455d4 100644 --- a/javalib/src/main/scala/java/nio/charset/CharsetDecoder.scala +++ b/javalib/src/main/scala/java/nio/charset/CharsetDecoder.scala @@ -14,15 +14,15 @@ abstract class CharsetDecoder protected ( // Config - private[this] var _replacement: String = "\uFFFD" - private[this] var _malformedInputAction: CodingErrorAction = + private var _replacement: String = "\uFFFD" + private var _malformedInputAction: CodingErrorAction = CodingErrorAction.REPORT - private[this] var _unmappableCharacterAction: CodingErrorAction = + private var _unmappableCharacterAction: CodingErrorAction = CodingErrorAction.REPORT // Status - private[this] var status: Int = INIT + private var status: Int = INIT // Methods diff --git a/javalib/src/main/scala/java/nio/charset/CharsetEncoder.scala b/javalib/src/main/scala/java/nio/charset/CharsetEncoder.scala index 467cc3dd6c..593e9d49c7 100644 --- a/javalib/src/main/scala/java/nio/charset/CharsetEncoder.scala +++ b/javalib/src/main/scala/java/nio/charset/CharsetEncoder.scala @@ -8,7 +8,7 @@ abstract class CharsetEncoder protected ( cs: Charset, _averageBytesPerChar: Float, _maxBytesPerChar: Float, - private[this] var _replacement: Array[Byte] + private var _replacement: Array[Byte] ) { import CharsetEncoder._ @@ -23,14 +23,14 @@ abstract class CharsetEncoder protected ( // Config - private[this] var _malformedInputAction: CodingErrorAction = + private var _malformedInputAction: CodingErrorAction = CodingErrorAction.REPORT - private[this] var _unmappableCharacterAction: CodingErrorAction = + private var _unmappableCharacterAction: CodingErrorAction = CodingErrorAction.REPORT // Status - private[this] var status: Int = INIT + private var status: Int = INIT // Methods diff --git a/javalib/src/main/scala/java/nio/file/AccessMode.scala b/javalib/src/main/scala/java/nio/file/AccessMode.scala index 83ecdb8fd2..67d52ad6e1 100644 --- a/javalib/src/main/scala/java/nio/file/AccessMode.scala +++ b/javalib/src/main/scala/java/nio/file/AccessMode.scala @@ -10,7 +10,7 @@ object AccessMode { final val READ = new AccessMode("READ", 1) final val WRITE = new AccessMode("WRITE", 1) - private[this] val cachedValues = + private val cachedValues = Array(EXECUTE, READ, WRITE) def values(): Array[AccessMode] = cachedValues.clone() def valueOf(name: String): AccessMode = { diff --git a/javalib/src/main/scala/java/nio/file/attribute/PosixFileAttributeViewImpl.scala b/javalib/src/main/scala/java/nio/file/attribute/PosixFileAttributeViewImpl.scala index 17ab7a79f5..ca4be89731 100644 --- a/javalib/src/main/scala/java/nio/file/attribute/PosixFileAttributeViewImpl.scala +++ b/javalib/src/main/scala/java/nio/file/attribute/PosixFileAttributeViewImpl.scala @@ -84,13 +84,13 @@ final class PosixFileAttributeViewImpl(path: Path, options: Array[LinkOption]) private def attributes = new PosixFileAttributes { - private[this] var st_ino: stat.ino_t = _ - private[this] var st_uid: stat.uid_t = _ - private[this] var st_gid: stat.gid_t = _ - private[this] var st_size: unistd.off_t = _ - private[this] var st_atime: time.time_t = _ - private[this] var st_mtime: time.time_t = _ - private[this] var st_mode: stat.mode_t = _ + private var st_ino: stat.ino_t = _ + private var st_uid: stat.uid_t = _ + private var st_gid: stat.gid_t = _ + private var st_size: unistd.off_t = _ + private var st_atime: time.time_t = _ + private var st_mtime: time.time_t = _ + private var st_mode: stat.mode_t = _ Zone { implicit z => val buf = getStat() diff --git a/javalib/src/main/scala/java/security/cert/CertificateEncodingException.scala b/javalib/src/main/scala/java/security/cert/CertificateEncodingException.scala index 1e71a5e7f1..09a3ce2650 100644 --- a/javalib/src/main/scala/java/security/cert/CertificateEncodingException.scala +++ b/javalib/src/main/scala/java/security/cert/CertificateEncodingException.scala @@ -6,8 +6,8 @@ import java.security.GeneralSecurityException @SerialVersionUID(6219492851589449162L) class CertificateEncodingException( - private[this] val message: String, - private[this] val cause: Throwable + private val message: String, + private val cause: Throwable ) extends CertificateException(message, cause) { def this(msg: String) = this(msg, null) diff --git a/javalib/src/main/scala/java/util/ArrayList.scala b/javalib/src/main/scala/java/util/ArrayList.scala index 60ba9c6a9c..da49ad1fa1 100644 --- a/javalib/src/main/scala/java/util/ArrayList.scala +++ b/javalib/src/main/scala/java/util/ArrayList.scala @@ -9,8 +9,8 @@ import java.util.function.Consumer // inner: The underlying array // _size: Keeps the track of the effective size of the underlying array. a.k.a. end index exclusive class ArrayList[E] private ( - private[this] var inner: Array[Any], - private[this] var _size: Int + private var inner: Array[Any], + private var _size: Int ) extends AbstractList[E] with List[E] with RandomAccess @@ -54,15 +54,15 @@ class ArrayList[E] private ( def this() = this(10) // by default, doubles the capacity. this mimicks C++ compiled by clang++-4.0.0 - private[this] def expand(): Unit = expand(inner.length * 2 max 1) + private def expand(): Unit = expand(inner.length * 2 max 1) - private[this] def expand(newCapacity: Int): Unit = { + private def expand(newCapacity: Int): Unit = { val newArr = Array.ofDim[Any](newCapacity) inner.copyToArray(newArr, 0, size()) inner = newArr } - private[this] def capacity(): Int = inner.length + private def capacity(): Int = inner.length def trimToSize(): Unit = expand(size()) diff --git a/javalib/src/main/scala/java/util/FormatterImpl.scala b/javalib/src/main/scala/java/util/FormatterImpl.scala index 7c703e3247..f45338b5c3 100644 --- a/javalib/src/main/scala/java/util/FormatterImpl.scala +++ b/javalib/src/main/scala/java/util/FormatterImpl.scala @@ -33,8 +33,8 @@ private[util] abstract class FormatterImpl protected ( dest = new JStringBuilder() } - private[this] var closed: Boolean = false - private[this] var lastIOException: IOException = null + private var closed: Boolean = false + private var lastIOException: IOException = null @inline private def trapIOExceptions(body: => Unit): Unit = { diff --git a/javalib/src/main/scala/java/util/HashMap.scala b/javalib/src/main/scala/java/util/HashMap.scala index 05a2ff6fe4..02a3ca0d04 100644 --- a/javalib/src/main/scala/java/util/HashMap.scala +++ b/javalib/src/main/scala/java/util/HashMap.scala @@ -43,12 +43,12 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) * `growTable()`. Since the number of buckets is not observable from the * outside, this deviation does not change any semantics. */ - private[this] var table = new Array[Node[K, V]](tableSizeFor(initialCapacity)) + private var table = new Array[Node[K, V]](tableSizeFor(initialCapacity)) /** The next size value at which to resize (capacity * load factor). */ - private[this] var threshold: Int = newThreshold(table.length) + private var threshold: Int = newThreshold(table.length) - private[this] var contentSize: Int = 0 + private var contentSize: Int = 0 /* Internal API for LinkedHashMap: these methods are overridden in * LinkedHashMap to implement its insertion- or access-order. @@ -330,7 +330,7 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) * the old value associated with `key`, or `null` if there was none */ @inline - private[this] def put0(key: K, value: V, ifAbsent: Boolean): V = + private def put0(key: K, value: V, ifAbsent: Boolean): V = put0(key, value, computeHash(key), ifAbsent) /** Puts a key-value pair into this map. @@ -352,7 +352,7 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) * @return * the old value associated with `key`, or `null` if there was none */ - private[this] def put0(key: K, value: V, hash: Int, ifAbsent: Boolean): V = { + private def put0(key: K, value: V, hash: Int, ifAbsent: Boolean): V = { // scalastyle:off return val newContentSize = contentSize + 1 if (newContentSize >= threshold) @@ -414,7 +414,7 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) * @param node * the entry for the given `key`, or `null` if there is no such entry */ - private[this] def put0( + private def put0( key: K, value: V, hash: Int, @@ -484,7 +484,7 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) } /** Grow the size of the table (always times 2). */ - private[this] def growTable(): Unit = { + private def growTable(): Unit = { val oldTable = table val oldlen = oldTable.length val newlen = oldlen * 2 @@ -531,10 +531,10 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) } /** Rounds up `capacity` to a power of 2, with a maximum of 2^30. */ - @inline private[this] def tableSizeFor(capacity: Int): Int = + @inline private def tableSizeFor(capacity: Int): Int = Math.min(Integer.highestOneBit(Math.max(capacity - 1, 4)) * 2, 1 << 30) - @inline private[this] def newThreshold(size: Int): Int = + @inline private def newThreshold(size: Int): Int = (size.toDouble * loadFactor.toDouble).toInt // Iterators @@ -565,10 +565,10 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) } private abstract class AbstractHashMapIterator[A] extends ju.Iterator[A] { - private[this] val len = table.length - private[this] var nextIdx: Int = _ // 0 - private[this] var nextNode: Node[K, V] = _ // null - private[this] var lastNode: Node[K, V] = _ // null + private val len = table.length + private var nextIdx: Int = _ // 0 + private var nextNode: Node[K, V] = _ // null + private var lastNode: Node[K, V] = _ // null protected[this] def extract(node: Node[K, V]): A diff --git a/javalib/src/main/scala/java/util/LinkedHashMap.scala b/javalib/src/main/scala/java/util/LinkedHashMap.scala index 1861331a94..9996db30fa 100644 --- a/javalib/src/main/scala/java/util/LinkedHashMap.scala +++ b/javalib/src/main/scala/java/util/LinkedHashMap.scala @@ -136,8 +136,8 @@ class LinkedHashMap[K, V]( private abstract class AbstractLinkedHashMapIterator[A] extends ju.Iterator[A] { - private[this] var nextNode: Node[K, V] = eldest - private[this] var lastNode: Node[K, V] = _ + private var nextNode: Node[K, V] = eldest + private var lastNode: Node[K, V] = _ protected[this] def extract(node: Node[K, V]): A diff --git a/javalib/src/main/scala/java/util/PriorityQueue.scala b/javalib/src/main/scala/java/util/PriorityQueue.scala index 00405f5f85..4edcefd024 100644 --- a/javalib/src/main/scala/java/util/PriorityQueue.scala +++ b/javalib/src/main/scala/java/util/PriorityQueue.scala @@ -75,9 +75,9 @@ class PriorityQueue[E] private ( // The index 0 is not used; the root is at index 1. // This is standard practice in binary heaps, to simplify arithmetics. - private[this] var inner = new Array[Any](16).asInstanceOf[Array[E]] + private var inner = new Array[Any](16).asInstanceOf[Array[E]] // Size of the objects stored in the inner array - private[this] var innerNextIdx = 1 + private var innerNextIdx = 1 override def add(e: E): Boolean = { if (e == null) @@ -156,10 +156,10 @@ class PriorityQueue[E] private ( def iterator(): Iterator[E] = { new Iterator[E] { - private[this] var inner: Array[E] = PriorityQueue.this.inner - private[this] var innerSize = innerNextIdx - private[this] var nextIdx: Int = 1 - private[this] var last: E = _ // null + private var inner: Array[E] = PriorityQueue.this.inner + private var innerSize = innerNextIdx + private var nextIdx: Int = 1 + private var last: E = _ // null def hasNext(): Boolean = nextIdx < innerSize @@ -239,7 +239,7 @@ class PriorityQueue[E] private ( * or down the tree, depending on which side is found to violate the heap * property. */ - private[this] def fixUpOrDown(m: Int): Unit = { + private def fixUpOrDown(m: Int): Unit = { val inner = this.inner // local copy if (m > 1 && comp.compare(inner(m >> 1), inner(m)) > 0) fixUp(m) @@ -250,7 +250,7 @@ class PriorityQueue[E] private ( /** Fixes the heap property from the child at index `m` up the tree, towards * the root. */ - private[this] def fixUp(m: Int): Unit = { + private def fixUp(m: Int): Unit = { val inner = this.inner // local copy /* At each step, even though `m` changes, the element moves with it, and @@ -277,7 +277,7 @@ class PriorityQueue[E] private ( /** Fixes the heap property from the child at index `m` down the tree, towards * the leaves. */ - private[this] def fixDown(m: Int): Unit = { + private def fixDown(m: Int): Unit = { val inner = this.inner // local copy val size = innerNextIdx - 1 diff --git a/javalib/src/main/scala/java/util/RedBlackTree.scala b/javalib/src/main/scala/java/util/RedBlackTree.scala index e0f2cacdd3..0664f37ed2 100644 --- a/javalib/src/main/scala/java/util/RedBlackTree.scala +++ b/javalib/src/main/scala/java/util/RedBlackTree.scala @@ -174,7 +174,7 @@ private[util] object RedBlackTree { // ---- comparator helper ---- @inline - private[this] def compare[A](key1: Any, key2: A)(implicit + private def compare[A](key1: Any, key2: A)(implicit comp: Comparator[_ >: A] ): Int = { /* The implementation of `compare` and/or its generic bridge may perform @@ -256,7 +256,7 @@ private[util] object RedBlackTree { } @tailrec - private[this] def getNode[A, B](node: Node[A, B], key: Any)(implicit + private def getNode[A, B](node: Node[A, B], key: Any)(implicit comp: Comparator[_ >: A] ): Node[A, B] = { if (node eq null) { @@ -458,7 +458,7 @@ private[util] object RedBlackTree { } @tailrec - private[this] def fixAfterInsert[A, B]( + private def fixAfterInsert[A, B]( tree: Tree[A, B], node: Node[A, B] ): Unit = { @@ -580,7 +580,7 @@ private[util] object RedBlackTree { * `parent` explicitly from above. */ @tailrec - private[this] def fixAfterDelete[A, B]( + private def fixAfterDelete[A, B]( tree: Tree[A, B], node: Node[A, B], parent: Node[A, B] @@ -679,7 +679,7 @@ private[util] object RedBlackTree { * If `node` has the maximum key (and is, therefore, the last node), this * method returns `null`. */ - private[this] def successor[A, B](node: Node[A, B]): Node[A, B] = { + private def successor[A, B](node: Node[A, B]): Node[A, B] = { if (node.right ne null) { minNodeNonNull(node.right) } else { @@ -698,7 +698,7 @@ private[util] object RedBlackTree { * If `node` has the minimum key (and is, therefore, the first node), this * method returns `null`. */ - private[this] def predecessor[A, B](node: Node[A, B]): Node[A, B] = { + private def predecessor[A, B](node: Node[A, B]): Node[A, B] = { if (node.left ne null) { maxNodeNonNull(node.left) } else { @@ -712,7 +712,7 @@ private[util] object RedBlackTree { } } - private[this] def rotateLeft[A, B](tree: Tree[A, B], x: Node[A, B]): Unit = { + private def rotateLeft[A, B](tree: Tree[A, B], x: Node[A, B]): Unit = { if (x ne null) { // assert(x.right ne null) val y = x.right @@ -734,7 +734,7 @@ private[util] object RedBlackTree { } } - private[this] def rotateRight[A, B](tree: Tree[A, B], x: Node[A, B]): Unit = { + private def rotateRight[A, B](tree: Tree[A, B], x: Node[A, B]): Unit = { if (x ne null) { // assert(x.left ne null) val y = x.left @@ -762,7 +762,7 @@ private[util] object RedBlackTree { * setting `from`'s parent to the `to`'s previous parent. The children of * `from` are left unchanged. */ - private[this] def transplant[A, B]( + private def transplant[A, B]( tree: Tree[A, B], to: Node[A, B], from: Node[A, B] @@ -789,12 +789,12 @@ private[util] object RedBlackTree { def valuesIterator[A, B](tree: Tree[A, B]): Iterator[B] = new ValuesIterator(tree) - private[this] abstract class AbstractTreeIterator[A, B, R]( + private abstract class AbstractTreeIterator[A, B, R]( tree: Tree[A, B], - private[this] var nextNode: Node[A, B] + private var nextNode: Node[A, B] ) extends Iterator[R] { - private[this] var lastNode: Node[A, B] = _ // null + private var lastNode: Node[A, B] = _ // null protected def advance(node: Node[A, B]): Node[A, B] protected def nextResult(node: Node[A, B]): R @@ -819,26 +819,26 @@ private[util] object RedBlackTree { } } - private[this] abstract class TreeIterator[A, B, R](tree: Tree[A, B]) + private abstract class TreeIterator[A, B, R](tree: Tree[A, B]) extends AbstractTreeIterator[A, B, R](tree, minNode(tree)) { protected final def advance(node: Node[A, B]): Node[A, B] = successor(node) } - private[this] final class EntriesIterator[A, B](tree: Tree[A, B]) + private final class EntriesIterator[A, B](tree: Tree[A, B]) extends TreeIterator[A, B, Map.Entry[A, B]](tree) { protected def nextResult(node: Node[A, B]): Map.Entry[A, B] = node } - private[this] final class KeysIterator[A, B](tree: Tree[A, B]) + private final class KeysIterator[A, B](tree: Tree[A, B]) extends TreeIterator[A, B, A](tree) { protected def nextResult(node: Node[A, B]): A = node.key } - private[this] final class ValuesIterator[A, B](tree: Tree[A, B]) + private final class ValuesIterator[A, B](tree: Tree[A, B]) extends TreeIterator[A, B, B](tree) { protected def nextResult(node: Node[A, B]): B = node.value @@ -876,7 +876,7 @@ private[util] object RedBlackTree { new ProjectionValuesIterator(tree, start, startKind, end, endKind) } - private[this] abstract class ProjectionIterator[A, B, R]( + private abstract class ProjectionIterator[A, B, R]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -896,7 +896,7 @@ private[util] object RedBlackTree { ProjectionIterator.nullIfAfterEnd(successor(node), end, endKind) } - private[this] object ProjectionIterator { + private object ProjectionIterator { @inline private def nullIfAfterEnd[A, B]( node: Node[A, B], @@ -912,7 +912,7 @@ private[util] object RedBlackTree { } } - private[this] final class ProjectionEntriesIterator[A, B]( + private final class ProjectionEntriesIterator[A, B]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -930,7 +930,7 @@ private[util] object RedBlackTree { def nextResult(node: Node[A, B]): Map.Entry[A, B] = node } - private[this] final class ProjectionKeysIterator[A, B]( + private final class ProjectionKeysIterator[A, B]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -948,7 +948,7 @@ private[util] object RedBlackTree { def nextResult(node: Node[A, B]): A = node.key } - private[this] final class ProjectionValuesIterator[A, B]( + private final class ProjectionValuesIterator[A, B]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -1039,7 +1039,7 @@ private[util] object RedBlackTree { new DescendingValuesIterator(tree, start, startKind, end, endKind) } - private[this] abstract class DescendingTreeIterator[A, B, R]( + private abstract class DescendingTreeIterator[A, B, R]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -1059,7 +1059,7 @@ private[util] object RedBlackTree { DescendingTreeIterator.nullIfBeforeEnd(predecessor(node), end, endKind) } - private[this] object DescendingTreeIterator { + private object DescendingTreeIterator { @inline private def nullIfBeforeEnd[A, B]( node: Node[A, B], @@ -1075,7 +1075,7 @@ private[util] object RedBlackTree { } } - private[this] final class DescendingEntriesIterator[A, B]( + private final class DescendingEntriesIterator[A, B]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -1093,7 +1093,7 @@ private[util] object RedBlackTree { def nextResult(node: Node[A, B]): Map.Entry[A, B] = node } - private[this] final class DescendingKeysIterator[A, B]( + private final class DescendingKeysIterator[A, B]( tree: Tree[A, B], start: A, startKind: BoundKind, @@ -1111,7 +1111,7 @@ private[util] object RedBlackTree { def nextResult(node: Node[A, B]): A = node.key } - private[this] final class DescendingValuesIterator[A, B]( + private final class DescendingValuesIterator[A, B]( tree: Tree[A, B], start: A, startKind: BoundKind, diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala index 9a17a48257..6829aa029b 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala @@ -2,7 +2,7 @@ package java.util.concurrent.atomic import java.util.function.IntUnaryOperator -class AtomicInteger(private[this] var value: Int) +class AtomicInteger(private var value: Int) extends Number with Serializable { diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala index 5f43cd984b..a27d45b6a4 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala @@ -2,7 +2,7 @@ package java.util.concurrent.atomic import java.util.function.LongUnaryOperator -class AtomicLong(private[this] var value: Long) +class AtomicLong(private var value: Long) extends Number with Serializable { def this() = this(0L) diff --git a/javalib/src/main/scala/java/util/stream/Collector.scala b/javalib/src/main/scala/java/util/stream/Collector.scala index 5859f6f324..a44b0c9377 100644 --- a/javalib/src/main/scala/java/util/stream/Collector.scala +++ b/javalib/src/main/scala/java/util/stream/Collector.scala @@ -27,7 +27,7 @@ object Collector { final val UNORDERED = new Characteristics("UNORDERED", 1) final val IDENTITY_FINISH = new Characteristics("IDENTITY_FINISH", 2) - private[this] val cachedValues = + private val cachedValues = Array(CONCURRENT, IDENTITY_FINISH, UNORDERED) def values(): Array[Characteristics] = cachedValues.clone() diff --git a/javalib/src/main/scala/scala/scalanative/nio/fs/FileHelpers.scala b/javalib/src/main/scala/scala/scalanative/nio/fs/FileHelpers.scala index 012ff31042..726f4de0f9 100644 --- a/javalib/src/main/scala/scala/scalanative/nio/fs/FileHelpers.scala +++ b/javalib/src/main/scala/scala/scalanative/nio/fs/FileHelpers.scala @@ -214,7 +214,7 @@ object FileHelpers { dir } - private[this] lazy val random = new scala.util.Random() + private lazy val random = new scala.util.Random() private def genTempFile( prefix: String, diff --git a/junit-runtime/src/main/scala/scala/scalanative/junit/Ansi.scala b/junit-runtime/src/main/scala/scala/scalanative/junit/Ansi.scala index 5b088fc1cc..a0997d037f 100644 --- a/junit-runtime/src/main/scala/scala/scalanative/junit/Ansi.scala +++ b/junit-runtime/src/main/scala/scala/scalanative/junit/Ansi.scala @@ -5,7 +5,7 @@ package junit private[junit] object Ansi { - private[this] final val NORMAL = "\u001B[0m" + private final val NORMAL = "\u001B[0m" def c(s: String, colorSequence: String): String = if (colorSequence == null) s diff --git a/junit-runtime/src/main/scala/scala/scalanative/junit/JUnitTask.scala b/junit-runtime/src/main/scala/scala/scalanative/junit/JUnitTask.scala index 173a82c2bb..c1dc2406a7 100644 --- a/junit-runtime/src/main/scala/scala/scalanative/junit/JUnitTask.scala +++ b/junit-runtime/src/main/scala/scala/scalanative/junit/JUnitTask.scala @@ -93,7 +93,7 @@ private[junit] final class JUnitTask( reporter.reportRunFinished(failed, ignored, total, timeInSeconds) } - private[this] def executeTestMethod( + private def executeTestMethod( bootstrapper: Bootstrapper, test: TestMetadata, reporter: Reporter diff --git a/nativelib/src/main/scala/scala/scalanative/runtime/MemoryPool.scala b/nativelib/src/main/scala/scala/scalanative/runtime/MemoryPool.scala index d89e4e4baf..0f2db5946f 100644 --- a/nativelib/src/main/scala/scala/scalanative/runtime/MemoryPool.scala +++ b/nativelib/src/main/scala/scala/scalanative/runtime/MemoryPool.scala @@ -14,9 +14,9 @@ import scala.scalanative.unsigned._ * Memory is reclaimed back to underlying allocator once the pool is finalized. */ final class MemoryPool private { - private[this] var chunkPageCount: ULong = MemoryPool.MIN_PAGE_COUNT - private[this] var chunk: MemoryPool.Chunk = null - private[this] var page: MemoryPool.Page = null + private var chunkPageCount: ULong = MemoryPool.MIN_PAGE_COUNT + private var chunk: MemoryPool.Chunk = null + private var page: MemoryPool.Page = null allocateChunk() /** Allocate a chunk of memory from system allocator. */ @@ -75,11 +75,11 @@ object MemoryPool { * sequentially in pages that are claimed from memory pool. Larger allocations * are allocated using the system allocator and persisted in an array buffer. */ -final class MemoryPoolZone(private[this] val pool: MemoryPool) extends Zone { - private[this] var tailPage = pool.claim() - private[this] var headPage = tailPage - private[this] var largeAllocations: scala.Array[Ptr[_]] = null - private[this] var largeOffset = 0 +final class MemoryPoolZone(private val pool: MemoryPool) extends Zone { + private var tailPage = pool.claim() + private var headPage = tailPage + private var largeAllocations: scala.Array[Ptr[_]] = null + private var largeOffset = 0 private def checkOpen(): Unit = if (!isOpen) diff --git a/posixlib/src/main/scala/scala/scalanative/posix/sys/select.scala b/posixlib/src/main/scala/scala/scalanative/posix/sys/select.scala index 7cdc64b2c0..3d1219dcff 100644 --- a/posixlib/src/main/scala/scala/scalanative/posix/sys/select.scala +++ b/posixlib/src/main/scala/scala/scalanative/posix/sys/select.scala @@ -39,7 +39,7 @@ object select { // Linux specifies an array of 64 bit longs. // 16 * 64 == 1024 == FD_SETSIZE. - private[this] type _16 = Digit2[_1, _6] + private type _16 = Digit2[_1, _6] type fd_set = CStruct1[CArray[CLongInt, _16]] diff --git a/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala b/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala index f8c5aec971..cc466487f4 100644 --- a/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala +++ b/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RPCCore.scala @@ -26,17 +26,17 @@ private[testinterface] abstract class RPCCore()(implicit ec: ExecutionContext) { import RPCCore._ /** Pending calls. */ - private[this] val pending = new java.util.HashMap[Long, PendingCall] + private val pending = new java.util.HashMap[Long, PendingCall] /** Reason why we are closing this RPCCore. If non-null, we are closing. */ @volatile - private[this] var closeReason: Throwable = _ + private var closeReason: Throwable = _ /** Next call ID we'll assign. */ - private[this] val nextID = new AtomicLong(0L) + private val nextID = new AtomicLong(0L) /** Currently registered endpoints. */ - private[this] val endpoints = new java.util.HashMap[OpCode, BoundEndpoint] + private val endpoints = new java.util.HashMap[OpCode, BoundEndpoint] /** Subclass should call this whenever a new message arrives */ final protected def handleMessage(msg: String): Unit = { diff --git a/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RunMuxRPC.scala b/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RunMuxRPC.scala index e2cc4acf81..bca6dfb65a 100644 --- a/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RunMuxRPC.scala +++ b/test-interface-common/src/main/scala/scala/scalanative/testinterface/common/RunMuxRPC.scala @@ -25,7 +25,7 @@ private[testinterface] final class RunMuxRPC(rpc: RPCCore) { * Access to the outer map needs to synchronized. Access to the inner map * only needs to be synchronize for writing. */ - private[this] val mux = + private val mux = mutable.Map.empty[RPCCore.OpCode, java.util.HashMap[RunID, _]] def call[Req](ep: MuxRPCEndpoint[Req], runId: RunID)( diff --git a/test-interface-sbt-defs/src/main/scala-2/sbt/testing/Status.scala b/test-interface-sbt-defs/src/main/scala-2/sbt/testing/Status.scala index dde1ce9a88..d32677844e 100644 --- a/test-interface-sbt-defs/src/main/scala-2/sbt/testing/Status.scala +++ b/test-interface-sbt-defs/src/main/scala-2/sbt/testing/Status.scala @@ -53,7 +53,7 @@ object Status { /** Indicates a test was declared as pending. */ final val Pending = new Status("Pending", 6) - private[this] val _values: Array[Status] = + private val _values: Array[Status] = Array(Success, Error, Failure, Skipped, Ignored, Canceled, Pending) /* No () allows to compile without warning on both Scala 2 & 3. diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/TestAdapterBridge.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/TestAdapterBridge.scala index 9c061b7d91..a627f8ff06 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/TestAdapterBridge.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/TestAdapterBridge.scala @@ -9,7 +9,7 @@ import scala.scalanative.testinterface.common._ private[testinterface] class TestAdapterBridge(rpcClient: NativeRPC) { - private[this] val mux = new RunMuxRPC(rpcClient) + private val mux = new RunMuxRPC(rpcClient) def start(): Unit = { rpcClient.attach(detectFrameworks)(detectFrameworksFun) diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala index ee51011737..fe8c3f6a86 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala @@ -29,9 +29,9 @@ private[testinterface] class ComRunner( } @volatile - private[this] var state: State = AwaitingConnection(Nil) + private var state: State = AwaitingConnection(Nil) - private[this] val promise: Promise[Unit] = Promise[Unit]() + private val promise: Promise[Unit] = Promise[Unit]() // TODO replace this with scheduled tasks on the execution context. new Thread { diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala index 7054a94bea..10dcb1034b 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala @@ -17,7 +17,7 @@ private[testinterface] final class NativeRunnerRPC( )(implicit ec: ExecutionContext) extends RPCCore() { - private[this] val serverSocket: ServerSocket = new ServerSocket( + private val serverSocket: ServerSocket = new ServerSocket( /* port = */ 0, /* backlog = */ 1 ) diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/ProcessRunner.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/ProcessRunner.scala index 3ff8e4d6fe..09fe29d7b8 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/ProcessRunner.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/ProcessRunner.scala @@ -12,7 +12,7 @@ private[testinterface] class ProcessRunner( port: Int ) extends AutoCloseable { - private[this] val process = { + private val process = { // Optional emualator config used internally for testing non amd64 architectures val emulatorOpts: List[String] = { val optEmulator = @@ -45,8 +45,8 @@ private[testinterface] class ProcessRunner( builder.start() } - private[this] val runnerPromise: Promise[Unit] = Promise[Unit]() - private[this] val runner = new Thread { + private val runnerPromise: Promise[Unit] = Promise[Unit]() + private val runner = new Thread { setName("TestRunner") override def run(): Unit = { val exitCode = process.waitFor() diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala index 89ee7bf69c..ab945abe11 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/adapter/TestAdapter.scala @@ -23,12 +23,12 @@ final class TestAdapter(config: TestAdapter.Config) { ) /** Map of ThreadId -> ManagedRunner */ - private[this] val runners = TrieMap.empty[Long, ManagedRunner] + private val runners = TrieMap.empty[Long, ManagedRunner] /** State management. May only be accessed under synchronization. */ - private[this] var closed = false - private[this] var nextRunID = 0 - private[this] var runs = Set.empty[RunMux.RunID] + private var closed = false + private var nextRunID = 0 + private var runs = Set.empty[RunMux.RunID] /** A custom execution context that delegates to the global one for execution, * but handles failures internally. diff --git a/unit-tests/shared/src/test/scala-3/scala/issues/Scala3IssuesTest.scala b/unit-tests/shared/src/test/scala-3/scala/issues/Scala3IssuesTest.scala index 03f1e63ef1..fb2dbe00bb 100644 --- a/unit-tests/shared/src/test/scala-3/scala/issues/Scala3IssuesTest.scala +++ b/unit-tests/shared/src/test/scala-3/scala/issues/Scala3IssuesTest.scala @@ -90,7 +90,7 @@ class Scala3IssuesTest: end Scala3IssuesTest private object issue2484 { - final class CallByNeed[A] private (private[this] var eval: () => A) { + final class CallByNeed[A] private (private var eval: () => A) { lazy val value: A = { val value0 = eval() eval = null diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/io/InputStreamReaderTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/io/InputStreamReaderTest.scala index 256f5f43cc..43cdf7e485 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/io/InputStreamReaderTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/io/InputStreamReaderTest.scala @@ -10,7 +10,7 @@ import org.scalanative.testsuite.utils.AssertThrows.assertThrows class InputStreamReaderTest { class MockInputStream extends InputStream { - private[this] var _closed: Boolean = false + private var _closed: Boolean = false def isClosed: Boolean = _closed diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/security/TimestampTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/security/TimestampTest.scala index 7c199b67b6..eaec13c098 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/security/TimestampTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/security/TimestampTest.scala @@ -15,7 +15,7 @@ import org.scalanative.testsuite.utils.AssertThrows.assertThrows */ class TimestampTest { - private[this] val now: Date = new Date() + private val now: Date = new Date() case object MockCertificate extends java.security.cert.Certificate("") { override def getEncoded: Array[Byte] = Array.empty[Byte] diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/AbstractCollectionTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/AbstractCollectionTest.scala index 6ceb0b62b8..63599d3bfe 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/AbstractCollectionTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/AbstractCollectionTest.scala @@ -48,8 +48,8 @@ object AbstractCollectionFactory { private var iterInner: Array[AnyRef] ) extends ju.Iterator[E] { - private[this] var nextIndex: Int = 0 - private[this] var canRemove: Boolean = false + private var nextIndex: Int = 0 + private var canRemove: Boolean = false def hasNext(): Boolean = { checkConcurrentModification() diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/BiPredicateTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/BiPredicateTest.scala index 068317246f..3b5bbc1115 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/BiPredicateTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/BiPredicateTest.scala @@ -98,7 +98,7 @@ object BiPredicateTest { throw new AssertionError(s"dontCallPredicate.test($t, $u)") } - private[this] def makeBiPredicate[T, U]( + private def makeBiPredicate[T, U]( f: (T, U) => Boolean ): BiPredicate[T, U] = { new BiPredicate[T, U] { diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/FunctionTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/FunctionTest.scala index 44b86f6c19..2f99f2a372 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/FunctionTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/function/FunctionTest.scala @@ -39,7 +39,7 @@ object FunctionTest { private val doubleFunc: Function[Int, Int] = makeFunction(x => x * 2) private val incFunc: Function[Int, Int] = makeFunction(x => x + 1) - private[this] def makeFunction[T, R](f: T => R): Function[T, R] = { + private def makeFunction[T, R](f: T => R): Function[T, R] = { new Function[T, R] { def apply(t: T): R = f(t) } From 72d149254bcd39b1c7cfb0b42112d83153a802fc Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 21 Dec 2023 14:38:45 +0000 Subject: [PATCH 27/38] Replace deprectated `protected[this]` with `protected` (cherry picked from commit 23ecf283e426a118274595b9ce0ba46a82d10ee2) --- .../src/main/scala/java/io/BufferedInputStream.scala | 10 +++++----- javalib/src/main/scala/java/util/AbstractList.scala | 4 ++-- javalib/src/main/scala/java/util/HashMap.scala | 8 ++++---- javalib/src/main/scala/java/util/LinkedHashMap.scala | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/javalib/src/main/scala/java/io/BufferedInputStream.scala b/javalib/src/main/scala/java/io/BufferedInputStream.scala index ea3321ab23..8a7c409f72 100644 --- a/javalib/src/main/scala/java/io/BufferedInputStream.scala +++ b/javalib/src/main/scala/java/io/BufferedInputStream.scala @@ -22,24 +22,24 @@ class BufferedInputStream(_in: InputStream, initialSize: Int) // per spec close will release system resources. This implies buf should be set to null // post close to ensure GC can release this resource /** The internal buffer array where the data is stored. */ - protected[this] var buf = new Array[Byte](initialSize) + protected var buf = new Array[Byte](initialSize) /** The index one greater than the index of the last valid byte in the buffer. */ - protected[this] var count: Int = 0 + protected var count: Int = 0 private var closed: Boolean = false /** The maximum read ahead allowed after a call to the mark method before* * subsequent calls to the reset method fail. */ - protected[this] var marklimit: Int = 0 + protected var marklimit: Int = 0 /** The value of the pos field at the time the last mark method was called. */ - protected[this] var markpos: Int = -1 + protected var markpos: Int = -1 /** The current position in the buffer. */ - protected[this] var pos: Int = 0 + protected var pos: Int = 0 override def available(): Int = { val (_, in) = ensureOpen() diff --git a/javalib/src/main/scala/java/util/AbstractList.scala b/javalib/src/main/scala/java/util/AbstractList.scala index 3c737e7bca..9624e7f5ba 100644 --- a/javalib/src/main/scala/java/util/AbstractList.scala +++ b/javalib/src/main/scala/java/util/AbstractList.scala @@ -159,12 +159,12 @@ abstract class AbstractList[E] protected () } } - protected[this] def checkIndexInBounds(index: Int): Unit = { + protected def checkIndexInBounds(index: Int): Unit = { if (index < 0 || index >= size()) throw new IndexOutOfBoundsException(index.toString) } - protected[this] def checkIndexOnBounds(index: Int): Unit = { + protected def checkIndexOnBounds(index: Int): Unit = { if (index < 0 || index > size()) throw new IndexOutOfBoundsException(index.toString) } diff --git a/javalib/src/main/scala/java/util/HashMap.scala b/javalib/src/main/scala/java/util/HashMap.scala index 02a3ca0d04..5c098a3d98 100644 --- a/javalib/src/main/scala/java/util/HashMap.scala +++ b/javalib/src/main/scala/java/util/HashMap.scala @@ -553,15 +553,15 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) nodeIterator().asInstanceOf[ju.Iterator[Map.Entry[K, V]]] private final class NodeIterator extends AbstractHashMapIterator[Node[K, V]] { - protected[this] def extract(node: Node[K, V]): Node[K, V] = node + protected def extract(node: Node[K, V]): Node[K, V] = node } private final class KeyIterator extends AbstractHashMapIterator[K] { - protected[this] def extract(node: Node[K, V]): K = node.key + protected def extract(node: Node[K, V]): K = node.key } private final class ValueIterator extends AbstractHashMapIterator[V] { - protected[this] def extract(node: Node[K, V]): V = node.value + protected def extract(node: Node[K, V]): V = node.value } private abstract class AbstractHashMapIterator[A] extends ju.Iterator[A] { @@ -570,7 +570,7 @@ class HashMap[K, V](initialCapacity: Int, loadFactor: Float) private var nextNode: Node[K, V] = _ // null private var lastNode: Node[K, V] = _ // null - protected[this] def extract(node: Node[K, V]): A + protected def extract(node: Node[K, V]): A /* Movements of `nextNode` and `nextIdx` are spread over `hasNext()` to * simplify initial conditions, and preserving as much performance as diff --git a/javalib/src/main/scala/java/util/LinkedHashMap.scala b/javalib/src/main/scala/java/util/LinkedHashMap.scala index 9996db30fa..af14306f6e 100644 --- a/javalib/src/main/scala/java/util/LinkedHashMap.scala +++ b/javalib/src/main/scala/java/util/LinkedHashMap.scala @@ -123,15 +123,15 @@ class LinkedHashMap[K, V]( private final class NodeIterator extends AbstractLinkedHashMapIterator[HashMap.Node[K, V]] { - protected[this] def extract(node: Node[K, V]): Node[K, V] = node + protected def extract(node: Node[K, V]): Node[K, V] = node } private final class KeyIterator extends AbstractLinkedHashMapIterator[K] { - protected[this] def extract(node: Node[K, V]): K = node.key + protected def extract(node: Node[K, V]): K = node.key } private final class ValueIterator extends AbstractLinkedHashMapIterator[V] { - protected[this] def extract(node: Node[K, V]): V = node.value + protected def extract(node: Node[K, V]): V = node.value } private abstract class AbstractLinkedHashMapIterator[A] @@ -139,7 +139,7 @@ class LinkedHashMap[K, V]( private var nextNode: Node[K, V] = eldest private var lastNode: Node[K, V] = _ - protected[this] def extract(node: Node[K, V]): A + protected def extract(node: Node[K, V]): A def hasNext(): Boolean = nextNode ne null From 356b880189894150029b4903907ae42777b4f124 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 21 Dec 2023 16:11:41 +0100 Subject: [PATCH 28/38] Fix more deprecations in all modules and run scalafmt (cherry picked from commit 0fad84d58ea2db0422f50af6d357f980b8170911) --- .../src/main/scala/java/lang/Character.scala | 208 +++++++++--------- .../nscplugin/CompilerCompat.scala | 2 +- .../scalanative/nscplugin/NirPositions.scala | 2 +- project/Build.scala | 13 +- project/Settings.scala | 15 +- ...le.scala2.patch => Selectable.scala.patch} | 18 +- .../scala/scalanative/interflow/Eval.scala | 2 +- .../scala/scalanative/interflow/Visit.scala | 2 +- .../scala/scalanative/linker/Infos.scala | 2 +- .../scala/scala/scalanative/IssuesTest.scala | 2 +- .../scala/reflect/StructuralTest.scala | 4 +- .../javalib/lang/CharacterTest.scala | 80 +++---- .../testsuite/javalib/lang/DoubleTest.scala | 44 ++-- .../testsuite/javalib/lang/FloatTest.scala | 44 ++-- .../testsuite/javalib/lang/StringTest.scala | 90 ++++---- .../testsuite/javalib/util/DateTest.scala | 4 +- .../scala/scalanative/util/ScopedVar.scala | 4 +- 17 files changed, 272 insertions(+), 264 deletions(-) rename scalalib/overrides-3.3/scala/reflect/{Selectable.scala2.patch => Selectable.scala.patch} (71%) diff --git a/javalib/src/main/scala/java/lang/Character.scala b/javalib/src/main/scala/java/lang/Character.scala index 9adbb3f8bd..011fa88691 100644 --- a/javalib/src/main/scala/java/lang/Character.scala +++ b/javalib/src/main/scala/java/lang/Character.scala @@ -1405,115 +1405,113 @@ object Character { // Refer to the following project for the transformation code. // https://github.com/ekrich/scala-unicode - private lazy val lowerRanges = Array[scala.Int](97, 122, 181, 224, 246, - 248, 254, 255, 257, 303, 305, 307, 311, 314, 328, 331, 375, 378, 382, 383, - 384, 387, 389, 392, 396, 402, 405, 409, 410, 414, 417, 421, 424, 429, 432, - 436, 438, 441, 445, 447, 453, 454, 456, 457, 459, 460, 462, 476, 477, 479, - 495, 498, 499, 501, 505, 543, 547, 563, 572, 575, 576, 578, 583, 591, 592, - 593, 594, 595, 596, 598, 599, 601, 603, 604, 608, 609, 611, 613, 614, 616, - 617, 618, 619, 620, 623, 625, 626, 629, 637, 640, 642, 643, 647, 648, 649, - 650, 651, 652, 658, 669, 670, 837, 881, 883, 887, 891, 893, 940, 941, 943, - 945, 961, 962, 963, 971, 972, 973, 974, 976, 977, 981, 982, 983, 985, 1007, - 1008, 1009, 1010, 1011, 1013, 1016, 1019, 1072, 1103, 1104, 1119, 1121, - 1153, 1163, 1215, 1218, 1230, 1231, 1233, 1327, 1377, 1414, 4304, 4346, - 4349, 4351, 5112, 5117, 7296, 7297, 7298, 7299, 7300, 7301, 7302, 7303, - 7304, 7545, 7549, 7566, 7681, 7829, 7835, 7841, 7935, 7936, 7943, 7952, - 7957, 7968, 7975, 7984, 7991, 8000, 8005, 8017, 8023, 8032, 8039, 8048, - 8049, 8050, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, 8064, - 8071, 8080, 8087, 8096, 8103, 8112, 8113, 8115, 8126, 8131, 8144, 8145, - 8160, 8161, 8165, 8179, 8526, 8560, 8575, 8580, 9424, 9449, 11312, 11358, - 11361, 11365, 11366, 11368, 11372, 11379, 11382, 11393, 11491, 11500, 11502, - 11507, 11520, 11557, 11559, 11565, 42561, 42605, 42625, 42651, 42787, 42799, - 42803, 42863, 42874, 42876, 42879, 42887, 42892, 42897, 42899, 42900, 42903, - 42921, 42933, 42943, 42947, 42952, 42954, 42998, 43859, 43888, 43967, 65345, - 65370, 66600, 66639, 66776, 66811, 68800, 68850, 71872, 71903, 93792, 93823, + private lazy val lowerRanges = Array[scala.Int](97, 122, 181, 224, 246, 248, + 254, 255, 257, 303, 305, 307, 311, 314, 328, 331, 375, 378, 382, 383, 384, + 387, 389, 392, 396, 402, 405, 409, 410, 414, 417, 421, 424, 429, 432, 436, + 438, 441, 445, 447, 453, 454, 456, 457, 459, 460, 462, 476, 477, 479, 495, + 498, 499, 501, 505, 543, 547, 563, 572, 575, 576, 578, 583, 591, 592, 593, + 594, 595, 596, 598, 599, 601, 603, 604, 608, 609, 611, 613, 614, 616, 617, + 618, 619, 620, 623, 625, 626, 629, 637, 640, 642, 643, 647, 648, 649, 650, + 651, 652, 658, 669, 670, 837, 881, 883, 887, 891, 893, 940, 941, 943, 945, + 961, 962, 963, 971, 972, 973, 974, 976, 977, 981, 982, 983, 985, 1007, 1008, + 1009, 1010, 1011, 1013, 1016, 1019, 1072, 1103, 1104, 1119, 1121, 1153, + 1163, 1215, 1218, 1230, 1231, 1233, 1327, 1377, 1414, 4304, 4346, 4349, + 4351, 5112, 5117, 7296, 7297, 7298, 7299, 7300, 7301, 7302, 7303, 7304, + 7545, 7549, 7566, 7681, 7829, 7835, 7841, 7935, 7936, 7943, 7952, 7957, + 7968, 7975, 7984, 7991, 8000, 8005, 8017, 8023, 8032, 8039, 8048, 8049, + 8050, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, 8064, 8071, + 8080, 8087, 8096, 8103, 8112, 8113, 8115, 8126, 8131, 8144, 8145, 8160, + 8161, 8165, 8179, 8526, 8560, 8575, 8580, 9424, 9449, 11312, 11358, 11361, + 11365, 11366, 11368, 11372, 11379, 11382, 11393, 11491, 11500, 11502, 11507, + 11520, 11557, 11559, 11565, 42561, 42605, 42625, 42651, 42787, 42799, 42803, + 42863, 42874, 42876, 42879, 42887, 42892, 42897, 42899, 42900, 42903, 42921, + 42933, 42943, 42947, 42952, 42954, 42998, 43859, 43888, 43967, 65345, 65370, + 66600, 66639, 66776, 66811, 68800, 68850, 71872, 71903, 93792, 93823, 125218, 125251) - private lazy val lowerDeltas = Array[scala.Int](32, 32, -743, 32, 32, - 32, 32, -121, 1, 1, 232, 1, 1, 1, 1, 1, 1, 1, 1, 300, -195, 1, 1, 1, 1, 1, - -97, 1, -163, -130, 1, 1, 1, 1, 1, 1, 1, 1, 1, -56, 1, 2, 1, 2, 1, 2, 1, 1, - 79, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, -10815, -10815, 1, 1, 1, -10783, -10780, - -10782, 210, 206, 205, 205, 202, 203, -42319, 205, -42315, 207, -42280, - -42308, 209, 211, -42308, -10743, -42305, 211, -10749, 213, 214, -10727, - 218, -42307, 218, -42282, 218, 69, 217, 217, 71, 219, -42261, -42258, -84, - 1, 1, 1, -130, -130, 38, 37, 37, 32, 32, 31, 32, 32, 64, 63, 63, 62, 57, 47, - 54, 8, 1, 1, 86, 80, -7, 116, 96, 1, 1, 32, 32, 80, 80, 1, 1, 1, 1, 1, 1, - 15, 1, 1, 48, 48, -3008, -3008, -3008, -3008, 8, 8, 6254, 6253, 6244, 6242, - 6242, 6243, 6236, 6181, -35266, -35332, -3814, -35384, 1, 1, 59, 1, 1, -8, - -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -74, -74, -86, -86, - -100, -100, -128, -128, -112, -112, -126, -126, -8, -8, -8, -8, -8, -8, -8, - -8, -9, 7205, -9, -8, -8, -8, -8, -7, -9, 28, 16, 16, 1, 26, 26, 48, 48, 1, - 10795, 10792, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7264, 7264, 7264, 7264, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -48, 1, 1, 1, 1, 1, 1, 1, 1, 928, 38864, - 38864, 32, 32, 40, 40, 40, 40, 64, 64, 32, 32, 32, 32, 34, 34) - - private lazy val lowerSteps = Array[scala.Byte](0, 1, 0, 0, 1, 0, 1, 0, - 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 2, - 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, - 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 1, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, - 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, - 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0, - 0, 1, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, - 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) - - private lazy val upperRanges = Array[scala.Int](65, 90, 192, 214, 216, - 222, 256, 302, 304, 306, 310, 313, 327, 330, 374, 376, 377, 381, 385, 386, - 388, 390, 391, 393, 394, 395, 398, 399, 400, 401, 403, 404, 406, 407, 408, - 412, 413, 415, 416, 420, 422, 423, 425, 428, 430, 431, 433, 434, 435, 437, - 439, 440, 444, 452, 453, 455, 456, 458, 459, 475, 478, 494, 497, 498, 500, - 502, 503, 504, 542, 544, 546, 562, 570, 571, 573, 574, 577, 579, 580, 581, - 582, 590, 880, 882, 886, 895, 902, 904, 906, 908, 910, 911, 913, 929, 931, - 939, 975, 984, 1006, 1012, 1015, 1017, 1018, 1021, 1023, 1024, 1039, 1040, - 1071, 1120, 1152, 1162, 1214, 1216, 1217, 1229, 1232, 1326, 1329, 1366, - 4256, 4293, 4295, 4301, 5024, 5103, 5104, 5109, 7312, 7354, 7357, 7359, - 7680, 7828, 7838, 7840, 7934, 7944, 7951, 7960, 7965, 7976, 7983, 7992, - 7999, 8008, 8013, 8025, 8031, 8040, 8047, 8072, 8079, 8088, 8095, 8104, - 8111, 8120, 8121, 8122, 8123, 8124, 8136, 8139, 8140, 8152, 8153, 8154, - 8155, 8168, 8169, 8170, 8171, 8172, 8184, 8185, 8186, 8187, 8188, 8486, - 8490, 8491, 8498, 8544, 8559, 8579, 9398, 9423, 11264, 11310, 11360, 11362, - 11363, 11364, 11367, 11371, 11373, 11374, 11375, 11376, 11378, 11381, 11390, - 11391, 11392, 11490, 11499, 11501, 11506, 42560, 42604, 42624, 42650, 42786, - 42798, 42802, 42862, 42873, 42875, 42877, 42878, 42886, 42891, 42893, 42896, - 42898, 42902, 42920, 42922, 42923, 42924, 42925, 42926, 42928, 42929, 42930, - 42931, 42932, 42942, 42946, 42948, 42949, 42950, 42951, 42953, 42997, 65313, - 65338, 66560, 66599, 66736, 66771, 68736, 68786, 71840, 71871, 93760, 93791, + private lazy val lowerDeltas = Array[scala.Int](32, 32, -743, 32, 32, 32, 32, + -121, 1, 1, 232, 1, 1, 1, 1, 1, 1, 1, 1, 300, -195, 1, 1, 1, 1, 1, -97, 1, + -163, -130, 1, 1, 1, 1, 1, 1, 1, 1, 1, -56, 1, 2, 1, 2, 1, 2, 1, 1, 79, 1, + 1, 1, 2, 1, 1, 1, 1, 1, 1, -10815, -10815, 1, 1, 1, -10783, -10780, -10782, + 210, 206, 205, 205, 202, 203, -42319, 205, -42315, 207, -42280, -42308, 209, + 211, -42308, -10743, -42305, 211, -10749, 213, 214, -10727, 218, -42307, + 218, -42282, 218, 69, 217, 217, 71, 219, -42261, -42258, -84, 1, 1, 1, -130, + -130, 38, 37, 37, 32, 32, 31, 32, 32, 64, 63, 63, 62, 57, 47, 54, 8, 1, 1, + 86, 80, -7, 116, 96, 1, 1, 32, 32, 80, 80, 1, 1, 1, 1, 1, 1, 15, 1, 1, 48, + 48, -3008, -3008, -3008, -3008, 8, 8, 6254, 6253, 6244, 6242, 6242, 6243, + 6236, 6181, -35266, -35332, -3814, -35384, 1, 1, 59, 1, 1, -8, -8, -8, -8, + -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -74, -74, -86, -86, -100, -100, + -128, -128, -112, -112, -126, -126, -8, -8, -8, -8, -8, -8, -8, -8, -9, + 7205, -9, -8, -8, -8, -8, -7, -9, 28, 16, 16, 1, 26, 26, 48, 48, 1, 10795, + 10792, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7264, 7264, 7264, 7264, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, -48, 1, 1, 1, 1, 1, 1, 1, 1, 928, 38864, 38864, + 32, 32, 40, 40, 40, 40, 64, 64, 32, 32, 32, 32, 34, 34) + + private lazy val lowerSteps = Array[scala.Byte](0, 1, 0, 0, 1, 0, 1, 0, 0, 2, + 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, + 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 2, 0, 0, + 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 1, + 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 1, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 0, + 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0, 0, 1, + 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, + 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) + + private lazy val upperRanges = Array[scala.Int](65, 90, 192, 214, 216, 222, + 256, 302, 304, 306, 310, 313, 327, 330, 374, 376, 377, 381, 385, 386, 388, + 390, 391, 393, 394, 395, 398, 399, 400, 401, 403, 404, 406, 407, 408, 412, + 413, 415, 416, 420, 422, 423, 425, 428, 430, 431, 433, 434, 435, 437, 439, + 440, 444, 452, 453, 455, 456, 458, 459, 475, 478, 494, 497, 498, 500, 502, + 503, 504, 542, 544, 546, 562, 570, 571, 573, 574, 577, 579, 580, 581, 582, + 590, 880, 882, 886, 895, 902, 904, 906, 908, 910, 911, 913, 929, 931, 939, + 975, 984, 1006, 1012, 1015, 1017, 1018, 1021, 1023, 1024, 1039, 1040, 1071, + 1120, 1152, 1162, 1214, 1216, 1217, 1229, 1232, 1326, 1329, 1366, 4256, + 4293, 4295, 4301, 5024, 5103, 5104, 5109, 7312, 7354, 7357, 7359, 7680, + 7828, 7838, 7840, 7934, 7944, 7951, 7960, 7965, 7976, 7983, 7992, 7999, + 8008, 8013, 8025, 8031, 8040, 8047, 8072, 8079, 8088, 8095, 8104, 8111, + 8120, 8121, 8122, 8123, 8124, 8136, 8139, 8140, 8152, 8153, 8154, 8155, + 8168, 8169, 8170, 8171, 8172, 8184, 8185, 8186, 8187, 8188, 8486, 8490, + 8491, 8498, 8544, 8559, 8579, 9398, 9423, 11264, 11310, 11360, 11362, 11363, + 11364, 11367, 11371, 11373, 11374, 11375, 11376, 11378, 11381, 11390, 11391, + 11392, 11490, 11499, 11501, 11506, 42560, 42604, 42624, 42650, 42786, 42798, + 42802, 42862, 42873, 42875, 42877, 42878, 42886, 42891, 42893, 42896, 42898, + 42902, 42920, 42922, 42923, 42924, 42925, 42926, 42928, 42929, 42930, 42931, + 42932, 42942, 42946, 42948, 42949, 42950, 42951, 42953, 42997, 65313, 65338, + 66560, 66599, 66736, 66771, 68736, 68786, 71840, 71871, 93760, 93791, 125184, 125217) - private lazy val upperDeltas = Array[scala.Int](-32, -32, -32, -32, -32, - -32, -1, -1, 199, -1, -1, -1, -1, -1, -1, 121, -1, -1, -210, -1, -1, -206, - -1, -205, -205, -1, -79, -202, -203, -1, -205, -207, -211, -209, -1, -211, - -213, -214, -1, -1, -218, -1, -218, -1, -218, -1, -217, -217, -1, -1, -219, - -1, -1, -2, -1, -2, -1, -2, -1, -1, -1, -1, -2, -1, -1, 97, 56, -1, -1, 130, - -1, -1, -10795, -1, 163, -10792, -1, 195, -69, -71, -1, -1, -1, -1, -1, - -116, -38, -37, -37, -64, -63, -63, -32, -32, -32, -32, -8, -1, -1, 60, -1, - 7, -1, 130, 130, -80, -80, -32, -32, -1, -1, -1, -1, -15, -1, -1, -1, -1, - -48, -48, -7264, -7264, -7264, -7264, -38864, -38864, -8, -8, 3008, 3008, - 3008, 3008, -1, -1, 7615, -1, -1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 74, 74, 9, 86, 86, 9, 8, 8, 100, 100, 8, 8, 112, - 112, 7, 128, 128, 126, 126, 9, 7517, 8383, 8262, -28, -16, -16, -1, -26, - -26, -48, -48, -1, 10743, 3814, 10727, -1, -1, 10780, 10749, 10783, 10782, - -1, -1, 10815, 10815, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 35332, -1, -1, -1, 42280, -1, -1, -1, -1, 42308, 42319, 42315, - 42305, 42308, 42258, 42282, 42261, -928, -1, -1, -1, 48, 42307, 35384, -1, - -1, -1, -32, -32, -40, -40, -40, -40, -64, -64, -32, -32, -32, -32, -34, - -34) - - private lazy val upperSteps = Array[scala.Byte](0, 1, 0, 1, 0, 1, 0, 2, - 0, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 2, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, - 1, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, - 2, 0, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, - 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 2, - 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, - 0, 1) + private lazy val upperDeltas = Array[scala.Int](-32, -32, -32, -32, -32, -32, + -1, -1, 199, -1, -1, -1, -1, -1, -1, 121, -1, -1, -210, -1, -1, -206, -1, + -205, -205, -1, -79, -202, -203, -1, -205, -207, -211, -209, -1, -211, -213, + -214, -1, -1, -218, -1, -218, -1, -218, -1, -217, -217, -1, -1, -219, -1, + -1, -2, -1, -2, -1, -2, -1, -1, -1, -1, -2, -1, -1, 97, 56, -1, -1, 130, -1, + -1, -10795, -1, 163, -10792, -1, 195, -69, -71, -1, -1, -1, -1, -1, -116, + -38, -37, -37, -64, -63, -63, -32, -32, -32, -32, -8, -1, -1, 60, -1, 7, -1, + 130, 130, -80, -80, -32, -32, -1, -1, -1, -1, -15, -1, -1, -1, -1, -48, -48, + -7264, -7264, -7264, -7264, -38864, -38864, -8, -8, 3008, 3008, 3008, 3008, + -1, -1, 7615, -1, -1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 74, 74, 9, 86, 86, 9, 8, 8, 100, 100, 8, 8, 112, 112, 7, 128, + 128, 126, 126, 9, 7517, 8383, 8262, -28, -16, -16, -1, -26, -26, -48, -48, + -1, 10743, 3814, 10727, -1, -1, 10780, 10749, 10783, 10782, -1, -1, 10815, + 10815, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 35332, + -1, -1, -1, 42280, -1, -1, -1, -1, 42308, 42319, 42315, 42305, 42308, 42258, + 42282, 42261, -928, -1, -1, -1, 48, 42307, 35384, -1, -1, -1, -32, -32, -40, + -40, -40, -40, -64, -64, -32, -32, -32, -32, -34, -34) + + private lazy val upperSteps = Array[scala.Byte](0, 1, 0, 1, 0, 1, 0, 2, 0, 0, + 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, + 2, 0, 2, 0, 0, 2, 0, 2, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, + 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, + 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 2, 0, 0, + 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) private object CaseUtil { lazy val a = lowerRanges(0) diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala index 3562275b6e..5ca93aa9b4 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/CompilerCompat.scala @@ -4,7 +4,7 @@ object CompilerCompat { private object SymUtilsCompatDef: val SymUtils = dotty.tools.dotc.core.Symbols - + private object SymUtilsCompatSelect: import SymUtilsCompatDef._ object Inner { diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala index 1328ec3b71..e5d3898f9a 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala @@ -35,7 +35,7 @@ class NirPositions(sourceURIMaps: List[GenNIR.URIMap])(using Context) { private object conversionCache { import dotty.tools.dotc.util._ private var lastDotcSource: SourceFile = uninitialized - private var lastNIRSource: nir.Position.SourceFile = uninitialized + private var lastNIRSource: nir.SourceFile = uninitialized def toNIRSource(dotcSource: SourceFile): nir.Position.SourceFile = { if (dotcSource != lastDotcSource) { diff --git a/project/Build.scala b/project/Build.scala index 1328c28949..b443345e05 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -119,12 +119,16 @@ object Build { ) { case (2, _) => Seq("-Xno-patmat-analysis") } + scalacOptions --= ignoredScalaDeprecations(scalaVersion.value) ) .dependsOnSource(nir) .dependsOnSource(util) lazy val junitPlugin = MultiScalaProject("junitPlugin", file("junit-plugin")) - .settings(compilerPluginSettings) + .settings( + compilerPluginSettings, + scalacOptions --= ignoredScalaDeprecations(scalaVersion.value) + ) // NIR compiler lazy val util = MultiScalaProject("util") @@ -280,8 +284,7 @@ object Build { .settings( mavenPublishSettings, docsSettings, - libraryDependencies ++= Deps.NativeLib(scalaVersion.value), - scalacOptions ++= Settings.ignoredScalaDeprecations(scalaVersion.value) + libraryDependencies ++= Deps.NativeLib(scalaVersion.value) ) .withNativeCompilerPlugin @@ -333,7 +336,9 @@ object Build { lazy val scalalib: MultiScalaProject = MultiScalaProject("scalalib") .enablePlugins(MyScalaNativePlugin) - .settings(mavenPublishSettings, disabledDocsSettings) + .settings(mavenPublishSettings, disabledDocsSettings, + scalacOptions --= ignoredScalaDeprecations(scalaVersion.value) + ) .withNativeCompilerPlugin .mapBinaryVersions { case version @ ("2.12" | "2.13") => diff --git a/project/Settings.scala b/project/Settings.scala index a16d851e81..b32b14a640 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -69,7 +69,8 @@ object Settings { javaReleaseSettings, publishSettings, mimaSettings, - docsSettings + docsSettings, + scalacOptions ++= ignoredScalaDeprecations(scalaVersion.value) ) def javaReleaseSettings = { @@ -555,8 +556,7 @@ object Settings { lazy val toolSettings: Seq[Setting[_]] = Def.settings( - javacOptions ++= Seq("-encoding", "utf8"), - scalacOptions ++= ignoredScalaDeprecations(scalaVersion.value) + javacOptions ++= Seq("-encoding", "utf8") ) def ignoredScalaDeprecations(scalaVersion: String): Seq[String] = { @@ -572,7 +572,11 @@ object Settings { def scala3Deprecations = Seq( "`= _` has been deprecated", - "`_` is deprecated for wildcard arguments of types" + "`_` is deprecated for wildcard arguments of types", + // -Wconf msg string cannot contain ':' character, it cannot be escaped + /*The syntax `x: _* is */ "no longer supported for vararg splice", + "The syntax ` _` is no longer supported", + "with as a type operator has been deprecated" ).map(msg => s"-Wconf:msg=$msg:s") CrossVersion @@ -626,8 +630,7 @@ object Settings { Compile / scalacOptions ++= scalaNativeCompilerOptions( "genStaticForwardersForNonTopLevelObjects" ), - NIROnlySettings, - scalacOptions ++= Settings.ignoredScalaDeprecations(scalaVersion.value), + NIROnlySettings ) // Calculates all prefixes of the current Scala version diff --git a/scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch b/scalalib/overrides-3.3/scala/reflect/Selectable.scala.patch similarity index 71% rename from scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch rename to scalalib/overrides-3.3/scala/reflect/Selectable.scala.patch index 9aa871e7b5..9fdb3442ae 100644 --- a/scalalib/overrides-3.3/scala/reflect/Selectable.scala2.patch +++ b/scalalib/overrides-3.3/scala/reflect/Selectable.scala.patch @@ -1,6 +1,6 @@ ---- 3.4.0-RC1/scala/reflect/Selectable.scala +--- 3.1.2/scala/reflect/Selectable.scala +++ overrides-3/scala/reflect/Selectable.scala -@@ -16,16 +16,17 @@ +@@ -16,16 +16,16 @@ */ protected def selectedValue: Any = this @@ -13,26 +13,26 @@ + // The Scala.js codegen relies on this method being final for correctness /** Select member with given name */ - final def selectDynamic(name: String): Any = +- final def selectDynamic(name: String): Any = - val rcls = selectedValue.getClass - try -- val fld = rcls.getField(NameTransformer.encode(name)).nn +- val fld = rcls.getField(name).nn - ensureAccessible(fld) - fld.get(selectedValue) - catch case ex: NoSuchFieldException => - applyDynamic(name)() -+ unreachable("selectDynamic") ++ final def selectDynamic(name: String): Any = unreachable("selectDynamic") // The Scala.js codegen relies on this method being final for correctness /** Select method and apply to arguments. -@@ -34,10 +35,7 @@ +@@ -34,10 +34,7 @@ * @param args The arguments to pass to the selected method */ - final def applyDynamic(name: String, paramTypes: Class[?]*)(args: Any*): Any = + final def applyDynamic(name: String, paramTypes: Class[_]*)(args: Any*): Any = - val rcls = selectedValue.getClass -- val mth = rcls.getMethod(NameTransformer.encode(name), paramTypes*).nn +- val mth = rcls.getMethod(name, paramTypes: _*).nn - ensureAccessible(mth) -- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]*) +- mth.invoke(selectedValue, args.asInstanceOf[Seq[AnyRef]]: _*) + unreachable("applyDynamic") object Selectable: diff --git a/tools/src/main/scala/scala/scalanative/interflow/Eval.scala b/tools/src/main/scala/scala/scalanative/interflow/Eval.scala index 3e0b3d2c37..1e1f75bf30 100644 --- a/tools/src/main/scala/scala/scalanative/interflow/Eval.scala +++ b/tools/src/main/scala/scala/scalanative/interflow/Eval.scala @@ -904,7 +904,7 @@ trait Eval { self: Interflow => } else { visiting = clsName :: visiting - val init = clsName member Sig.Ctor(Seq.empty) + val init = clsName.member(nir.Sig.Ctor(Seq.empty)) val isPure = if (!shallVisit(init)) { true diff --git a/tools/src/main/scala/scala/scalanative/interflow/Visit.scala b/tools/src/main/scala/scala/scalanative/interflow/Visit.scala index 0b255cc26e..21bd1f5c21 100644 --- a/tools/src/main/scala/scala/scalanative/interflow/Visit.scala +++ b/tools/src/main/scala/scala/scalanative/interflow/Visit.scala @@ -60,7 +60,7 @@ trait Visit { self: Interflow => case meth: Method => visitRoot(name) case cls: Class if cls.isModule => - val init = cls.name member Sig.Ctor(Seq.empty) + val init = cls.name.member(nir.Sig.Ctor(Seq.empty)) if (hasOriginal(init)) { visitRoot(init) } diff --git a/tools/src/main/scala/scala/scalanative/linker/Infos.scala b/tools/src/main/scala/scala/scalanative/linker/Infos.scala index c826fbf964..645f4902c7 100644 --- a/tools/src/main/scala/scala/scalanative/linker/Infos.scala +++ b/tools/src/main/scala/scala/scalanative/linker/Infos.scala @@ -126,7 +126,7 @@ final class Class( val hasNoFields = fields.isEmpty val hasEmptyOrNoCtor = { - val ctor = name member Sig.Ctor(Seq.empty) + val ctor = name.member(nir.Sig.Ctor(Seq.empty)) top.infos .get(ctor) .fold[Boolean] { diff --git a/unit-tests/native/src/test/scala/scala/scalanative/IssuesTest.scala b/unit-tests/native/src/test/scala/scala/scalanative/IssuesTest.scala index 7cfc23e820..4747716d65 100644 --- a/unit-tests/native/src/test/scala/scala/scalanative/IssuesTest.scala +++ b/unit-tests/native/src/test/scala/scala/scalanative/IssuesTest.scala @@ -116,7 +116,7 @@ class IssuesTest { val world = "world" m(hello) = world val h = m.getOrElse(hello, "Failed !") - assertTrue(h equals world) + assertTrue(h.equals(world)) } @deprecated val fptrBoxed: CFuncPtr0[Integer] = () => new Integer(1) diff --git a/unit-tests/shared/src/test/scala-3/scala/reflect/StructuralTest.scala b/unit-tests/shared/src/test/scala-3/scala/reflect/StructuralTest.scala index 76ba949e7f..a325217b08 100644 --- a/unit-tests/shared/src/test/scala-3/scala/reflect/StructuralTest.scala +++ b/unit-tests/shared/src/test/scala-3/scala/reflect/StructuralTest.scala @@ -24,7 +24,7 @@ class StructuralTest() { @Test def testStructuralVal(): Unit = { // Consider one module upcasting all these instances to T. These casts are clearly well-typed. - type T = { val a: Int } + type T = { def a: Int } def upcast1(v: Foo1): T = v def upcast2(v: Foo2): T = v def upcast3(v: Foo3): T = v @@ -88,7 +88,7 @@ class StructuralTest() { } @Test def testStructuralVar(): Unit = { - type T = { val a: Int; def a_=(x: Int): Unit } + type T = { def a: Int; def a_=(x: Int): Unit } def upcast3(v: Foo3): T = v def consume(v: T) = v.a inline def consumeInl(v: T) = v.a diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CharacterTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CharacterTest.scala index 5dcf55f9b1..604de9d998 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CharacterTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/CharacterTest.scala @@ -496,83 +496,83 @@ class CharacterTest { @Test def toLowerCaseLow(): Unit = { // low chars - assertTrue(toLowerCase('\n') equals '\n') + assertEquals(toLowerCase('\n'), '\n') } @Test def toLowerCaseAscii(): Unit = { // ascii chars - assertTrue(toLowerCase('A') equals 'a') - assertTrue(toLowerCase('a') equals 'a') - assertFalse(toLowerCase('a') equals 'A') - assertTrue(toLowerCase('F') equals 'f') - assertTrue(toLowerCase('Z') equals 'z') + assertEquals(toLowerCase('A'), 'a') + assertEquals(toLowerCase('a'), 'a') + assertNotEquals(toLowerCase('a'), 'A') + assertEquals(toLowerCase('F'), 'f') + assertEquals(toLowerCase('Z'), 'z') } @Test def toLowerCaseCompat(): Unit = { // compat characters are directly from the DB // (03F4,GREEK CAPITAL THETA SYMBOL,Lu,0,L, 0398,N,,03B8,) - assertTrue(toLowerCase(0x03f4) equals 0x03b8) - assertTrue(toLowerCase('Θ') equals 'θ') + assertEquals(toLowerCase(0x03f4), 0x03b8) + assertEquals(toLowerCase('Θ'), 'θ') // (2161,ROMAN NUMERAL TWO,Nl,0,L, 0049 0049,N,,2171,) - assertTrue(toLowerCase(0x2161) equals 0x2171) + assertEquals(toLowerCase(0x2161), 0x2171) // check lower to lower - assertTrue(toLowerCase('µ') equals 'µ') + assertEquals(toLowerCase('µ'), 'µ') } @Test def toLowerCaseAlt(): Unit = { // alternating upper and lower case // (256,257,-1,0)(302,303,-1,2) - assertTrue(toLowerCase(256) equals 257) - assertTrue(toLowerCase(257) equals 257) - assertTrue(toLowerCase(258) equals 259) - assertTrue(toLowerCase(302) equals 303) + assertEquals(toLowerCase(256), 257) + assertEquals(toLowerCase(257), 257) + assertEquals(toLowerCase(258), 259) + assertEquals(toLowerCase(302), 303) } @Test def toLowerCaseHigh(): Unit = { // high points - assertTrue(toLowerCase(65313) equals 65345) - assertTrue(toLowerCase(65338) equals 65370) - assertTrue(toLowerCase(65339) equals 65339) + assertEquals(toLowerCase(65313), 65345) + assertEquals(toLowerCase(65338), 65370) + assertEquals(toLowerCase(65339), 65339) } @Test def toLowerCaseAbove(): Unit = { // top and above range - assertTrue(toLowerCase(0x10ffff) equals 0x10ffff) - assertTrue(toLowerCase(0x110000) equals 0x110000) + assertEquals(toLowerCase(0x10ffff), 0x10ffff) + assertEquals(toLowerCase(0x110000), 0x110000) } @Test def toUpperCaseLow(): Unit = { // low chars - assertTrue(toUpperCase('\n') equals '\n') + assertEquals(toUpperCase('\n'), '\n') } @Test def toUpperCaseAscii(): Unit = { // ascii chars - assertTrue(toUpperCase('a') equals 'A') - assertTrue(toUpperCase('A') equals 'A') - assertFalse(toUpperCase('A') equals 'a') - assertTrue(toUpperCase('f') equals 'F') - assertTrue(toUpperCase('z') equals 'Z') + assertEquals(toUpperCase('a'), 'A') + assertEquals(toUpperCase('A'), 'A') + assertNotEquals(toUpperCase('A'), 'a') + assertEquals(toUpperCase('f'), 'F') + assertEquals(toUpperCase('z'), 'Z') } @Test def toUpperCaseCompat(): Unit = { // compat characters are directly from the DB // (03D0,GREEK BETA SYMBOL,Ll,0,L, 03B2,N,0392,,0392) - assertTrue(toUpperCase(0x03d0) equals 0x0392) - assertTrue(toUpperCase('β') equals 'Β') + assertEquals(toUpperCase(0x03d0), 0x0392) + assertEquals(toUpperCase('β'), 'Β') // (00B5,MICRO SIGN,Ll,0,L, 03BC,N,039C,,039C) - assertTrue(toUpperCase(0x00b5) equals 0x039c) - assertTrue(toUpperCase('μ') equals 'Μ') + assertEquals(toUpperCase(0x00b5), 0x039c) + assertEquals(toUpperCase('μ'), 'Μ') } @Test def toUpperCaseAlt(): Unit = { // alternating upper and lower case // (257,256,1,0)(303,302,1,2) - assertTrue(toUpperCase(257) equals 256) - assertTrue(toUpperCase(258) equals 258) - assertTrue(toUpperCase(259) equals 258) - assertTrue(toUpperCase(303) equals 302) + assertEquals(toUpperCase(257), 256) + assertEquals(toUpperCase(258), 258) + assertEquals(toUpperCase(259), 258) + assertEquals(toUpperCase(303), 302) } @Test def toUpperCaseHigh(): Unit = { @@ -580,20 +580,20 @@ class CharacterTest { // (65345,65313,32,0)(65370,65338,32,1) // (66600,66560,40,0)(66639,66599,40,1) // (71872,71840,32,0)(71903,71871,32,1) - assertTrue(toUpperCase(65345) equals 65313) - assertTrue(toUpperCase(65370) equals 65338) - assertTrue(toUpperCase(66600) equals 66560) + assertEquals(toUpperCase(65345), 65313) + assertEquals(toUpperCase(65370), 65338) + assertEquals(toUpperCase(66600), 66560) } @Test def toUpperCaseAbove(): Unit = { // top and above range - assertTrue(toUpperCase(0x10ffff) equals 0x10ffff) - assertTrue(toUpperCase(0x110000) equals 0x110000) + assertEquals(toUpperCase(0x10ffff), 0x10ffff) + assertEquals(toUpperCase(0x110000), 0x110000) } @Test def unicodeBlockOf(): Unit = { - assertTrue(UnicodeBlock.of('a') equals UnicodeBlock.BASIC_LATIN) - assertTrue(UnicodeBlock.of('א') equals UnicodeBlock.HEBREW) + assertEquals(UnicodeBlock.of('a'), UnicodeBlock.BASIC_LATIN) + assertEquals(UnicodeBlock.of('א'), UnicodeBlock.HEBREW) } // from scala-js tests diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/DoubleTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/DoubleTest.scala index f15bd901c1..b94f273856 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/DoubleTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/DoubleTest.scala @@ -31,73 +31,73 @@ class DoubleTest { @Test def testEquals(): Unit = { val pzero = +0.0 val nzero = -0.0 - assertTrue(pzero equals pzero) - assertTrue(nzero equals nzero) - assertFalse(pzero equals nzero) + assertTrue(pzero.equals(pzero)) + assertTrue(nzero.equals(nzero)) + assertFalse(pzero.equals(nzero)) val szero = 1.0 - 1.0 - assertTrue(pzero equals szero) + assertTrue(pzero.equals(szero)) val bpzero: java.lang.Double = pzero val bnzero: java.lang.Double = nzero - assertFalse(bpzero equals bnzero) + assertFalse(bpzero.equals(bnzero)) val bszero: java.lang.Double = szero - assertTrue(bpzero equals bszero) + assertTrue(bpzero.equals(bszero)) val num1 = 123.45 val num2 = 123.45 - assertTrue(num1 equals num2) + assertTrue(num1.equals(num2)) val bnum1: java.lang.Double = num1 val bnum2: java.lang.Double = num2 assertTrue(bnum1 == bnum2) val pmax1 = scala.Double.MaxValue val pmax2 = scala.Double.MaxValue - assertTrue(pmax1 equals pmax2) + assertTrue(pmax1.equals(pmax2)) val pmax3 = scala.Double.MaxValue + 1 - assertTrue(pmax1 equals pmax3) + assertTrue(pmax1.equals(pmax3)) val bpmax1: java.lang.Double = scala.Double.MaxValue val bpmax2: java.lang.Double = scala.Double.MaxValue - assertTrue(bpmax1 equals bpmax2) + assertTrue(bpmax1.equals(bpmax2)) val bpmax3: java.lang.Double = scala.Double.MaxValue + 1 - assertTrue(bpmax1 equals bpmax3) + assertTrue(bpmax1.equals(bpmax3)) val pmin1 = scala.Double.MinValue val pmin2 = scala.Double.MinValue - assertTrue(pmin1 equals pmin2) + assertTrue(pmin1.equals(pmin2)) val pmin3 = scala.Double.MinValue + 1 - assertTrue(pmin1 equals pmin3) + assertTrue(pmin1.equals(pmin3)) val bpmin1: java.lang.Double = scala.Double.MinValue val bpmin2: java.lang.Double = scala.Double.MinValue - assertTrue(bpmin1 equals bpmin2) + assertTrue(bpmin1.equals(bpmin2)) val bpmin3: java.lang.Double = scala.Double.MinValue + 1 - assertTrue(bpmin1 equals bpmin3) + assertTrue(bpmin1.equals(bpmin3)) val pinf1 = scala.Double.PositiveInfinity val pinf2 = scala.Double.MaxValue + scala.Double.MaxValue - assertTrue(pinf1 equals pinf2) + assertTrue(pinf1.equals(pinf2)) val bpinf1: java.lang.Double = pinf1 val bpinf2: java.lang.Double = pinf2 - assertTrue(bpinf1 equals bpinf2) + assertTrue(bpinf1.equals(bpinf2)) val ninf1 = scala.Double.NegativeInfinity val ninf2 = scala.Double.MinValue + scala.Double.MinValue - assertTrue(ninf1 equals ninf2) + assertTrue(ninf1.equals(ninf2)) val bninf1: java.lang.Double = ninf1 val bninf2: java.lang.Double = ninf2 - assertTrue(bninf1 equals bninf2) + assertTrue(bninf1.equals(bninf2)) - assertTrue(Double.NaN equals Double.NaN) + assertTrue(Double.NaN.equals(Double.NaN)) val x = Double.NaN val y = longBitsToDouble(doubleToRawLongBits(x) | 1) - assertTrue(x equals y) + assertTrue(x.equals(y)) val z = longBitsToDouble(doubleToLongBits(x) | 1) - assertTrue(x equals z) + assertTrue(x.equals(z)) } @Test def testEqualEqual(): Unit = { diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/FloatTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/FloatTest.scala index d8cc35fe0f..e9ca0acfdb 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/FloatTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/FloatTest.scala @@ -26,73 +26,73 @@ class FloatTest { @Test def testEquals(): Unit = { val pzero = +0.0f val nzero = -0.0f - assertTrue(pzero equals pzero) - assertTrue(nzero equals nzero) - assertFalse(pzero equals nzero) + assertTrue(pzero.equals(pzero)) + assertTrue(nzero.equals(nzero)) + assertFalse(pzero.equals(nzero)) val szero = 1.0f - 1.0f - assertTrue(pzero equals szero) + assertTrue(pzero.equals(szero)) val bpzero: java.lang.Float = pzero val bnzero: java.lang.Float = nzero - assertFalse(bpzero equals bnzero) + assertFalse(bpzero.equals(bnzero)) val bszero: java.lang.Float = szero - assertTrue(bpzero equals bszero) + assertTrue(bpzero.equals(bszero)) val num1 = 123.45f val num2 = 123.45f - assertTrue(num1 equals num2) + assertTrue(num1.equals(num2)) val bnum1: java.lang.Float = num1 val bnum2: java.lang.Float = num2 assertTrue(bnum1 == bnum2) val pmax1 = scala.Float.MaxValue val pmax2 = scala.Float.MaxValue - assertTrue(pmax1 equals pmax2) + assertTrue(pmax1.equals(pmax2)) val pmax3 = scala.Float.MaxValue + 1 - assertTrue(pmax1 equals pmax3) + assertTrue(pmax1.equals(pmax3)) val bpmax1: java.lang.Float = scala.Float.MaxValue val bpmax2: java.lang.Float = scala.Float.MaxValue - assertTrue(bpmax1 equals bpmax2) + assertTrue(bpmax1.equals(bpmax2)) val bpmax3: java.lang.Float = scala.Float.MaxValue + 1 - assertTrue(bpmax1 equals bpmax3) + assertTrue(bpmax1.equals(bpmax3)) val pmin1 = scala.Float.MinValue val pmin2 = scala.Float.MinValue - assertTrue(pmin1 equals pmin2) + assertTrue(pmin1.equals(pmin2)) val pmin3 = scala.Float.MinValue + 1 - assertTrue(pmin1 equals pmin3) + assertTrue(pmin1.equals(pmin3)) val bpmin1: java.lang.Float = scala.Float.MinValue val bpmin2: java.lang.Float = scala.Float.MinValue - assertTrue(bpmin1 equals bpmin2) + assertTrue(bpmin1.equals(bpmin2)) val bpmin3: java.lang.Float = scala.Float.MinValue + 1 - assertTrue(bpmin1 equals bpmin3) + assertTrue(bpmin1.equals(bpmin3)) val pinf1 = scala.Float.PositiveInfinity val pinf2 = scala.Float.MaxValue + scala.Float.MaxValue - assertTrue(pinf1 equals pinf2) + assertTrue(pinf1.equals(pinf2)) val bpinf1: java.lang.Float = pinf1 val bpinf2: java.lang.Float = pinf2 - assertTrue(bpinf1 equals bpinf2) + assertTrue(bpinf1.equals(bpinf2)) val ninf1 = scala.Float.NegativeInfinity val ninf2 = scala.Float.MinValue + scala.Float.MinValue - assertTrue(ninf1 equals ninf2) + assertTrue(ninf1.equals(ninf2)) val bninf1: java.lang.Float = ninf1 val bninf2: java.lang.Float = ninf2 - assertTrue(bninf1 equals bninf2) + assertTrue(bninf1.equals(bninf2)) - assertTrue(Float.NaN equals Float.NaN) + assertTrue(Float.NaN.equals(Float.NaN)) val x = Float.NaN val y = intBitsToFloat(floatToRawIntBits(x) | 1) - assertTrue(x equals y) + assertTrue(x.equals(y)) val z = intBitsToFloat(floatToIntBits(x) | 1) - assertTrue(x equals z) + assertTrue(x.equals(z)) } @Test def testEqualEqual(): Unit = { diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/StringTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/StringTest.scala index eb5ae8137d..99396d6948 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/StringTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/lang/StringTest.scala @@ -180,10 +180,10 @@ class StringTest { } @Test def replaceChar(): Unit = { - assertTrue("test".replace('t', 'p') equals "pesp") - assertTrue("Test".replace('t', 'p') equals "Tesp") - assertTrue("Test".replace('T', 'p') equals "pest") - assertTrue("Test".replace('0', '1') equals "Test") + assertTrue("test".replace('t', 'p').equals("pesp")) + assertTrue("Test".replace('t', 'p').equals("Tesp")) + assertTrue("Test".replace('T', 'p').equals("pest")) + assertTrue("Test".replace('0', '1').equals("Test")) } @Test def replaceCharSequence(): Unit = { @@ -192,29 +192,29 @@ class StringTest { assertTrue(replace(input)) val inputWithPrefix = ("[" + input).substring(1) - assertTrue(inputWithPrefix equals input) + assertEquals(inputWithPrefix, input) assertTrue(replace(inputWithPrefix)) val inputWithSuffix = (input + "]").substring(0, input.length) - assertTrue(inputWithSuffix equals input) + assertEquals(inputWithSuffix, input) assertTrue(replace(inputWithSuffix)) val inputWithBoth = ("[" + input + "]").substring(1, input.length + 1) - assertTrue(inputWithBoth equals input) + assertEquals(inputWithBoth, input) assertTrue(replace(inputWithBoth)) } - check("test", _.replace("t", "p") equals "pesp") - check("Test", _.replace("t", "p") equals "Tesp") - check("test", _.replace("e", "oa") equals "toast") - check("Test", _.replace("T", "p") equals "pest") - check("spantanplans", _.replace("an", ".") equals "sp.t.pl.s") - check("spantanplans", _.replace("an", "") equals "sptpls") - check("Test", _.replace("0", "1") equals "Test") - check("Test", _.replace("e", "") equals "Tst") - check("Test", _.replace("t", "") equals "Tes") - check("Test", _.replace("", "") equals "Test") - check("Test", _.replace("", "--") equals "--T--e--s--t--") + check("test", _.replace("t", "p").equals("pesp")) + check("Test", _.replace("t", "p").equals("Tesp")) + check("test", _.replace("e", "oa").equals("toast")) + check("Test", _.replace("T", "p").equals("pest")) + check("spantanplans", _.replace("an", ".").equals("sp.t.pl.s")) + check("spantanplans", _.replace("an", "").equals("sptpls")) + check("Test", _.replace("0", "1").equals("Test")) + check("Test", _.replace("e", "").equals("Tst")) + check("Test", _.replace("t", "").equals("Tes")) + check("Test", _.replace("", "").equals("Test")) + check("Test", _.replace("", "--").equals("--T--e--s--t--")) } @Test def replaceAllNonAscii(): Unit = { @@ -430,39 +430,40 @@ class StringTest { } @Test def toUpperCase(): Unit = { - assertTrue("".toUpperCase() equals "") + assertEquals("".toUpperCase(), "") // ascii - assertTrue("Hello".toUpperCase() equals "HELLO") + assertEquals("Hello".toUpperCase(), "HELLO") // latin - assertTrue("Perché".toUpperCase() equals "PERCHÉ") + assertEquals("Perché".toUpperCase(), "PERCHÉ") // high (2 Char String) - 0x10400 or \ud801\udc00 val iStr = new String(Character.toChars(0x10400)) - assertTrue(iStr.length equals 2) - assertTrue(iStr.toUpperCase equals iStr) + assertEquals(iStr.length, 2) + assertEquals(iStr.toUpperCase, iStr) val bStr = "\ud801\udc00" - assertTrue(bStr.length equals 2) - assertTrue(bStr.toUpperCase equals "\ud801\udc00") - assertTrue("𐐨aaaa".toUpperCase equals "𐐀AAAA") - assertTrue("aaaa𐐨".toUpperCase equals "AAAA𐐀") - assertTrue("aa𐐨aa".toUpperCase equals "AA𐐀AA") + assertEquals(bStr.length, 2) + assertEquals(bStr.toUpperCase, "\ud801\udc00") + assertEquals("𐐨aaaa".toUpperCase, "𐐀AAAA") + assertEquals("aaaa𐐨".toUpperCase, "AAAA𐐀") + assertEquals("aa𐐨aa".toUpperCase, "AA𐐀AA") // partial in surrogate range // case of poor slicing or construction of string - assertTrue("\ud801aaaa".toUpperCase equals "\ud801AAAA") - assertTrue("aaaa\ud801".toUpperCase equals "AAAA\ud801") - assertTrue("\udc00aaaa".toUpperCase equals "\udc00AAAA") - assertTrue("aaaa\udc00".toUpperCase equals "AAAA\udc00") + assertEquals("\ud801aaaa".toUpperCase, "\ud801AAAA") + assertEquals("aaaa\ud801".toUpperCase, "AAAA\ud801") + assertEquals("\udc00aaaa".toUpperCase, "\udc00AAAA") + assertEquals("aaaa\udc00".toUpperCase, "AAAA\udc00") // case of one high surrogate val hChar = '\ud801' val hStr = hChar.toString assertTrue(Character.isHighSurrogate(hChar)) - assertTrue(hStr.length equals 1) - assertTrue(hStr.toUpperCase equals hStr) + assertEquals(hStr.length, 1) + assertEquals(hStr.toUpperCase, hStr) // toUpperCase should consider String's offset - assertTrue( + assertEquals( + "SCALA NATIVE", "Hi, Scala Native!" .subSequence(4, 16) .toString - .toUpperCase equals "SCALA NATIVE" + .toUpperCase ) } @@ -573,18 +574,19 @@ class StringTest { } @Test def toLowerCase(): Unit = { - assertTrue("".toLowerCase() equals "") - assertTrue("Hello".toLowerCase() equals "hello") - assertTrue("PERCHÉ".toLowerCase() equals "perché") - assertTrue("𐐀AAAA".toLowerCase equals "𐐨aaaa") - assertTrue("AAAA𐐀".toLowerCase equals "aaaa𐐨") - assertTrue("AA𐐀AA".toLowerCase equals "aa𐐨aa") + assertEquals("".toLowerCase(), "") + assertEquals("Hello".toLowerCase(), "hello") + assertEquals("PERCHÉ".toLowerCase(), "perché") + assertEquals("𐐀AAAA".toLowerCase, "𐐨aaaa") + assertEquals("AAAA𐐀".toLowerCase, "aaaa𐐨") + assertEquals("AA𐐀AA".toLowerCase, "aa𐐨aa") // toLowerCase should consider String's offset - assertTrue( + assertEquals( + "scala native", "Hi, Scala Native!" .subSequence(4, 16) .toString - .toLowerCase equals "scala native" + .toLowerCase ) } diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/DateTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/DateTest.scala index d48172f6b1..68be7a36e9 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/DateTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/util/DateTest.scala @@ -27,7 +27,7 @@ class DateTest { @Test def testClone(): Unit = { val clone = now.clone().asInstanceOf[Date] - assertTrue(clone.getTime equals now.getTime) + assertEquals(clone.getTime, now.getTime) } @Test def testCompareTo(): Unit = { @@ -51,7 +51,7 @@ class DateTest { @Test def testSetTime(): Unit = { val nowBefore = new Date(nowUt) nowBefore.setTime(afterUt) - assertTrue(nowBefore equals after) + assertEquals(nowBefore, after) } @Test def testToString(): Unit = { diff --git a/util/src/main/scala/scala/scalanative/util/ScopedVar.scala b/util/src/main/scala/scala/scalanative/util/ScopedVar.scala index 4298b4391c..55b8463043 100644 --- a/util/src/main/scala/scala/scalanative/util/ScopedVar.scala +++ b/util/src/main/scala/scala/scalanative/util/ScopedVar.scala @@ -8,7 +8,7 @@ class ScopedVar[A] { import ScopedVar.Assignment private var init = false - @nowarn + @nowarn("msg=`= _` has been deprecated") private var value: A = _ def get: A = if (!init) throw ScopedVar.Unitialized() else value @@ -40,7 +40,7 @@ object ScopedVar { implicit def toValue[T](scVar: ScopedVar[T]): T = scVar.get - @nowarn + @nowarn("msg=`_` is deprecated for wildcard arguments of types") def scoped[T](ass: Assignment[_]*)(body: => T): T = { val stack = ass.map(_.push()) try body From f4930d0dfe074a6bc07acf9e5fb612b83040e7c3 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Sun, 14 Jan 2024 12:28:34 +0100 Subject: [PATCH 29/38] fix: Use only Charset instances in javalib instead of encoding strings (#3671) (cherry picked from commit cb5e3c0f587787506e72faaf3d3574dfb6ab60b8) --- javalib/src/main/scala/java/net/URIEncoderDecoder.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/javalib/src/main/scala/java/net/URIEncoderDecoder.scala b/javalib/src/main/scala/java/net/URIEncoderDecoder.scala index a0b8926fd1..6b0d3213ec 100644 --- a/javalib/src/main/scala/java/net/URIEncoderDecoder.scala +++ b/javalib/src/main/scala/java/net/URIEncoderDecoder.scala @@ -1,13 +1,14 @@ package java.net import java.io.ByteArrayOutputStream; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets -object URIEncoderDecoder { +// ScalaNative specific +private[net] object URIEncoderDecoder { val digits: String = "0123456789ABCDEF" - val encoding: String = "UTF8" + val encoding = StandardCharsets.UTF_8 def validate(s: String, legal: String): Unit = { var i: Int = 0 From 2beee936232b8370e6593e539e1ff58d3cb3c220 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Mon, 15 Jan 2024 11:23:45 +0100 Subject: [PATCH 30/38] fix: Suppress warnings in ScopedVar on Scala 3.4.x (cherry picked from commit ee9b1aafc6e54117ffe13f5da9614b8035de914f) --- .../main/scala/scala/scalanative/util/ScopedVar.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/src/main/scala/scala/scalanative/util/ScopedVar.scala b/util/src/main/scala/scala/scalanative/util/ScopedVar.scala index 55b8463043..bb533909e4 100644 --- a/util/src/main/scala/scala/scalanative/util/ScopedVar.scala +++ b/util/src/main/scala/scala/scalanative/util/ScopedVar.scala @@ -46,4 +46,13 @@ object ScopedVar { try body finally stack.reverse.foreach(_.pop()) } + // @nowarn("msg=The syntax `x: _\\*` is no longer supported for vararg splices") + // @nowarn("msg=`_` is deprecated for wildcard arguments of types") + @nowarn() // Cannot define multiple @nowarn annottations in Scala 2.12 + def scopedPushIf[T]( + shouldPushAssignments: Boolean + )(lazyAssignments: => Seq[Assignment[_]])(body: => T): T = { + if (shouldPushAssignments) scoped(lazyAssignments: _*)(body) + else body + } } From 3c7ca0ab391acbe9a09bbdd7592f648b6f33be4f Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Mon, 15 Jan 2024 11:24:19 +0100 Subject: [PATCH 31/38] chore: Remove no longer unused @nowarn compat annottions (cherry picked from commit bd847a577165d8dbd8668e55d85694dc7ca3419c) --- .../scalanative/compat/ScalaStream.scala | 21 ------------------ .../scala/scalanative/compat/annotation.scala | 8 ------- .../scala/scalanative/compat/annotation.scala | 8 ------- .../scala/scalanative/compat/annotation.scala | 5 ----- .../scala/scalanative/compat/annotation.scala | 5 ----- .../main/scala/java/util/PriorityQueue.scala | 2 +- .../src/test/scala-2.11/scala/Issue2305.scala | 22 ------------------- 7 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 javalib/src/main/scala-2.11/scala/scalanative/compat/ScalaStream.scala delete mode 100644 javalib/src/main/scala-2.11/scala/scalanative/compat/annotation.scala delete mode 100644 javalib/src/main/scala-2.12/scala/scalanative/compat/annotation.scala delete mode 100644 javalib/src/main/scala-2.13/scala/scalanative/compat/annotation.scala delete mode 100644 javalib/src/main/scala-3/scala/scalanative/compat/annotation.scala delete mode 100644 unit-tests/native/src/test/scala-2.11/scala/Issue2305.scala diff --git a/javalib/src/main/scala-2.11/scala/scalanative/compat/ScalaStream.scala b/javalib/src/main/scala-2.11/scala/scalanative/compat/ScalaStream.scala deleted file mode 100644 index 37d6b61e66..0000000000 --- a/javalib/src/main/scala-2.11/scala/scalanative/compat/ScalaStream.scala +++ /dev/null @@ -1,21 +0,0 @@ -package scala.scalanative.compat - -import java.util.stream.WrappedScalaStream -import scala.collection.immutable -import scala.language.implicitConversions - -private[scalanative] object ScalaStream { - type Underlying[T] = immutable.Stream[T] - val Underlying = immutable.Stream - - implicit class ScalaStreamImpl[T](val underyling: Underlying[T]) - extends AnyVal { - def wrappedStream(closeHanlder: Option[Runnable] = None) = - new WrappedScalaStream[T](underyling, closeHanlder) - } - - implicit def seqToScalaStream[T](seq: Iterable[T]): Underlying[T] = { - seq.to[Underlying] - } - -} diff --git a/javalib/src/main/scala-2.11/scala/scalanative/compat/annotation.scala b/javalib/src/main/scala-2.11/scala/scalanative/compat/annotation.scala deleted file mode 100644 index 99dfc78eb1..0000000000 --- a/javalib/src/main/scala-2.11/scala/scalanative/compat/annotation.scala +++ /dev/null @@ -1,8 +0,0 @@ -package scala.scalanative.compat - -import scala.annotation.StaticAnnotation - -object annotation { - // Stub for nowarn annotations to allow compilation with legacy versions of Scala - class nowarn(value: String = "") extends StaticAnnotation -} diff --git a/javalib/src/main/scala-2.12/scala/scalanative/compat/annotation.scala b/javalib/src/main/scala-2.12/scala/scalanative/compat/annotation.scala deleted file mode 100644 index 99dfc78eb1..0000000000 --- a/javalib/src/main/scala-2.12/scala/scalanative/compat/annotation.scala +++ /dev/null @@ -1,8 +0,0 @@ -package scala.scalanative.compat - -import scala.annotation.StaticAnnotation - -object annotation { - // Stub for nowarn annotations to allow compilation with legacy versions of Scala - class nowarn(value: String = "") extends StaticAnnotation -} diff --git a/javalib/src/main/scala-2.13/scala/scalanative/compat/annotation.scala b/javalib/src/main/scala-2.13/scala/scalanative/compat/annotation.scala deleted file mode 100644 index cc06fa4a11..0000000000 --- a/javalib/src/main/scala-2.13/scala/scalanative/compat/annotation.scala +++ /dev/null @@ -1,5 +0,0 @@ -package scala.scalanative.compat - -object annotation { - type nowarn = scala.annotation.nowarn -} diff --git a/javalib/src/main/scala-3/scala/scalanative/compat/annotation.scala b/javalib/src/main/scala-3/scala/scalanative/compat/annotation.scala deleted file mode 100644 index cc06fa4a11..0000000000 --- a/javalib/src/main/scala-3/scala/scalanative/compat/annotation.scala +++ /dev/null @@ -1,5 +0,0 @@ -package scala.scalanative.compat - -object annotation { - type nowarn = scala.annotation.nowarn -} diff --git a/javalib/src/main/scala/java/util/PriorityQueue.scala b/javalib/src/main/scala/java/util/PriorityQueue.scala index 4edcefd024..2587b7fd71 100644 --- a/javalib/src/main/scala/java/util/PriorityQueue.scala +++ b/javalib/src/main/scala/java/util/PriorityQueue.scala @@ -14,7 +14,7 @@ package java.util import scala.annotation.tailrec -import scala.scalanative.compat.annotation.nowarn +import scala.annotation.nowarn class PriorityQueue[E] private ( private val comp: Comparator[_ >: E], diff --git a/unit-tests/native/src/test/scala-2.11/scala/Issue2305.scala b/unit-tests/native/src/test/scala-2.11/scala/Issue2305.scala deleted file mode 100644 index c7725673a1..0000000000 --- a/unit-tests/native/src/test/scala-2.11/scala/Issue2305.scala +++ /dev/null @@ -1,22 +0,0 @@ -package scala - -import org.junit.Test -import org.junit.Assert._ -import scala.reflect.macros.blackbox.Context -import scala.reflect.runtime.universe._ -import scala.language.experimental.macros - -/* Dummy test used determinate if a trait of macro can compile to nir. - * If it does compile, it passes - */ -class Issue2305 { - - trait Foo { - def fooImpl(c: Context)(input: c.Tree): c.Tree - } - - @Test def macroTraitCanCompile(): Unit = { - assertTrue(true) - } - -} From eadbcaccda22328083cd8b7c1a3886dea914bd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Mon, 15 Jan 2024 18:52:42 +0100 Subject: [PATCH 32/38] feature: Log linked libraries (#3674) (cherry picked from commit 1df0556116db296fe25af1d367546d410470ae71) --- tools/src/main/scala/scala/scalanative/build/LLVM.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/src/main/scala/scala/scalanative/build/LLVM.scala b/tools/src/main/scala/scala/scalanative/build/LLVM.scala index 25d1aa9cb5..47f1a0f7e2 100644 --- a/tools/src/main/scala/scala/scalanative/build/LLVM.scala +++ b/tools/src/main/scala/scala/scalanative/build/LLVM.scala @@ -155,6 +155,7 @@ private[scalanative] object LLVM { else Seq("pthread", "dl") platformsLinks ++ srclinks ++ gclinks } + config.logger.info(s"Linking with [${links.mkString(", ")}]") val linkopts = config.linkingOptions ++ links.map("-l" + _) val flags = { From f2276dc2fc168c67d01b3af7e04a7c3659b1e620 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 17 Jan 2024 21:04:53 +0100 Subject: [PATCH 33/38] Fix compilation under 3.4.x --- javalib/src/main/scala/java/lang/Thread.scala | 2 +- .../scala/java/lang/process/UnixProcess.scala | 18 +++++++++--------- .../main/scala/java/nio/HeapFloatBuffer.scala | 2 +- .../java/nio/MappedByteBufferDoubleView.scala | 2 +- .../java/nio/MappedByteBufferFloatView.scala | 2 +- .../java/nio/MappedByteBufferLongView.scala | 2 +- .../java/nio/MappedByteBufferShortView.scala | 2 +- .../util/concurrent/ConcurrentHashMap.scala | 6 +++--- .../scala/java/util/concurrent/Semaphore.scala | 2 +- .../util/concurrent/atomic/AtomicBoolean.scala | 2 +- .../util/concurrent/atomic/AtomicInteger.scala | 4 +--- .../util/concurrent/atomic/AtomicLong.scala | 4 +--- .../concurrent/atomic/AtomicReference.scala | 3 +-- .../util/concurrent/atomic/LongAdder.scala | 2 +- .../nir/serialization/BinaryDeserializer.scala | 2 +- .../nir/serialization/BinarySerializer.scala | 8 ++++---- .../scalanative/nscplugin/NirGenPhase.scala | 8 ++++---- .../scalanative/nscplugin/NirPositions.scala | 2 +- .../nscplugin/PrepNativeInteropLate.scala | 1 - project/BinaryIncompatibilities.scala | 5 ++++- project/Build.scala | 7 +++++-- project/Settings.scala | 8 -------- .../sbtplugin/ScalaNativeCrossVersion.scala | 2 +- .../scalanative/build/core/NativeLib.scala | 2 +- .../scala/scalanative/codegen/CodeGen.scala | 8 ++++---- .../scala/scalanative/NIRCompilerTest.scala | 6 +++--- 26 files changed, 52 insertions(+), 60 deletions(-) diff --git a/javalib/src/main/scala/java/lang/Thread.scala b/javalib/src/main/scala/java/lang/Thread.scala index c06e7f2d57..47893f1822 100644 --- a/javalib/src/main/scala/java/lang/Thread.scala +++ b/javalib/src/main/scala/java/lang/Thread.scala @@ -8,7 +8,7 @@ class Thread private (runnable: Runnable) extends Runnable { if (runnable ne Thread.MainRunnable) ??? private var interruptedState = false - private[this] var name: String = "main" // default name of the main thread + private var name: String = "main" // default name of the main thread private[java] var threadLocalRandomSeed: scala.Long = 0 private[java] var threadLocalRandomProbe: Int = 0 diff --git a/javalib/src/main/scala/java/lang/process/UnixProcess.scala b/javalib/src/main/scala/java/lang/process/UnixProcess.scala index 1ec1c5d8e1..d7d496645b 100644 --- a/javalib/src/main/scala/java/lang/process/UnixProcess.scala +++ b/javalib/src/main/scala/java/lang/process/UnixProcess.scala @@ -87,31 +87,31 @@ private[lang] class UnixProcess private ( res } - private[this] val _inputStream = + private val _inputStream = PipeIO[PipeIO.Stream]( this, new FileDescriptor(!outfds), builder.redirectOutput() ) - private[this] val _errorStream = + private val _errorStream = PipeIO[PipeIO.Stream]( this, new FileDescriptor(!errfds), builder.redirectError() ) - private[this] val _outputStream = + private val _outputStream = PipeIO[OutputStream]( this, new FileDescriptor(!(infds + 1)), builder.redirectInput() ) - private[this] var _exitValue = -1 + private var _exitValue = -1 private[lang] def checkResult(): CInt = { if (_exitValue == -1) setExitValue(UnixProcess.checkResult(pid)) _exitValue } - private[this] def setExitValue(value: CInt): Unit = { + private def setExitValue(value: CInt): Unit = { if (_exitValue == -1 && value != -1) { _exitValue = value _inputStream.drain() @@ -119,7 +119,7 @@ private[lang] class UnixProcess private ( _outputStream.close() } } - private[this] def waitFor(ts: Ptr[timespec]): Int = { + private def waitFor(ts: Ptr[timespec]): Int = { val res = stackalloc[CInt]() !res = -1 val result = UnixProcess.waitForPid(pid, ts, res) @@ -131,7 +131,7 @@ private[lang] class UnixProcess private ( object UnixProcess { @link("pthread") @extern - private[this] object ProcessMonitor { + private object ProcessMonitor { @name("scalanative_process_monitor_notify") def notifyMonitor(): Unit = extern @name("scalanative_process_monitor_check_result") @@ -304,10 +304,10 @@ object UnixProcess { environment: java.util.Map[String, String], bin: String ): Seq[String] = { - if ((bin startsWith "/") || (bin startsWith ".")) { + if (bin.startsWith("/") || bin.startsWith(".")) { Seq(bin) } else { - val path = environment get "PATH" match { + val path = environment.get("PATH") match { case null => "/bin:/usr/bin:/usr/local/bin" case p => p } diff --git a/javalib/src/main/scala/java/nio/HeapFloatBuffer.scala b/javalib/src/main/scala/java/nio/HeapFloatBuffer.scala index a369c32f4c..7c14fb93c6 100644 --- a/javalib/src/main/scala/java/nio/HeapFloatBuffer.scala +++ b/javalib/src/main/scala/java/nio/HeapFloatBuffer.scala @@ -15,7 +15,7 @@ private[nio] final class HeapFloatBuffer private ( private def genBuffer = GenBuffer[FloatBuffer](this) private def genHeapBuffer = GenHeapBuffer[FloatBuffer](this) - private[this] implicit def newHeapFloatBuffer + private implicit def newHeapFloatBuffer : HeapFloatBuffer.NewHeapFloatBuffer.type = HeapFloatBuffer.NewHeapFloatBuffer diff --git a/javalib/src/main/scala/java/nio/MappedByteBufferDoubleView.scala b/javalib/src/main/scala/java/nio/MappedByteBufferDoubleView.scala index 7f2c12cfb2..c80f5ef710 100644 --- a/javalib/src/main/scala/java/nio/MappedByteBufferDoubleView.scala +++ b/javalib/src/main/scala/java/nio/MappedByteBufferDoubleView.scala @@ -19,7 +19,7 @@ private[nio] final class MappedByteBufferDoubleView private ( protected lazy val genMappedBufferView = GenMappedBufferView[DoubleBuffer](this) @inline private def byteArrayBits = genMappedBufferView.byteArrayBits - private[this] implicit def newMappedDoubleBufferView + private implicit def newMappedDoubleBufferView : GenMappedBufferView.NewMappedBufferView[DoubleBuffer] = MappedByteBufferDoubleView.NewMappedByteBufferDoubleView diff --git a/javalib/src/main/scala/java/nio/MappedByteBufferFloatView.scala b/javalib/src/main/scala/java/nio/MappedByteBufferFloatView.scala index 44696ebdac..e59341cde8 100644 --- a/javalib/src/main/scala/java/nio/MappedByteBufferFloatView.scala +++ b/javalib/src/main/scala/java/nio/MappedByteBufferFloatView.scala @@ -18,7 +18,7 @@ private[nio] final class MappedByteBufferFloatView private ( private def genBuffer = GenBuffer[FloatBuffer](this) protected def genMappedBufferView = GenMappedBufferView[FloatBuffer](this) private lazy val byteArrayBits = genMappedBufferView.byteArrayBits - private[this] implicit def newMappedFloatBufferView + private implicit def newMappedFloatBufferView : GenMappedBufferView.NewMappedBufferView[FloatBuffer] = MappedByteBufferFloatView.NewMappedByteBufferFloatView diff --git a/javalib/src/main/scala/java/nio/MappedByteBufferLongView.scala b/javalib/src/main/scala/java/nio/MappedByteBufferLongView.scala index 18a8315732..28d88b9631 100644 --- a/javalib/src/main/scala/java/nio/MappedByteBufferLongView.scala +++ b/javalib/src/main/scala/java/nio/MappedByteBufferLongView.scala @@ -18,7 +18,7 @@ private[nio] final class MappedByteBufferLongView private ( private def genBuffer = GenBuffer[LongBuffer](this) protected def genMappedBufferView = GenMappedBufferView[LongBuffer](this) @inline private def byteArrayBits = genMappedBufferView.byteArrayBits - private[this] implicit def newMappedLongBufferView + private implicit def newMappedLongBufferView : GenMappedBufferView.NewMappedBufferView[LongBuffer] = MappedByteBufferLongView.NewMappedByteBufferLongView diff --git a/javalib/src/main/scala/java/nio/MappedByteBufferShortView.scala b/javalib/src/main/scala/java/nio/MappedByteBufferShortView.scala index 960f4f38fe..9fe3736111 100644 --- a/javalib/src/main/scala/java/nio/MappedByteBufferShortView.scala +++ b/javalib/src/main/scala/java/nio/MappedByteBufferShortView.scala @@ -19,7 +19,7 @@ private[nio] final class MappedByteBufferShortView private ( protected def genMappedBufferView = GenMappedBufferView[ShortBuffer](this) @inline private def byteArrayBits = genMappedBufferView.byteArrayBits - private[this] implicit def newMappedShortBufferView + private implicit def newMappedShortBufferView : GenMappedBufferView.NewMappedBufferView[ShortBuffer] = MappedByteBufferShortView.NewMappedByteBufferShortView diff --git a/javalib/src/main/scala/java/util/concurrent/ConcurrentHashMap.scala b/javalib/src/main/scala/java/util/concurrent/ConcurrentHashMap.scala index 273df9bd58..dd3b9bca75 100644 --- a/javalib/src/main/scala/java/util/concurrent/ConcurrentHashMap.scala +++ b/javalib/src/main/scala/java/util/concurrent/ConcurrentHashMap.scala @@ -26,7 +26,7 @@ class ConcurrentHashMap[K, V] private (initialCapacity: Int, loadFactor: Float) def this(initialCapacity: Int, loadFactor: Float, concurrencyLevel: Int) = this(initialCapacity, loadFactor) // ignore concurrencyLevel - private[this] val inner: InnerHashMap[K, V] = + private val inner: InnerHashMap[K, V] = new InnerHashMap[K, V](initialCapacity, loadFactor) override def size(): Int = @@ -148,8 +148,8 @@ object ConcurrentHashMap { } private abstract class AbstractCHMIterator[A] extends Iterator[A] { - private[this] val innerIter = makeSnapshot().iterator() - private[this] var lastNode: Node[K, V] = _ // null + private val innerIter = makeSnapshot().iterator() + private var lastNode: Node[K, V] = _ // null protected[this] def extract(node: Node[K, V]): A diff --git a/javalib/src/main/scala/java/util/concurrent/Semaphore.scala b/javalib/src/main/scala/java/util/concurrent/Semaphore.scala index c117a12997..72d92f2f04 100644 --- a/javalib/src/main/scala/java/util/concurrent/Semaphore.scala +++ b/javalib/src/main/scala/java/util/concurrent/Semaphore.scala @@ -14,7 +14,7 @@ package java.util.concurrent import java.util.{Collection, Collections} -class Semaphore(private[this] var permits: Int, fairness: Boolean) +class Semaphore(private var permits: Int, fairness: Boolean) extends java.io.Serializable { def this(permits: Int) = this(permits, false) diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicBoolean.scala b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicBoolean.scala index 60b4005e43..d77dd4e296 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicBoolean.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicBoolean.scala @@ -1,6 +1,6 @@ package java.util.concurrent.atomic -class AtomicBoolean(private[this] var value: Boolean) extends Serializable { +class AtomicBoolean(private var value: Boolean) extends Serializable { def this() = this(false) final def get(): Boolean = value diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala index 6829aa029b..ce9609f27b 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala @@ -2,9 +2,7 @@ package java.util.concurrent.atomic import java.util.function.IntUnaryOperator -class AtomicInteger(private var value: Int) - extends Number - with Serializable { +class AtomicInteger(private var value: Int) extends Number with Serializable { def this() = this(0) diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala index a27d45b6a4..8cbe77fdbc 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicLong.scala @@ -2,9 +2,7 @@ package java.util.concurrent.atomic import java.util.function.LongUnaryOperator -class AtomicLong(private var value: Long) - extends Number - with Serializable { +class AtomicLong(private var value: Long) extends Number with Serializable { def this() = this(0L) final def get(): Long = value diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicReference.scala b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicReference.scala index 8f474fc756..d9d23c578a 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/AtomicReference.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/AtomicReference.scala @@ -5,8 +5,7 @@ package java.util.concurrent.atomic import java.util.function.UnaryOperator -class AtomicReference[T <: AnyRef](private[this] var value: T) - extends Serializable { +class AtomicReference[T <: AnyRef](private var value: T) extends Serializable { def this() = this(null.asInstanceOf[T]) diff --git a/javalib/src/main/scala/java/util/concurrent/atomic/LongAdder.scala b/javalib/src/main/scala/java/util/concurrent/atomic/LongAdder.scala index 9afde19efb..63396c5d5b 100644 --- a/javalib/src/main/scala/java/util/concurrent/atomic/LongAdder.scala +++ b/javalib/src/main/scala/java/util/concurrent/atomic/LongAdder.scala @@ -15,7 +15,7 @@ package java.util.concurrent.atomic import java.io.Serializable class LongAdder extends Number with Serializable { - private[this] var value: Long = 0L + private var value: Long = 0L final def add(x: Long): Unit = value = value + x diff --git a/nir/src/main/scala/scala/scalanative/nir/serialization/BinaryDeserializer.scala b/nir/src/main/scala/scala/scalanative/nir/serialization/BinaryDeserializer.scala index fb705b5004..b2e2bf28cb 100644 --- a/nir/src/main/scala/scala/scalanative/nir/serialization/BinaryDeserializer.scala +++ b/nir/src/main/scala/scala/scalanative/nir/serialization/BinaryDeserializer.scala @@ -13,7 +13,7 @@ final class BinaryDeserializer(buffer: ByteBuffer, bufferName: String) { import buffer._ - private[this] var lastPosition: Position = Position.NoPosition + private var lastPosition: Position = Position.NoPosition private val (prelude, header, files) : (Prelude, Seq[(Global, Int)], Array[URI]) = { diff --git a/nir/src/main/scala/scala/scalanative/nir/serialization/BinarySerializer.scala b/nir/src/main/scala/scala/scalanative/nir/serialization/BinarySerializer.scala index dcca3cfa8f..c58692548d 100644 --- a/nir/src/main/scala/scala/scalanative/nir/serialization/BinarySerializer.scala +++ b/nir/src/main/scala/scala/scalanative/nir/serialization/BinarySerializer.scala @@ -10,11 +10,11 @@ import scala.collection.mutable import scala.scalanative.nir.serialization.{Tags => T} final class BinarySerializer { - private[this] val bufferUnderyling = new JumpBackByteArrayOutputStream - private[this] val buffer = new DataOutputStream(bufferUnderyling) + private val bufferUnderyling = new JumpBackByteArrayOutputStream + private val buffer = new DataOutputStream(bufferUnderyling) - private[this] var lastPosition: Position = Position.NoPosition - private[this] val fileIndexMap = mutable.Map.empty[URI, Int] + private var lastPosition: Position = Position.NoPosition + private val fileIndexMap = mutable.Map.empty[URI, Int] // Methods were renamed in order to not pollute git blame history. // Original implementation used ByteBuffers diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenPhase.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenPhase.scala index ce5f0ae4f4..4636fc5b01 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenPhase.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenPhase.scala @@ -175,10 +175,10 @@ abstract class NirGenPhase[G <: Global with Singleton](override val global: G) ) } - private[this] object nirPositionCachedConverter { + private object nirPositionCachedConverter { import scala.reflect.internal.util._ - private[this] var lastNscSource: SourceFile = _ - private[this] var lastNIRSource: nir.Position.SourceFile = _ + private var lastNscSource: SourceFile = _ + private var lastNIRSource: nir.Position.SourceFile = _ def toNIRSource(nscSource: SourceFile): nir.Position.SourceFile = { if (nscSource != lastNscSource) { @@ -188,7 +188,7 @@ abstract class NirGenPhase[G <: Global with Singleton](override val global: G) lastNIRSource } - private[this] def convert( + private def convert( nscSource: SourceFile ): nir.Position.SourceFile = { nscSource.file.file match { diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala index e5d3898f9a..1328ec3b71 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirPositions.scala @@ -35,7 +35,7 @@ class NirPositions(sourceURIMaps: List[GenNIR.URIMap])(using Context) { private object conversionCache { import dotty.tools.dotc.util._ private var lastDotcSource: SourceFile = uninitialized - private var lastNIRSource: nir.SourceFile = uninitialized + private var lastNIRSource: nir.Position.SourceFile = uninitialized def toNIRSource(dotcSource: SourceFile): nir.Position.SourceFile = { if (dotcSource != lastDotcSource) { diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala index 357216571c..92ddae16ae 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala @@ -4,7 +4,6 @@ import dotty.tools.dotc.plugins.PluginPhase import dotty.tools._ import dotc._ import dotc.ast.tpd._ -import dotc.transform.SymUtils.setter import core.Contexts._ import core.Definitions import core.Names._ diff --git a/project/BinaryIncompatibilities.scala b/project/BinaryIncompatibilities.scala index 4e12da2cf7..a7b3364dc4 100644 --- a/project/BinaryIncompatibilities.scala +++ b/project/BinaryIncompatibilities.scala @@ -96,7 +96,10 @@ object BinaryIncompatibilities { final val AuxLib, JavaLib, ScalaLib, Scala3Lib: Filters = Nil final val TestRunner: Filters = Nil - final val TestInterface: Filters = Nil + final val TestInterface: Filters = Seq( + // internals + exclude[Problem]("scala.scalanative.testinterface.TestMain.*") + ) final val TestInterfaceSbtDefs: Filters = Nil final val JUnitRuntime: Filters = Seq( // Internal method, package-private diff --git a/project/Build.scala b/project/Build.scala index b443345e05..18f0ee5cac 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -118,7 +118,7 @@ object Build { Seq.empty[String] ) { case (2, _) => Seq("-Xno-patmat-analysis") - } + }, scalacOptions --= ignoredScalaDeprecations(scalaVersion.value) ) .dependsOnSource(nir) @@ -336,7 +336,9 @@ object Build { lazy val scalalib: MultiScalaProject = MultiScalaProject("scalalib") .enablePlugins(MyScalaNativePlugin) - .settings(mavenPublishSettings, disabledDocsSettings, + .settings( + mavenPublishSettings, + disabledDocsSettings, scalacOptions --= ignoredScalaDeprecations(scalaVersion.value) ) .withNativeCompilerPlugin @@ -375,6 +377,7 @@ object Build { scalacOptions ++= Seq( "-language:implicitConversions" ), + scalacOptions --= Seq("-Xfatal-warnings", "-deprecation"), libraryDependencies += ("org.scala-native" %%% "scalalib" % nativeVersion) .excludeAll(ExclusionRule("org.scala-native")) .cross(CrossVersion.for3Use2_13), diff --git a/project/Settings.scala b/project/Settings.scala index b32b14a640..c88f5358d4 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -624,14 +624,6 @@ object Settings { }, exportJars := true ) - lazy val commonJavalibSettings = Def.settings( - recompileAllOrNothingSettings, - noJavaReleaseSettings, // we don't emit classfiles - Compile / scalacOptions ++= scalaNativeCompilerOptions( - "genStaticForwardersForNonTopLevelObjects" - ), - NIROnlySettings - ) // Calculates all prefixes of the current Scala version // (including the empty prefix) to construct Scala version depenent diff --git a/sbt-scala-native/src/main/scala/scala/scalanative/sbtplugin/ScalaNativeCrossVersion.scala b/sbt-scala-native/src/main/scala/scala/scalanative/sbtplugin/ScalaNativeCrossVersion.scala index 7f90ecd9a2..1827ca7688 100644 --- a/sbt-scala-native/src/main/scala/scala/scalanative/sbtplugin/ScalaNativeCrossVersion.scala +++ b/sbt-scala-native/src/main/scala/scala/scalanative/sbtplugin/ScalaNativeCrossVersion.scala @@ -9,7 +9,7 @@ import scala.scalanative.nir.Versions object ScalaNativeCrossVersion { val currentBinaryVersion = Versions.currentBinaryVersion - private[this] def crossVersionAddPlatformPart( + private def crossVersionAddPlatformPart( cross: CrossVersion, part: String ): CrossVersion = { diff --git a/tools/src/main/scala/scala/scalanative/build/core/NativeLib.scala b/tools/src/main/scala/scala/scalanative/build/core/NativeLib.scala index 681d092242..11062c584f 100644 --- a/tools/src/main/scala/scala/scalanative/build/core/NativeLib.scala +++ b/tools/src/main/scala/scala/scalanative/build/core/NativeLib.scala @@ -67,7 +67,7 @@ private[scalanative] object NativeLib { .forEach(new java.util.function.Consumer[Path] { def accept(path: Path): Unit = { def matchesPattern = - path.getFileName().toString() matches nativeCodePattern + path.getFileName().toString().matches(nativeCodePattern) def notIgnored = expectedPaths.contains(path.toAbsolutePath()) diff --git a/tools/src/main/scala/scala/scalanative/codegen/CodeGen.scala b/tools/src/main/scala/scala/scalanative/codegen/CodeGen.scala index ac637b029a..aef47276c4 100644 --- a/tools/src/main/scala/scala/scalanative/codegen/CodeGen.scala +++ b/tools/src/main/scala/scala/scalanative/codegen/CodeGen.scala @@ -149,10 +149,10 @@ object CodeGen { val buf = mutable.UnrolledBuffer.empty[Global] buf ++= Lower.depends buf ++= Generate.depends - buf += Rt.Object.name member Rt.ScalaEqualsSig - buf += Rt.Object.name member Rt.ScalaHashCodeSig - buf += Rt.Object.name member Rt.JavaEqualsSig - buf += Rt.Object.name member Rt.JavaHashCodeSig + buf += Rt.Object.name.member(Rt.ScalaEqualsSig) + buf += Rt.Object.name.member(Rt.ScalaHashCodeSig) + buf += Rt.Object.name.member(Rt.JavaEqualsSig) + buf += Rt.Object.name.member(Rt.JavaHashCodeSig) buf.toSeq } } diff --git a/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala b/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala index 8849662541..a34edb7cff 100644 --- a/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala +++ b/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala @@ -12,7 +12,7 @@ class NIRCompilerTest extends AnyFlatSpec with Matchers with Inspectors { "The compiler" should "return products of compilation" in { val files = - NIRCompiler { _ compile "class A" } + NIRCompiler { _.compile("class A") } .filter(Files.isRegularFile(_)) .map(_.getFileName.toString) val expectedNames = Seq("A.class", "A.nir") @@ -41,14 +41,14 @@ class NIRCompilerTest extends AnyFlatSpec with Matchers with Inspectors { it should "report compilation errors" in { assertThrows[api.CompilationFailedException] { - NIRCompiler { _ compile "invalid" } + NIRCompiler { _.compile("invalid") } } } it should "compile to a specified directory" in { val temporaryDir = Files.createTempDirectory("my-target") val nirFiles = - NIRCompiler(outDir = temporaryDir) { _ compile "class A" } + NIRCompiler(outDir = temporaryDir) { _.compile("class A") } .filter(Files.isRegularFile(_)) forAll(nirFiles) { _.getParent should be(temporaryDir) } } From 47bf17c9189ed12817257c8141a065aa5e407921 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 18 Jan 2024 11:35:50 +0100 Subject: [PATCH 34/38] Fix CI issues after backports --- .github/actions/windows-setup-env/action.yml | 2 +- project/BinaryIncompatibilities.scala | 5 ++++- project/ScalaVersions.scala | 3 +-- .../scalanative/testinterface/NativeRPC.scala | 6 ++++-- .../scalanative/testinterface/TestMain.scala | 2 +- .../scalanative/testinterface/ComRunner.scala | 21 ++++++++++++++++--- .../testinterface/NativeRunnerRPC.scala | 17 +++++++++++---- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.github/actions/windows-setup-env/action.yml b/.github/actions/windows-setup-env/action.yml index 52f8f57a38..208fea55d6 100644 --- a/.github/actions/windows-setup-env/action.yml +++ b/.github/actions/windows-setup-env/action.yml @@ -9,7 +9,7 @@ inputs: default: "8" llvm-version: description: "LLVM version to use" - default: "17.0.6" + default: "11.0.1" outputs: vcpkg-dir: description: "Directory containing installed libraries" diff --git a/project/BinaryIncompatibilities.scala b/project/BinaryIncompatibilities.scala index a7b3364dc4..8573566ba4 100644 --- a/project/BinaryIncompatibilities.scala +++ b/project/BinaryIncompatibilities.scala @@ -95,10 +95,13 @@ object BinaryIncompatibilities { final val WindowsLib: Filters = Nil final val AuxLib, JavaLib, ScalaLib, Scala3Lib: Filters = Nil - final val TestRunner: Filters = Nil + final val TestRunner: Filters = Seq( + // exclude[Problem]("scala.scalanative.testinterface.ComRunner.*") + ) final val TestInterface: Filters = Seq( // internals exclude[Problem]("scala.scalanative.testinterface.TestMain.*") + // exclude[Problem]("scala.scalanative.testinterface.NativeRPC.*") ) final val TestInterfaceSbtDefs: Filters = Nil final val JUnitRuntime: Filters = Seq( diff --git a/project/ScalaVersions.scala b/project/ScalaVersions.scala index b2c0e229d9..36898786b0 100644 --- a/project/ScalaVersions.scala +++ b/project/ScalaVersions.scala @@ -21,10 +21,9 @@ object ScalaVersions { val crossScala212 = (13 to 18).map(v => s"2.12.$v") val crossScala213 = (4 to 12).map(v => s"2.13.$v") val crossScala3 = List( - (0 to 3).map(v => s"3.1.$v"), // Bug in compiler leads to errors in tests, don't use it as default until RC2 Seq("3.4.0-RC1"), - (2 to 3).map(v => s"3.1.$v"), + (0 to 3).map(v => s"3.1.$v"), (0 to 2).map(v => s"3.2.$v"), (0 to 1).map(v => s"3.3.$v") ).flatten diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala index ff99bd1942..478a981d2f 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/NativeRPC.scala @@ -10,9 +10,11 @@ import java.nio.charset.StandardCharsets import scala.scalanative.meta.LinktimeInfo /** Native RPC Core. */ -private[testinterface] class NativeRPC(clientSocket: Socket)(implicit +private[testinterface] class NativeRPC( + clientSocket: Socket, ec: ExecutionContext -) extends RPCCore { +) extends RPCCore()(ec) { + def this(clientSocket: Socket) = this(clientSocket, ExecutionContext.global) private lazy val inStream = new DataInputStream(clientSocket.getInputStream) private lazy val outStream = new DataOutputStream( clientSocket.getOutputStream diff --git a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala index 663e6b9a1d..a677d75fbc 100644 --- a/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala +++ b/test-interface/src/main/scala/scala/scalanative/testinterface/TestMain.scala @@ -68,7 +68,7 @@ object TestMain { if (LinktimeInfo.isFreeBSD) setFreeBSDWorkaround() val serverPort = args(0).toInt val clientSocket = new Socket("127.0.0.1", serverPort) - val nativeRPC = new NativeRPC(clientSocket)(ExecutionContext.global) + val nativeRPC = new NativeRPC(clientSocket, ExecutionContext.global) val bridge = new TestAdapterBridge(nativeRPC) bridge.start() diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala index fe8c3f6a86..bd62706a6f 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/ComRunner.scala @@ -18,11 +18,26 @@ private[testinterface] class ComRunner( processRunner: ProcessRunner, serverSocket: ServerSocket, logger: Logger, - handleMessage: String => Unit -)(implicit ec: ExecutionContext) - extends AutoCloseable { + handleMessage: String => Unit, + ec: ExecutionContext +) extends AutoCloseable { + def this( + processRunner: ProcessRunner, + serverSocket: ServerSocket, + logger: Logger, + handleMessage: String => Unit + ) = this( + processRunner, + serverSocket, + logger, + handleMessage, + ExecutionContext.global + ) + import ComRunner._ + implicit def executionContext: ExecutionContext = ec + processRunner.future.onComplete { case Failure(exception) => forceClose(exception) case Success(_) => onNativeTerminated() diff --git a/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala b/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala index 10dcb1034b..d3ab69c3b4 100644 --- a/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala +++ b/test-runner/src/main/scala/scala/scalanative/testinterface/NativeRunnerRPC.scala @@ -13,9 +13,17 @@ private[testinterface] final class NativeRunnerRPC( executableFile: File, envVars: Map[String, String], args: Seq[String], - logger: Logger -)(implicit ec: ExecutionContext) - extends RPCCore() { + logger: Logger, + ec: ExecutionContext +) extends RPCCore()(ec) { + def this( + executableFile: File, + envVars: Map[String, String], + args: Seq[String], + logger: Logger + ) = this(executableFile, envVars, args, logger, ExecutionContext.global) + + implicit def executionContext: ExecutionContext = ec private val serverSocket: ServerSocket = new ServerSocket( /* port = */ 0, @@ -28,7 +36,8 @@ private[testinterface] final class NativeRunnerRPC( logger, serverSocket.getLocalPort ) - val runner = new ComRunner(processRunner, serverSocket, logger, handleMessage) + val runner = + new ComRunner(processRunner, serverSocket, logger, handleMessage) /* Once the com closes, ensure all still pending calls are failing. * Note: We do not need to give a grace time here, since the reply From 04691231def972daa75fcf67e6a60fb79ba2df57 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Thu, 18 Jan 2024 12:59:47 +0100 Subject: [PATCH 35/38] Fix conditions for SocketTest.trafficClass on Windows --- .../testsuite/javalib/net/SocketTest.scala | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/SocketTest.scala b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/SocketTest.scala index dc5a2e67bf..f33b99c865 100644 --- a/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/SocketTest.scala +++ b/unit-tests/shared/src/test/scala/org/scalanative/testsuite/javalib/net/SocketTest.scala @@ -139,12 +139,20 @@ class SocketTest { } @Test def trafficClass(): Unit = { - // When execution on Windows with Java 17 trafficClass is not set. - // s.getTrafficClass returns 0 instead of 0x28 - assumeFalse( - "Skipped due to unexpected behaviour in JDK 17 on Windows", - Platform.isWindows && Platform.executingInJVMOnJDK17 - ) + val disabled = Platform.isWindows && { + // No sense testing in these cases + val prop = System.getProperty("java.net.preferIPv4Stack") + val useIPv4 = (prop != null) && (prop.toLowerCase() == "true") + /* Windows lacks support for setoption IPV6_TCLASS. + * + * When execution on Windows with Java 17 trafficClass is not set. + * s.getTrafficClass returns 0 instead of 0x28 + * See above, it is normal for some network implementations to not + * take the hint. + */ + (!useIPv4) || (Platform.executingInJVMOnJDK17) + } + assumeFalse("Invalid behaviour on JDK 17+", disabled) val s = new Socket() try { s.setTrafficClass(0x28) From 28cad55238301d3edbf8e72b2365d52508c11f44 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Fri, 19 Jan 2024 10:25:53 +0100 Subject: [PATCH 36/38] fix: Fix handling of erased extern calls with variadic arguments (#3691) * Fix handling of erased extern varages by attaching typer types. Fix a bug leading to truncation of Long to Size on 32-bit systems Share parts of common symbol utils betwen prepNativeInterop phases * Fix CVarArgTest - use correct format for long arguments (cherry picked from commit 39ed7241f08755de3ee77c4c180a78b90f1f7339) --- .../nscplugin/NirDefinitions.scala | 2 + .../scalanative/nscplugin/NirGenExpr.scala | 56 ++++++++++++--- .../nscplugin/PrepNativeInterop.scala | 33 ++++++++- .../nscplugin/NativeInteropUtil.scala | 66 +++++++++++++++++ .../nscplugin/NirDefinitions.scala | 3 + .../scalanative/nscplugin/NirGenExpr.scala | 17 +++-- .../nscplugin/PostInlineNativeInterop.scala | 72 +++++++++++++++++++ .../nscplugin/PrepNativeInterop.scala | 39 +--------- .../nscplugin/PrepNativeInteropLate.scala | 33 --------- .../scala/scalanative/NIRCompilerTest.scala | 59 ++++++++++++++- .../scalanative/unsafe/CVarArgTest.scala | 49 +++++++------ 11 files changed, 321 insertions(+), 108 deletions(-) create mode 100644 nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NativeInteropUtil.scala create mode 100644 nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PostInlineNativeInterop.scala delete mode 100644 nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirDefinitions.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirDefinitions.scala index c0cc19601c..a784e045d0 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirDefinitions.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirDefinitions.scala @@ -10,6 +10,8 @@ trait NirDefinitions { import rootMirror._ object nirDefinitions { + case class NonErasedType(tpe: Type) extends PlainAttachment + case class NonErasedTypes(tpes: List[Type]) extends PlainAttachment // Native library diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala index fd0b215f8f..6f7f933679 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/NirGenExpr.scala @@ -956,6 +956,35 @@ trait NirGenExpr[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => } } + private def ensureUnboxed( + value: nir.Val, + tpeEnteringPosterasure: Type + )(implicit buf: ExprBuffer, pos: nir.Position): nir.Val = { + tpeEnteringPosterasure match { + case tpe if isPrimitiveValueType(tpe) => + val targetTpe = genType(tpeEnteringPosterasure) + if (targetTpe == value.ty) value + else buf.unbox(genBoxType(tpe), value, nir.Next.None) + + case tpe: ErasedValueType => + val valueClass = tpe.valueClazz + val unboxMethod = treeInfo.ValueClass.valueUnbox(tpe) + val castedValue = buf.genCastOp(value.ty, genType(valueClass), value) + buf.genApplyMethod( + sym = unboxMethod, + statically = false, + self = castedValue, + argsp = Nil + ) + + case tpe => + val unboxed = buf.unboxValue(tpe, partial = true, value) + if (unboxed == value) // no need to or cannot unbox, we should cast + buf.genCastOp(genType(tpeEnteringPosterasure), genType(tpe), value) + else unboxed + } + } + // Compute a set of method symbols that SAM-generated class needs to implement. def functionMethodSymbols(tree: Function): Seq[Symbol] = { val funSym = tree.tpe.typeSymbolDirect @@ -2451,11 +2480,17 @@ trait NirGenExpr[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => def genArg( argp: Tree, - paramTpe: global.Type + paramTpe: global.Type, + isVarArg: Boolean = false ): nir.Val = { implicit def pos: nir.Position = argp.pos - val externType = genExternType(paramTpe) - val value = (genExpr(argp), Type.box.get(externType)) match { + implicit def exprBuf: ExprBuffer = buf + val rawValue = genExpr(argp) + val maybeUnboxed = + if (isVarArg) ensureUnboxed(rawValue, paramTpe.finalResultType) + else rawValue + val externType = genExternType(paramTpe.finalResultType) + val value = (maybeUnboxed, Type.box.get(externType)) match { case (value @ Val.Null, Some(unboxedType)) => externType match { case Type.Ptr | _: Type.RefKind => value @@ -2481,10 +2516,15 @@ trait NirGenExpr[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => implicit def pos: nir.Position = tree.pos val sym = tree.symbol val tpe = - if (tree.symbol != null && tree.symbol.exists) - tree.symbol.tpe.finalResultType - else tree.tpe - val arg = genArg(tree, tpe) + tree.attachments + .get[nirDefinitions.NonErasedType] + .map(_.tpe) + .getOrElse { + if (tree.symbol != null && tree.symbol.exists) + tree.symbol.tpe.finalResultType + else tree.tpe + } + val arg = genArg(tree, tpe, isVarArg = true) def isUnsigned = Type.isUnsignedType(genType(tpe)) // Decimal varargs needs to be promoted to at least Int, and float needs to be promoted to Double val promotedArg = arg.ty match { @@ -2494,7 +2534,7 @@ trait NirGenExpr[G <: nsc.Global with Singleton] { self: NirGenPhase[G] => val conv = if (isUnsigned) nir.Conv.Zext else nir.Conv.Sext - buf.conv(conv, Type.Int, arg, unwind) + buf.conv(conv, nir.Type.Int, arg, unwind) case _ => arg } res += promotedArg diff --git a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/PrepNativeInterop.scala b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/PrepNativeInterop.scala index bbb6eb4747..9c7b283215 100644 --- a/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/PrepNativeInterop.scala +++ b/nscplugin/src/main/scala-2/scala/scalanative/nscplugin/PrepNativeInterop.scala @@ -76,7 +76,16 @@ abstract class PrepNativeInterop[G <: Global with Singleton]( } } - override def transform(tree: Tree): Tree = + override def transform(tree: Tree): Tree = { + // Recursivly widen and dealias all nested types (compler dealiases only top-level) + def widenDealiasType(tpe0: Type): Type = { + val tpe = + if (tpe0.typeSymbol.isAbstract) tpe0.upperBound + else tpe0 + val widened = tpe.dealiasWiden.map(_.dealiasWiden) + if (widened != tpe) widened.map(widenDealiasType(_)) + else widened + } tree match { // Catch calls to Predef.classOf[T]. These should NEVER reach this phase // but unfortunately do. In normal cases, the typer phase replaces these @@ -98,13 +107,20 @@ abstract class PrepNativeInterop[G <: Global with Singleton]( // Replace call by literal constant containing type if (typer.checkClassTypeOrModule(tpeArg)) { val widenedTpe = tpeArg.tpe.dealias.widen - println("rewriting class of for" + widenedTpe) typer.typed { Literal(Constant(widenedTpe)) } } else { reporter.error(tpeArg.pos, s"Type ${tpeArg} is not a class type") EmptyTree } + case Apply(fun, args) + if isExternType(fun.symbol.owner) && + fun.tpe.paramss.exists(isScalaVarArgs(_)) => + args.foreach { arg => + arg.updateAttachment(NonErasedType(widenDealiasType(arg.tpe))) + } + tree + // Catch the definition of scala.Enumeration itself case cldef: ClassDef if cldef.symbol == EnumerationClass => enterOwner(OwnerKind.EnumImpl) { super.transform(cldef) } @@ -188,8 +204,21 @@ abstract class PrepNativeInterop[G <: Global with Singleton]( case _ => super.transform(tree) } + } } + private def isExternType(sym: Symbol): Boolean = { + sym != null && + (sym.isModuleClass || sym.isTraitOrInterface) && + sym.annotations.exists(_.symbol == ExternAnnotationClass) + } + + // Differs from ExternClass defined in NirDefinitions, but points to the same type + // At the phases of prepNativeInterop the symbol has different name + private lazy val ExternAnnotationClass = rootMirror.getRequiredClass( + "scala.scalanative.unsafe.extern" + ) + private def isScalaEnum(implDef: ImplDef) = implDef.symbol.tpe.typeSymbol isSubClass EnumerationClass diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NativeInteropUtil.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NativeInteropUtil.scala new file mode 100644 index 0000000000..814c0f9b01 --- /dev/null +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NativeInteropUtil.scala @@ -0,0 +1,66 @@ +package scala.scalanative.nscplugin + +import dotty.tools.dotc.plugins.PluginPhase +import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Contexts.ctx +import dotty.tools.dotc.core.Definitions +import dotty.tools.dotc.core.Symbols +import dotty.tools.dotc.core.Flags._ +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.* +import dotty.tools.dotc.ast.tpd._ +import dotty.tools.dotc.core.Names._ +import dotty.tools.dotc.core.Types._ +import dotty.tools.dotc.core.Flags._ +import NirGenUtil.ContextCached + +trait NativeInteropUtil { self: PluginPhase => + + /** Returns the definitions in the current context. */ + protected def defn(using Context): Definitions = ctx.definitions + + /** Returns the Native IR definitions in the current context. */ + protected def defnNir(using Context): NirDefinitions = NirDefinitions.get + + /** `true` iff `dd` is a toplevel declaration that is defined externally. */ + def isTopLevelExtern(dd: ValOrDefDef)(using Context) = { + dd.rhs.symbol == defnNir.UnsafePackage_extern && + dd.symbol.isWrappedToplevelDef + } + + extension (sym: Symbols.Symbol) + /** `true` iff `sym` a trait or Java interface declaration. */ + def isTraitOrInterface(using Context): Boolean = + sym.is(Trait) || sym.isAllOf(JavaInterface) + + /** `true` iff `sym` is a scala module. */ + def isScalaModule(using Context): Boolean = + sym.is(ModuleClass, butNot = Lifted) + + /** `true` iff `sym` is a C-bridged type or a declaration defined + * externally. + */ + def isExtern(using Context): Boolean = sym.exists && { + sym.owner.isExternType || + sym.hasAnnotation(defnNir.ExternClass) || + (sym.is(Accessor) && sym.field.isExtern) + } + + /** `true` iff `sym` is a C-bridged type (e.g., `unsafe.CSize`). */ + def isExternType(using Context): Boolean = + (isScalaModule || sym.isTraitOrInterface) && + sym.hasAnnotation(defnNir.ExternClass) + + /** `true` iff `sym` is an exported definition. */ + def isExported(using Context) = + sym.hasAnnotation(defnNir.ExportedClass) || + sym.hasAnnotation(defnNir.ExportAccessorsClass) + + /** `true` iff `sym` uses variadic arguments. */ + def usesVariadicArgs(using Context) = sym.paramInfo.stripPoly match { + case MethodTpe(_, paramTypes, _) => + paramTypes.exists(param => param.isRepeatedParam) + case t => t.isVarArgsMethod + } + end extension + +} diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirDefinitions.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirDefinitions.scala index 893c2b56e7..062933abab 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirDefinitions.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirDefinitions.scala @@ -11,11 +11,14 @@ import dotty.tools.backend.jvm.DottyPrimitives import scala.annotation.{threadUnsafe => tu} import dotty.tools.dotc.parsing.Scanners.IndentWidth.Run import dotty.tools.dotc.core.Definitions +import dotty.tools.dotc.util.Property.StickyKey import NirGenUtil.ContextCached object NirDefinitions { private val cached = ContextCached(NirDefinitions()) def get(using Context): NirDefinitions = cached.get + object NonErasedType extends StickyKey[Type] + object NonErasedTypes extends StickyKey[List[Type]] } // scalafmt: { maxColumn = 120} diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala index a0e434aa17..e7ec4ed4c0 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/NirGenExpr.scala @@ -1492,11 +1492,17 @@ trait NirGenExpr(using Context) { def genArg( argp: Tree, - paramTpe: Types.Type + paramTpe: Types.Type, + isVarArg: Boolean = false ): nir.Val = { given nir.Position = argp.span + given ExprBuffer = buf val externType = genExternType(paramTpe.finalResultType) - val value = (genExpr(argp), Type.box.get(externType)) match { + val rawValue = genExpr(argp) + val maybeUnboxed = + if (isVarArg) ensureUnboxed(rawValue, paramTpe.finalResultType) + else rawValue + val value = (maybeUnboxed, Type.box.get(externType)) match { case (value @ Val.Null, Some(unboxedType)) => externType match { case Type.Ptr | _: Type.RefKind => value @@ -1522,8 +1528,11 @@ trait NirGenExpr(using Context) { for tree <- seqLiteral.elems do given nir.Position = tree.span - val arg = genArg(tree, tree.tpe) - def isUnsigned = Type.isUnsignedType(genType(tree.tpe)) + val tpe = tree + .getAttachment(NirDefinitions.NonErasedType) + .getOrElse(tree.tpe) + val arg = genArg(tree, tpe, isVarArg = true) + def isUnsigned = Type.isUnsignedType(genType(tpe)) // Decimal varargs needs to be promoted to at least Int, and Float needs to be promoted to Double val promotedArg = arg.ty match { case Type.Float => diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PostInlineNativeInterop.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PostInlineNativeInterop.scala new file mode 100644 index 0000000000..2c03436d11 --- /dev/null +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PostInlineNativeInterop.scala @@ -0,0 +1,72 @@ +package scala.scalanative.nscplugin + +import dotty.tools.dotc.plugins.PluginPhase +import dotty.tools._ +import dotc._ +import dotc.ast.tpd._ +import scala.scalanative.nscplugin.CompilerCompat.SymUtilsCompat.setter +import core.Contexts._ +import core.Definitions +import core.Names._ +import core.Symbols._ +import core.Types._ +import core.Flags._ +import core.StdNames._ +import core.Constants.Constant +import NirGenUtil.ContextCached +import dotty.tools.dotc.transform.SeqLiterals + +/** This phase does: + * - handle TypeApply -> Apply conversion for intrinsic methods + */ +object PostInlineNativeInterop { + val name = "scalanative-prepareInterop-postinline" +} + +class PostInlineNativeInterop extends PluginPhase with NativeInteropUtil { + override val runsAfter = Set(transform.Inlining.name, PrepNativeInterop.name) + override val runsBefore = Set(transform.FirstTransform.name) + val phaseName = PostInlineNativeInterop.name + override def description: String = "prepare ASTs for Native interop" + + private class DealiasTypeMapper(using Context) extends TypeMap { + override def apply(tp: Type): Type = + val sym = tp.typeSymbol + val dealiased = + if sym.isOpaqueAlias then sym.opaqueAlias + else tp + dealiased.widenDealias match + case AppliedType(tycon, args) => + AppliedType(this(tycon), args.map(this)) + case ty => ty + } + + override def transformApply(tree: Apply)(using Context): Tree = { + val defnNir = this.defnNir + def dealiasTypeMapper = DealiasTypeMapper() + + // Attach exact type information to the AST to preserve the type information + // during the type erase phase and refer to it in the NIR generation phase. + tree match + case Apply(fun, args) + if fun.symbol.isExtern && fun.symbol.usesVariadicArgs => + args + .collectFirst { + case SeqLiteral(args, _) => args + case Typed(SeqLiteral(args, _), _) => args + } + .toList + .flatten + .foreach { varArg => + varArg.pushAttachment( + NirDefinitions.NonErasedType, + varArg.typeOpt.widenDealias + ) + } + tree + + case _ => tree + + } + +} diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala index d8ad3f78eb..71caeac76a 100644 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala +++ b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInterop.scala @@ -23,49 +23,12 @@ object PrepNativeInterop { val name = "scalanative-prepareInterop" } -class PrepNativeInterop extends PluginPhase { +class PrepNativeInterop extends PluginPhase with NativeInteropUtil { override val runsAfter = Set(transform.PostTyper.name) override val runsBefore = Set(transform.Pickler.name) val phaseName = PrepNativeInterop.name override def description: String = "prepare ASTs for Native interop" - def defn(using Context): Definitions = ctx.definitions - def defnNir(using Context): NirDefinitions = NirDefinitions.get - - private def isTopLevelExtern(dd: ValOrDefDef)(using Context) = { - dd.rhs.symbol == defnNir.UnsafePackage_extern && - dd.symbol.isWrappedToplevelDef - } - - extension (sym: Symbol) - def isTraitOrInterface(using Context): Boolean = - sym.is(Trait) || sym.isAllOf(JavaInterface) - - def isScalaModule(using Context): Boolean = - sym.is(ModuleClass, butNot = Lifted) - - def isExtern(using Context): Boolean = sym.exists && { - sym.owner.isExternType || - sym.hasAnnotation(defnNir.ExternClass) || - (sym.is(Accessor) && sym.field.isExtern) - } - - def isExternType(using Context): Boolean = - (isScalaModule || sym.isTraitOrInterface) && - sym.hasAnnotation(defnNir.ExternClass) - - def isExported(using Context) = - sym.hasAnnotation(defnNir.ExportedClass) || - sym.hasAnnotation(defnNir.ExportAccessorsClass) - - /** `true` iff `sym` uses variadic arguments. */ - def usesVariadicArgs(using Context) = sym.paramInfo.stripPoly match { - case MethodTpe(_, paramTypes, _) => - paramTypes.exists(param => param.isRepeatedParam) - case t => t.isVarArgsMethod - } - end extension - private val exportTargets = collection.mutable.Map.empty[Symbol, Symbol] override def runOn( units: List[CompilationUnit] diff --git a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala b/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala deleted file mode 100644 index 92ddae16ae..0000000000 --- a/nscplugin/src/main/scala-3/scala/scalanative/nscplugin/PrepNativeInteropLate.scala +++ /dev/null @@ -1,33 +0,0 @@ -package scala.scalanative.nscplugin - -import dotty.tools.dotc.plugins.PluginPhase -import dotty.tools._ -import dotc._ -import dotc.ast.tpd._ -import core.Contexts._ -import core.Definitions -import core.Names._ -import core.Symbols._ -import core.Types._ -import core.StdNames._ -import core.Constants.Constant -import NirGenUtil.ContextCached -import dotty.tools.dotc.core.Flags - -/** This phase does: - * - handle TypeApply -> Apply conversion for intrinsic methods - */ -object PostInlineNativeInterop { - val name = "scalanative-prepareInterop-postinline" -} - -class PostInlineNativeInterop extends PluginPhase { - override val runsAfter = Set(transform.Inlining.name, PrepNativeInterop.name) - override val runsBefore = Set(transform.FirstTransform.name) - val phaseName = PostInlineNativeInterop.name - override def description: String = "prepare ASTs for Native interop" - - def defn(using Context): Definitions = ctx.definitions - def defnNir(using Context): NirDefinitions = NirDefinitions.get - -} diff --git a/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala b/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala index a34edb7cff..2d89ab30af 100644 --- a/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala +++ b/tools/src/test/scala/scala/scalanative/NIRCompilerTest.scala @@ -5,7 +5,7 @@ import java.nio.file.Files import org.scalatest._ import org.scalatest.matchers.should.Matchers import org.scalatest.flatspec.AnyFlatSpec - +import scala.scalanative.linker.StaticForwardersSuite.compileAndLoad import scala.scalanative.api.CompilationFailedException class NIRCompilerTest extends AnyFlatSpec with Matchers with Inspectors { @@ -432,4 +432,61 @@ class NIRCompilerTest extends AnyFlatSpec with Matchers with Inspectors { |}""".stripMargin }) + it should "use unboxed types for extern var args" in { + compileAndLoad( + "Test.scala" -> + """import scala.scalanative.unsafe._ + | + |@extern object FFI { + | def printf(format: CString, args: Any*): Unit = extern + |} + | + |object Test{ + | def main(): Unit = { + | def string: Ptr[Byte] = ??? + | def int: Ptr[Int] = ??? + | def long: Ptr[Long] = ??? + | def float: Ptr[Float] = ??? + | FFI.printf(c"", !(string + 1), string, !int, !long, long, !float) + | } + |} + |""".stripMargin + ) { defns => + val TestModule = nir.Global.Top("Test$") + val MainMethod = + TestModule.member(nir.Sig.Method("main", Seq(nir.Type.Unit))) + val FFIModule = nir.Global.Top("FFI$") + val PrintfMethod = FFIModule.member(nir.Sig.Extern("printf")) + val callArgs: Seq[nir.Val] = defns + .collectFirst { + case nir.Defn.Define(_, MainMethod, _, insts) => insts + } + .flatMap { + _.collectFirst { + case nir.Inst.Let( + _, + nir.Op.Call(_, nir.Val.Global(PrintfMethod, _), args), + _ + ) => + args + } + } + .headOption + .getOrElse { + fail("Not found either tested method or the extern calls"); ??? + } + val expectedCallArgs = Seq( + nir.Type.Ptr, // format CString + nir.Type.Int, // byte extended to Int + nir.Type.Ptr, // Ptr[Byte] + nir.Type.Int, // int, + nir.Type.Long, // long + nir.Type.Ptr, // Ptr[Long] + nir.Type.Double // float extended to double + ) + + (expectedCallArgs.toList).shouldEqual(callArgs.map(_.ty).toList) + } + } + } diff --git a/unit-tests/native/src/test/scala/scala/scalanative/unsafe/CVarArgTest.scala b/unit-tests/native/src/test/scala/scala/scalanative/unsafe/CVarArgTest.scala index 4d18af094c..85107f854a 100644 --- a/unit-tests/native/src/test/scala/scala/scalanative/unsafe/CVarArgTest.scala +++ b/unit-tests/native/src/test/scala/scala/scalanative/unsafe/CVarArgTest.scala @@ -18,7 +18,7 @@ class CVarArgTest { val buff: Ptr[CChar] = stackalloc[CChar](1024.toUInt) generator(buff, cstr) val got = fromCString(buff) - assertEquals(got, output) + assertEquals(output, got) } @Test def empty(): Unit = @@ -250,11 +250,11 @@ class CVarArgTest { ) @Test def longValue0(): Unit = - vatest(c"%d", "0")(stdio.sprintf(_, _, 0L)) + vatest(c"%lld", "0")(stdio.sprintf(_, _, 0L)) @Test def longValue1(): Unit = - vatest(c"%d", "1")(stdio.sprintf(_, _, 1L)) + vatest(c"%lld", "1")(stdio.sprintf(_, _, 1L)) @Test def longValueMinus1(): Unit = - vatest(c"%d", "-1")(stdio.sprintf(_, _, -1L)) + vatest(c"%lld", "-1")(stdio.sprintf(_, _, -1L)) @Test def longValueMin(): Unit = { vatest(c"%lld", "-9223372036854775808")( stdio.sprintf(_, _, java.lang.Long.MIN_VALUE) @@ -266,31 +266,36 @@ class CVarArgTest { ) } @Test def longArgs1(): Unit = - vatest(c"%d", "1")(stdio.sprintf(_, _, 1L)) + vatest(c"%lld", "1")(stdio.sprintf(_, _, 1L)) @Test def longArgs2(): Unit = - vatest(c"%d %d", "1 2")(stdio.sprintf(_, _, 1L, 2L)) + vatest(c"%lld %lld", "1 2")(stdio.sprintf(_, _, 1L, 2L)) @Test def longArgs3(): Unit = - vatest(c"%d %d %d", "1 2 3")(stdio.sprintf(_, _, 1L, 2L, 3L)) + vatest(c"%lld %lld %lld", "1 2 3")(stdio.sprintf(_, _, 1L, 2L, 3L)) @Test def longArgs4(): Unit = - vatest(c"%d %d %d %d", "1 2 3 4")(stdio.sprintf(_, _, 1L, 2L, 3L, 4L)) + vatest(c"%lld %lld %lld %lld", "1 2 3 4")( + stdio.sprintf(_, _, 1L, 2L, 3L, 4L) + ) @Test def longArgs5(): Unit = - vatest(c"%d %d %d %d %d", "1 2 3 4 5")( + vatest(c"%lld %lld %lld %lld %lld", "1 2 3 4 5")( stdio.sprintf(_, _, 1L, 2L, 3L, 4L, 5L) ) @Test def longArgs6(): Unit = - vatest(c"%d %d %d %d %d %d", "1 2 3 4 5 6")( + vatest(c"%lld %lld %lld %lld %lld %lld", "1 2 3 4 5 6")( stdio.sprintf(_, _, 1L, 2L, 3L, 4L, 5L, 6L) ) @Test def longArgs7(): Unit = - vatest(c"%d %d %d %d %d %d %d", "1 2 3 4 5 6 7")( + vatest(c"%lld %lld %lld %lld %lld %lld %lld", "1 2 3 4 5 6 7")( stdio.sprintf(_, _, 1L, 2L, 3L, 4L, 5L, 6L, 7L) ) @Test def longArgs8(): Unit = - vatest(c"%d %d %d %d %d %d %d %d", "1 2 3 4 5 6 7 8")( + vatest(c"%lld %lld %lld %lld %lld %lld %lld %lld", "1 2 3 4 5 6 7 8")( stdio.sprintf(_, _, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L) ) @Test def longArgs9(): Unit = - vatest(c"%d %d %d %d %d %d %d %d %d", "1 2 3 4 5 6 7 8 9")( + vatest( + c"%lld %lld %lld %lld %lld %lld %lld %lld %lld", + "1 2 3 4 5 6 7 8 9" + )( stdio.sprintf(_, _, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L) ) @@ -573,23 +578,23 @@ class CVarArgTest { vatest(c"%llu", "18446744073709551615")(stdio.sprintf(_, _, ULong.MaxValue)) } @Test def ulongArgs1(): Unit = - vatest(c"%d", "1")(stdio.sprintf(_, _, 1.toULong)) + vatest(c"%llu", "1")(stdio.sprintf(_, _, 1.toULong)) @Test def ulongArgs2(): Unit = - vatest(c"%d %d", "1 2")(stdio.sprintf(_, _, 1.toULong, 2.toULong)) + vatest(c"%llu %llu", "1 2")(stdio.sprintf(_, _, 1.toULong, 2.toULong)) @Test def ulongArgs3(): Unit = - vatest(c"%d %d %d", "1 2 3")( + vatest(c"%llu %llu %llu", "1 2 3")( stdio.sprintf(_, _, 1.toULong, 2.toULong, 3.toULong) ) @Test def ulongArgs4(): Unit = - vatest(c"%d %d %d %d", "1 2 3 4")( + vatest(c"%llu %llu %llu %llu", "1 2 3 4")( stdio.sprintf(_, _, 1.toULong, 2.toULong, 3.toULong, 4.toULong) ) @Test def ulongArgs5(): Unit = - vatest(c"%d %d %d %d %d", "1 2 3 4 5")( + vatest(c"%llu %llu %llu %llu %llu", "1 2 3 4 5")( stdio.sprintf(_, _, 1.toULong, 2.toULong, 3.toULong, 4.toULong, 5.toULong) ) @Test def ulongArgs6(): Unit = - vatest(c"%d %d %d %d %d %d", "1 2 3 4 5 6")( + vatest(c"%llu %llu %llu %llu %llu %llu", "1 2 3 4 5 6")( stdio.sprintf( _, _, @@ -603,7 +608,7 @@ class CVarArgTest { ) @Test def ulongArgs7(): Unit = vatest( - c"%d %d %d %d %d %d %d", + c"%llu %llu %llu %llu %llu %llu %llu", "1 2 3 4 5 6 7" )( stdio.sprintf( @@ -620,7 +625,7 @@ class CVarArgTest { ) @Test def ulongArgs8(): Unit = vatest( - c"%d %d %d %d %d %d %d %d", + c"%llu %llu %llu %llu %llu %llu %llu %llu", "1 2 3 4 5 6 7 8" )( stdio.sprintf( @@ -638,7 +643,7 @@ class CVarArgTest { ) @Test def ulongArgs9(): Unit = vatest( - c"%d %d %d %d %d %d %d %d %d", + c"%llu %llu %llu %llu %llu %llu %llu %llu %llu", "1 2 3 4 5 6 7 8 9" )( stdio.sprintf( From 626bb503464a9c092ab187b4c39cede933c70db5 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Fri, 19 Jan 2024 01:46:02 +0100 Subject: [PATCH 37/38] fix: Make a list of linked libraries distinct seq (#3694) (cherry picked from commit 174fcb02fcd8097e15425205922d70dbd154c017) --- tools/src/main/scala/scala/scalanative/build/LLVM.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/src/main/scala/scala/scalanative/build/LLVM.scala b/tools/src/main/scala/scala/scalanative/build/LLVM.scala index 47f1a0f7e2..5b003e7560 100644 --- a/tools/src/main/scala/scala/scalanative/build/LLVM.scala +++ b/tools/src/main/scala/scala/scalanative/build/LLVM.scala @@ -154,7 +154,7 @@ private[scalanative] object LLVM { if (config.targetsWindows) Seq("Dbghelp") else Seq("pthread", "dl") platformsLinks ++ srclinks ++ gclinks - } + }.distinct config.logger.info(s"Linking with [${links.mkString(", ")}]") val linkopts = config.linkingOptions ++ links.map("-l" + _) From 6a047568daad62dcad3049d6921cbb2a1ae6bb50 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Fri, 19 Jan 2024 12:44:09 +0100 Subject: [PATCH 38/38] Set version to 0.4.17 and generate changelog --- docs/changelog/0.4.17.md | 139 ++++++++++++++++++ docs/changelog/index.rst | 1 + docs/conf.py | 4 +- .../scala/scalanative/nir/Versions.scala | 2 +- 4 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/0.4.17.md diff --git a/docs/changelog/0.4.17.md b/docs/changelog/0.4.17.md new file mode 100644 index 0000000000..ed485b1da5 --- /dev/null +++ b/docs/changelog/0.4.17.md @@ -0,0 +1,139 @@ + +# 0.4.17 (2024-01-19) + +We're happy to announce the release of Scala Native 0.4.17, which is the next maintance release. +The new version introduces support for the Scala 3.4.0 and fixes some of found bugs. + +## Compatibility notes +Due to the limitations of versions 0.4.x the Scala 3 Standard Library NIR outputs are based on Scala 3.3.0. Any runtime usage of methods introduced to Scala 3 standard library after 3.3.0 would not work and would result in linking error. Compile time only methods like macros or mirrors would still work. This issue would be handled in Scala Native 0.5.x by using a different publishing strategy. + +Scala standard library used by this release is based on the following versions: + + + + + + + + + + + + + + + + + + + +
Scala binary versionScala release
2.122.12.18
2.132.13.12
33.3.0
+ + + + + + + + + + + + + + + + +
Commits since last release37
Merged PRs24
Contributors6
+ +## Contributors + +Big thanks to everybody who contributed to this release or reported an issue! + +``` +$ git shortlog -sn --no-merges v0.4.16..v0.4.17 + 27 Wojciech Mazur + 4 LeeTibbert + 2 João Costa + 2 Michel Davit + 1 Alex Dupre + 1 Paul Thordarson +``` + +## Merged PRs + +## [v0.4.17](https://github.com/scala-native/scala-native/tree/v0.4.17) (2024-01-19) + +[Full Changelog](https://github.com/scala-native/scala-native/compare/v0.4.16...v0.4.17) + +**Merged pull requests:** +## Java Standard Library +- Simplifiy `java.io.FileDescriptor.valid()` test, invalidate file descriptor on close. + [\#3578](https://github.com/scala-native/scala-native/pull/3578) + ([WojciechMazur](https://github.com/WojciechMazur)) +- Respect `java.lang.Clonable` trait and throw exception on clone when it's missing + [\#3579](https://github.com/scala-native/scala-native/pull/3579) + ([WojciechMazur](https://github.com/WojciechMazur)) +- Skip addr memcmp if getifaddrs returns a null ifa_addr pointer + [\#3626](https://github.com/scala-native/scala-native/pull/3626) + ([RustedBones](https://github.com/RustedBones)) +- Mutate socket localAddr only on successful bind + [\#3627](https://github.com/scala-native/scala-native/pull/3627) + ([RustedBones](https://github.com/RustedBones)) +- Fix compilation on FreeBSD. + [\#3625](https://github.com/scala-native/scala-native/pull/3625) + ([alexdupre](https://github.com/alexdupre)) +- improvement: Make `ArrayIndexOutBoundsExceptions` compliant with JVM 8+ - + [\#3638](https://github.com/scala-native/scala-native/pull/3638) + ([WojciechMazur](https://github.com/WojciechMazur)) +- Fix #3631: Regex now handles OR alternatives with more than two clauses + [\#3642](https://github.com/scala-native/scala-native/pull/3642) + ([LeeTibbert](https://github.com/LeeTibbert)) +- javalib: Format IPv4-mapped IPv6 addresses as IPv6 + [\#3654](https://github.com/scala-native/scala-native/pull/3654) + ([LeeTibbert](https://github.com/LeeTibbert)) + + +## Scala Native compiler plugin +- When generating top-level extern methods check its annotations for `link`/`define` + [\#3604](https://github.com/scala-native/scala-native/pull/3604) + ([WojciechMazur](https://github.com/WojciechMazur)) +- improvement: In NIR codegen always use `nir.Type.Unit` for if return type if one of branches is unit type + [\#3644](https://github.com/scala-native/scala-native/pull/3644) + ([WojciechMazur](https://github.com/WojciechMazur)) +- Support Scala 3.4.0-RC1 + [\#3628](https://github.com/scala-native/scala-native/pull/3628) + ([WojciechMazur](https://github.com/WojciechMazur)) +- fix: Fix handling of erased extern calls with variadic arguments + [\#3691](https://github.com/scala-native/scala-native/pull/3691) + ([WojciechMazur](https://github.com/WojciechMazur)) +- fix: Allow to define multi-level exports referring finally to extern method + [\#3665](https://github.com/scala-native/scala-native/pull/3665) + ([WojciechMazur](https://github.com/WojciechMazur)) + +## POSIX bindings +- Fix typo on VEOL @name annotation in termios module + [\#3606](https://github.com/scala-native/scala-native/pull/3606) + ([kapunga](https://github.com/kapunga)) +- Fix #3655: provide posixlib syslog method + [\#3656](https://github.com/scala-native/scala-native/pull/3656) + ([LeeTibbert](https://github.com/LeeTibbert)) + + +## JUnit runtime +- Exlcude internal part of stacktraces from JUnit error reports + [\#3617](https://github.com/scala-native/scala-native/pull/3617) + ([WojciechMazur](https://github.com/WojciechMazur)) + +## Test runners +- feature: Setup debug signal handlers in the TestMain only when requested + [\#3660](https://github.com/scala-native/scala-native/pull/3660) + ([WojciechMazur](https://github.com/WojciechMazur)) + +## Toolchain +- Log linked libraries + [\#3674](https://github.com/scala-native/scala-native/pull/3674) + ([JD557](https://github.com/JD557)) +- fix: Make a list of linked libraries distinct sequence + [\#3694](https://github.com/scala-native/scala-native/pull/3694) + ([WojciechMazur](https://github.com/WojciechMazur)) diff --git a/docs/changelog/index.rst b/docs/changelog/index.rst index cfc9b1f80a..8e0b74af84 100644 --- a/docs/changelog/index.rst +++ b/docs/changelog/index.rst @@ -6,6 +6,7 @@ Changelog .. toctree:: :maxdepth: 1 + 0.4.17 0.4.16 0.4.15 0.4.14 diff --git a/docs/conf.py b/docs/conf.py index 10807418b1..0f28244b57 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -69,9 +69,9 @@ def generateScalaNativeCurrentYear(): # built documents. # # The short X.Y version. -version = u'0.4.17-SNAPSHOT' +version = u'0.4.17' # The full version, including alpha/beta/rc tags. -release = u'0.4.17-SNAPSHOT' +release = u'0.4.17' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/nir/src/main/scala/scala/scalanative/nir/Versions.scala b/nir/src/main/scala/scala/scalanative/nir/Versions.scala index e69c7824c2..56c18a28dd 100644 --- a/nir/src/main/scala/scala/scalanative/nir/Versions.scala +++ b/nir/src/main/scala/scala/scalanative/nir/Versions.scala @@ -25,7 +25,7 @@ object Versions { final val revision: Int = 9 // a.k.a. MINOR version /* Current public release version of Scala Native. */ - final val current: String = "0.4.17-SNAPSHOT" + final val current: String = "0.4.17" final val currentBinaryVersion: String = binaryVersion(current) private object FullVersion {