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

[Feature Request] is_trivial #3581

Open
1 task done
rd4com opened this issue Oct 1, 2024 · 2 comments
Open
1 task done

[Feature Request] is_trivial #3581

rd4com opened this issue Oct 1, 2024 · 2 comments
Labels
enhancement New feature or request mojo-repo Tag all issues with this label

Comments

@rd4com
Copy link
Contributor

rd4com commented Oct 1, 2024

Review Mojo's priorities

What is your request?

It would be nice to have a function that check if an AnyRegType became AnyType:

fn is_trivial[T:AnyTrivialRegType]()->Bool:
    return True
fn is_trivial[T:AnyType]()->Bool:
    return False
 
def main():
    print(is_trivial[Int]()) #not yet

What is your motivation for this change?

To simplify List that currently take 2 parameters: type and is_trivial_hint,

it could also be useful in InlinedFixedVector.__del__ 👍

This can also be used to do perf optimizations in the library (e.g. know whether we can use memcpy instead of copy, etc - see various C++ STL algorithms for inspiration here).

Any other details?

No response

@rd4com rd4com added enhancement New feature or request mojo-repo Tag all issues with this label labels Oct 1, 2024
martinvuyk added a commit to martinvuyk/mojo that referenced this issue Oct 1, 2024
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Copy link
Collaborator

JoeLoser commented Oct 4, 2024

Unfortunately, I don't think it's quite that simple as you've shown in your example. In the compiler, we know if the type is "trivial", but we don't have sufficient information to do this in the library. Reassigning to the compiler team, but do know I requested this a month or two back during Gabriel's string optimization work.

Copy link
Collaborator

JoeLoser commented Oct 4, 2024

Just like all types inherit from AnyType, I think you'd want types (in the stdlib and user defined types) to implicitly conform to Trivial for example based on the triviality bit known in the front end for a given type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants