-
Notifications
You must be signed in to change notification settings - Fork 323
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 - superclass approach #11770
base: develop
Are you sure you want to change the base?
Conversation
I think the generated code looks reasonably nice, but:
As a concept it is nice, but the real challenge is going to be the implementation of real |
I see one failure related to |
- Do not use asserts or any other exceptions. - Error is printed ony in the main processing loop.
Unapply & applyIn order to make necessary modifications in 0a1f5a8 demonstrates how a Java class I assume VSCode with Metals extension will also not be able to deduce that The question is: is this really worth it? Wouldn't it be better to just incrementally rewrite pattern matching in Scala that uses deconstruct to simpler variants that just matches on types? For example: val callArg = new JSpecified(true, None, lit)
callArg match {
case JSpecified(isSynthetic, _, _) =>
isSynthetic shouldEqual true
} Could be rewritten to callArg match {
case specified: JSpecified =>
specified.isSynthetic shouldEqual true
} without any behavioral changes. Moreover, the latter is OK in IDE. I would like to first create a PR that simplifies pattern matching, for TL;DR;Don't try to bend Java classes to look like Scala case classes. Just refactor deconstructing pattern matches in Scala to simpler variants. |
I don't mind how this particular IDE behaves. All that matters is whether the code compiles and behaves as it should. |
One of our long-term visions is to replace all Scala code in |
I doubt. Metals is using completely different technology than your IDE. |
This reverts commit 0a1f5a8.
# Conflicts: # engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/OperatorToFunctionTest.scala
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few notes.
/** | ||
* A class annotated with this annotation will be processed by the IR processor. The processor will | ||
* generate a super class that is meant to be extended by this class. The generated class will have | ||
* the same package as this class, and its name will have the "Gen" suffix. Majority of the methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to extract the name of the super class from class X extends MyParent
definition. E.g. then the name of the super class could be arbitrary. It would have to be in the same package, but there would be no restriction on the Gen
suffix.
* | ||
* @return | ||
*/ | ||
String interfaces() default "org.enso.compiler.core.IR"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is not used yet. I see plural being used here. In such case the value should be []
array. I would also suggest to use Class[]
that way one prevents typos as the referenced classes must exist. Btw. looking at Block
I see it implements IRKind.Primitive
- that interface isn't subtype of IR
...
|
||
/** | ||
* Constructor parameter annotated with this annotation will be represented as a child field in the | ||
* generated super class. Children of IR elements for a tree. A child will be part of the methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* generated super class. Children of IR elements for a tree. A child will be part of the methods | |
* generated super class. Children of IR elements form a tree. A child will be part of the methods |
* Constructor parameter annotated with this annotation will be represented as a child field in the | ||
* generated super class. Children of IR elements for a tree. A child will be part of the methods | ||
* traversing the tree, like {@code mapExpression} and {@code children}. The parameter type must be | ||
* a subtype of {@code org.enso.compiler.ir.IR}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* a subtype of {@code org.enso.compiler.ir.IR}. | |
* a subtype of {@link org.enso.compiler.ir.IR}. |
import org.enso.runtime.parser.dsl.GenerateFields; | ||
import org.enso.runtime.parser.dsl.GenerateIR; | ||
|
||
@GenerateIR(interfaces = "org.enso.compiler.core.ir.Expression") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Class[]
might be better. Then this line would become:
@GenerateIR(interfaces = "org.enso.compiler.core.ir.Expression") | |
@GenerateIR(interfaces =Expression.class) |
@@ -61,3 +61,7 @@ final class DiagnosticStorage(initDiagnostics: Seq[Diagnostic] = Seq()) | |||
new DiagnosticStorage(this.diagnostics) | |||
} | |||
} | |||
|
|||
object DiagnosticStorage { | |||
def empty(): DiagnosticStorage = new DiagnosticStorage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create()
or createEmpty()
might be better to indicate that a new instance of this mutable class is always created.
Alternative approach to #11267
Pull Request Description
The overall description is the same as in #11267, but this approach tries to generate super classes as suggested in https://github.com/enso-org/enso/pull/11267/files#r1869342527
Important Notes
An example of generated code for JExpression is:
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
or the Snowflake database integration, a run of the Extra Tests has been scheduled.