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] Optional start and length arg for String._strref_dangerous #2719

Open
wants to merge 16 commits into
base: nightly
Choose a base branch
from

Conversation

fknfilewalker
Copy link

@fknfilewalker fknfilewalker commented May 17, 2024

Normally when one wants to create a truncated StringRef, a ptr to the String together with offsets need to be used. This is annoying and dangerous and could be done more safely during the _strref_dangerous call. This also adds bound guards

Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
@fknfilewalker fknfilewalker requested a review from a team as a code owner May 17, 2024 19:02
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
Copy link
Contributor

@laszlokindrat laszlokindrat left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! @JoeLoser Do you have thoughts on this?

stdlib/src/builtin/string.mojo Outdated Show resolved Hide resolved
@laszlokindrat laszlokindrat self-assigned this May 18, 2024
fknfilewalker and others added 5 commits May 18, 2024 10:33
Co-authored-by: Laszlo Kindrat <laszlokindrat@gmail.com>
Signed-off-by: Lukas Lipp <15105596+fknfilewalker@users.noreply.github.com>
Signed-off-by: Lukas Lipp <15105596+fknfilewalker@users.noreply.github.com>
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
@fknfilewalker fknfilewalker requested a review from a team as a code owner May 18, 2024 09:19
fknfilewalker and others added 4 commits May 18, 2024 11:43
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
Signed-off-by: Lukas Lipp <15105596+fknfilewalker@users.noreply.github.com>
Signed-off-by: Lukas Lipp <15105596+fknfilewalker@users.noreply.github.com>
@JoeLoser
Copy link
Collaborator

Thanks for the patch! @JoeLoser Do you have thoughts on this?

In general, use of _strref_dangerous and friends will go away in favor of some of the StringSlice (safe string slice) work going on internally, right? I need to look closer at it before I can give a good review here.

@laszlokindrat
Copy link
Contributor

Thanks for the patch! @JoeLoser Do you have thoughts on this?

In general, use of _strref_dangerous and friends will go away in favor of some of the StringSlice (safe string slice) work going on internally, right? I need to look closer at it before I can give a good review here.

Yeah, although I think this could be useful in the meanwhile, and low risk since it's a hidden API anyway.

@fknfilewalker Could you please rebase after the next nightly, and change this patch to update the potential uses in https://github.com/modularml/mojo/pull/2710 and maybe other places? That would give us a definitive picture of how much this actually helps.

Signed-off-by: Lukas Lipp <15105596+fknfilewalker@users.noreply.github.com>
Copy link
Contributor

@laszlokindrat laszlokindrat left a comment

Choose a reason for hiding this comment

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

Thank you! I have a few more requests, but LGTM otherwise!

stdlib/src/builtin/string.mojo Outdated Show resolved Hide resolved
stdlib/src/builtin/string.mojo Outdated Show resolved Hide resolved
docs/changelog.md Outdated Show resolved Hide resolved
fknfilewalker and others added 3 commits May 26, 2024 14:57
Signed-off-by: Lukas Lipp <15105596+fknfilewalker@users.noreply.github.com>
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
@laszlokindrat
Copy link
Contributor

Also, can you please update String.{end,start}swith (and any other places you're aware of) to use these?

Signed-off-by: Lukas Lipp <llipp@cg.tuwien.ac.at>
@fknfilewalker
Copy link
Author

fknfilewalker commented May 26, 2024

Also, can you please update String.{end,start}swith (and any other places you're aware of) to use these?

For now I only checked string.mojo and there are not many places where it is really helpful and since you want to replace it with StringSlice anyway maybe we should just drop this?

@laszlokindrat
Copy link
Contributor

Is it really only one place where it's useful? I would have expected more. If you find one or two more places, I think we should land it, otherwise you're probably right, it's not pulling its weight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants