Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast error ? #8268

Closed
hutou opened this issue Oct 4, 2019 · 7 comments
Closed

Cast error ? #8268

hutou opened this issue Oct 4, 2019 · 7 comments

Comments

@hutou
Copy link
Contributor

hutou commented Oct 4, 2019

Given the following code :

alias CellType = Bool | Char | Int::Signed | Int::Unsigned | Float32 | Float64 | String | Symbol
x = 7.as(CellType)
y = x.as(Number)
puts typeof(y)
puts y * 2

displayed results are :

(Float32 | Float64 | Int128 | Int16 | Int32 | Int64 | Int8 | UInt128 | UInt16 | UInt32 | UInt64 | UInt8)
14

But if I try to multiply y with any other value than 2, for example
puts y * 3
I get :

/usr/bin/ld: _main.o: in function `__crystal_main':
./eval:4: undefined reference to `__muloti4'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/home/crystal/.cache/crystal/crystal-run-eval.tmp'  -rdynamic  -lpcre -lm -lgc -lpthread /usr/lib/crystal/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

This error appears from the 0.31 release

@oprypin
Copy link
Member

oprypin commented Oct 4, 2019

Yep, this is real
https://carc.in/#/r/7ozm

@bcardiff
Copy link
Member

bcardiff commented Oct 4, 2019

@hutou can you describe your environment? arch/distro

The issue is related to the partial Int128 bits support?

As a workaround, you should be able to

alias CellType = Float32 | Float64 | Int16 | Int32 | Int64 | Int8 | UInt16 | UInt32 | UInt64 | UInt8
x = 7.as(CellType)
y = x.as(Number)
puts typeof(y)
puts y * 2
puts y * 3

Might be fixed after #7093

@oprypin
Copy link
Member

oprypin commented Oct 4, 2019

@bcardiff it also happens on carc.in!
That's probably Arch Linux

@hutou
Copy link
Contributor Author

hutou commented Oct 4, 2019

@bcardiff Environment is : Gnome 3.34.0 on Archlinux (5.3.1-arch1-1-ARCH - x86_64)
As you suggest, removing UInt128 and Int128 from CellType solves the problem

@RX14
Copy link
Contributor

RX14 commented Oct 6, 2019

y * 2 will be optimized to a shift, avoiding the muloti4 call. This is just about compiler-rt.

@jhass
Copy link
Member

jhass commented Mar 17, 2020

So is this something we need to fix in Archlinux packaging or in the compiler?

@straight-shoota
Copy link
Member

straight-shoota commented Apr 25, 2021

The reproduction is trivial: 1.to_i128 * 3. The missing symbol muloti4 is supposed to implement multiplication of 128-bit integers in compiler-rt.

We're just missing support for 128-bit arithmetics and the Int::Signed and Int::Unsigned unions include Int128 and UInt128 types. This is just a duplicate of #8373.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants