PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

Literals with precision cannot be used to create a Literal

Open hiker opened this issue 2 years ago • 2 comments

Passing 1.0_r_def as name to the Literal constructor aborts (since the string does not match the regular expression).

    _real_value = r'^[+-]?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?$'

For now I remove _r_def at the end of a real literal, and _i_def at the end of an integer literal, but that does not seem to be the best solution.

hiker avatar Oct 17 '22 05:10 hiker

Note that the above solution is wrong and an obvious bad work around, since different precisions could be used, which will still cause an exception. Plus the existing code in #1883, scalar() hard-codes the precision to be i_def or r_def, so care must be taken if there is a precision specified, to declare the literals appropriately.

hiker avatar Oct 17 '22 07:10 hiker

The locations mentioned in #1920 are also useful here - at this stage the tree is still intact and has precision split into a separate element, which is only then combined back into a single string.

hiker avatar Oct 17 '22 12:10 hiker

Unless I'm missing something, the precision should become part of the datatype that is provided to the Literal constructor?

arporter avatar Nov 01 '22 08:11 arporter

Can this be closed now? Ultimately, we will use PSyIR for the Algorithm layer which will then remove this problem altogether as the kernel argument list will all be in PSyIR.

arporter avatar Nov 15 '22 11:11 arporter

OK, I've followed the suggested way of using psyir_from_expression, and this avoids the problem, so I'm ok with closing this.

hiker avatar Nov 16 '22 23:11 hiker