Skip to content
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

Path-dependent types turn into type projections #57

Closed
ggevay opened this issue Jun 11, 2018 · 4 comments
Closed

Path-dependent types turn into type projections #57

ggevay opened this issue Jun 11, 2018 · 4 comments

Comments

@ggevay
Copy link

ggevay commented Jun 11, 2018

I'm still struggling with getting TypeTag to work. Now the problem is that it is path-dependent on the universe.

Simplified example: Let's say that I have these types:

class Outer {
  class Inner
}

Then

  println(dbg_code"""
              val x = new Outer
              val y: x.Inner = ???""")

prints

code"""{
  val x_0 = new test.Outer();
  val y_1 = ((scala.Predef.???): (test.Outer)#Inner);
  ()
}"""

where x.inner turned into Outer#Inner.

This is a problem in Emma, because after some code fragment runs through Squid, I'm getting errors such as

found   : scala.reflect.api.JavaUniverse#TypeTag[String]
 required: reflect.runtime.universe.TypeTag[String]
@LPTK
Copy link
Member

LPTK commented Jun 11, 2018

Sorry, I should have pointed you to this Squid feature list from the start. There is expressly no support for path-dependent types in Squid.

I am wondering why you need to embed type tags in the DSL code fragments, though. What is the use case?

@ggevay
Copy link
Author

ggevay commented Jun 11, 2018

Oh, OK.

We need this because most Flink/Spark methods require TypeTag/ClassTag. So after lowering to Flink/Spark, we have TypeTag everywhere.

@LPTK
Copy link
Member

LPTK commented Jun 11, 2018

Ugh... that's a bit annoying.

Note that ClassTag should [EDIT: typo] not be problematic. As for TypeTag, it's actually problematic because scala.reflect.runtime.universe is not a module but a simple val, defined as:

lazy val universe: api.JavaUniverse = new runtime.JavaUniverse

One workaround would be to define your own module universe as:

object universe extends runtime.JavaUniverse

...though that would not help if you want to use definitions you can't change such as the Spark ones.
Maybe then, it would be sufficient to declare an implicit conversion from scala.reflect.api.JavaUniverse#TypeTag[T] to reflect.runtime.universe.TypeTag[T], implemented as a cast?

EDIT: I'm wondering what kind of code it generates to actually create the type tags – code that would also need to be embedded. Is it some intricate stuff with local classes? Or do you remove these implicits as alluded in #55?

@LPTK
Copy link
Member

LPTK commented Jun 11, 2018

I made a typo in the message above: class tags are not problematic; they embed well. For example:

scala> import squid.TestDSL.Predef._
import squid.TestDSL.Predef._

scala> code"scala.reflect.classTag[String]"
res0: squid.TestDSL.ClosedCode[scala.reflect.ClassTag[String]] = code"scala.reflect.`package`.classTag[java.lang.String](scala.reflect.ClassTag.apply[java.lang.String](_root_.scala.Predef.classOf[String]))"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants