RFR: 8194743: Compiler implementation for Statements before super() [v3]

Jim Laskey james.laskey at oracle.com
Tue May 16 21:49:02 UTC 2023


Don’t forget to update the tests to use the @enablePreview flag. 

📱

> On May 16, 2023, at 6:37 PM, 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 incrementally with one additional commit since the last revision:
> 
>  Make "statements before super()" support a preview feature.
> 
>  Thanks to Jim Laskey for help with preview logic.
> 
> -------------
> 
> Changes:
>  - all: https://git.openjdk.org/jdk/pull/13656/files
>  - new: https://git.openjdk.org/jdk/pull/13656/files/0e638da2..3c9322b6
> 
> Webrevs:
> - full: https://webrevs.openjdk.org/?repo=jdk&pr=13656&range=02
> - incr: https://webrevs.openjdk.org/?repo=jdk&pr=13656&range=01-02
> 
>  Stats: 58 lines in 9 files changed: 55 ins; 0 del; 3 mod
>  Patch: https://git.openjdk.org/jdk/pull/13656.diff
>  Fetch: git fetch https://git.openjdk.org/jdk.git pull/13656/head:pull/13656
> 
> PR: https://git.openjdk.org/jdk/pull/13656


More information about the kulla-dev mailing list