stanford-ppl / Forge

A prototype meta DSL that generates Delite DSL implementations from a specification-like program.
49 stars 23 forks source link

Generating return types on DSL methods #32

Open AustinBGibbons opened 11 years ago

AustinBGibbons commented 11 years ago

I'm having some problems with addition/subtraction

First, I was inlining curr+1 and forge_int_plus(curr, 1), and this both result in type Int(0) but should be type String

Now I assign it to a variable and refer to that variable, and this generates a slew of error: not found (one for each kernel) - ie

/home/gibbons4/ppl/Delite/generatedCache/scala/src/runtime/Executable0.scala:8: error: not found: value kernel_x1 val xx1 : Unit = kernel_x1() ^ /home/gibbons4/ppl/Delite/generatedCache/scala/src/runtime/Executable0.scala:9: error: not found: value kernel_x2 val xx2 : scala.collection.mutable.HashMap[Float, Int] = kernel_x2()

This was from testing in Maps-Dev - https://github.com/stanford-ppl/Forge/blob/ee166f464d14ee5addb3bd6abfb900afcece388e/src/examples/MapTest.scala

asujeeth commented 11 years ago

I don't understand.. why should forge_int_plus(curr, 1) return a type String? Or are you saying that is an error that gets reported by Scala? And what do you mean by "inlining"?

AustinBGibbons commented 11 years ago

Er sorry - I thought I had put that somewhere as an issue.

If I call

method(forge_int_plus(curr, 1))

I can run the library version and build the .deg file, but running delite produces -

/home/gibbons4/ppl/Delite/generatedCache/scala/src/kernels/x47.scala:23: error: value - is not a member of Any x33 - 1}

(and similar)

The generated snippet looks like this val x41 = { x33 - 1}

(Which I think should be fine)

If instead I do

val new_value = forge_int_plus(curr, 1) method(new_value)

I ge the above error (but not the is not a member of Any error)

asujeeth commented 11 years ago

What's the type of curr?

AustinBGibbons commented 11 years ago

MInt

    val curr = $self.ms_count($1)

where

  infix ("ms_count") (T :: MInt) implements composite ${
    map_getOrElse(getMap($self), $1, 0) match {
      case x: Int => x
      case x: Rep[Int] => x
    }
  }
asujeeth commented 11 years ago

That match statement will return Any, since it can return either an Int or a Rep[Int]. I'm not sure why it compiles at all though -- maybe we leave return types off the generated methods and let them be inferred, and it infers Any.

Note also that because of erasure, matching on x: Rep[Int] is the same as matching on x: Rep[_]

AustinBGibbons commented 11 years ago

Okay, I'm going to relabel this as enhancement for generating return types for all methods