Hi Miguel,
given that we (mostly :) use the JVM, what is the point of such transformation.
I understand why you can need this for a C or a LLVM backend but
for the JVM a transformation like this will hurt the perf,
the interpreter perf (too much bytecode)
and the JIT inlining heuristic (too much bytecode => no inlining).

other comments inlined:

On 06/29/2011 03:14 PM, Miguel Garcia wrote:

Hi,

In case you've been looking for a low-level IR for Scala ASTs, now you can inspect and transform a three-address-like IR (which are also valid Scala ASTs) emitted by a compiler plugin to that effect.

Sample input:

    object Test {
      def main(args: Array[String]) {
        val res =
if(b(1) + b(2) * b(3) > 0) { throw new Exception; "thenBranch" }
          else { "elseBranch" }
      }
      def b(n: Int) = { scala.Console.println(n); n }
    }



Sample output (excerpt):

    def main(args: Array[java.lang.String]): Unit = {
      var tmp10: java.lang.String = _;
      val tmp1: Int = Test.this.b(1);
      val tmp2: Int = tmp1;
      val tmp3: Int = Test.this.b(2);
      val tmp4: Int = tmp3;
      val tmp5: Int = Test.this.b(3);
      val tmp6: Int = tmp4.*(tmp5);
      val tmp7: Int = tmp2.+(tmp6);
      val tmp8: Int = tmp7;
      val tmp9: Boolean = tmp8.>(0);
      if (tmp9)
        {
          val tmp11: java.lang.Exception = new java.lang.Exception();
          throw tmp11;
          tmp10 = "thenBranch"
        }
      else
        tmp10 = "elseBranch";
      val res: java.lang.String = tmp10;
      ()
    }

I'm curious why tmp10 = "thenBranch" appears.
You do your transformation after the typechecking pass but before the dead
instruction detection (why the code compile BTW).

Is it because there is no such pass in the scala compiler ?

Another question, can you compare the interest of this transformation with
a SSA to AST ?



The PDF at
http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/2011Q2/Moving3A.pdf <http://lamp.epfl.ch/%7Emagarcia/ScalaCompilerCornerReloaded/2011Q2/Moving3A.pdf>
is the technical documentation for the sources at
http://lampsvn.epfl.ch/trac/scala/browser/scala-experimental/trunk/imp/src



If you want to use this plugin *today*, please notice [1] (that came to light during the development of this plugin). Alternatively, the plugin sources show how to workaround that.


Comments and suggestions are welcome (at http://groups.google.com/forum/#!forum/scala-internals <http://groups.google.com/forum/#%21forum/scala-internals>).


Miguel
http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded <http://lamp.epfl.ch/%7Emagarcia/ScalaCompilerCornerReloaded>


[1] http://issues.scala-lang.org/browse/SI-4738

Rémi

--
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to jvm-languages@googlegroups.com.
To unsubscribe from this group, send email to 
jvm-languages+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to