Indeed, that is the crux of my earlier questions. I've got it working at 
runtime, however I'm unsure of which approach to take for compile-time.

Adding new `ScriptBytecodeAdapter`/`InvokerHelper` methods that call a 
`VMPlugin` method allows for optimising other scenarios, such as 
`DefaultGroovyMethods.asImmutable(List)`.

You can find my current implementation here: PaintNinja/groovy at 
GROOVY-11294-record-immutable-tolist 
(github.com)<https://github.com/PaintNinja/groovy/tree/GROOVY-11294-record-immutable-tolist>

As for compile-time optimisations, I'm not very familiar with Groovy's compiler 
internals. What would be the most suitable place to do JVM version-specific 
optimisations?
Note that the exact type of immutable list used also varies on the nullity of 
items and the length of the array, so for optimal performance it's 
unfortunately not as simple as one method for all lists on one Java version and 
another method on a different version.

________________________________
From: Milles, Eric (TR Technology) via dev <dev@groovy.apache.org>
Sent: 22 January 2024 18:04
To: dev@groovy.apache.org <dev@groovy.apache.org>
Subject: RE: Questions regarding implementation approach for GROOVY-11294


The exercise is an interesting one: how to add support for something like 
`List.of(…)` for Java 8-21 when the method exists only for 9+ and some behavior 
you seek in only in 16+.



However, is it worthwhile in this case to add new `ScriptBytecodeAdapter` 
methods to support this for records instead of just writing the bytecode you 
need based on the compile-time target bytecode version?


Reply via email to