Skip to content

Commit

Permalink
Merge pull request scala#6309 from milessabin/topic/unconditional-par…
Browse files Browse the repository at this point in the history
…tial-unification

Partial unification unconditional; deprecate -Xexperimental
  • Loading branch information
adriaanm committed Apr 6, 2018
2 parents 106290b + 7d5e0b0 commit ced7076
Show file tree
Hide file tree
Showing 71 changed files with 76 additions and 87 deletions.
2 changes: 1 addition & 1 deletion project/ScalaOptionParser.scala
Expand Up @@ -88,7 +88,7 @@ object ScalaOptionParser {
"-Yide-debug", "-Yinfer-argument-types",
"-Yissue-debug", "-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand",
"-Yno-completion", "-Yno-generic-signatures", "-Yno-imports", "-Yno-predef",
"-Yoverride-objects", "-Yoverride-vars", "-Ypatmat-debug", "-Yno-adapted-args", "-Ypartial-unification", "-Ypos-debug", "-Ypresentation-debug",
"-Yoverride-objects", "-Yoverride-vars", "-Ypatmat-debug", "-Yno-adapted-args", "-Ypos-debug", "-Ypresentation-debug",
"-Ypresentation-strict", "-Ypresentation-verbose", "-Yquasiquote-debug", "-Yrangepos", "-Yreify-copypaste", "-Yreify-debug", "-Yrepl-class-based",
"-Yrepl-sync", "-Yshow-member-pos", "-Yshow-symkinds", "-Yshow-symowners", "-Yshow-syms", "-Yshow-trees", "-Yshow-trees-compact", "-Yshow-trees-stringified", "-Ytyper-debug",
"-Ywarn-adapted-args", "-Ywarn-dead-code", "-Ywarn-inaccessible", "-Ywarn-infer-any", "-Ywarn-nullary-override", "-Ywarn-nullary-unit", "-Ywarn-numeric-widen", "-Ywarn-unused-import", "-Ywarn-value-discard",
Expand Down
7 changes: 2 additions & 5 deletions src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Expand Up @@ -30,9 +30,6 @@ trait ScalaSettings extends AbsScalaSettings
*/
protected def defaultClasspath = Option(System.getenv("CLASSPATH")).getOrElse(".")

/** Enabled under -Xexperimental. */
protected def experimentalSettings = List[BooleanSetting](YpartialUnification)

/** Enabled under -Xfuture. */
protected def futureSettings = List[BooleanSetting]()

Expand Down Expand Up @@ -233,7 +230,6 @@ trait ScalaSettings extends AbsScalaSettings
val YdisableFlatCpCaching = BooleanSetting ("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.")
val YcachePluginClassLoader = CachePolicy.setting("plugin", "compiler plugins")
val YcacheMacroClassLoader = CachePolicy.setting("macro", "macros")
val YpartialUnification = BooleanSetting ("-Ypartial-unification", "Enable partial unification in type constructor inference")
val Yvirtpatmat = BooleanSetting ("-Yvirtpatmat", "Enable pattern matcher virtualization")

val exposeEmptyPackage = BooleanSetting ("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly()
Expand Down Expand Up @@ -441,7 +437,8 @@ trait ScalaSettings extends AbsScalaSettings
opt.enable(optChoices.lInline)
optInlineFrom.value = List("**")
})
val Xexperimental = BooleanSetting("-Xexperimental", "Enable experimental extensions.") enablingIfNotSetByUser experimentalSettings
val Xexperimental = BooleanSetting("-Xexperimental", "Enable experimental extensions in Scala 2.12 and earlier.")
.withDeprecationMessage(s"In 2.13 all options previously enabled by -Xexperimental are enabled by default or removed.")

