RFR: 8194743: Compiler implementation for Statements before super() [v7]
Vicente Romero
vromero at openjdk.org
Fri Jul 7 20:12:58 UTC 2023
On Tue, 13 Jun 2023 15:14:41 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
>> This is a first draft of a patch for JEP 447.
>>
>> Summary of changes:
>>
>> 1. Track when we're within a constructor "prologue" via new flag `AttrContext.ctorPrologue`
>> 1. Add checks for illegal early access to `this` in constructor prologues, and update existing checks to distinguish between static context vs. constructor prologue context
>> 1. Verify allowed placement of `super()`/`this()` calls via new method `Check.checkSuperInitCalls()`
>> 1. Remove/refactor assumptions in several places that `super()`/`this()` was always the first statement
>>
>> The changes in `Flow.java` are an example of <span>#</span>4. `Flow.FlowAnalyzer` checks for uncaught checked exceptions. For initializer blocks, this was previously done by requiring that any checked exceptions thrown be declared as thrown by all constructors containing `super()`. This list of checked exceptions was being pre-calculated before recursing into the initial constructors. This worked because initializer blocks were executed at the beginning of each initial constructor right after `super()` is called.
>>
>> Now initializer blocks are traversed as each `super()` invocation is encountered, reflecting what actually happens at runtime. Similarly, final fields are marked as DA after encountering `this()`, not automatically at the beginning of those constructors. These changes produce equivalent checks, but are compatible with the new flexibility of placement of `super()`/`this()` as well as possible future changes that could occur along these same lines.
>
> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 25 commits:
>
> - Merge branch 'master' into SuperInit
> - Fix mistake in previous merge commit 80ba6be4.
> - Merge branch 'master' into SuperInit
> - Rename unit test to be consistent with other feature exampless.
> - Update unit test after merged-in commit eaa80ad08.
> - Add unit tests with local class decl's prior to super().
> - Merge branch 'master' into SuperInit
> - Use @enablePreview in tests in preference to explicit command line flags.
> - Make "statements before super()" support a preview feature.
>
> Thanks to Jim Laskey for help with preview logic.
> - Small refactoring to avoid redundant test.
> - ... and 15 more: https://git.openjdk.org/jdk/compare/c0aa6bf4...a5f8cc5e
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 3975:
> 3973: }
> 3974:
> 3975: private class SuperThisChecker extends TreeScanner {
we usually create only one instance of these type of visitors that will be used very often and reuse it whenever necessary
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 4078:
> 4076:
> 4077: @Override
> 4078: public void visitClassDef(JCClassDecl tree) {
will you be descending into lambdas with this visitor?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1256278772
PR Review Comment: https://git.openjdk.org/jdk/pull/13656#discussion_r1256331686
More information about the compiler-dev
mailing list