-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[mojo-compiler] CompTime interpreter should be able to fold pop.call_llvm_intrinsic
#933
Comments
Thanks for filing! We haven't implemented compile-time interpretation of LLVM intrinsics, and it's not clear that's a worthwhile endeavor. That said, there are other ways we can make this work. |
@Mogball Regardless of how the internal works, I'd still expect this code to run. Because from a users perspective, I was trying to implement |
A decorator would be useful from a library design perspective to clearly communicate to users what functions are not intended to run at compile time. However, the language can't rely on library authors always being meticulous with using the decorator, which is why it provides a detailed, if cryptic, error message. I do agree that the category of functions in |
FYI: There is an
|
@abduld Thanks for the pointer. I'm familiar with this implementation yet didn't know the existence of this function in the stdlib. |
math.bit
functions doesn't run at compile timepop.call_llvm_intrinsic
I've renamed this issue to track the general problem from my observations this past week. From our internal Mojo discussion on this yesterday, we do want to implement support for this (folding Some notes I'll share from our internal discussion:
The big issue is probably plumbing (4) correctly from the list above. |
We can inject fold/interpret hooks into the LLVMDialect. We're not bound by upstream in this regard. I suspect there will be resistance to adding intrinsics folders upstream anyways. |
Signed-off-by: martinvuyk <[email protected]>
@JoeLoser, somehow, above's code seems to be working now. I've tested it, and it worked:
Note: this is the code adapted from the description based on some However, I'm not sure if the bug is fixed. |
@msaelices I think it's because it's being eliminated as dead code. This still fails: fn main():
alias n = count_leading_zeros(10)
print(n) |
@lattner ping on this issue since you asked :) |
Awesome, I put together a fix, I'll discuss with the team tomorrow and see if they like it. |
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes #933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17 Signed-off-by: Manuel Saelices <[email protected]>
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17 Signed-off-by: Derek Smith <[email protected]>
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17 Signed-off-by: Derek Smith <[email protected]>
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17 Signed-off-by: Derek Smith <[email protected]>
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17 Signed-off-by: Derek Smith <[email protected]>
This teaches the mojo comptime interpreter about LLVM intrinsics, at least for simple cases involving integer operands and results (it would be straightforward to extend this to other types now). This fixes modularml#933 and Fixes MOCO-138 and Fixes MOCO-504 MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17 Signed-off-by: Derek Smith <[email protected]>
Bug description
math.bit
functions doesn't run at compile time.Steps to reproduce
Consider the following code:
It produces the following error message:
System information
The text was updated successfully, but these errors were encountered: