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] Count leading zeros can't be used at compile time #3847

Closed
martinvuyk opened this issue Dec 8, 2024 · 1 comment
Closed

[BUG] Count leading zeros can't be used at compile time #3847

martinvuyk opened this issue Dec 8, 2024 · 1 comment
Labels
bug Something isn't working mojo Issues that are related to mojo mojo-repo Tag all issues with this label

Comments

@martinvuyk
Copy link
Contributor

martinvuyk commented Dec 8, 2024

Bug description

Count leading zeros can't be used at compile time. This is actually part of #933. This blocks a lot of other work to fully support unicode due to it needing this function.

part of the error: note: LLVM intrinsic operand has unknown value: #pop<simd 15> : !pop.scalar<ui8>

CC: @lattner

Steps to reproduce

from bit import count_leading_zeros

fn _utf8_first_byte_sequence_length(b: Byte) -> Int:
    """Get the length of the sequence starting with given byte. Do note that
    this does not work correctly if given a continuation byte."""

    debug_assert(
        (b & 0b1100_0000) != 0b1000_0000,
        "Function does not work correctly if given a continuation byte.",
    )
    return int(count_leading_zeros(~b)) + int(b < 0b1000_0000)

fn main():
    print(_utf8_first_byte_sequence_length(ord("a")) == 1)
    print(_utf8_first_byte_sequence_length("🔥".as_bytes()[0]) == 4)
    alias `🔥` = "🔥".as_bytes()[0]
    alias length = _utf8_first_byte_sequence_length(`🔥`)
    print(length == 4)

System information

- Provide version information for Mojo by pasting the output of `mojo -v`
`mojo 24.6.0.dev2024120805`
@martinvuyk martinvuyk added bug Something isn't working mojo-repo Tag all issues with this label labels Dec 8, 2024
@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2025
@martinvuyk
Copy link
Contributor Author

martinvuyk commented Feb 5, 2025

Why would this not be planned? we need Unicode support in StringLiteral. And the StringSlice iterator uses this function, and many other things that users will want to run at compile time.

Unless we get a way to branch when the code is running at compile time, this is needed

PS: I'm not saying I want this tomorrow, but it should be on the roadmap to at least provide alternatives (like a boolean when running code at compile time) for these cases.

@ematejska ematejska added the mojo Issues that are related to mojo label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo Issues that are related to mojo mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants