-
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
Part 2 of system for builtin objects #3454
Part 2 of system for builtin objects #3454
Conversation
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( |
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 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.
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.
You mean in the comments? Because we don't show anywhere that for any processor. The generated classes are essentially your source of truth
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 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.
@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.
a2f755e
to
d6a3614
Compare
"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 |
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 really like it
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.
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.") |
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.
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) |
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.
holy cow these are such a cool idea! :O
Pull Request Description
This is the 2nd part of DSL improvements that allow us to generate a lot of
builtins-related boilerplate code.
and generate @BuiltinType classes
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:
./run dist
and./run watch
.