From a1182963a810b019a7b7897d3b066f9b9fac76fb Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Sat, 15 Mar 2025 22:01:00 +0100 Subject: [PATCH 1/3] Deprecate `-Yno-kind-polymorphism` --- compiler/src/dotty/tools/dotc/config/ScalaSettings.scala | 1 + compiler/src/dotty/tools/dotc/core/Definitions.scala | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index d2d716769990..e5c9ba73e2a7 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -443,6 +443,7 @@ private sealed trait YSettings: val YwithBestEffortTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Ywith-best-effort-tasty", "Allow to compile using best-effort tasty files. If such file is used, the compiler will stop after the pickler phase.") // Experimental language features + @deprecated(message = "Scheduled for removal.", since = "3.7.0") val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism.") val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.") val YnoFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-flexible-types", "Disable turning nullable Java return types and parameter types into flexible types, which behave like abstract types with a nullable lower bound and non-nullable upper bound.") diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index cf2795648484..c1939d6f8fa6 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -449,10 +449,7 @@ class Definitions { @tu lazy val AnyKindClass: ClassSymbol = { val cls = newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil, newScope(0)) - if (!ctx.settings.YnoKindPolymorphism.value) - // Enable kind-polymorphism by exposing scala.AnyKind - cls.entered - cls + cls.entered } def AnyKindType: TypeRef = AnyKindClass.typeRef From 05fb82a606f63e20ee0455e8b99f5fbb7b55411e Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Sat, 15 Mar 2025 22:01:17 +0100 Subject: [PATCH 2/3] update doc --- docs/_docs/reference/other-new-features/kind-polymorphism.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/_docs/reference/other-new-features/kind-polymorphism.md b/docs/_docs/reference/other-new-features/kind-polymorphism.md index e452ee8384f9..1cba78a42302 100644 --- a/docs/_docs/reference/other-new-features/kind-polymorphism.md +++ b/docs/_docs/reference/other-new-features/kind-polymorphism.md @@ -43,5 +43,4 @@ It is declared `abstract` and `final`, so it can be neither instantiated nor ext `AnyKind` plays a special role in Scala's subtype system: It is a supertype of all other types no matter what their kind is. It is also assumed to be kind-compatible with all other types. Furthermore, `AnyKind` is treated as a higher-kinded type (so it cannot be used as a type of values), but at the same time it has no type parameters (so it cannot be instantiated). -**Note:** This feature is considered experimental but stable and it can be disabled under compiler flag -(i.e. `-Yno-kind-polymorphism`). +**Note:** This feature is now stable. The compiler flag `-Yno-kind-polymorphism` that used to disable it will be deprecated from 3.7.0. From f36cc315a2a8abc48e01f142b2b01a89668ef1a1 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Mon, 17 Mar 2025 21:47:25 +0100 Subject: [PATCH 3/3] add message for deprecating -Yno-kind-polymorphism and update the doc --- compiler/src/dotty/tools/dotc/config/ScalaSettings.scala | 4 ++-- docs/_docs/reference/other-new-features/kind-polymorphism.md | 2 +- tests/neg/no-kind-polymorphism-anykind.scala | 3 --- tests/pos/deprecated-no-kind-polymorphism-anykind.scala | 5 +++++ 4 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 tests/neg/no-kind-polymorphism-anykind.scala create mode 100644 tests/pos/deprecated-no-kind-polymorphism-anykind.scala diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index e5c9ba73e2a7..99dd80a26cae 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -443,8 +443,8 @@ private sealed trait YSettings: val YwithBestEffortTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Ywith-best-effort-tasty", "Allow to compile using best-effort tasty files. If such file is used, the compiler will stop after the pickler phase.") // Experimental language features - @deprecated(message = "Scheduled for removal.", since = "3.7.0") - val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism.") + @deprecated(message = "This flag has no effect and will be removed in a future version.", since = "3.7.0") + val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism. (This flag has no effect)", deprecation = Deprecation.removed()) val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.") val YnoFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-flexible-types", "Disable turning nullable Java return types and parameter types into flexible types, which behave like abstract types with a nullable lower bound and non-nullable upper bound.") val YcheckInitGlobal: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init-global", "Check safe initialization of global objects.") diff --git a/docs/_docs/reference/other-new-features/kind-polymorphism.md b/docs/_docs/reference/other-new-features/kind-polymorphism.md index 1cba78a42302..4bb1e659dfe9 100644 --- a/docs/_docs/reference/other-new-features/kind-polymorphism.md +++ b/docs/_docs/reference/other-new-features/kind-polymorphism.md @@ -43,4 +43,4 @@ It is declared `abstract` and `final`, so it can be neither instantiated nor ext `AnyKind` plays a special role in Scala's subtype system: It is a supertype of all other types no matter what their kind is. It is also assumed to be kind-compatible with all other types. Furthermore, `AnyKind` is treated as a higher-kinded type (so it cannot be used as a type of values), but at the same time it has no type parameters (so it cannot be instantiated). -**Note:** This feature is now stable. The compiler flag `-Yno-kind-polymorphism` that used to disable it will be deprecated from 3.7.0. +**Note:** This feature is now stable. The compiler flag `-Yno-kind-polymorphism` is deprecated as of 3.7.0, has no effect (is ignored), and will be removed in a future version. diff --git a/tests/neg/no-kind-polymorphism-anykind.scala b/tests/neg/no-kind-polymorphism-anykind.scala deleted file mode 100644 index b14491468d00..000000000000 --- a/tests/neg/no-kind-polymorphism-anykind.scala +++ /dev/null @@ -1,3 +0,0 @@ -//> using options -Yno-kind-polymorphism - -trait Foo[T <: AnyKind] // error: Not found: type AnyKind diff --git a/tests/pos/deprecated-no-kind-polymorphism-anykind.scala b/tests/pos/deprecated-no-kind-polymorphism-anykind.scala new file mode 100644 index 000000000000..1697acaca6f9 --- /dev/null +++ b/tests/pos/deprecated-no-kind-polymorphism-anykind.scala @@ -0,0 +1,5 @@ +// This test is kept as a placeholder for historical reasons. +// The -Yno-kind-polymorphism flag is now deprecated and has no effect. +// Kind polymorphism with AnyKind is always enabled. + +trait Foo[T <: AnyKind] // This now works as AnyKind is always defined