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

Towards a full-blown builtins DSL (part 3) #3471

Merged
merged 20 commits into from
Jun 13, 2022

Conversation

hubertp
Copy link
Contributor

@hubertp hubertp commented May 23, 2022

Pull Request Description

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.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run.sh ide dist and ./run.sh ide watch.

@hubertp hubertp marked this pull request as draft May 23, 2022 13:12
Copy link
Contributor

@kustosz kustosz left a 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

public String getName() {
return this.truffleFile.getName();
}

@Builtin.Method
Copy link
Contributor

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

@hubertp hubertp force-pushed the wip/hubert/builtin-objects-file-181499077 branch from 68c45cc to 477c7ef Compare May 24, 2022 13:29
@hubertp hubertp marked this pull request as ready for review May 27, 2022 13:40
@hubertp hubertp changed the title WIP: Towards a full-blown builtins DSL (part 3) Towards a full-blown builtins DSL (part 3) May 27, 2022
@hubertp hubertp requested a review from kustosz May 30, 2022 16:24
Copy link
Contributor

@kustosz kustosz left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That can go, true.

private final TruffleFile truffleFile;
private static final String home = System.getProperty("user.home");
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough

hubertp added 12 commits June 7, 2022 12:27
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.
@hubertp hubertp force-pushed the wip/hubert/builtin-objects-file-181499077 branch from 23a9ea3 to 92f39ba Compare June 7, 2022 13:29
@hubertp hubertp requested a review from kustosz June 7, 2022 13:29
@hubertp
Copy link
Contributor Author

hubertp commented Jun 7, 2022

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.

@hubertp hubertp requested a review from radeusgd June 8, 2022 15:52
@hubertp hubertp force-pushed the wip/hubert/builtin-objects-file-181499077 branch from fd6a32e to fcc650f Compare June 8, 2022 15:53
Copy link
Contributor

@kustosz kustosz left a comment

Choose a reason for hiding this comment

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

Love it!

@hubertp hubertp mentioned this pull request Jun 10, 2022
4 tasks
Copy link
Contributor

@4e6 4e6 left a comment

Choose a reason for hiding this comment

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

Awesome!

CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines +715 to +719
## 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"
Copy link
Member

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.

Copy link
Contributor Author

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

hubertp and others added 4 commits June 10, 2022 15:52
Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org>
…sl/Builtin.java

Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org>
@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Jun 13, 2022
@hubertp hubertp removed the CI: Ready to merge This PR is eligible for automatic merge label Jun 13, 2022
@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Jun 13, 2022
@mergify mergify bot merged commit fd46e84 into develop Jun 13, 2022
@mergify mergify bot deleted the wip/hubert/builtin-objects-file-181499077 branch June 13, 2022 11:48
kazcw pushed a commit that referenced this pull request Jun 29, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants