Generate compilable code for non-finite floating-point values#36965
Generate compilable code for non-finite floating-point values#36965junhyeong9812 wants to merge 1 commit into
Conversation
PrimitiveDelegate generated code via "$LF" for Float and "(double) $L" for Double, which emit the value's toString() verbatim. For NaN and infinities this produced non-compilable source such as "NaNF" or "(double) Infinity", causing the generated AOT sources to fail to compile. Detect NaN (via isNaN, since NaN is never equal to itself) and the positive/negative infinities, emitting the corresponding constant field references (Float.NaN, Double.POSITIVE_INFINITY, etc.) through the "$T" placeholder. Finite values keep their existing handling. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
4bac16c to
a30836e
Compare
|
The Could the build be re-run when convenient? Happy to rebase or adjust if anything else is needed. |
|
For reference, a closer look at the unrelated CI failure ( The assertion expects
So the cancellation path is reached only when This looks like a pre-existing timing sensitivity in the test rather than anything related to this change; the test passes locally on a clean run. I could not find an existing tracked issue for it. I have intentionally kept it out of this PR to stay focused, but I am happy to open a separate issue (or look into a fix) if that would be useful. |
|
@junhyeong9812 I've started a new run for the workflow. If you've got some spare cycles, we'd love to get a separate contribution to fix that flaky test. Cheers! |
Overview
The AOT
ValueCodeGeneratoremitted non-compilable Java for non-finiteFloatandDoublevalues (NaN, positive and negative infinity), so any bean property or constructor argument holding such a value broke compilation of the generated AOT sources. This change emits proper constant field references instead.Problem
PrimitiveDelegaterendered floats viaCodeBlock.of("$LF", value)and doubles viaCodeBlock.of("(double) $L", value). Since$Lemits the value'stoString()verbatim, the non-finite values became invalid source:Float.NaNNaNFFloat.POSITIVE_INFINITYInfinityFDouble.NaN(double) NaNDouble.POSITIVE_INFINITY(double) InfinityFix
Detect
NaNwithisNaN()(becauseNaN == NaNis alwaysfalse) and the infinities with==, emitting the corresponding constant field references through the$Tplaceholder (Float.NaN,Double.POSITIVE_INFINITY, and so on), which are valid compile-time constants. Finite values keep their existing handling, so normal numbers are unaffected. Tests coveringFloat/Double× {NaN,+Infinity,-Infinity} are added toValueCodeGeneratorTests.