Skip to content

Conversation

@soraros
Copy link
Contributor

@soraros soraros commented Apr 14, 2025

So the following works without rebind:

var v: UInt8 = pack_bits(SIMD[DType.bool, 8](1))

_uint gets inlined even when n isn't concrete, cluttering tooltips and types.
Can call-by-value be triggered only when n is concrete?

CC @lattner since it's related to @always_inline("builtin").

@soraros soraros requested a review from a team as a code owner April 14, 2025 10:23
return DType.uint64
# fmt: off
return (
DType.uint8 if n == 8
Copy link
Contributor Author

@soraros soraros Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the if expression since hlcf.if is not supported in builtin.

@soraros soraros force-pushed the pack-bits-simplify branch from 7069a15 to 103f2d7 Compare April 14, 2025 10:51
Signed-off-by: Yiwu Chen <210at85@gmail.com>
@soraros soraros force-pushed the pack-bits-simplify branch from 103f2d7 to 136ec29 Compare April 15, 2025 16:12
@JoeLoser
Copy link
Collaborator

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Apr 18, 2025
@modularbot
Copy link
Collaborator

✅🟣 This contribution has been merged 🟣✅

Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the main branch during the next Mojo nightly release, typically within the next 24-48 hours.

We use Copybara to merge external contributions, click here to learn more.

@modularbot modularbot added merged-internally Indicates that this pull request has been merged internally merged-externally Merged externally in public mojo repo labels Apr 18, 2025
@modularbot
Copy link
Collaborator

Landed in a638dc7! Thank you for your contribution 🎉

@soraros soraros deleted the pack-bits-simplify branch April 20, 2025 02:03
@lattner
Copy link
Collaborator

lattner commented Apr 21, 2025

Thanks @soraros . Just catching up: the point of always_inline(builtin) isn't to inline everything that "could be constant folded". It is really about things that are necessary to use in dependent types. There is longer term work to improve the Mojo intepreter that may make it more powerful - this will be useful for this sort of thing as well as for requires clauses - but the parser-time interpreter will always be limited to not knowing about the target (e.g. pointer sizes) so it will be inherently limited in what it can do.

modularbot pushed a commit that referenced this pull request May 6, 2025
[External] [stdlib] Improve type refinement for `pack_bits`

So the following works without `rebind`:
```mojo
var v: UInt8 = pack_bits(SIMD[DType.bool, 8](1))
```

`_uint` gets inlined even when `n` isn't concrete, cluttering tooltips
and types.
Can call-by-value be triggered only when `n` is concrete?

CC @lattner since it's related to `@always_inline("builtin")`.

Co-authored-by: soraros <soraros@users.noreply.github.com>
Closes #4345
MODULAR_ORIG_COMMIT_REV_ID: e5fea6172778283a2b9cb7999e82702f2da8ba1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imported-internally Signals that a given pull request has been imported internally. merged-externally Merged externally in public mojo repo merged-internally Indicates that this pull request has been merged internally

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants