On Thu, 5 Mar 2026 14:24:28 GMT, Erik Joelsson <[email protected]> wrote:

>> There's an enum 
>> `src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java#PreviewFeature.Feature`
>>  that defines the current preview features, in particular those that have an 
>> API. The API is then marked with the appropriate enum constant.
>> 
>> There's a problem with this enum: javac's APIs may also need to use 
>> constants from the enum, and as javac is built twice, once with the 
>> bootstrap JDK to get the so called "interim javac" (which is then used to 
>> compile nearly all the rest of the JDK), and second time to get the final 
>> version of javac, this enum needs to be dragged into the interim compilation 
>> as well.
>> 
>> As a consequence, the bootstrap JDK classfiles are resolved against this 
>> up-to-date feature enum. And if any of the bootstrap JDK classfiles would 
>> refer to an enum constant that is not part of this up-to-date feature enum, 
>> javac would report a warning, failing the build.
>> 
>> As a consequence, the guidance is that when a preview feature ceases to be 
>> preview (either by maturing to a final and permanent feature, or by 
>> removal), we keep the appropriate enum constant as long as the bootstrap JDK 
>> may use it.
>> 
>> This works, but causes constant confusion, and unnecessary work, as 
>> finalizing a preview feature requires another action in the next release to 
>> cleanup the enum constant.
>> 
>> This PR is exploring an alternative solution: it takes the up-to-date 
>> `Feature` enum, and auto-generates a hybrid enum containing constants both 
>> from the up-to-date and bootstrap `Feature` enum. As a consequence, the 
>> up-to-date enum does not need to contain any legacy constants, as those are 
>> automatically injected for the interim build. This hybrid enum  should never 
>> be used outside of the interim javac build.
>> 
>> As a consequence, when a feature ceases to be a preview feature, we can 
>> clean up the feature enum immediately, leading to less confusion and less 
>> downstream work.
>
> make/CompileInterimLangtools.gmk line 130:
> 
>> 128:       $$(INTERIM_LANGTOOLS_BASE_MODULES), $$(call 
>> FindTransitiveDepsForModule, $1)))
>> 129: 
>> 130:   $$(BUILD_$1.interim): $$(foreach d, $$($1_DEPS_INTERIM), 
>> $$(BUILD_$$d)) $(COPY_PREVIEW_FEATURES)
> 
> Note how we declared a dependency from building of the interim module to 
> `$(COPY_PREVIEW_FEATURES)` here. You replaced `$(COPY_PREVIEW_FEATURES)` with 
> `$(BUILDTOOLS_OUTPUTDIR)/gensrc/java.base.interim/jdk/internal/javac/PreviewFeature.java`
>  so you need to update this dependency declaration too.

Thanks, I've adjusted the code, and it works well!

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/30072#discussion_r2894129513

Reply via email to