-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Force consistent MT post-redux normalisation, disallow infinite match types #18073
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9726e1a
Force MT reduction simplification, disallow infinite match types
dwijnand 1e19250
Remove use of simplified in MT reduction
dwijnand 326feb1
Fix handling of Nothing in OrType atoms
dwijnand 8aec1d1
Revert back to simplified, rather than normalizeHard
dwijnand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// like mt-recur.scala, but covariant | ||
class Cov[+T] | ||
|
||
type Recur[X] = X match | ||
case Int => Cov[Recur[X]] | ||
|
||
def x = ??? : Recur[Int] // error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// an example of an infinite recursion match type | ||
// using an _invariant_ type constructor | ||
// see mt-recur.cov.scala for covariant | ||
// used to track the behaviour of match type reduction | ||
class Inv[T] | ||
|
||
type Recur[X] = X match | ||
case Int => Inv[Recur[X]] | ||
|
||
def x = ??? : Recur[Int] // error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import scala.compiletime.ops.int.* | ||
|
||
object NatExample { | ||
sealed trait Nat | ||
object Nat { | ||
case object Zero extends Nat | ||
case class Succ[N <: Nat](prev: N) extends Nat | ||
|
||
given zero: Zero.type = Zero | ||
given buildSucc[N <: Nat](using n: N): Succ[N] = Succ(n) | ||
|
||
def value[N <: Nat](using n: N): N = n | ||
|
||
type FromInt[I <: Int] <: Nat = I match | ||
case 0 => Zero.type | ||
case _ => Succ[FromInt[I - 1]] | ||
|
||
summon[FromInt[0] =:= Zero.type] | ||
summon[FromInt[1] =:= Succ[Zero.type]] | ||
summon[FromInt[2] =:= Succ[Succ[Zero.type]]] | ||
summon[FromInt[3] =:= Succ[Succ[Succ[Zero.type]]]] | ||
summon[FromInt[4] =:= Succ[Succ[Succ[Succ[Zero.type]]]]] | ||
|
||
@main def test = { | ||
require(summon[FromInt[0]] == Zero) | ||
require(summon[FromInt[1]] == Succ(Zero)) | ||
require(summon[FromInt[2]] == Succ(Succ(Zero))) | ||
require(summon[FromInt[3]] == Succ(Succ(Succ(Zero)))) | ||
// we can summon 4 if we write it out: | ||
require(summon[Succ[Succ[Succ[Succ[Zero.type]]]]] == Succ(Succ(Succ(Succ(Zero))))) | ||
// was: we cannot summon 4 using the match type | ||
require(summon[FromInt[4]] == Succ(Succ(Succ(Succ(Zero))))) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import scala.compiletime.ops.int | ||
|
||
type Count0[N,T] <: Tuple = (N,T) match | ||
case (0,_) => EmptyTuple | ||
case (N,String) => String *: Count0[int.-[N, 1], String] | ||
case (N,Int) => Int *: Count0[int.-[N, 1], Int] | ||
case (N,Float) => Float *: Count0[int.-[N, 1], Float] | ||
case (N,Double) => Double *: Count0[int.-[N, 1], Double] | ||
|
||
|
||
type Count1[N,T] <: Tuple = (N,T) match | ||
case (0,T) => EmptyTuple | ||
case (N,String) => String *: Count1[int.-[N, 1], String] | ||
case (N,Int) => Int *: Count1[int.-[N, 1], Int] | ||
case (N,Float) => Float *: Count1[int.-[N, 1], Float] | ||
case (N,Double) => Double *: Count1[int.-[N, 1], Double] | ||
|
||
def t01 = summon[Count0[1, Int] =:= Int *: EmptyTuple ] | ||
def t02 = summon[Count0[2, Int] =:= Int *: Int *: EmptyTuple] | ||
def t03 = summon[Count0[3, Int] =:= Int *: Int *: Int *: EmptyTuple] | ||
def t04 = summon[Count0[4, Int] =:= Int *: Int *: Int *: Int *: EmptyTuple] | ||
def t05 = summon[Count0[5, Int] =:= Int *: Int *: Int *: Int *: Int *: EmptyTuple] | ||
|
||
def t11 = summon[Count1[1, Int] =:= Int *: EmptyTuple ] | ||
def t12 = summon[Count1[2, Int] =:= Int *: Int *: EmptyTuple] | ||
def t13 = summon[Count1[3, Int] =:= Int *: Int *: Int *: EmptyTuple] // was: Fail from here | ||
def t14 = summon[Count1[4, Int] =:= Int *: Int *: Int *: Int *: EmptyTuple] | ||
def t15 = summon[Count1[5, Int] =:= Int *: Int *: Int *: Int *: Int *: EmptyTuple] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scala.compiletime.ops.int, int.- | ||
|
||
type Count[N, T] <: Tuple = (N, T) match | ||
case (0, T) => EmptyTuple | ||
case (N, T) => T *: Count[N - 1, T] | ||
|
||
val a: Count[3, Int] = (1, 2, 3) | ||
val b: Count[4, Int] = (1, 2, 3, 4) | ||
val c: Count[5, Int] = (1, 2, 3, 4, 5) | ||
val d: Count[6, Int] = (1, 2, 3, 4, 5, 6) | ||
val z: Count[23, Int] = ( | ||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | ||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | ||
21, 22, 23) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// scalac: -Yno-deep-subtypes:false | ||
// Minimisation of tests/run-macros/i17257 | ||
// to understand how changes to match type reduction | ||
// impacted this use of Tuple.IsMappedBy. | ||
// | ||
// During match type reduction | ||
// if we do NOT simplify the case lambda parameter instances | ||
// then this large tuple make TypeComparer breach LogPendingSubTypesThreshold | ||
// which, under -Yno-deep-subtypes, crashes the compilation. | ||
class C[+A] | ||
def foo[T <: Tuple : Tuple.IsMappedBy[C]] = ??? | ||
def bar[X] = foo[( | ||
C[X], C[X], C[X], C[X], C[X], C[X], C[X], C[X], C[X], C[X], | ||
C[X], C[X], C[X], C[X], C[X], C[X], C[X], C[X], C[X], C[X], | ||
C[X], C[X], C[X], | ||
)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// while making MT post-redux consistent in its normalisation/simplification | ||
// one version of the change broke a line of the perspective community project in CI | ||
// this is a minimisation of the failure | ||
|
||
import scala.compiletime._, scala.deriving._ | ||
|
||
transparent inline def foo(using m: Mirror): Unit = | ||
constValueTuple[m.MirroredElemLabels].toList.toSet // was: | ||
//-- [E057] Type Mismatch Error: cat.scala:8:14 ---------------------------------- | ||
//8 |def test = foo(using summon[Mirror.Of[Cat]]) | ||
// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// |Type argument ("name" : String) | Nothing does not conform to lower bound m$proxy1.MirroredElemLabels match { | ||
// | case EmptyTuple => Nothing | ||
// | case h *: t => h | Tuple.Fold[t, Nothing, [x, y] =>> x | y] | ||
// |} | ||
// |----------------------------------------------------------------------------- | ||
// |Inline stack trace | ||
// |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// |This location contains code that was inlined from cat.scala:4 | ||
//4 | constValueTuple[m.MirroredElemLabels].toList.toSet | ||
// | ^ | ||
|
||
case class Cat(name: String) | ||
|
||
def test = foo(using summon[Mirror.Of[Cat]]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.