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

Part 2 of system for builtin objects #3454

Merged
merged 14 commits into from
May 19, 2022

Conversation

hubertp
Copy link
Contributor

@hubertp hubertp commented May 13, 2022

Pull Request Description

This is the 2nd part of DSL improvements that allow us to generate a lot of
builtins-related boilerplate code.

  • generate multiple method nodes for methods/constructors with varargs
  • expanded processing to allow for @Builtin to be added to classes and
    and generate @BuiltinType classes
  • generate code that wraps exceptions to panic via wrapException
    annotation element (see @Builtin.WrapException`

Also rewrote @Builtin annotations to be more structured and introduced some nesting, such as
@Builtin.Method or @Builtin.WrapException.

This is part of incremental work and a follow up on #3444.

Important Notes

Notice the number of boilerplate classes removed to see the impact.
For now only applied to Array but should be applicable to other types.

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 dist and ./run watch.

Expanded processing to allow for @Builtin to be added to classes.
More boilerplate gone.
When a method or constructor has vararg parameter, we may want to
generate multiple BuiltinMethod representation, up to some number of
parameters.
The approach has been extended in a generic way to take it into
consideration when `expandVargars` parameter is bigger than zero.

This allowed us to remove 4 more hardcoded classes.
Added `wrapException` annotation element that allows us to catch and
wrap runtime exceptions into panic.
`Array.at` and `Array.set_at` nodes are now generated from simple methods.

Additionally, we also have to propagate user-defined annotations on
parameters.
generateBuiltinType(gen, builtinType, stdLibName);
}

private void generateBuiltinType(
Copy link
Member

Choose a reason for hiding this comment

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

It might be interesting to see the generated output for a particular usage. It is hard to envision that without actually trying to compile the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean in the comments? Because we don't show anywhere that for any processor. The generated classes are essentially your source of truth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a lot of documentation as part of the rewrite I did to the DSL. Hopefully that improves the situation.

The existing Builtin DSL was becoming a bit too crowded with multiple
elements and default values. That wouldn't scale so had to refactor it.

The functionality stays almost the same except that now we really can
have repeatable @WrapException annotation indicating multiple
catch-clauses for possible exceptions that need to be wrapped.

Added a ton of documentation as the implenetation of the processor is
getting a bit more complicated.
@hubertp
Copy link
Contributor Author

hubertp commented May 18, 2022

@4e6 ping

Discovered a problem with separate compilation when generating exception
wrappers. The latter requires information about all builtin types
annotations but that is not present in separate compilation.
Instead we do a similar trick as in other processors - we read metadata
and diff the results.

The change is bigger than a single method because I didn't want to write
a yet another parser of metadata entries. Instead, every annotation
processor has to provide that implementation and it can be re-used.
@hubertp hubertp force-pushed the wip/hubert/builtin-objects-part-2-181499077 branch from a2f755e to d6a3614 Compare May 18, 2022 16:31
"UTF-8", // Specify character encoding used by Java source files
"-deprecation", // Shows a description of each use or override of a deprecated member or class
"-g", // Include debugging information
"-Xlint:unchecked", // Enable additional warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like it

@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label May 19, 2022
@mergify mergify bot merged commit 688df98 into develop May 19, 2022
@mergify mergify bot deleted the wip/hubert/builtin-objects-part-2-181499077 branch May 19, 2022 10:43
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.

The varargs part of this seems unnecessary, but I love the WrapException stuff!

@@ -30,6 +32,7 @@ public class Array implements TruffleObject {
*
* @param items the element values
*/
@Builtin.Method(expandVarargs = 4, description = "Creates an array with given elements.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooof. I think this is pointless. The new_{n} family were just helpers for the java-side tests for when they had no access to stdlib. We should have got rid of them a loooong time ago. And it seems like the whole expandVarargs functionality is basically useless otherwise? At least I can't think of another case.

@@ -104,6 +105,19 @@ long getArraySize() {
return items.length;
}

@Builtin.Method(name = "at", description = "Gets an array element at the given index.")
@Builtin.WrapException(from = IndexOutOfBoundsException.class, to = InvalidArrayIndexError.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

holy cow these are such a cool idea! :O

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.

4 participants