Skip to content

Commit 3697677

Browse files
committed
Merge pull request #75 from alexeyr/array-fixes
Array fixes
2 parents 2b3f2a3 + d7e97f7 commit 3697677

File tree

12 files changed

+27
-26
lines changed

12 files changed

+27
-26
lines changed

src/common/ArrayOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ trait ScalaGenArrayOps extends BaseGenArrayOps with ScalaGenBase {
192192
val ARRAY_LITERAL_MAX_SIZE = 1000
193193

194194
override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match {
195-
case a@ArrayNew(n) => emitValDef(sym, src"new Array[${a.m}]($n)")
195+
case a@ArrayNew(n) => emitValDef(sym, src"new Array[${remap(a.m)}]($n)")
196196
case e@ArrayFromSeq(xs) => {
197197
emitData(sym, xs)
198198
emitValDef(sym,
@@ -224,7 +224,7 @@ trait ScalaGenArrayOps extends BaseGenArrayOps with ScalaGenBase {
224224
case ArrayCopy(src,srcPos,dest,destPos,len) => emitValDef(sym, src"System.arraycopy($src,$srcPos,$dest,$destPos,$len)")
225225
case a@ArraySort(x) =>
226226
gen"""val $sym = {
227-
|val d = new Array[${a.m}]($x.length)
227+
|val d = new Array[${remap(a.m)}]($x.length)
228228
|System.arraycopy($x, 0, d, 0, $x.length)
229229
|scala.util.Sorting.quickSort(d)
230230
|d

src/common/Structs.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ trait StructExp extends StructOps with StructTags with BaseExp with EffectExp wi
178178
// FIXME: move to codegen? we should be able to have different policies/naming schemes
179179
case rm: RefinedManifest[_] => "Anon" + math.abs(rm.fields.map(f => f._1.## + f._2.toString.##).sum)
180180
case _ if (m <:< manifest[AnyVal]) => m.toString
181+
case _ if m.erasure.isArray => "ArrayOf" + structName(m.typeArguments.head)
181182
case _ => m.erasure.getSimpleName + m.typeArguments.map(a => structName(a)).mkString("")
182183
}
183184

test-out/epfl/test7-fusion2.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ super.focusExactScopeFat with result changed from List(Sym(28)) to List(Sym(53))
2828
*******************************************/
2929
class Test extends ((Unit)=>(Unit)) {
3030
def apply(x0:Unit): Unit = {
31-
var x45 = 0
32-
var x46 = 0
31+
var x45: Double = 0
32+
var x46: Double = 0
3333
for (x1 <- 0 until 100) {
3434
val x29 = 2.0*x1
3535
val x31 = 1.0+x29

test-out/epfl/test7-fusion22.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def apply(x0:Unit): Unit = {
3535
val x37 = 1.0+2.0
3636
var x3 = new Array[Double](50)
3737
var x7 = new Array[Double](50)
38-
var x11 = 0
39-
var x38 = 0
38+
var x11: Double = 0
39+
var x38: Double = 0
4040
for (x2 <- 0 until 50) {
4141
x3(x2) = 1.0
4242
x7(x2) = 2.0

test-out/epfl/test7-fusion23.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ for (x1 <- 0 until 100) {
3737
val x43 = 1.0+2.0
3838
var x3 = new Array[Double](x1)
3939
var x29 = new Array[Double](x1)
40-
var x32 = 0
41-
var x44 = 0
40+
var x32: Double = 0
41+
var x44: Double = 0
4242
for (x2 <- 0 until x1) {
4343
x3(x2) = 1.0
4444
x29(x2) = 2.0

test-out/epfl/test7-fusion3.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ val x5 = x4 > 50
1414
if (x5) x6 += x4
1515
}
1616
val x7 = x6.length
17-
var x10 = 0
17+
var x10: Int = 0
1818
for (x8 <- 0 until x7) {
1919
val x9 = x6.apply(x8)
2020
x10 += x9

test-out/epfl/test7-fusion4.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ super.focusExactScopeFat with result changed from List(Sym(12)) to List(Sym(25))
1919
*******************************************/
2020
class Test extends ((Unit)=>(Unit)) {
2121
def apply(x0:Unit): Unit = {
22-
var x23 = 0
22+
var x23: Int = 0
2323
for (x1 <- 0 until 100) {
2424
val x13 = x1 > 50
2525
if (x13) x23 += x1

test-out/epfl/test9-struct2.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ x2
2525
}
2626
val x16 = x0 > 7
2727
val x21 = if (x16) {
28-
val x6 = new Record[]Anon189207751(x4,x5)
28+
val x6 = new ArrayOfAnon189207751(x4,x5)
2929
x6
3030
} else {
3131
val x17 = x13
3232
val x18 = x14
33-
val x19 = new Record[]Anon189207751(x17,x18)
33+
val x19 = new ArrayOfAnon189207751(x17,x18)
3434
x19
3535
}
3636
x13 = x4
3737
x14 = x5
3838
val x24 = x13
3939
val x25 = x14
40-
val x26 = new Record[]Anon189207751(x24,x25)
40+
val x26 = new ArrayOfAnon189207751(x24,x25)
4141
val x27 = println(x26)
4242
val x28 = println(x21)
4343
x28
@@ -47,4 +47,4 @@ x28
4747
End of Generated Code
4848
*******************************************/
4949

50-
case class Record[]Anon189207751(re: Array[Double], im: Array[Int])
50+
case class ArrayOfAnon189207751(re: Array[Double], im: Array[Int])

test-out/epfl/test9-struct2b.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ x13 = x11
3434
x14 = x10
3535
val x42 = x13
3636
val x43 = x14
37-
val x44 = new Record[]Anon189207751(x42,x43)
37+
val x44 = new ArrayOfAnon189207751(x42,x43)
3838
val x45 = println(x44)
39-
val x46 = new Record[]Anon189207751(x38,x39)
39+
val x46 = new ArrayOfAnon189207751(x38,x39)
4040
val x47 = println(x46)
4141
val x36 = x47
4242
x36
@@ -46,4 +46,4 @@ x36
4646
End of Generated Code
4747
*******************************************/
4848

49-
case class Record[]Anon189207751(re: Array[Int], im: Array[Double])
49+
case class ArrayOfAnon189207751(re: Array[Int], im: Array[Double])

test-out/epfl/test9-struct3.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var x4 = new Array[Int](100)
1818
for (x1 <- 0 until 100) {
1919
x4(x1) = x1
2020
}
21-
val x17 = new Record[]Anon189207751(x4,x4)
21+
val x17 = new ArrayOfAnon189207751(x4,x4)
2222
val x18 = println(x17)
2323
val x15 = x18
2424
x15
@@ -28,4 +28,4 @@ x15
2828
End of Generated Code
2929
*******************************************/
3030

31-
case class Record[]Anon189207751(re: Array[Int], im: Array[Int])
31+
case class ArrayOfAnon189207751(re: Array[Int], im: Array[Int])

0 commit comments

Comments
 (0)