Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,12 @@ object anthology extends SoundnessModule {

object `scala` extends SoundnessSubModule {
def moduleDeps = Seq(core, anticipation.log, ambience.core, galilei.core)
def compileIvyDeps = Agg(ivy"org.scala-lang:scala3-compiler_3:${scalaVersion()}")
def ivyDeps = Agg(
ivy"org.scala-lang:scala3-compiler_3:${scalaVersion()}",
ivy"org.scala-js:scalajs-library_2.13:1.18.2",
ivy"org.scala-js:scalajs-javalib:1.18.2",
ivy"org.scala-js:scalajs-linker_2.13:1.18.2"
)
}

object `java` extends SoundnessSubModule {
Expand Down
9 changes: 5 additions & 4 deletions lib/anthology/src/scala/anthology-scala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ import dotty.tools.dotc.reporting.*

import language.adhocExtensions

object scalacOptions:
val newSyntax = Scalac.Option[Scalac.Versions](t"-new-syntax")
def sourceFuture = Scalac.Option[Scalac.Versions](t"-source", t"future")
val experimental = Scalac.Option[3.4 | 3.5 | 3.6 | 3.7](t"-experimental")
package scalacOptions:
val newSyntax = ScalacOption[Scalac.All](t"-new-syntax")
def sourceFuture = ScalacOption[Scalac.All](t"-source", t"future")
val experimental = ScalacOption[3.4 | 3.5 | 3.6 | 3.7](t"-experimental")
val scalaJs = ScalacOption[Scalac.All](t"-scalajs")

object warnings:
val feature = Scalac.Option[Scalac.Versions](t"-feature")
Expand Down
65 changes: 58 additions & 7 deletions lib/anthology/src/scala/anthology.Scalac.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ object Scalac:
def refresh(): Unit = synchronized { Scala3 = new dtd.Compiler() }
def compiler(): dtd.Compiler = Scala3

case class Scalac[version <: Scalac.Versions](options: List[Scalac.Option[version]]):

case class Scalac[version <: Scalac.All](options: List[Scalac.Option[version]]):
def commandLineArguments: List[Text] = options.flatMap(_.flags)

def apply(classpath: LocalClasspath)[path: Abstractable across Paths to Text]
Expand All @@ -82,15 +81,17 @@ case class Scalac[version <: Scalac.Versions](options: List[Scalac.Option[versio

object ProgressApi extends dtdsi.ProgressCallback:
private var last: Int = -1

override def informUnitStarting(stage: String | Null, unit: dtd.CompilationUnit | Null)
: Unit =
()

()

override def progress
(current: Int,
total: Int,
currentStage: String | Null,
nextStage: String | Null)
total: Int,
currentStage: String | Null,
nextStage: String | Null)
: Boolean =

val int = (100.0*current/total).toInt
Expand All @@ -114,9 +115,12 @@ case class Scalac[version <: Scalac.Versions](options: List[Scalac.Option[versio
::: List(t"")

Log.info(CompileEvent.Running(args))
setup(args.map(_.s).to(Array), ctx).map(_(1)).get

setup(args.map(_.s).to(Array), ctx).map(_(1)).getOrElse:
abort(CompilerError())

def run(): CompileProcess =
println("running")
given dtdc.Contexts.Context = currentCtx.fresh.pipe: ctx =>
ctx
. setReporter(reporter)
Expand All @@ -129,13 +133,60 @@ case class Scalac[version <: Scalac.Versions](options: List[Scalac.Option[versio
scalacProcess.put:
task(t"scalac"):
try
println("compiling")
Scalac.compiler().newRun.tap: run =>
run.compileSources(sourceFiles)
println("and")
if !reporter.hasErrors then finish(Scalac.Scala3, run)

scalacProcess.put
(if reporter.hasErrors then CompileResult.Failure else CompileResult.Success)

println(options)
if options.has(scalacOptions.scalaJs) then
println("has Scala.JS")
import org.scalajs.linker.*
import org.scalajs.linker.interface.*
import org.scalajs.logging.*
import scala.concurrent.*, duration.*

val logger = new Logger:
def log(level: Level, message: => String): Unit = println(message)
def trace(exception: => Throwable): Unit = exception.printStackTrace()

println("logger = "+logger)

val config = StandardConfig().withExperimentalUseWebAssembly(true).withOptimizer(true).withMinify(true).withModuleKind(ModuleKind.ESModule)
println("config = "+config)

val linker = try StandardImpl.linker(config)
catch case error: Throwable =>
error.printStackTrace()
???

println("linker = "+linker)
val irFileCache: IRFileCache = StandardImpl.irFileCache()
val cache = irFileCache.newCache
import scala.concurrent.ExecutionContext.Implicits.global
val scalalib: Seq[IRContainer] = Await.result(PathIRContainer.fromClasspath(List(java.nio.file.Paths.get("/Users/propensive/work/soundness/scalajs-library_2.13-1.18.2.jar").nn)), 5.minutes)(0)
val scalalib2: Seq[IRContainer] = Await.result(PathIRContainer.fromClasspath(List(java.nio.file.Paths.get("/Users/propensive/work/soundness/scalajs-scalalib_2.13-2.13.16+1.18.2.jar").nn)), 5.minutes)(0)
val javalib: Seq[IRContainer] = Await.result(PathIRContainer.fromClasspath(List(java.nio.file.Paths.get("/Users/propensive/work/soundness/scalajs-javalib-1.18.2.jar").nn)), 5.minutes)(0)
val scalalibFiles: Seq[IRFile] = Await.result(cache.cached(scalalib), 5.minutes)
val scalalibFiles2: Seq[IRFile] = Await.result(cache.cached(scalalib2), 5.minutes)
val javalibFiles: Seq[IRFile] = Await.result(cache.cached(javalib), 5.minutes)

println("linking")
val output = PathOutputDirectory(java.nio.file.Paths.get("js").nn)
println(out.generic.s+"/foo/Hello$.sjsir")
val irFile1: IRFile = Await.result(PathIRFile(java.nio.file.Paths.get(out.generic.s+"/foo/Hello$.sjsir").nn), 5.minutes)
val irFile2: IRFile = Await.result(PathIRFile(java.nio.file.Paths.get(out.generic.s+"/foo/Hello.sjsir").nn), 5.minutes)
val mainMethod = ModuleInitializer.mainMethod("foo.Hello", "mainxyz")
println(mainMethod)
try println("Result: "+Await.result(linker.link(List(irFile1, irFile2) ++ scalalibFiles ++ scalalibFiles2 ++ javalibFiles, mainMethod :: Nil, output, logger), 1.minutes))
catch case throwable: Throwable =>
println(throwable)
throwable.printStackTrace()

catch case suc.NonFatal(error) =>
scalacProcess.put(CompileResult.Crash(error.stackTrace))
Scalac.refresh()
Expand Down
82 changes: 81 additions & 1 deletion lib/anthology/src/test/anthology.Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,86 @@ package anthology

import soundness.*

import workingDirectories.jre
import systemProperties.jre
import supervisors.global
import asyncTermination.cancel
import logging.silent
import stdioSources.virtualMachine.ansi

import strategies.throwUnsafely

object Tests extends Suite(m"Anthology Tests"):
def run(): Unit =
()

suite(m"Scala compiler tests"):

val helloWorld = t"""
package foo

@main
def run(): Unit = println("Hello world")
"""

val sources = Map(t"hello.scala" -> helloWorld)

test(m"Compile hello world"):
val classpath = LocalClasspath.system()
val dir: Path on Linux = workingDirectory[Path on Linux] / Name[Linux](t"tmp")

recover:
case CompilerError() =>
println(t"Compiler error")

case AsyncError(_) =>
println(t"Async error")

. within:
val process = Scalac[3.6](Nil)(classpath)(sources, dir)
val progress = async(process.progress.each(println(_)))

process.complete()
process.notices.each(println(_))
progress.await()

. assert()

suite(m"Scala.js compiler tests"):

val helloWorld = t"""
package foo

object Hello:
def mainxyz(): Unit =
def recur(n: Int, m: Int, c: Int): Int =
if c == 0 then n else recur(m, n + m, c - 1)

val result = recur(1, 2, 8)
println(result)

"""


val sources = Map(t"hello.scala" -> helloWorld)

test(m"Compile hello world"):
val classpath = LocalClasspath.system()
val dir: Path on Linux = workingDirectory[Path on Linux] / Name[Linux](t"tmp")

recover:
case CompilerError() =>
println(t"Compiler error")

case AsyncError(_) =>
println(t"Async error")

. within:
val process = Scalac[3.6](List(scalacOptions.scalaJs))(classpath)(sources, dir)
val progress = async(process.progress.each(println(_)))

process.complete()
process.notices.each(println(_))
progress.await()


. assert()
3 changes: 1 addition & 2 deletions lib/capricious/src/core/capricious.Random.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ class Random(private val generator: su.Random):
def unitInterval(): Double = generator.nextDouble()
def apply[value: Randomizable](): value = value.from(this)

transparent inline def shuffle[element](seq: Seq[element]): Seq[element] =
generator.shuffle(seq)
transparent inline def shuffle[element](seq: Seq[element]): Seq[element] = generator.shuffle(seq)
4 changes: 2 additions & 2 deletions lib/digression/src/core/digression.StackTrace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object StackTrace:
"ⲛ".tt -> "class initializer".tt,
"ℓ".tt -> "lazy initializer".tt,
"Σ".tt -> "specialized method".tt,
"Ξ".tt -> "object".tt)
"".tt -> "object".tt)

def rewrite(name: String, method: Boolean = false): Text =
val buffer: StringBuilder = StringBuilder()
Expand Down Expand Up @@ -228,7 +228,7 @@ object StackTrace:

else if rewritten.s.endsWith("#") then
val pivot = rewritten.s.lastIndexOf(".")
val sub = if rewritten.s.endsWith("⋮#") then "⋮" else "Ξ"
val sub = if rewritten.s.endsWith("⋮#") then "⋮" else ""

(rewritten.s.substring(0, pivot).nn+"."+sub+rewritten.s.substring(pivot + 1).nn.dropRight(1))
. tt
Expand Down
1 change: 1 addition & 0 deletions lib/hellenism/src/core/hellenism.Classpath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ package hellenism

import java.net as jn

import ambience.*
import anticipation.*
import contingency.*
import fulminate.*
Expand Down
4 changes: 4 additions & 0 deletions lib/hellenism/src/core/hellenism.LocalClasspath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
package hellenism

import java.lang as jl

import ambience.*
import anticipation.*
import contingency.*
Expand Down Expand Up @@ -62,6 +64,8 @@ object LocalClasspath:

new LocalClasspath(entries, entries.to(Set))

def system()(using SystemProperties): LocalClasspath raises SystemPropertyError =
jl.System.getProperty("java.class.path").nn.tt.decode[LocalClasspath]

def apply
(entries: List
Expand Down
Loading