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] Add split overloads #4015

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

martinvuyk
Copy link
Contributor

Add all split overloads with examples. Part of #3528

cc: @ConnorGray

Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
@ConnorGray
Copy link
Collaborator

This looks fantastic and is much easier to keep all the context in my head, making review snappy. Thank you so much for doing that Martin 😄

Other than a question about method placement, this looks ready to go.

@ConnorGray
Copy link
Collaborator

!sync

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

Hmm, it seems this is running into Mojo compiler assertion failures in CI internally.

I'm able to reproduce a crash using $ mojo package ./stdlib/src/ to build this PR. (Curious that the CI here succeeds? That's odd.). The crash I've been seeing looks like this:

1.  Crash resolving decl body at loc("collections/string/string.mojo":1445:8)
    >>     fn split(self, sep: StringSlice, maxsplit: Int) raises -> List[String]:
              ^...................................................................
    >>         """Split the string by a separator.
    >> 
    >>         Args:
    >>             sep: The string to split on.
2.  Crash parsing statement at loc("collections/string/string.mojo":1466:9)
    >>         return _to_string_list(self.as_string_slice().split(sep, maxsplit))
               ^..................................................................<

Are you able to call these new split() functions in any example programs locally, without running into a compiler crash?

I think this is running into the same parameter inference problem I ran into when I recently did some work on StringSlice.split(), which led me to use the explicit parameters you see in the signature here:

    fn split[
        sep_mut: Bool,
        sep_origin: Origin[sep_mut], //,
    ](
        self,
        sep: StringSlice[sep_origin],
        maxsplit: Int = -1,
    ) raises -> List[
        String
    ]:

I notice that you still change StringSlice.split() to return a List[StringSlice] (spelled as List[Self]) in this PR — I'm fairly certain that's the cause of the crash.

Originally I thought this PR was writing out each of these overloads as a way you found to workaround that crash, but it appears that may not have been the goal?

My best guess is that this issue occurs when something goes wrong inferring origin parameters when StringSlice appears in both as the sep: StringSlice argument and in the return List[StringSlice[..]], but I haven't narrowed down a minimal repro myself.

@martinvuyk martinvuyk requested a review from a team as a code owner February 26, 2025 22:06
@martinvuyk
Copy link
Contributor Author

martinvuyk commented Feb 26, 2025

@ConnorGray I can't repro the crash

I notice that you still change StringSlice.split() to return a List[StringSlice] (spelled as List[Self]) in this PR — I'm fairly certain that's the cause of the crash.

AFAIK the Self type has the origin bound defined and is not the same as some_argument: StringSlice

Originally I thought this PR was writing out each of these overloads as a way you found to workaround that crash, but it appears that may not have been the goal?

I didn't experience any crash 🤷‍♂️ . The List[Self] was mainly because I found List[StringSlice[origin]] verbose and I'm lazy

Could you test it with reverting back to parametrizing the origin?

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants