-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Is there/can there be a tailcall optimisation for match types? #23130
Unanswered
bishabosha
asked this question in
Compiler internals Q&A
-
step 1. copy to clipboard a 200 elem tuple.
scala -e 'println((1 to 200).mkString("(", ",", ")"))' | pbcopy
start repl with a small stack size
$ scala -J -Xss512k scala>val tup = <paste> scala>summon[Tuple.Last[tup.type] =:= Int] -- Error: ---------------------------------------------------------------------- 1 |summon[Tuple.Last[tup.type] =:= Int] | ^ |Recursion limit exceeded. |Maybe there is an illegal cyclic reference? |If that's not the case, you could also try to increase the stacksize using the -Xss JVM option. |For the unprocessed stack trace, compile with -Xno-enrich-error-messages. |A recurring operation is (inner to outer): | | reduce type (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | Int, Int, Int, Int, Int, Int) match ...
surely Tuple.Last
shouldn't blow the stack because internally its representation as a match type can be turned into a loop?
object Tuple { ... /** Type of the last element of a tuple */ type Last[X <: Tuple] = X match { case x *: EmptyTuple => x case _ *: xs => Last[xs] }
as it is unfortunately most of the tuple match types are not written in a tail recursive way if this optimisation was ever brought to production, are they frozen for compatibility or only the bound matters?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment