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
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6e33120
Add parser-dsl and parser-processor projects
Akirathan Oct 6, 2024
69f9247
Add JModule
Akirathan Oct 6, 2024
0e4ceb0
Fix module declaration - no compiler module dependency
Akirathan Oct 7, 2024
9891eb7
Add annotation processor testing.
Akirathan Oct 7, 2024
a3bf203
Rewrite some IR elements to IRNode annotated interfaces
Akirathan Oct 9, 2024
08b0571
IRProcessor does some sanity checks
Akirathan Oct 9, 2024
51796ba
IRNode does not have name parameter
Akirathan Oct 9, 2024
3ea7a90
IRProcessor generates source file for record
Akirathan Oct 9, 2024
f6bf733
Add imports and overriden IR methods to generated record
Akirathan Oct 10, 2024
1870ef2
Add field processing
Akirathan Oct 10, 2024
826245d
IRProcessor generates classes, not records
Akirathan Oct 14, 2024
fc89b3d
IRProcessor generates overrides for user-defined parameterless methods
Akirathan Oct 14, 2024
1fc0497
Add Field.isExpression method
Akirathan Oct 17, 2024
d2bb8c3
sbt picks up Scala case classes generated by Java annotation processor
Akirathan Oct 18, 2024
68a070b
IRProcessor generates Scala classes.
Akirathan Oct 18, 2024
cf08781
Revert "sbt picks up Scala case classes generated by Java annotation …
Akirathan Oct 21, 2024
f930e53
Revert "IRProcessor generates Scala classes."
Akirathan Oct 21, 2024
298c883
IRProcessor handles primitive fields
Akirathan Oct 21, 2024
bc1e9c9
Remove unused methods
Akirathan Oct 21, 2024
ef05c64
IRProcessor fails fast
Akirathan Oct 21, 2024
aa0a5b6
IRProcessor can collect fields from super interfaces
Akirathan Oct 21, 2024
c6def78
Fix collecting fields from super interfaces.
Akirathan Oct 22, 2024
8cea491
Prepare IRNodeProcessor for processing multiple nested interfaces
Akirathan Oct 22, 2024
f5cb331
IRNodeProcessor handles multiple nested interfaces
Akirathan Oct 22, 2024
2393e18
runtime-parser-processor does not depend on runtime-parser
Akirathan Oct 22, 2024
cf1d079
Move parser processor tests to a separate project
Akirathan Oct 22, 2024
f63bda1
runtime-parser-processor does not depend on runtime-parser
Akirathan Oct 22, 2024
158a4f1
runtime-parser depends on runtime-parser-processor
Akirathan Oct 22, 2024
1289374
IRProcessor adds package
Akirathan Oct 25, 2024
73a9d31
ParserDependenciesTest ensures that IRNodeProcessor is on class path
Akirathan Oct 25, 2024
be4396c
runtime-parser-processor module provides annotation processor service
Akirathan Oct 25, 2024
3665232
Fix getSimpleTypeName in ReferenceField
Akirathan Oct 25, 2024
260d11d
No nested @IRNode annotation
Akirathan Oct 25, 2024
df95a4e
JModule extends IR
Akirathan Oct 25, 2024
7918fd2
IRNodeProcessor handles parametrized List child
Akirathan Oct 25, 2024
9ae8e3f
runtime-parser-processor-tests runs with enabled assertions
Akirathan Oct 25, 2024
cf264cf
Test IRNode with List of children
Akirathan Oct 25, 2024
0f21885
All IR interfaces use scala list, not java.util.List
Akirathan Oct 25, 2024
18b2d10
Do not process already overriden methods
Akirathan Oct 25, 2024
26239a3
Enable IRProcessor in runtime-parser
Akirathan Oct 29, 2024
9c3a580
Ensure that only fields from current interface and its super interfac…
Akirathan Oct 29, 2024
c6b1987
Implement passData, location and diagnostics methods
Akirathan Oct 30, 2024
399ca43
Override duplicate method
Akirathan Oct 30, 2024
7a97c61
Fix duplicate method generation
Akirathan Oct 30, 2024
8acfa30
Move duplicate method generation to a separate class
Akirathan Oct 31, 2024
7988276
Duplicate method duplicates also non-child fields
Akirathan Oct 31, 2024
c84ebb7
Simplify tests
Akirathan Oct 31, 2024
8a778f0
During runtime-parser-processor-test compilation, IRNodeProcessor runs
Akirathan Oct 31, 2024
86d1b0e
docs
Akirathan Oct 31, 2024
8aa64bd
Add some IR interfaces to the testing code
Akirathan Oct 31, 2024
e91f09e
test generated list children
Akirathan Oct 31, 2024
dd34e5d
DuplicateMethodGenerator duplicates also meta fields
Akirathan Nov 1, 2024
2a2b6d3
Builder allows setting meta fields
Akirathan Nov 1, 2024
7def7b1
Add tests for duplicated metadata
Akirathan Nov 1, 2024
66aba89
Add runtime-parser-processor-tests to the enso aggregate
Akirathan Nov 1, 2024
f6b75ed
Add IRCopyMethod annotation
Akirathan Nov 1, 2024
9bccf1c
Iteration over super interfaces is handled only via SuperInterfaceVis…
Akirathan Nov 1, 2024
f027307
Simplify super interface iteration
Akirathan Nov 1, 2024
687d0e1
Builder has a copy constructor
Akirathan Nov 1, 2024
bd9b7e4
Implement CopyMethodGenerator
Akirathan Nov 1, 2024
98f4743
Fix all tests
Akirathan Nov 1, 2024
92d9004
Test copy method generation
Akirathan Nov 1, 2024
69728be
Do not try to override static or default methods
Akirathan Nov 1, 2024
7709597
docs
Akirathan Nov 1, 2024
7d012fe
Allow multiple copy methods
Akirathan Nov 4, 2024
cb06f03
CopyMethodGenerator generates copy method with correct order of param…
Akirathan Nov 4, 2024
c08c035
Test valid parameter names for copy method
Akirathan Nov 4, 2024
43ed045
More tests
Akirathan Nov 4, 2024
69258cf
Generate mapExpressions method
Akirathan Nov 5, 2024
f888cee
Add mock definition of JCallArgument
Akirathan Nov 5, 2024
57c5bff
Use qualified type names in mapExpressions method
Akirathan Nov 6, 2024
be2d374
Implement JBlank.create factory method
Akirathan Nov 6, 2024
b828603
JExpression overrides duplicate and mapExpressions
Akirathan Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.enso.runtime.parser.processor;

