1
- package dotty .tools .dotc
1
+ package dotty .tools
2
+ package dotc
2
3
package transform
3
4
4
- import core .*
5
+ import ast .tpd
6
+ import core .* , Contexts .* , Decorators .* , Symbols .* , Flags .* , StdNames .*
7
+ import reporting .trace
5
8
import MegaPhase .*
6
- import Contexts .*
7
- import Symbols .*
8
- import Flags .*
9
- import StdNames .*
10
- import dotty .tools .dotc .ast .tpd
11
-
12
-
13
9
14
10
/** This phase rewrites calls to `Array.apply` to a direct instantiation of the array in the bytecode.
15
11
*
@@ -22,37 +18,30 @@ class ArrayApply extends MiniPhase {
22
18
23
19
override def description : String = ArrayApply .description
24
20
25
- private var transformListApplyLimit = 8
26
-
27
- private def reducingTransformListApply [A ](depth : Int )(body : => A ): A = {
28
- val saved = transformListApplyLimit
29
- transformListApplyLimit -= depth
30
- try body
31
- finally transformListApplyLimit = saved
32
- }
21
+ private val transformListApplyLimit = 8
33
22
34
- override def transformApply (tree : tpd. Apply )(using Context ): tpd. Tree =
23
+ override def transformApply (tree : Apply )(using Context ): Tree =
35
24
if isArrayModuleApply(tree.symbol) then
36
25
tree.args match
37
- case StripAscription (Apply (wrapRefArrayMeth, (seqLit : tpd. JavaSeqLiteral ) :: Nil )) :: ct :: Nil
26
+ case StripAscription (Apply (wrapRefArrayMeth, (seqLit : JavaSeqLiteral ) :: Nil )) :: ct :: Nil
38
27
if defn.WrapArrayMethods ().contains(wrapRefArrayMeth.symbol) && elideClassTag(ct) =>
39
28
seqLit
40
29
41
- case elem0 :: StripAscription (Apply (wrapRefArrayMeth, (seqLit : tpd. JavaSeqLiteral ) :: Nil )) :: Nil
30
+ case elem0 :: StripAscription (Apply (wrapRefArrayMeth, (seqLit : JavaSeqLiteral ) :: Nil )) :: Nil
42
31
if defn.WrapArrayMethods ().contains(wrapRefArrayMeth.symbol) =>
43
- tpd. JavaSeqLiteral (elem0 :: seqLit.elems, seqLit.elemtpt)
32
+ JavaSeqLiteral (elem0 :: seqLit.elems, seqLit.elemtpt)
44
33
45
34
case _ =>
46
35
tree
47
36
48
37
else if isListOrSeqModuleApply(tree.symbol) then
49
38
tree.args match
50
39
// <List or Seq>(a, b, c) ~> new ::(a, new ::(b, new ::(c, Nil))) but only for reference types
51
- case StripAscription (Apply (wrapArrayMeth, List (StripAscription (rest : tpd. JavaSeqLiteral )))) :: Nil
40
+ case StripAscription (Apply (wrapArrayMeth, List (StripAscription (rest : JavaSeqLiteral )))) :: Nil
52
41
if defn.WrapArrayMethods ().contains(wrapArrayMeth.symbol) &&
53
42
rest.elems.lengthIs < transformListApplyLimit =>
54
- rest.elems.foldRight(tpd. ref(defn.NilModule )): (elem, acc) =>
55
- tpd. New (defn.ConsType , List (elem.ensureConforms(defn.ObjectType ), acc))
43
+ rest.elems.foldRight(ref(defn.NilModule )): (elem, acc) =>
44
+ New (defn.ConsType , List (elem.ensureConforms(defn.ObjectType ), acc))
56
45
57
46
case _ =>
58
47
tree
0 commit comments