Closed mpalat closed 1 month ago
Please include me in all design and implementation discussions and reviews.
As a first step, I suggest we figure out if parser/scanner changes are required by capturing all snippets from the JEP document into test cases - do we have any parse failures if we do that ?
As a first step, I suggest we figure out if parser/scanner changes are required by capturing all snippets from the JEP document into test cases - do we have any parse failures if we do that ?
Is there an easy/standard way to do that or are you saying we just look for syntax errors?
As a first step, I suggest we figure out if parser/scanner changes are required by capturing all snippets from the JEP document into test cases - do we have any parse failures if we do that ?
Is there an easy/standard way to do that or are you saying we just look for syntax errors?
We can see what errors we get, or better yet whether diagnose parse gets entered while compiling the snippets.
Please include me in all design and implementation discussions and reviews.
... and include me on all spec issues :)
When this is scheduled for standardization I will assume ownership - for now, please feel free to engage me for any design or implementation consultation and code review as needed. Thanks
When this is scheduled for standardization I will assume ownership
by "standardization" you mean having a stable spec, or maturing from preview to standard?
When this is scheduled for standardization I will assume ownership
by "standardization" you mean having a stable spec, or maturing from preview to standard?
I meant the latter.
@stephan-herrmann - Would you be able to take this up (partly/completely rest of it?) - I am off for the next few days on an important personal work and cannot spend time on work until I am back [Aug 5th] and may have to take a few days later too. In case you are able to spare time to work on this next week, it would be of great help- Please feel free to take it up partly/completely depending on your availability. [@srikanth-sankaran - open to you as well but since you are out I am not sure about your availability]. Thanks.
Some - perhaps academic - observations:
case float f ->
javac uses SwitchBootstraps.typeSwitch()
Let's hope that such issues will clear up when the feature leaves preview!
Some - perhaps academic - observations:
- we already use this class since 988d0b8, @mpalat how did you find out about that class, has it been mentioned in some document or post on the mailing list?
@stephan-herrmann initially I tried implementing this by myself in the generated code which met with limited success. And I should confess that on a comparative check with javac generated code I saw this method and hence decided to use the same since it is already available at runtime.
Here's a first attempt of a mapping between spec changes and implementation already done:
PrimitiveConversionRoute
added in #2499
Details see next comment :heavy_check_mark: CodeStream.invokeExactConversionsSupport()
using ExactConversionsSupport
(#2499) :heavy_check_mark:
BigDecimal
, but since this is what javac uses, too, so be it.BaseTypeBinding.isExactWidening()
(#2499)
SwitchBootstraps.typeSwitch()
(since JDK 17) usage expanded in #2866 :heavy_check_mark: Let's check for completeness of individual parts:
§5.7 conversions: the part concerning primitives is represented by PrimitiveConversionRoute added in https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2298
Enum PrimitiveConversionRoute
:heavy_check_mark:
Covers all conversions relating to primitives
Computation in Pattern.findPrimitiveConversionRoute()
:heavy_check_mark:
Had 3 TODOs, which I'm fleshing out in my current PR #2878. Note that "a widening reference conversion followed by an unboxing conversion" is more an academic thing, see https://mail.openjdk.org/pipermail/amber-spec-experts/2024-August/004204.html and answers by Brian and Rémi.
Code gen for all conversion routes :heavy_check_mark:
TypePattern.generateTestingConversion()
InstanceOfExpression.generateTypeCheck()
since 7f70a8577247e8095fe83377f0f5c1d18c20d8d2Test coverage :heavy_check_mark: Findings from running all compiler regression tests at compliance 23 with coverage enabled:
InstanceOfExpression.checkRefForPrimitivesAndAddSecretVariable()
turned out to be dead code: called only when the destination type is non-reifiable, but then wants that destination type to be primitive, which can't be.While working on all those type tests and conversions, I repeatedly got entangled in confusing terminology, particularly where the type of a switch selector was named the "expectedType" for each case statement. One such confusion actually surfaced in bogus error messages like this:
final short s = 100;
Integer i1 = ...;
switch (i1) {
case s:
}
ecj reported:
case s:
^
Type mismatch: cannot convert from short to Integer
Nobody has any business converting any short value to Integer. An Integer value is provided and to be matched against (not even converted to) a short value. Taking inspiration from javac I'm correcting the error to
Case constant of type short is incompatible with switch selector type Integer
Much has been argued in this issue and in #2869.
At this point I've run out of obvious things to implement or fix, so let's call victory for now - until playing with the feature will reveal shortcomings, but those will live in their own issues.
Much has been argued in this issue and in #2869.
At this point I've run out of obvious things to implement or fix, so let's call victory for now - until playing with the feature will reveal shortcomings, but those will live in their own issues.
Thanks a lot @stephan-herrmann for stepping in for this issue and also for the exceptionally fast code implementations. [maybe I should fall sick more often :)]. Going through the code and the comments - In case of any (odd) cases found, will raise individual issues.
Mentioning #2891 for the story of nested patterns (primitive type pattern nested in record pattern).
ref: https://openjdk.org/jeps/455
Summary Enhance pattern matching by allowing primitive type patterns in all pattern contexts, and extend instanceof and switch to work with all primitive types.
spec delta: https://cr.openjdk.org/~abimpoudis/instanceof/latest/