Skip to content
This repository

Need disambiguation for int literals that can be both native and boxed #8

Closed
moritz opened this Issue December 01, 2011 · 1 comment

2 participants

Moritz Lenz Will Coleda
Moritz Lenz
Owner

Nom currently has a problem which IMHO is in big parts a spec issue. Here it comes.

Since no separate literals for native types are specced, a literal like 123 in is polymorphic in rakudo, and can be used both as Int or int, depending on compile-time context.

Unfortunately that means that an expression like 0x7FFFFFFF * 0x7FFFFFFF will overflow on a machine with 32 bit ints, because the compiler picks the infix:<*>(int, int) candidates, which overflows (as it is allowed to).

I can see several possible solutions:

  • spec some separate way to write int vs. Int literals
  • assume that literals are always Int, and only allow coercion when assigning to an int-typed variable (but would make things like my int $x = 2; $x * 5 less efficient)
  • require constant folding in Int space when operators only operate on literals, and only make the result of the constant folding polymorphic
  • allow the overflow, even if it's suprising to the user.
Will Coleda
Collaborator

Failures from the current situation visible in t/spec/S03-operators/overflow.t using rakudo/nom on feather.

Larry Wall TimToady closed this issue from a commit December 28, 2013
Larry Wall Temp values default to boxed unless 'use native'
Attempt to bring some correctness (with the option for speed) to
the use of builtin operators that might return boxed or unboxed
values.  Also wave hands feebly about native literals.

Attempts to resolve #8.
d519b6f
Larry Wall TimToady closed this in d519b6f December 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.