Skip to content

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

moritz opened this Issue Dec 1, 2011 · 1 comment

2 participants

Perl 6 member
moritz commented Dec 1, 2011

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.
coke commented Dec 1, 2011

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

@TimToady TimToady added a commit that closed this issue Dec 29, 2013
@TimToady TimToady 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.
@TimToady TimToady closed this in d519b6f Dec 29, 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.