Skip to content

Create a scala3-library artefact #22399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fa04fee
chore: Add sbt plugin to copy from a jar
hamzaremmal Dec 17, 2024
448edd2
chore: enable the stdlib plugin in stdlib
hamzaremmal Jan 17, 2025
2e586c3
chore: add all the files in scala.annotation
hamzaremmal Jan 17, 2025
849d189
chore: add all the files in scala.annotation.meta
hamzaremmal Jan 17, 2025
cdf3771
chore: add all the files in scala.annotation.unchecked
hamzaremmal Jan 17, 2025
0c081cf
chore: add all the files in scala.beans
hamzaremmal Jan 17, 2025
7470ea5
chore: add all the files in scala.collection
hamzaremmal Jan 17, 2025
bdb1a7e
chore: add all the files in scala.compat
hamzaremmal Jan 17, 2025
33493b2
chore: add all the files in scala.concurrent
hamzaremmal Jan 17, 2025
d99325c
chore: add all the files in scala.io
hamzaremmal Jan 17, 2025
fe299a8
chore: add all the files in scala.jdk
hamzaremmal Jan 17, 2025
30678b7
chore: add all the files in scala.math
hamzaremmal Jan 17, 2025
bfbe6b9
chore: add all the files in scala.ref
hamzaremmal Jan 17, 2025
a00daaf
chore: add all the files in scala.reflect
hamzaremmal Jan 17, 2025
48cc50e
chore: add all the files in scala.reflect.macros
hamzaremmal Jan 17, 2025
725f72a
chore: add all the files in scala.runtime.java8
hamzaremmal Jan 17, 2025
2abbfac
chore: add all the files in scala.runtime
hamzaremmal Jan 17, 2025
03f3789
chore: add all the files in scala.sys
hamzaremmal Jan 17, 2025
e6a5ead
chore: add all the files in scala.util
hamzaremmal Jan 17, 2025
abf65b0
chore: add all the files in scala.util.control
hamzaremmal Jan 17, 2025
2aed484
chore: add all the files in scala.util.hashing
hamzaremmal Jan 17, 2025
25f67c5
chore: add all the files in scala.util.matching
hamzaremmal Jan 17, 2025
2f79634
chore: add all the files in scala
hamzaremmal Jan 17, 2025
fe34107
chore: dotc cannot compile AnyVal
hamzaremmal Jan 17, 2025
2e1e154
chore: copy memebrs from stdlibPatches to Predef and language
hamzaremmal Jan 17, 2025
761456e
chore: disable all the warnings for now in stdlib
hamzaremmal Jan 17, 2025
57c6bce
chore: make the compiler and library compile
hamzaremmal Jan 17, 2025
01a7a33
chore: enable the copy plugin in scala3-library
hamzaremmal Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class GenBCode extends Phase { self =>
result
finally
// frontendAccess and postProcessor are created lazilly, clean them up only if they were initialized
if _frontendAccess ne null then
if !(_frontendAccess eq null) then
frontendAccess.compilerSettings.outputDirectory match {
case jar: JarArchive =>
if (ctx.run.nn.suspendedUnits.nonEmpty)
Expand All @@ -120,7 +120,7 @@ class GenBCode extends Phase { self =>
jar.close()
case _ => ()
}
if _postProcessor ne null then
if !(_postProcessor eq null) then
postProcessor.classfileWriter.close()
generatedClassHandler.close()
}
Expand Down
59 changes: 59 additions & 0 deletions library/src/scala/AnyVal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
/*
package scala

/** `AnyVal` is the root class of all ''value types'', which describe values
* not implemented as objects in the underlying host system. Value classes
* are specified in Scala Language Specification, section 12.2.
*
* The standard implementation includes nine `AnyVal` subtypes:
*
* [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]],
* [[scala.Short]], and [[scala.Byte]] are the ''numeric value types''.
*
* [[scala.Unit]] and [[scala.Boolean]] are the ''non-numeric value types''.
*
* Other groupings:
*
* - The ''subrange types'' are [[scala.Byte]], [[scala.Short]], and [[scala.Char]].
* - The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]].
* - The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
*
* A subclass of `AnyVal` is called a ''user-defined value class''
* and is treated specially by the compiler. Properly-defined user value classes provide a way
* to improve performance on user-defined types by avoiding object allocation at runtime, and by
* replacing virtual method invocations with static method invocations.
*
* User-defined value classes which avoid object allocation...
*
* - must have a single `val` parameter that is the underlying runtime representation.
* - can define `def`s, but no `val`s, `var`s, or nested `trait`s, `class`es or `object`s.
* - typically extend no other trait apart from `AnyVal`.
* - cannot be used in type tests or pattern matching.
* - may not override `equals` or `hashCode` methods.
*
* A minimal example:
* {{{
* class Wrapper(val underlying: Int) extends AnyVal {
* def foo: Wrapper = new Wrapper(underlying * 19)
* }
* }}}
*
* It's important to note that user-defined value classes are limited, and in some circumstances,
* still must allocate a value class instance at runtime. These limitations and circumstances are
* explained in greater detail in the [[https://docs.scala-lang.org/overviews/core/value-classes.html Value Classes and Universal Traits]].
*/
abstract class AnyVal extends Any {
def getClass(): Class[_ <: AnyVal] = null
}
*/
25 changes: 25 additions & 0 deletions library/src/scala/AnyValCompanion.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala

/** A common supertype for companion classes of primitive types.
*
* A common trait for /companion/ objects of primitive types comes handy
* when parameterizing code on types. For instance, the specialized
* annotation is passed a sequence of types on which to specialize:
* {{{
* class Tuple1[@specialized(Unit, Int, Double) T]
* }}}
*
*/
private[scala] trait AnyValCompanion extends Specializable { }
104 changes: 104 additions & 0 deletions library/src/scala/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala

import java.lang.System.{currentTimeMillis => currentTime}

import scala.annotation.nowarn
import scala.collection.mutable.ListBuffer

/** The `App` trait can be used to quickly turn objects
* into executable programs. Here is an example:
* {{{
* object Main extends App {
* Console.println("Hello World: " + (args mkString ", "))
* }
* }}}
*
* No explicit `main` method is needed. Instead,
* the whole class body becomes the “main method”.
*
* `args` returns the current command line arguments as an array.
*
* ==Caveats==
*
* '''''It should be noted that this trait is implemented using the [[DelayedInit]]
* functionality, which means that fields of the object will not have been initialized
* before the main method has been executed.'''''
*
* Future versions of this trait will no longer extend `DelayedInit`.
*
* In Scala 3, the `DelayedInit` feature was dropped. `App` exists only in a limited form
* that also does not support command line arguments and will be deprecated in the future.
*
* [[https://docs.scala-lang.org/scala3/book/methods-main-methods.html @main]] methods are the
* recommended scheme to generate programs that can be invoked from the command line in Scala 3.
*
* {{{
* @main def runMyProgram(args: String*): Unit = {
* // your program here
* }
* }}}
*
* If programs need to cross-build between Scala 2 and Scala 3, it is recommended to use an
* explicit `main` method:
* {{{
* object Main {
* def main(args: Array[String]): Unit = {
* // your program here
* }
* }
* }}}
*/
@nowarn("""cat=deprecation&origin=scala\.DelayedInit""")
trait App extends DelayedInit {

/** The time when the execution of this program started, in milliseconds since 1
* January 1970 UTC. */
final val executionStart: Long = currentTime

/** The command line arguments passed to the application's `main` method.
*/
protected final def args: Array[String] = _args

private[this] var _args: Array[String] = _

private[this] val initCode = new ListBuffer[() => Unit]

/** The init hook. This saves all initialization code for execution within `main`.
* This method is normally never called directly from user code.
* Instead it is called as compiler-generated code for those classes and objects
* (but not traits) that inherit from the `DelayedInit` trait and that do not
* themselves define a `delayedInit` method.
* @param body the initialization code to be stored for later execution
*/
@deprecated("the delayedInit mechanism will disappear", "2.11.0")
override def delayedInit(body: => Unit): Unit = {
initCode += (() => body)
}

/** The main method.
* This stores all arguments so that they can be retrieved with `args`
* and then executes all initialization code segments in the order in which
* they were passed to `delayedInit`.
* @param args the arguments passed to the main method
*/
final def main(args: Array[String]) = {
this._args = args
for (proc <- initCode) proc()
if (util.Properties.propIsSet("scala.time")) {
val total = currentTime - executionStart
Console.println("[total " + total + "ms]")
}
}
}
Loading
Loading