Skip to content

Upgrade to Scala 3.7.0-RC1 #4745

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
21 changes: 11 additions & 10 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.lolgab.mill.mima.Mima
import coursier.maven.MavenRepository
import de.tobiasroeser.mill.vcs.version.VcsVersion
import com.goyeau.mill.scalafix.ScalafixModule
import mill._
import mill.{idea => _, _}
import mill.define.NamedTask
import mill.main.Tasks
import mill.scalalib._
Expand Down Expand Up @@ -51,7 +51,7 @@ object Deps {
// The Scala version to use
// When updating, run "Publish Bridges" Github Actions for the new version
// and then add to it `bridgeScalaVersions`
val scalaVersion = "3.6.2"
val scalaVersion = "3.7.0-RC1"
val scala2Version = "2.13.15"
// The Scala 2.12.x version to use for some workers
val workerScalaVersion212 = "2.12.20"
Expand Down Expand Up @@ -162,7 +162,7 @@ object Deps {
val osLib = ivy"com.lihaoyi::os-lib:0.11.5-M2"
val pprint = ivy"com.lihaoyi::pprint:0.9.0"
val mainargs = ivy"com.lihaoyi::mainargs:0.7.6"
val millModuledefsVersion = "0.11.3-M5"
val millModuledefsVersion = "0.11.3-M7"
val millModuledefsString = s"com.lihaoyi::mill-moduledefs:${millModuledefsVersion}"
val millModuledefs = ivy"${millModuledefsString}"
val millModuledefsPlugin =
Expand Down Expand Up @@ -489,17 +489,18 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul
def scalacOptions =
super.scalacOptions() ++ Seq(
"-deprecation",
"-feature"
"-feature",
) ++ (
if (ZincWorkerUtil.isScala3(scalaVersion())) Seq(
"-experimental",
// "-Werror",
"-Wunused:all",
// "-Wunused:all",
// "-Xfatal-warnings",
"-Wconf:msg=An existential type that came from a Scala-2 classfile:silent",
"-Wconf:msg=import scala.language.implicitConversions:silent",
"-Wconf:msg=IterableOnceExtensionMethods:silent",
"-Wconf:msg=is deprecated:silent",
"-Wconf:msg=cannot be checked at runtime:silent"
// "-Wconf:msg=An existential type that came from a Scala-2 classfile:silent",
// "-Wconf:msg=import scala.language.implicitConversions:silent",
// "-Wconf:msg=IterableOnceExtensionMethods:silent",
// "-Wconf:msg=is deprecated:silent",
// "-Wconf:msg=cannot be checked at runtime:silent"
// "-Wconf:msg=unused:silent"
// "-no-indent",
// "-Wvalue-discard",
Expand Down
2 changes: 1 addition & 1 deletion ci/mill-bootstrap.patch
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ index 92bfb2c2f8f..9854c30dac1 100644
-import com.goyeau.mill.scalafix.ScalafixModule
+//import de.tobiasroeser.mill.vcs.version.VcsVersion
+//import com.goyeau.mill.scalafix.ScalafixModule
import mill._
import mill.{idea => _, _}
import mill.define.NamedTask
import mill.main.Tasks
import mill.scalalib._
Expand Down
14 changes: 0 additions & 14 deletions core/api/src/mill/api/ExecResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,4 @@ object ExecResult {
}
}

def catchWrapException[T](t: => T): Result[T] = {
try mill.api.Result.Success(t)
catch {
case e: InvocationTargetException =>
mill.api.Result.Failure(makeResultException(e.getCause, new java.lang.Exception()).left.get)
case e: Exception =>
mill.api.Result.Failure(makeResultException(e, new java.lang.Exception()).left.get)
}
}

def makeResultException(e: Throwable, base: java.lang.Exception): Left[String, Nothing] = {
val outerStack = new mill.api.ExecResult.OuterStack(base.getStackTrace)
Left(mill.api.ExecResult.Exception(e, outerStack).toString)
}
}
35 changes: 32 additions & 3 deletions core/api/src/mill/api/MillException.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
package mill.api


import java.lang.reflect.InvocationTargetException

/**
* This exception is specifically handled in [[mill.runner.MillMain]] and [[mill.runner.MillServerMain]]. You can use it, if you need to exit Mill with a nice error message.
*
* @param msg The error message, to be displayed to the user.
*/
class MillException(msg: String) extends Exception(msg)

object MillException {

def catchWrapException[T](t: => T): Result[T] = {
try mill.api.Result.Success(t)
catch { case e =>
mill.api.Result.Failure(
makeResultException(e, new java.lang.Exception()).toString
)
}
}

def unwrapException(t: Throwable) = t match {
case e: ExceptionInInitializerError if e.getCause != null => e.getCause
case e: InvocationTargetException if e.getCause != null => e.getCause
case e: NoClassDefFoundError if e.getCause != null => e.getCause
case e => e
}

def makeResultException(e: Throwable, base: java.lang.Exception): mill.api.ExecResult.Exception = {
val outerStack = new mill.api.ExecResult.OuterStack(base.getStackTrace)
mill.api.ExecResult.Exception(unwrapException(e), outerStack)
}
}


class BuildScriptException(msg: String, script: Option[String])
extends MillException(
script.map(_ + ": ").getOrElse("") + "Build script contains errors:\n" + msg
) {
extends MillException(
script.map(_ + ": ").getOrElse("") + "Build script contains errors:\n" + msg
) {
def this(msg: String) = this(msg, None)
}
2 changes: 1 addition & 1 deletion core/constants/src/mill/constants/CodeGenConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CodeGenConstants {
* we import to work around the need for the `.package` suffix, so
* we add an `_` and call it `build_`
*/
public static final String globalPackagePrefix = "build_";
public static final String globalPackagePrefix = "build";

/**
* What the wrapper objects are called. Not `package` because we don't
Expand Down
2 changes: 1 addition & 1 deletion core/define/src/mill/define/BaseModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class BaseModule(

// `Discover` needs to be defined by every concrete `BaseModule` object, to gather
// compile-time metadata about the tasks and commands at for use at runtime
protected def millDiscover: Discover
protected[mill] def millDiscover: Discover

// We need to propagate the `Discover` object implicitly throughout the module tree
// so it can be used for override detection
Expand Down
13 changes: 9 additions & 4 deletions core/define/src/mill/define/Discover.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ import scala.collection.mutable
* can then be used later to look up the `MainData` for any module.
*/
class Discover(val classInfo: Map[Class[?], Discover.ClassInfo]) {
def resolveEntrypoint(cls: Class[?], name: String) = {
val res = for {
(cls2, node) <- classInfo
def resolveClassInfo(cls: Class[?]) = {
for {
(cls2, node) <- classInfo.iterator
if cls2.isAssignableFrom(cls)
} yield (cls2, node)
}
def resolveEntrypoint(cls: Class[?], name: String) = {
val res = for{
(cls2, node) <- resolveClassInfo(cls)
ep <- node.entryPoints
if ep.mainName.getOrElse(ep.defaultName) == name
} yield ep

res.headOption
res.nextOption
}
}

Expand Down
15 changes: 11 additions & 4 deletions core/define/src/mill/define/internal/Reflect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private[mill] object Reflect {
val arr: Array[java.lang.reflect.Method] = getMethods(outer)
.collect {
case (m, n)
if filter(n) &&
if filter(n.stripSuffix("_alias")) &&
(!noParams || m.getParameterCount == 0) &&
inner.isAssignableFrom(m.getReturnType) =>
m
Expand Down Expand Up @@ -94,7 +94,7 @@ private[mill] object Reflect {
noParams = true,
getMethods
)
.map(m => (m.getName, m))
.map(m => (m.getName.stripSuffix("_alias"), m))

val companionClassOpt = outerCls.getName match {
case s"$prefix$$" =>
Expand All @@ -107,18 +107,25 @@ private[mill] object Reflect {
.filter(implicitly[ClassTag[T]].runtimeClass.isAssignableFrom(_))
.flatMap { c =>
c.getName.stripPrefix(outerCls.getName) match {
case s"$name$$" if filter(scala.reflect.NameTransformer.decode(name)) =>
case s"$name$$" if filter(scala.reflect.NameTransformer.decode(name).stripSuffix("_alias")) =>
c.getFields.find(f => f.getName == "MODULE$").map(name -> _)
case _ => None
}

}
.distinct

val third = outerCls.getFields
.filter(f => implicitly[ClassTag[T]].runtimeClass.isAssignableFrom(f.getType) && f.getName != "MODULE$")
.map(f => scala.reflect.NameTransformer.decode(f.getName) -> f.getType.getField("MODULE$"))
.filter(t => filter(t._1))

// Sometimes `getClasses` returns stuff in odd orders, make sure to sort for determinism
second.sortInPlaceBy(_._1)

first ++ second
val res: Array[(String, java.lang.reflect.Member)] = (first ++ second ++ third)

res.distinctBy(_._1)
}

def reflectNestedObjects02[T: ClassTag](
Expand Down
26 changes: 13 additions & 13 deletions core/define/test/src/mill/define/MacroErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ object MacroErrorTests extends TestSuite {
val expectedMsg =
"Task{} members must be defs defined in a Module class/trait/object body"

val err = compileError("object Foo extends TestBaseModule{ val x = Task {1} }")
val err: utest.CompileError = compileError("object Foo extends TestBaseModule{ val x = Task {1} }")
assert(err.msg == expectedMsg)
}

test("badParameterSets") {
test("command") {
val e = compileError("""
val e: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def w = Task.Command{1}
lazy val millDiscover = Discover[this.type]
Expand All @@ -30,7 +30,7 @@ object MacroErrorTests extends TestSuite {
}

test("target") {
val e = compileError("""
val e: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def x() = Task {1}
lazy val millDiscover = Discover[this.type]
Expand All @@ -43,7 +43,7 @@ object MacroErrorTests extends TestSuite {
)
}
test("input") {
val e = compileError("""
val e: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def y() = Task.Input{1}
lazy val millDiscover = Discover[this.type]
Expand All @@ -56,7 +56,7 @@ object MacroErrorTests extends TestSuite {
)
}
test("sources") {
val e = compileError("""
val e: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def z() = Task.Sources{os.pwd}
lazy val millDiscover = Discover[this.type]
Expand All @@ -69,7 +69,7 @@ object MacroErrorTests extends TestSuite {
)
}
test("persistent") {
val e = compileError("""
val e: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def a() = Task(persistent = true){1}
lazy val millDiscover = Discover[this.type]
Expand Down Expand Up @@ -101,14 +101,14 @@ object MacroErrorTests extends TestSuite {
}
}
test("neg1") {
val e = compileError("""def a = Task { 1 }""")
val e: utest.CompileError = compileError("""def a = Task { 1 }""")
assert(e.msg.contains(
"Task{} members must be defs defined in a Module class/trait/object body"
))
}

test("neg2") {
val e = compileError("object foo extends TestBaseModule{ val a = Task { 1 } }")
val e: utest.CompileError = compileError("object foo extends TestBaseModule{ val a = Task { 1 } }")
assert(e.msg.contains(
"Task{} members must be defs defined in a Module class/trait/object body"
))
Expand All @@ -117,7 +117,7 @@ object MacroErrorTests extends TestSuite {

val expectedMsg =
"Target#apply() call cannot use `val n` defined within the Task{...} block"
val err = compileError("""
val err: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def a = Task { 1 }
val arr = Array(a)
Expand All @@ -136,7 +136,7 @@ object MacroErrorTests extends TestSuite {

val expectedMsg =
"Target#apply() call cannot use `val x` defined within the Task{...} block"
val err = compileError("""
val err: utest.CompileError = compileError("""
object foo extends TestBaseModule{
def a = Task { 1 }
val arr = Array(a)
Expand Down Expand Up @@ -166,7 +166,7 @@ object MacroErrorTests extends TestSuite {
}

test("badCrossKeys") {
val error = utest.compileError(
val error: utest.CompileError = utest.compileError(
"""
object foo extends TestBaseModule{
object cross extends Cross[MyCrossModule](Seq(1, 2, 3))
Expand All @@ -181,7 +181,7 @@ object MacroErrorTests extends TestSuite {
}

test("badCrossKeys2") {
val error = utest.compileError(
val error: utest.CompileError = utest.compileError(
"""
object foo extends TestBaseModule{
object cross extends Cross[MyCrossModule](Seq((1, 2), (2, 2), (3, 3)))
Expand All @@ -202,7 +202,7 @@ object MacroErrorTests extends TestSuite {
}

test("invalidCrossType") {
val error = utest.compileError(
val error: utest.CompileError = utest.compileError(
"""
object foo extends TestBaseModule{
object cross extends Cross[MyCrossModule](null.asInstanceOf[sun.misc.Unsafe])
Expand Down
3 changes: 2 additions & 1 deletion core/exec/src/mill/exec/Execution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private[mill] case class Execution(
}
} catch {
case e: Throwable if !scala.util.control.NonFatal(e) =>
throw new Exception(e)
if (e.getCause != null) throw e.getCause
else throw new Exception(e)
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions core/resolve/src/mill/resolve/Resolve.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import mill.define.{
SelectMode
}
import mill.api.Result
import mill.resolve.ResolveCore.{Resolved, makeResultException}
import mill.resolve.ResolveCore.Resolved
import mill.api.MillException.{catchWrapException, makeResultException}

private[mill] object Resolve {
object Segments extends Resolve[Segments] {
Expand Down Expand Up @@ -58,9 +59,11 @@ private[mill] object Resolve {

val taskList: Seq[Result[Option[NamedTask[?]]]] = resolved.map {
case r: Resolved.NamedTask =>
val instantiated = ResolveCore
.instantiateModule(rootModule, r.segments.init, cache)
.flatMap(instantiateNamedTask(r, _, cache))
val instantiated = catchWrapException {
ResolveCore
.instantiateModule(rootModule, r.segments.init, cache)
.flatMap(instantiateNamedTask(r, _, cache))
}.flatMap(identity)
instantiated.map(Some(_))

case r: Resolved.Command =>
Expand Down Expand Up @@ -136,7 +139,7 @@ private[mill] object Resolve {
)
.head

ResolveCore.catchWrapException(
catchWrapException(
definition.invoke(p).asInstanceOf[NamedTask[?]]
)
}
Expand All @@ -149,7 +152,7 @@ private[mill] object Resolve {
nullCommandDefaults: Boolean,
allowPositionalCommandArgs: Boolean
) = {
ResolveCore.catchWrapException {
catchWrapException {
val invoked = invokeCommand0(
p,
r.segments.last.value,
Expand Down Expand Up @@ -208,7 +211,7 @@ private[mill] object Resolve {
} match {
case mainargs.Result.Success(v: Command[_]) => Result.Success(v)
case mainargs.Result.Failure.Exception(e) =>
Result.Failure(makeResultException(e, new Exception()).left.get)
Result.Failure(makeResultException(e, new Exception()).toString)
case f: mainargs.Result.Failure =>
Result.Failure(
mainargs.Renderer.renderResult(
Expand Down
Loading
Loading