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

[stdlib] Audit uses of StaticIntTuple #2515

Open
JoeLoser opened this issue May 4, 2024 · 8 comments
Open

[stdlib] Audit uses of StaticIntTuple #2515

JoeLoser opened this issue May 4, 2024 · 8 comments
Labels
good first issue Good for newcomers mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library refactoring Refactoring/clean up of code

Comments

@JoeLoser
Copy link
Collaborator

JoeLoser commented May 4, 2024

Similar in spirit to #2514, it would be nice to audit our use of StaticIntTuple in the standard library which is a mix of InlineArray[Int, size] with some odd APIs that make it represents dimensions or tuple-like things.

Where it makes sense, it would be good to simplify APIs to not be coupled to this unique/non-generic type. For example, this Int._divmod function should just return a Tuple[Int, Int] instead of using this unique type. There's no reason to prefer StaticIntTuple[2] over Tuple[Int, Int] here.

Feel free to ask questions about specific APIs if you're not sure whether to change it or not.

@JoeLoser JoeLoser added good first issue Good for newcomers mojo-stdlib Tag for issues related to standard library refactoring Refactoring/clean up of code labels May 4, 2024
@YichengDWu
Copy link
Contributor

I propose to use 'NTuple[2, Int]' as the type alias for 'Tuple[Int, Int]', and 'NTuple[N, T]' in general, so that it can be easily dispatch on 'N'.

@JoeLoser
Copy link
Collaborator Author

JoeLoser commented May 5, 2024

I propose to use 'NTuple[2, Int]' as the type alias for 'Tuple[Int, Int]', and 'NTuple[N, T]' in general, so that it can be easily dispatch on 'N'.

Can you elaborate on the value of the type alias? I'm not sure I understand the full value yet. Are there places you have in mind in the library that would benefit from this?

@YichengDWu
Copy link
Contributor

NTuple[2, Int] = Tuple[Int, Int]
NTuple[3, Int] = Tuple[Int, Int, Int]

Or In general I should be able to write

alias NTuple[N, T] = Tuple[VariadicPack[T, N]]

Then I can dispatch on NTuple[5,Int] instead of Tuple[Int, Int, Int, Int ,Int], it's just shorter.

@artemiogr97
Copy link
Contributor

@JoeLoser while working on this I found a potential issue, StaticIntTuple is imported in builtin/int.mojo which exposes it everywhere as all builtins, is exposing stuff in this way intentional?

@gabrieldemarmiesse
Copy link
Contributor

gabrieldemarmiesse commented May 5, 2024

@JoeLoser while working on this I found a potential issue, StaticIntTuple is imported in builtin/int.mojo which exposes it everywhere as all builtins, is exposing stuff in this way intentional?

Maybe we should open an issue to have a new mechanism in the stdlib to define what exactly does not need import and what needs imports.

This issue has bitten me quite a few times.

EDIT: Created the issue and proposed a fix that must be implemented partly on the compiler side:

@artemiogr97
Copy link
Contributor

Seems like StaticIntTuple is used a lot in the tests, for those cases it should be possible to replace it once Tuple conforms to the Stringable trait

@msaelices
Copy link

Off-topic: Why _divmod instead of the Python __divmod__?

@gabrieldemarmiesse
Copy link
Contributor

@msaelices it's ongoing changes, you can take a look at #2335

@ematejska ematejska added mojo-repo Tag all issues with this label and removed mojo-stdlib Tag for issues related to standard library labels May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 7, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library refactoring Refactoring/clean up of code
Projects
None yet
Development

No branches or pull requests

6 participants