Skip to content

Commit

Permalink
set scalac -Xsource:2.13 -Ypartial-unification globally (digital-asse…
Browse files Browse the repository at this point in the history
…t#6469)

* add -Xsource:2.13, -Ypartial-unification to common_scalacopts

* add now-referenced scalaz-core where needed

* work around bad type signatures in scalatest Aggregating, Containing

* unused Any suppression

* work around bad partial-unification wrought by type alias

* remove unused Conversions import

- not required in 4f68cfc either, so unsure how it's survived this long

* work around Future.traverse; remove unused show import

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END

* remove unused bounds

* remove -Ypartial-unification and -Xsource:2.13 where they were explicitly passed

* longer comment on what the options do

- suggested by @stefanobaghino-da; thanks

* forget Future.traverse, just use scalaz, it knows how to do this
  • Loading branch information
S11001001 authored Jun 24, 2020
1 parent afc573d commit a51d0db
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 55 deletions.
6 changes: 6 additions & 0 deletions bazel_tools/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ common_scalacopts = [
# warn if using deprecated stuff
"-deprecation",
"-Xfuture",
# these two flags turn on source-incompatible enhancements that are always
# on in Scala 2.13. Despite the naming, though, the most impactful and
# 2.13-like change is -Ypartial-unification. -Xsource:2.13 only turns on
# some minor, but in one specific case (scala/bug#10283) essential bug fixes
"-Xsource:2.13",
"-Ypartial-unification",
# better error reporting for pureconfig
"-Xmacro-settings:materialize-derivations",
"-Xfatal-warnings",
Expand Down
1 change: 1 addition & 0 deletions daml-lf/interface/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ da_scala_test(
"//daml-lf/data",
"//daml-lf/language",
"//daml-lf/parser",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)
2 changes: 1 addition & 1 deletion daml-lf/interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repl")
da_scala_library(
name = "interpreter",
srcs = glob(["src/main/**/*.scala"]),
scalacopts = lf_scalacopts + ["-Xsource:2.13"],
scalacopts = lf_scalacopts,
tags = ["maven_coordinates=com.daml:daml-lf-interpreter:__VERSION__"],
visibility = [
"//compiler/repl-service:__subpackages__",
Expand Down
3 changes: 3 additions & 0 deletions daml-lf/interpreter/perf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ da_scala_binary(
"//daml-lf/interpreter",
"//daml-lf/language",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)

Expand All @@ -70,6 +71,7 @@ da_scala_binary(
"//daml-lf/interpreter",
"//daml-lf/language",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)

Expand Down Expand Up @@ -100,5 +102,6 @@ da_scala_binary(
"//daml-lf/interpreter",
"//daml-lf/language",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)
1 change: 1 addition & 0 deletions daml-lf/language/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ da_scala_test(
deps = [
":language",
"//daml-lf/data",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)
1 change: 1 addition & 0 deletions daml-lf/parser/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ da_scala_library(
"//daml-lf/data",
"//daml-lf/language",
"@maven//:org_scala_lang_modules_scala_parser_combinators_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)

Expand Down
1 change: 1 addition & 0 deletions daml-lf/repl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ da_scala_binary(
"//daml-lf/validation",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_jline_jline",
"@maven//:org_scalaz_scalaz_core_2_12",
"@maven//:org_typelevel_paiges_core_2_12",
],
)
1 change: 1 addition & 0 deletions daml-lf/scenario-interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ da_scala_benchmark_jmh(
"//daml-lf/language",
"//daml-lf/transaction",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:org_scalaz_scalaz_core_2_12",
],
)

Expand Down
2 changes: 1 addition & 1 deletion daml-lf/transaction-test-lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ da_scala_library(
plugins = [
"@maven//:org_spire_math_kind_projector_2_12",
],
scalacopts = lf_scalacopts + ["-Xsource:2.13"],
scalacopts = lf_scalacopts,
tags = ["maven_coordinates=com.daml:daml-lf-transaction-test-lib:__VERSION__"],
visibility = ["//visibility:public"],
deps = [
Expand Down
2 changes: 1 addition & 1 deletion daml-lf/transaction/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ da_java_proto_library(
da_scala_library(
name = "transaction",
srcs = glob(["src/main/**/*.scala"]),
scalacopts = lf_scalacopts + ["-Xsource:2.13"],
scalacopts = lf_scalacopts,
tags = ["maven_coordinates=com.daml:daml-lf-transaction:__VERSION__"],
visibility = ["//visibility:public"],
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import scalaz.std.either._
import scalaz.std.list._
import scalaz.std.option._
import scalaz.std.map._
import scalaz.std.scalaFuture._
import scalaz.syntax.tag._
import scalaz.syntax.traverse._
import scala.language.higherKinds
Expand Down Expand Up @@ -196,18 +197,10 @@ object Runner {
implicit ec: ExecutionContext,
seq: ExecutionSequencerFactory): Future[Participants[GrpcLedgerClient]] = {
for {
// The standard library is incredibly weird. Option is not Traversable so we have to convert to a list and back.
// Map is but it doesn’t return a Map so we have to call toMap afterwards.
defaultClient <- Future
.traverse(participantParams.default_participant.toList)(x =>
connectApiParameters(x, applicationId, tlsConfig, maxInboundMessageSize))
.map(_.headOption)
participantClients <- Future
.traverse(participantParams.participants: Map[Participant, ApiParameters])({
case (k, v) =>
connectApiParameters(v, applicationId, tlsConfig, maxInboundMessageSize).map((k, _))
})
.map(_.toMap)
defaultClient <- participantParams.default_participant.traverse(x =>
connectApiParameters(x, applicationId, tlsConfig, maxInboundMessageSize))
participantClients <- participantParams.participants.traverse(v =>
connectApiParameters(v, applicationId, tlsConfig, maxInboundMessageSize))
} yield Participants(defaultClient, participantClients, participantParams.party_participants)
}

Expand All @@ -225,14 +218,8 @@ object Runner {

}
for {
// Apparently Future.traverse is too stupid to traverse an
// Option so you first have to convert to a list and then convert back.
defClient <- Future
.traverse(participantParams.default_participant.toList)(client(_))
.map(_.headOption)
otherClients <- Future
.traverse(participantParams.participants)({ case (k, v) => client(v).map(c => (k, c)) })
.map(_.toMap)
defClient <- participantParams.default_participant.traverse(client(_))
otherClients <- participantParams.participants.traverse(client)
} yield Participants(defClient, otherClients, participantParams.party_participants)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.nio.file.Paths

import org.scalatest.{FlatSpec, Matchers, OptionValues}

@SuppressWarnings(Array("org.wartremover.warts.Any"))
class ConfSpec extends FlatSpec with Matchers with OptionValues {

behavior of "Conf.parse"
Expand Down Expand Up @@ -36,6 +35,17 @@ class ConfSpec extends FlatSpec with Matchers with OptionValues {
Conf.parse(Array("-o", "output", "-d", "package.ClassName", "input")) shouldNot be(empty)
}

// XXX SC remove in Scala 2.13. aggregatingNatureOfGenTraversable is
// mis-signed because it forces Map[K, V] to destructure as
// TRAV[e] = Map[K, e], which is of course not <: GenTraversable[e]. And it's
// needless, as proven below, just like the similar problem with
// Future.traverse's sig
import scala.collection.GenTraversable, org.scalatest.enablers.Aggregating
private[this] implicit def `fixed sig aggregatingNatureOfGenTraversable`[
E: org.scalactic.Equality,
TRAV]: Aggregating[TRAV with GenTraversable[E]] =
Aggregating.aggregatingNatureOfGenTraversable[E, GenTraversable]

it should "return a Conf with expected single unmapped input and output" in {
val conf = Conf.parse(Array("-o", "output", "input")).value
conf.darFiles should contain theSameElementsAs Map(Paths.get("input") -> None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class RecordSpec extends FlatSpec with Matchers {
record.getFieldsMap shouldBe empty
}

// XXX SC remove in 2.13; see notes in ConfSpec
import scala.collection.GenTraversable, org.scalatest.enablers.Aggregating
private[this] implicit def `fixed sig aggregatingNatureOfGenTraversable`[
E: org.scalactic.Equality,
TRAV]: Aggregating[TRAV with GenTraversable[E]] =
Aggregating.aggregatingNatureOfGenTraversable[E, GenTraversable]

it should "build a record with an empty field map if there are no labels" in {
val fields = List(
ValueOuterClass.RecordField
Expand Down
1 change: 1 addition & 0 deletions language-support/java/codegen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ da_scala_test(
"@maven//:com_squareup_javapoet",
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
"@maven//:org_scalatest_scalatest_2_12",
"@maven//:org_scalaz_scalaz_core_2_12",
"@maven//:org_slf4j_slf4j_api",
],
)
Expand Down
6 changes: 0 additions & 6 deletions language-support/scala/bindings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ da_scala_library(
plugins = [
"@maven//:org_spire_math_kind_projector_2_12",
],
scalacopts = [
"-Xsource:2.13",
],
tags = ["maven_coordinates=com.daml:bindings-scala:__VERSION__"],
visibility = [
"//visibility:public",
Expand All @@ -41,9 +38,6 @@ da_scala_test_suite(
plugins = [
"@maven//:org_spire_math_kind_projector_2_12",
],
scalacopts = [
"-Xsource:2.13",
],
deps = [
":bindings",
"@maven//:com_chuusai_shapeless_2_12",
Expand Down
3 changes: 0 additions & 3 deletions language-support/scala/codegen-sample-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ da_scala_library(
name = "daml-lf-codegen-sample-app-testing",
srcs = testing_utils,
resources = glob(["src/test/resources/**/*"]),
scalacopts = ["-Xsource:2.13"],
deps = [
"//bazel_tools/runfiles:scala_runfiles",
"@maven//:org_scalaz_scalaz_core_2_12",
Expand All @@ -95,7 +94,6 @@ da_scala_test(
"src/test/scala/com/digitalasset/codegen/ScalaCodeGenIT.scala",
],
),
scalacopts = ["-Xsource:2.13"],
deps = [
":daml-lf-codegen-sample-app",
"//language-support/scala/bindings",
Expand All @@ -120,7 +118,6 @@ da_scala_test(
jvm_flags = [
"-Dcom.daml.sandbox.jar=ledger/sandbox/sandbox-binary_deploy.jar",
],
scalacopts = ["-Xsource:2.13"],
deps = [
":daml-lf-codegen-sample-app",
":daml-lf-codegen-sample-app-testing",
Expand Down
2 changes: 0 additions & 2 deletions language-support/scala/codegen-testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ da_scala_library(
# Plugins have to be specified as JARs.
"@maven//:org_spire_math_kind_projector_2_12",
],
scalacopts = ["-Xsource:2.13"],
visibility = [
"//visibility:public",
],
Expand Down Expand Up @@ -71,7 +70,6 @@ da_scala_test_suite(
],
exclude = testing_utils,
),
scalacopts = ["-Xsource:2.13"],
deps = [
":codegen-testing",
":codegen-testing-testing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.daml.codegen.lf

import com.daml.codegen.lf.DamlDataTypeGen.DataType
import com.daml.codegen.lf.DamlDataTypeGen.{DataType, VariantField}
import com.daml.lf.iface
import scalaz.Monoid
import scalaz.std.list._
Expand All @@ -23,7 +23,8 @@ object UsedTypeParams {

private def foldMapGenTypes[Z: Monoid](typeDecl: DataType)(f: iface.Type => Z): Z = {
val notAGT = (s: String) => mzero[Z]
typeDecl.foldMap(_.bifoldMap(f)(_.bifoldMap(_ foldMap (_.bifoldMap(notAGT)(f)))(f)))
(typeDecl: ScopedDataType[iface.DataType[iface.Type, VariantField]])
.foldMap(_.bifoldMap(f)(_.bifoldMap(_ foldMap (_.bifoldMap(notAGT)(f)))(f)))
}

private def collectTypeParams(field: iface.Type): Set[String] = field match {
Expand Down
2 changes: 0 additions & 2 deletions language-support/scala/examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ da_scala_binary(
srcs = glob(["quickstart-scala/application/src/main/scala/**/*.scala"]),
main_class = "com.daml.quickstart.iou.IouMain",
resources = glob(["quickstart-scala/application/src/main/resources/**/*"]),
scalacopts = ["-Xsource:2.13"],
deps = [
":quickstart-scala-codegen-lib",
"//language-support/scala/bindings",
Expand All @@ -73,7 +72,6 @@ da_scala_binary(
srcs = glob(["iou-no-codegen/application/src/main/scala/**/*.scala"]),
main_class = "com.daml.quickstart.iou.IouMain",
resources = glob(["iou-no-codegen/application/src/main/resources/**/*"]),
scalacopts = ["-Xsource:2.13"],
deps = [
"//language-support/scala/bindings",
"//language-support/scala/bindings-akka",
Expand Down
1 change: 0 additions & 1 deletion ledger-service/db-backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ da_scala_library(
"@maven//:com_github_ghik_silencer_plugin_2_12_11",
],
scalacopts = [
"-Xsource:2.13",
"-P:silencer:checkUnused",
] + lf_scalacopts,
tags = ["maven_coordinates=com.daml:http-json-db-backend:__VERSION__"],
Expand Down
2 changes: 0 additions & 2 deletions ledger-service/http-json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ load("//rules_daml:daml.bzl", "daml_compile")

hj_scalacopts = [
"-P:wartremover:traverser:org.wartremover.warts.NonUnitStatements",
"-Ypartial-unification",
"-Xsource:2.13",
]

da_scala_library(
Expand Down
8 changes: 0 additions & 8 deletions ledger-service/jwt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ load(
"da_scala_test",
)

hj_scalacopts = [
"-Ypartial-unification",
"-Xsource:2.13",
]

da_scala_library(
name = "jwt",
srcs = glob(["src/main/scala/**/*.scala"]),
scalacopts = hj_scalacopts,
tags = ["maven_coordinates=com.daml:jwt:__VERSION__"],
visibility = ["//visibility:public"],
runtime_deps = [
Expand All @@ -38,7 +32,6 @@ da_scala_binary(
name = "jwt-bin",
srcs = glob(["src/main/scala/**/*.scala"]),
main_class = "com.daml.jwt.Main",
scalacopts = hj_scalacopts,
runtime_deps = [
":jwt",
"@maven//:ch_qos_logback_logback_classic",
Expand All @@ -60,7 +53,6 @@ da_scala_test(
size = "medium",
srcs = glob(["src/test/scala/**/*.scala"]),
resources = glob(["src/test/resources/**/*"]),
scalacopts = hj_scalacopts,
deps = [
":jwt",
"@maven//:com_auth0_java_jwt",
Expand Down
1 change: 0 additions & 1 deletion ledger-service/lf-value-json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ load(
da_scala_library(
name = "lf-value-json",
srcs = glob(["src/main/scala/**/*.scala"]),
scalacopts = ["-Xsource:2.13"],
tags = ["maven_coordinates=com.daml:lf-value-json:__VERSION__"],
visibility = [
"//visibility:public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class CommandTrackerFlowTest

}

// XXX SC remove in Scala 2.13; see notes in ConfSpec
import scala.collection.GenTraversable, org.scalatest.enablers.Containing
private[this] implicit def `fixed sig containingNatureOfGenTraversable`[
E: org.scalactic.Equality,
TRAV]: Containing[TRAV with GenTraversable[E]] =
Containing.containingNatureOfGenTraversable[E, GenTraversable]

"Command tracking flow" when {

"two commands are submitted with the same ID" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import org.scalatest.mockito.MockitoSugar
import org.scalatest.{Matchers, WordSpec}

class FileBasedLedgerDataExportSpec extends WordSpec with Matchers with MockitoSugar {
// XXX SC remove in Scala 2.13; see notes in ConfSpec
import scala.collection.GenTraversable, org.scalatest.enablers.Containing
private[this] implicit def `fixed sig containingNatureOfGenTraversable`[
E: org.scalactic.Equality,
TRAV]: Containing[TRAV with GenTraversable[E]] =
Containing.containingNatureOfGenTraversable[E, GenTraversable]

"addParentChild" should {
"add entry to correlation ID mapping" in {
val instance = new FileBasedLedgerDataExporter(mock[DataOutputStream])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import anorm.{BatchSql, NamedParameter}
import com.daml.lf.data.Ref
import com.daml.lf.transaction.Node.GlobalKey
import com.daml.lf.value.Value.ContractId
import com.daml.platform.store.Conversions._
import com.daml.platform.store.serialization.{KeyHasher, ValueSerializer}
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}

Expand Down
2 changes: 1 addition & 1 deletion libs-scala/scalatest-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ da_scala_test(
name = "test",
size = "small",
srcs = glob(["src/test/**/*.scala"]),
scalacopts = lf_scalacopts + ["-Ypartial-unification"],
scalacopts = lf_scalacopts,
deps = [
":scalatest-utils",
"@maven//:org_scalaz_scalaz_core_2_12",
Expand Down
Loading

0 comments on commit a51d0db

Please sign in to comment.