import java.util.Objects;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;

final class MapExpressionsMethodGenerator {
private final ExecutableElement mapExpressionsMethod;
Expand Down Expand Up @@ -58,7 +60,7 @@ String generateMapExpressionsMethodCode() {

var newChildName = child.getName() + "Mapped";
sb.append(" ")
.append(childsMapExprMethodRetType.getSimpleName())
.append(typeName(childsMapExprMethodRetType))
.append(" ")
.append(newChildName);
if (child.isNullable()) {
Expand Down Expand Up @@ -128,5 +130,12 @@ String generateMapExpressionsMethodCode() {
return sb.toString();
}

private String typeName(Element element) {
if (element instanceof TypeElement typeElement) {
return typeElement.getQualifiedName().toString();
}
return element.getSimpleName().toString();
}

private record MappedChild(String newChildName, Field child, boolean shouldCast) {}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package org.enso.compiler.core.ir;

import java.util.function.Function;
import org.enso.compiler.core.IR;
import org.enso.compiler.core.ir.JExpressionGen.IfThenElseGen;
import org.enso.runtime.parser.dsl.IRChild;
import org.enso.runtime.parser.dsl.IRCopyMethod;
import org.enso.runtime.parser.dsl.IRNode;
import scala.Option;
import scala.collection.immutable.List;

@IRNode
public interface JExpression extends IR {

@Override
JExpression mapExpressions(Function<Expression, Expression> fn);

@Override
JExpression duplicate(
boolean keepLocations,
boolean keepMetadata,
boolean keepDiagnostics,
boolean keepIdentifiers);

interface JBlock extends JExpression {
@IRChild
List<JExpression> expressions();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.enso.compiler.core.ir;

import org.enso.compiler.core.ir.JNameGen.JBlankGen;
import org.enso.compiler.core.ir.module.scope.JDefinition;
import org.enso.runtime.parser.dsl.IRChild;
import org.enso.runtime.parser.dsl.IRNode;
Expand All @@ -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.

static JBlank create() {
return JBlankGen.builder().build();
}
}

interface JLiteral extends JName {
@IRChild(required = false)
Expand Down
Loading