modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.15k stars 2.59k forks source link

[BUG]: to_int() not working with SIMD parameter #1315

Closed helehex closed 1 week ago

helehex commented 11 months ago

Bug description

This works for FloatLiteral, but not for any SIMD.

Steps to reproduce

fn main():
    let myint  : MyInt[1] = MyInt[1](6)
    let myfloat: MyFloat[1] = MyFloat[1](myint) # this works
    let mysimd : MyInt64[1] = MyInt64[1](myint) # this doesnt

@value
struct MyInt[param: Int]:
    var value: Int

struct MyFloat[param: FloatLiteral]:
    var value: FloatLiteral
    fn __init__(inout self, other: MyInt[param.to_int()]):
        self.value = other.value

struct MyInt64[param: Int64]:
    var value: Int64
    fn __init__(inout self, other: MyInt[param.to_int()]):
        self.value = other.value

System information

Host Information
  ================

  Target Triple: x86_64-unknown-linux
  CPU: skylake
  CPU Features: 64bit, adx, aes, avx, avx2, bmi, bmi2, clflushopt, cmov, crc32, cx16, cx8, f16c, fma, fsgsbase, fxsr, invpcid, lzcnt, mmx, movbe, pclmul, popcnt, prfchw, rdrnd, rdseed, rtm, sahf, sgx, sse, sse2, sse3, sse4.1, sse4.2, ssse3, x87, xsave, xsavec, xsaveopt, xsaves

mojo 0.5.0 (6e50a738)

modular 0.2.2 (95d42445)
soraros commented 11 months ago

It's not exclusive to to_int. Many other methods on SIMD don't work in parameter context as well.

JoeLoser commented 4 months ago

Repros with

fn main():
    let myint  : MyInt[1] = MyInt[1](6)
    let myfloat: MyFloat[1] = MyFloat[1](myint) # this works
    let mysimd : MyInt64[1] = MyInt64[1](myint) # this doesnt

@value
struct MyInt[param: Int]:
    var value: Int

struct MyFloat[param: FloatLiteral]:
    var value: FloatLiteral
    fn __init__(inout self, other: MyInt[int(param)]):
        self.value = other.value

struct MyInt64[param: Int64]:
    var value: Int64
    fn __init__(inout self, other: MyInt[int(param)]):
        self.value = other.value

now since to_int got removed in favor of int(…).

helehex commented 3 months ago
fn main():
    alias param = Float64(1)
    var myint = MyInt[int(param)](6)
    var myf64 = MyFloat64[param](myint)
    print(myf64.value)
    # prints: '6'

@value
struct MyInt[param: Int]:
    var value: Int

struct MyFloat64[param: Float64]:
    var value: Float64
    fn __init__(inout self, other: MyInt[int(param)]):
        self.value = other.value

Reusing an alias value like this can work

helehex commented 1 week ago

The reproduction is getting very outdated (wasn't very good to begin with), but everything seems to work now so I'm closing this.