// Feature extensions
val XmacroSettings = MultiStringSetting("-Xmacro-settings", "option", "Custom settings for macros.")
Expand Down
Expand Up @@ -223,7 +223,7 @@ trait MatchTranslation {
// val packedPt = repeatedToSeq(typer.packedType(match_, context.owner))
val selectorSym = freshSym(selector.pos, pureType(selectorTp)) setFlag treeInfo.SYNTH_CASE_FLAGS

// pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala with -Xexperimental
// pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala
val combined = combineCases(selector, selectorSym, nonSyntheticCases map translateCase(selectorSym, pt), pt, matchOwner, defaultOverride)

if (StatisticsStatics.areSomeColdStatsEnabled) statistics.stopTimer(statistics.patmatNanos, start)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -2966,7 +2966,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
*
* Based on the expected type pt, potentially synthesize an instance of
* - PartialFunction,
* - a type with a Single Abstract Method (under -Xexperimental for now).
* - a type with a Single Abstract Method.
*/
private def typedFunction(fun: Function, mode: Mode, pt: Type): Tree = {
val vparams = fun.vparams
Expand Down
3 changes: 0 additions & 3 deletions src/manual/scala/man1/scalac.scala
Expand Up @@ -199,9 +199,6 @@ object scalac extends Command {
CmdOption("Xelide-below", Argument("n")),
"Calls to " & MItalic("@elidable") &
" methods are omitted if method priority is lower than argument."),
Definition(
CmdOption("Xexperimental"),
"Enable experimental extensions"),
Definition(
CmdOption("Xfatal-warnings"),
"Fail the compilation if there are any warnings."),
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Definitions.scala
Expand Up @@ -839,7 +839,7 @@ trait Definitions extends api.StandardDefinitions {
(sym eq PartialFunctionClass) || (sym eq AbstractPartialFunctionClass)
}

private[this] val doSam = settings.isScala212 || (settings.isScala211 && settings.Xexperimental)
private[this] val doSam = settings.isScala212

/** The single abstract method declared by type `tp` (or `NoSymbol` if it cannot be found).
*
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -3333,7 +3333,7 @@ trait Types
// This is a higher-kinded type var with same arity as tp.
// If so (see scala/bug#7517), side effect: adds the type constructor itself as a bound.
isSubArgs(lhs, rhs, params, AnyDepth) && {addBound(tp.typeConstructor); true}
} else if (settings.YpartialUnification && numCaptured > 0) {
} else if (settings.isScala213 && numCaptured > 0) {
// Simple algorithm as suggested by Paul Chiusano in the comments on scala/bug#2712
//
// https://github.com/scala/bug/issues/2712#issuecomment-292374655
Expand Down
Expand Up @@ -36,7 +36,6 @@ abstract class MutableSettings extends AbsSettings {
def valueSetByUser: Option[T] = if (isSetByUser) Some(value) else None
}

def Xexperimental: BooleanSetting
def XfullLubs: BooleanSetting
def XnoPatmatAnalysis: BooleanSetting
def Xprintpos: BooleanSetting
Expand All @@ -53,7 +52,6 @@ abstract class MutableSettings extends AbsSettings {
def printtypes: BooleanSetting
def uniqid: BooleanSetting
def verbose: BooleanSetting
def YpartialUnification: BooleanSetting
def Yvirtpatmat: BooleanSetting

// Define them returning a `Boolean` to avoid breaking bincompat change
Expand Down
2 changes: 0 additions & 2 deletions src/reflect/scala/reflect/runtime/Settings.scala
Expand Up @@ -30,7 +30,6 @@ private[reflect] class Settings extends MutableSettings {
override def value: List[String] = v
}

val Xexperimental = new BooleanSetting(false)
val XfullLubs = new BooleanSetting(false)
val XnoPatmatAnalysis = new BooleanSetting(false)
val strictInference = new BooleanSetting(false)
Expand All @@ -47,7 +46,6 @@ private[reflect] class Settings extends MutableSettings {
val printtypes = new BooleanSetting(false)
val uniqid = new BooleanSetting(false)
val verbose = new BooleanSetting(false)
val YpartialUnification = new BooleanSetting(false)
val Yvirtpatmat = new BooleanSetting(false)

val Yrecursion = new IntSetting(0)
Expand Down
6 changes: 6 additions & 0 deletions test/files/neg/deprecated-experimental.check
@@ -0,0 +1,6 @@
warning: -Xexperimental is deprecated: In 2.13 all options previously enabled by -Xexperimental are enabled by default or removed.
deprecated-experimental.scala:1: error: expected class or object definition
wibble
^
one warning found
one error found
1 change: 1 addition & 0 deletions test/files/neg/deprecated-experimental.flags
@@ -0,0 +1 @@
-deprecation -Xexperimental
1 change: 1 addition & 0 deletions test/files/neg/deprecated-experimental.scala
@@ -0,0 +1 @@
wibble
2 changes: 1 addition & 1 deletion test/files/neg/names-defaults-neg-pu.flags
@@ -1 +1 @@
-deprecation -Ypartial-unification
-deprecation
2 changes: 1 addition & 1 deletion test/files/neg/sealed-java-enums.flags
@@ -1 +1 @@
-Xexperimental -Xfatal-warnings
-Xfatal-warnings
4 changes: 2 additions & 2 deletions test/files/neg/t2712-1.check
Expand Up @@ -3,11 +3,11 @@ t2712-1.scala:7: error: no type parameters for method foo: (m: M[A])Unit exist s
argument expression's type is not compatible with formal parameter type;
found : test.Two[Int,String]
required: ?M[?A]
def test(ma: Two[Int, String]) = foo(ma) // should fail with -Ypartial-unification *disabled*
def test(ma: Two[Int, String]) = foo(ma) // should fail with -Xsource:2.12
^
t2712-1.scala:7: error: type mismatch;
found : test.Two[Int,String]
required: M[A]
def test(ma: Two[Int, String]) = foo(ma) // should fail with -Ypartial-unification *disabled*
def test(ma: Two[Int, String]) = foo(ma) // should fail with -Xsource:2.12
^
two errors found
1 change: 1 addition & 0 deletions test/files/neg/t2712-1.flags
@@ -0,0 +1 @@
-Xsource:2.12
2 changes: 1 addition & 1 deletion test/files/neg/t2712-1.scala
Expand Up @@ -4,5 +4,5 @@ trait Two[A, B]

object Test {
def foo[M[_], A](m: M[A]) = ()
def test(ma: Two[Int, String]) = foo(ma) // should fail with -Ypartial-unification *disabled*
def test(ma: Two[Int, String]) = foo(ma) // should fail with -Xsource:2.12
}
4 changes: 2 additions & 2 deletions test/files/neg/t2712-2.check
Expand Up @@ -3,11 +3,11 @@ t2712-2.scala:16: error: type mismatch;
required: test.Two[test.X1,Object]
Note: test.X2 <: Object (and test.Foo <: test.Two[test.X1,test.X2]), but trait Two is invariant in type B.
You may wish to define B as +B instead. (SLS 4.5)
test1(foo): One[X3] // fails with -Ypartial-unification enabled
test1(foo): One[X3] // fails without -Xsource:2.12
^
t2712-2.scala:16: error: type mismatch;
found : test.Two[test.X1,Object]
required: test.One[test.X3]
test1(foo): One[X3] // fails with -Ypartial-unification enabled
test1(foo): One[X3] // fails without -Xsource:2.12
^
two errors found
1 change: 0 additions & 1 deletion test/files/neg/t2712-2.flags

This file was deleted.

4 changes: 2 additions & 2 deletions test/files/neg/t2712-2.scala
Expand Up @@ -13,6 +13,6 @@ object Test {

val foo = new Foo

test1(foo): One[X3] // fails with -Ypartial-unification enabled
test1(foo): Two[X1, X2] // fails without -Ypartial-unification
test1(foo): One[X3] // fails without -Xsource:2.12
test1(foo): Two[X1, X2] // fails with -Xsource:2.12
}
2 changes: 1 addition & 1 deletion test/files/neg/t2712-3.check
@@ -1,6 +1,6 @@
t2712-3.scala:17: error: type mismatch;
found : test.One[test.X3]
required: test.Two[test.X1,test.X2]
test1(foo): Two[X1, X2] // fails without -Ypartial-unification
test1(foo): Two[X1, X2] // fails with -Xsource:2.12
^
one error found
1 change: 1 addition & 0 deletions test/files/neg/t2712-3.flags
@@ -0,0 +1 @@
-Xsource:2.12
4 changes: 2 additions & 2 deletions test/files/neg/t2712-3.scala
Expand Up @@ -13,6 +13,6 @@ object Test {

val foo = new Foo

test1(foo): One[X3] // fails with -Ypartial-unification enabled
test1(foo): Two[X1, X2] // fails without -Ypartial-unification
test1(foo): One[X3] // fails without -Xsource:2.12
test1(foo): Two[X1, X2] // fails with -Xsource:2.12
}
1 change: 0 additions & 1 deletion test/files/neg/t2712-8.flags

This file was deleted.

1 change: 1 addition & 0 deletions test/files/neg/t5683.flags
@@ -0,0 +1 @@
-Xsource:2.12
13 changes: 13 additions & 0 deletions test/files/neg/t8237-default-212.check
@@ -0,0 +1,13 @@
t8237-default-212.scala:5: error: no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])Nothing exist so that it can be applied to arguments (List[Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[Int]
required: ?T[?T[List[?T[X forSome { type X }]]]]
test4(test4$default$1)
^
t8237-default-212.scala:5: error: type mismatch;
found : List[Int]
required: T[T[List[T[X forSome { type X }]]]]
test4(test4$default$1)
^
two errors found
1 change: 1 addition & 0 deletions test/files/neg/t8237-default-212.flags
@@ -0,0 +1 @@
-Xsource:2.12
29 changes: 29 additions & 0 deletions test/files/neg/t8237-default-212.scala
@@ -0,0 +1,29 @@
// This test case was extracted from `names-defaults-neg.scala`
// It pinpoints an improvement an error message that results from
// a type inference failure
object Test extends App {
test4(test4$default$1)

def test4[T[P]](x: T[T[List[T[X forSome { type X }]]]]) = ???
def test4$default$1[T[P]]: List[Int] = ???
}

/*
OLD:
no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])Nothing exist so that it can be applied to arguments (List[Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[Int]
required: ?T
test4(test4$default$1)
^
NEW:
no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])Nothing exist so that it can be applied to arguments (List[Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : List[Int]
required: ?T[?T[List[?T[X forSome { type X }]]]
test4(test4$default$1)
*/
1 change: 0 additions & 1 deletion test/files/neg/t8237-default-pu.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/infersingle.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/t2712-1.flags

This file was deleted.

2 changes: 0 additions & 2 deletions test/files/pos/t2712-2.flags

This file was deleted.

2 changes: 0 additions & 2 deletions test/files/pos/t2712-3.flags

This file was deleted.

2 changes: 0 additions & 2 deletions test/files/pos/t2712-4.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/t2712-5.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/t2712-6.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/t2712-7.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/t5683.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/t9178b.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_alts_subst.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_binding_opt.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_castbinder.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_exist1.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_exist2.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_exist3.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_gadt_array.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_infer_single_1.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_instof_valuetype.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/pos/virtpatmat_obj_in_case.flags

This file was deleted.

2 changes: 1 addition & 1 deletion test/files/run/checked.scala
@@ -1,4 +1,4 @@
/* Test checked initializers. Needs to be run with -Xexperimental and -checkinit
/* Test checked initializers. Needs to be run with -checkinit
*/

// 0 inherited fields
Expand Down
1 change: 0 additions & 1 deletion test/files/run/constrained-types.scala
Expand Up @@ -75,7 +75,6 @@ val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message
"""

override def transformSettings(s: Settings): Settings = {
s.Xexperimental.value = true
s.deprecation.value = true
// when running that compiler, give it a scala-library to the classpath
s.classpath.value = sys.props("java.class.path")
Expand Down
1 change: 0 additions & 1 deletion test/files/run/inferred-type-constructors-hou.flags

This file was deleted.

1 change: 1 addition & 0 deletions test/files/run/inferred-type-constructors.check
Expand Up @@ -47,6 +47,7 @@ warning: there were two feature warnings; re-run with -feature for details
List[Nothing]
scala.collection.immutable.Vector[Nothing]
scala.collection.immutable.Iterable[(Int, Int)]
scala.collection.immutable.Map[Int,Int]
scala.collection.immutable.Set[Int]
Seq[Int]
Array[Int]
Expand Down
1 change: 1 addition & 0 deletions test/files/run/inferred-type-constructors.scala
Expand Up @@ -113,6 +113,7 @@ object Test {

whatis(extract(Nil))
whatis(extract(Vector()))
whatis(extract(scala.collection.immutable.Iterable[(Int, Int)]()))
whatis(extract(Map[Int,Int]()))
whatis(extract(Set[Int]()))
whatis(extract(Seq[Int]()))
Expand Down
2 changes: 0 additions & 2 deletions test/files/run/sammy_java8.scala
Expand Up @@ -5,8 +5,6 @@ object Test extends CompilerTest {
import global._

override lazy val units: List[CompilationUnit] = {
global.settings.Xexperimental.value = true

// This test itself does not depend on JDK8.
javaCompilationUnits(global)(samSource) ++
compilationUnits(global)(useSamSource)
Expand Down
1 change: 0 additions & 1 deletion test/files/run/t9178a.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/t9489.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_apply.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_casting.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_literal.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_npe.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_partial.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_stringinterp.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_switch.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_tailcalls_verifyerror.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_try.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_typed.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_unapply.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_unapplyprod.flags

This file was deleted.

1 change: 0 additions & 1 deletion test/files/run/virtpatmat_unapplyseq.flags

This file was deleted.

12 changes: 0 additions & 12 deletions test/junit/scala/tools/nsc/settings/SettingsTest.scala
Expand Up @@ -26,18 +26,6 @@ class SettingsTest {
assertThrows[IllegalArgumentException](check("-Ytest-setting:rubbish"))
}

@Test def userSettingsHavePrecedenceOverExperimental() {
def check(args: String*): MutableSettings#BooleanSetting = {
val s = new MutableSettings(msg => throw new IllegalArgumentException(msg))
val (ok, residual) = s.processArguments(args.toList, processAll = true)
assert(residual.isEmpty)
s.YpartialUnification // among -Xexperimental
}
assertTrue(check("-Xexperimental").value)
assertFalse(check("-Xexperimental", "-Ypartial-unification:false").value)
assertFalse(check("-Ypartial-unification:false", "-Xexperimental").value)
}

// for the given args, select the desired setting
private def check(args: String*)(b: MutableSettings => Boolean): Boolean = {
val s = new MutableSettings(msg => throw new IllegalArgumentException(msg))
Expand Down

0 comments on commit ced7076

Please sign in to comment.