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

[BUG]: Interpreter crash with UInt8x32 in alias #1602

Closed
lsh opened this issue Jan 6, 2024 · 2 comments
Closed

[BUG]: Interpreter crash with UInt8x32 in alias #1602

lsh opened this issue Jan 6, 2024 · 2 comments
Labels
bug Something isn't working crash mojo Issues that are related to mojo mojo-lang Tag for all issues related to language.

Comments

@lsh
Copy link
Contributor

lsh commented Jan 6, 2024

Bug description

It seems like an alias in a SIMD[DType.uint8, 32] will cause the interpreter to crash on my machine.

Steps to reproduce

fn is_ascii_punctuation(c: Int) -> Bool:
    let c32 = SIMD[DType.uint8, 32].splat(c)
    # replace alias with let and this works correctly
    alias mask = SIMD[DType.uint8, 32](
        ord("!"),
        ord('"'),
        ord("#"),
        ord("$"),
        ord("%"),
        ord("&"),
        ord("'"),
        ord("("),
        ord(")"),
        ord("*"),
        ord("+"),
        ord(","),
        ord("-"),
        ord("."),
        ord("/"),
        ord(":"),
        ord(";"),
        ord("<"),
        ord("="),
        ord(">"),
        ord("?"),
        ord("@"),
        ord("["),
        ord("\\"),
        ord("]"),
        ord("^"),
        ord("_"),
        ord("`"),
        ord("{"),
        ord("|"),
        ord("}"),
        ord("~"),
    )
    return (c32 == mask).reduce_or()

fn main():
    print(is_ascii_punctuation(ord("a")))

outputs

/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/builtin/_startup.mojo:76:1: error: no viable expansions found
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/builtin/_startup.mojo:76:1: note:   call expansion failed - no concrete specializations
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/builtin/_startup.mojo:11:1: note:     no viable expansions found
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/builtin/_startup.mojo:23:14: note:       call expansion failed - no concrete specializations
/Users/$USER/dev/mojo/main.mojo:40:1: note:         no viable expansions found
fn main():
^
/Users/$USER/dev/mojo/main.mojo:41:31: note:           call expansion failed - no concrete specializations
    print(is_ascii_punctuation(ord("a")))
                              ^
/Users/$USER/dev/mojo/main.mojo:2:1: note:             no viable expansions found
fn is_ascii_punctuation(c: Int) -> Bool:
^
/Users/$USER/dev/mojo/main.mojo:4:5: note:               failed to evaluate 'apply'
    alias mask = SIMD[DType.uint8, 32](
    ^
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/builtin/string.mojo:33:1: note:                 interpreter is out of memory!
mojo: error: failed to run the pass manager

System information

- What OS did you do install Mojo on ? MacOS 14
- Provide version information for Mojo by pasting the output of `mojo -v`
mojo 0.6.1 (876ded2e)
- Provide Modular CLI version by pasting the output of `modular -v`
modular 0.3.1 (589ce200)
@lsh lsh added bug Something isn't working mojo Issues that are related to mojo labels Jan 6, 2024
@mikowals
Copy link
Contributor

mikowals commented Jan 6, 2024

I think the bug comes from calling ord on many different strings during compile. Splitting the alias into two SIMD of length 16 still reproduces the bug. The bug disappears by calling ord to get all the Ints outside of the alias declaration.

# works fine
fn is_ascii_punctuation(c: Int) -> Bool:
    alias mask = SIMD[DType.uint8, 32](
        33,
        34,
        35,
        36,
        37,
        38,
        39,
        40,
        41,
        42,
        43,
        44,
        45,
        46,
        47,
        58,
        59,
        60,
        61,
        62,
        63,
        64,
        91,
        92,
        93,
        94,
        95,
        96,
        123,
        124,
        125,
        126,
    )

    return (mask == c).reduce_or()
# this reproduces error
fn is_ascii_punctuation(c: Int) -> Bool:
    alias mask = SIMD[DType.uint8, 16](
        ord("!"),
        ord('"'),
        ord("#"),
        ord("$"),
        ord("%"),
        ord("&"),
        ord("'"),
        ord("("),
        ord(")"),
        ord("*"),
        ord("+"),
        ord(","),
        ord("-"),
        ord("."),
        ord("/"),
        ord(":"),
    )
    alias mask2 = SIMD[DType.uint8, 16](
        ord(";"),
        ord("<"),
        ord("="),
        ord(">"),
        ord("?"),
        ord("@"),
        ord("["),
        ord("\\"),
        ord("]"),
        ord("^"),
        ord("_"),
        ord("`"),
        ord("{"),
        ord("|"),
        ord("}"),
        ord("~"),
    )
    return True

@ematejska ematejska added the mojo-lang Tag for all issues related to language. label Jan 9, 2024
@Mogball
Copy link
Collaborator

Mogball commented Feb 23, 2024

This has been fixed on top-of-tree.

@Mogball Mogball closed this as completed Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash mojo Issues that are related to mojo mojo-lang Tag for all issues related to language.
Projects
None yet
Development

No branches or pull requests

4 participants