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

[PoC] Generate IR definitions with annotation processor #11267

Draft
wants to merge 73 commits into
base: develop
Choose a base branch
from

Conversation

Akirathan
Copy link
Member

@Akirathan Akirathan commented Oct 7, 2024

Closes #11498

Pull Request Description

Introduces runtime-parser-processor annotation processor that processes interfaces annotated with @IRNode.

Introduces these 3 new sbt projects:

  • runtime-parser-dsl is a project that contains only the annotation definitions, has no dependencies.
  • runtime-parser-processor is a project that contains the definition of the annotation processor. Has no dependencies.
  • runtime-parser project now depends on runtime-parser-dsl and runtime-parser-processor.

Important Notes

Links to the docs:

Examples of used annotations:

To see the generated code, it is enough to sbt> runtime-parser/compile. All the tests are inside the runtime-parser-processor-test project.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • Run SigTest on runtime-compiler on develop and on this PR.
  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.

@JaroslavTulach
Copy link
Member

One of the issues with newly generated Java classes is the way to consume them from existing Scala passes. Preferably we do it in a way that doesn't require changes to the existing Scala code. Once I asked

"Knowing how to generate a Java class to be able to apply and unapply it would be great!"

@hubertp has provided following advice when it comes to pattern matching:

package org.enso.compiler.core.ir;

import org.enso.compiler.core.IR;
import org.enso.compiler.core.Identifier;
import scala.Option;
import scala.PartialFunction;
import scala.Tuple2$;
import scala.collection.immutable.List;

import java.util.UUID;
import java.util.function.Function;

public class Foo implements Expression {

    private final Integer a;
    private final String b;

    public Foo(Integer a, String b) {
        this.a = a;
        this.b = b;
    }

    public static scala.Option<scala.Tuple2<Integer, String>> unapply(Object x) {
        if (x instanceof Foo f) {
            return Option.apply(Tuple2$.MODULE$.apply(f.a, f.b));
        } else {
            return Option.empty();
        }
    }

and then

package org.enso.compiler.core.ir

object TestPattern {

  def testMe(x: Object): Unit = {
    x match {
      case Foo(a, b) =>
        println("A " + a + ", B " + b);
      case _ =>
        println("nope")
    }
  }

  def main(args: Array[String]): Unit = {
    testMe(new Foo(1, "foo"))
  }

}

"works just fine" according to @hubertp.

@Akirathan
Copy link
Member Author

An abandoned idea to generate Scala classes is the following commits that are now reverted:

@enso-bot
Copy link

enso-bot bot commented Oct 21, 2024

Pavel Marek reports a new STANDUP for today (2024-10-21):

Progress: - IRProcessor traverser super interfaces and collects all the fields

  • Reverted back to Java class generation It should be finished by 2024-11-07.

@enso-bot
Copy link

enso-bot bot commented Nov 1, 2024

Pavel Marek reports a new STANDUP for yesterday (2024-10-31):

Progress: - Review #11365

  • Merged Fix Meta.get_qualified_type_name when run as single file #11401
  • IR generator - almost finished duplicate method generation.
    • copy method generation
    • The solution for a PoC with a very simple (adding explicitly parameters to some method calls) changes to runtime-parser is almost ready. It should be finished by 2024-11-07.

@enso-bot
Copy link

enso-bot bot commented Nov 1, 2024

Pavel Marek reports a new STANDUP for today (2024-11-01):

Progress: - Quick start bazel with Pawel

  • Started to work on a (hopefully simple) fix for Java Values are displayed differently in the Chrome Devtools debugger #7890.
  • All tests on IR processor are passing
    • So far, none of the generated IR classes is used in an actual compilation, it is tested in a sandbox.
    • Implemented generation of the duplicate method.
    • Added IRCopyMethod annotation for generating copy methods for only some fields (or metadata). It should be finished by 2024-11-07.

@@ -18,7 +19,11 @@ JName duplicate(
boolean keepDiagnostics,
boolean keepIdentifiers);

interface JBlank extends JName {}
interface JBlank extends JName {
Copy link
Member

@JaroslavTulach JaroslavTulach Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sample JXyz interfaces should probably be moved outside of real code to tests. To separate what is demo and what is the supposed to be the production code.

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

Successfully merging this pull request may close these issues.

Generate IR definitions by annotation processor
2 participants