-
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
Towards a full-blown builtins DSL (part 3) #3471
Conversation
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.
This is starting to look like such a cool system <3
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java
Show resolved
Hide resolved
public String getName() { | ||
return this.truffleFile.getName(); | ||
} | ||
|
||
@Builtin.Method |
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 love how these are now just auto-exporting
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/FunctionThrowingIOException.java
Outdated
Show resolved
Hide resolved
68c45cc
to
477c7ef
Compare
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.
This is awesome, my dreams coming true. A few questions inline. Also, I'd like to ask for all the dsl-related classes to contain docs with examples showing source code and generated code, so that it's clear what does what
== that = this.prim_file.isEqual that.prim_file | ||
== that = this.is_equal that | ||
|
||
is_equal : File -> Boolean |
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.
why is this method needed?
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.
That can go, true.
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java
Show resolved
Hide resolved
private final TruffleFile truffleFile; | ||
private static final String home = System.getProperty("user.home"); |
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.
Such a static constant may be problematic when NativeImage is created from these classes and the class initializers are executed at build time. home
would be a constant in the code referring to the home directory on the build machine.
Better to avoid such static constants and always read the property.
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.
Fair enough
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinsProcessor.java
Show resolved
Hide resolved
WIP Partially auto-generated, partially manually written builtins nodes for File. The next step is to auto-generate builtins craft using enhanced annotation processor.
Enhanced processor to handle methods - `list` - `delete` - `outputStream` - `inputStream` One thing that was visible from the hardcoded node classes was that we had to handle situations where `asGuestValue`/`toHostObject` conversions were inferred automatically. As more types are marked as builtin(e.g. `Output_Stream`) those conversions will be very easy to drop.
Specializations force a similar, yet slightly different, code-gen of builtin methods compared to non-specialized variants. Half-way down the road it was clear which parts could be generalized and which could not. Did some re-shuffling to simplify File API and avoid some unnecessary specializations (like `File.new` builtins). The end result: all File builtins are now generated from method signatures. Added a bunch of ManagedResource methods as well, because why not.
Processor with >1.5k loc was getting hard to manage. Split the logic into individual files.
Forgot that try/catch inference was only supported in non-specialized nodes. Translated that to the specialized generator as well. Now it was possible to generate all System builtin methods from public methods. Also, we now generate Enso-friendly parameter names; previously it would be impossible to pass arguments by name.
Some tweaks to address review.
Builtins DSL in Action. Had to modify processor so that we can - specialize with fallbacks - infer AcceptWarnings or Warnings aren't propagated Some duplication exists in Warning definitions to deal with Vector -> Array conversion. We might want to revisit that at some point.
23a9ea3
to
92f39ba
Compare
Added a ton of documentation. Should be much clearer what specific annotations are capable of. Also, compared to the initial submission, got rid of more handwritten classes using the new DSL. |
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java
Outdated
Show resolved
Hide resolved
fd6a32e
to
fcc650f
Compare
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.
Love it!
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java
Show resolved
Hide resolved
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.
Awesome!
## PRIVATE | ||
|
||
Utility function that lists immediate children of a directory. | ||
list_immediate_children_array : Array File | ||
list_immediate_children_array = @Builtin_Method "File.list_immediate_children_array" |
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.
Maybe instead we should call this with suffix (or prefix?) _builtin
? Or _primitive
? Then all 'internal' methods would have similar names which would be helpful understanding which are those.
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.
Good idea, but I'd rather leave it to a separate PR
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java
Outdated
Show resolved
Hide resolved
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/Builtin.java
Outdated
Show resolved
Hide resolved
lib/scala/interpreter-dsl/src/main/java/org/enso/interpreter/dsl/BuiltinsProcessor.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Radosław Waśko <[email protected]>
…sl/Builtin.java Co-authored-by: Radosław Waśko <[email protected]>
Auto-generate all builtin methods for builtin `File` type from method signatures. Similarly, for `ManagedResource` and `Warning`. Additionally, support for specializations for overloaded and non-overloaded methods is added. Coverage can be tracked by the number of hard-coded builtin classes that are now deleted. ## Important notes Notice how `type File` now lacks `prim_file` field and we were able to get rid off all of those propagating method calls without writing a single builtin node class. Similarly `ManagedResource` and `Warning` are now builtins and `Prim_Warnings` stub is now gone.
Pull Request Description
Auto-generate all builtin methods for builtin
File
type from method signatures.Similarly, for
ManagedResource
andWarning
.Additionally, support for specializations for overloaded and non-overloaded methods is added.
Coverage can be tracked by the number of hard-coded builtin classes that are now deleted.
Important notes
Notice how
type File
now lacksprim_file
field and we were able to get rid off all of thosepropagating method calls without writing a single builtin node class.
Similarly
ManagedResource
andWarning
are now builtins andPrim_Warnings
stub is now gone.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run.sh ide dist
and./run.sh ide watch
.