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

with_ascii_lowercased zig builtin #7496

Merged
merged 5 commits into from
Jan 20, 2025

Conversation

HajagosNorbert
Copy link
Collaborator

Please, before you approve, check out the zig code changes, since I'm unsure about handling reference counts. Tests were passing whether I put a referece count decrement statement in the with_ascii_lowercased function or not for the non-unique strings branch, so the string.decref(); is in there quiet arbitrarily.

initFromBigStr isn't used anywhere, so I deleted it.

The test with_ascii_lowercased_non_zero_refcounttest in crates/compiler/test_gen/src/gen_str.rs is an attempt at testing the function when the refcount of it's input string is > 1, but I'm not sure if that's what it does actually.

@HajagosNorbert
Copy link
Collaborator Author

CI was failing on the roc formatter check and on the use of camelCased Str.dropPrefix in one of the test.
I don't know why the macos-apple-silicon job ran from > 1h.

@Anton-4 Anton-4 self-assigned this Jan 18, 2025
@Anton-4
Copy link
Collaborator

Anton-4 commented Jan 18, 2025

This is the same issue as in #7514, I'll be looking at it today

@HajagosNorbert
Copy link
Collaborator Author

This is the same issue as in #7514, I'll be looking at it today

Thanks Anton!

Anton-4 added a commit that referenced this pull request Jan 18, 2025
@Anton-4 Anton-4 mentioned this pull request Jan 18, 2025
Copy link
Collaborator

@smores56 smores56 left a comment

Choose a reason for hiding this comment

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

Generally looks good, just a couple comments

## expect "CAFÉ".with_ascii_lowercased() == "cafÉ"
## ```
##
## This function is useful for things like [command-line options](https://en.wikipedia.org/wiki/Command-line_interface#Command-line_option) and [environment variables](https://en.wikipedia.org/wiki/Environment_variablewhere you ## know in advance that you're dealing with a hardcoded string containing only ASCII characters. It has better performance than lowercasing operations which take Unicode into account.
Copy link
Collaborator

Choose a reason for hiding this comment

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

These comments are missing some newlines.

assert_evals_to!(
r#"
original = "cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ"
res = Str.with_ascii_lowercased original
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using PNC instead of WSA to avoid needing to update these tests in the near future

@@ -374,7 +375,12 @@ pub const RocStr = extern struct {
return 1;
}

const ptr: [*]usize = @as([*]usize, @ptrCast(@alignCast(self.bytes)));
const data_ptr = if (self.isSeamlessSlice())
Copy link
Collaborator

Choose a reason for hiding this comment

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

We check self.isSeamlessSlice() twice in this function. It's not an expensive operation per se, but it's multiple operations. Can we maybe avoid checking it multiple times by storing in a var or something?

@Anton-4
Copy link
Collaborator

Anton-4 commented Jan 20, 2025

@HajagosNorbert to get the fix from PR #7532 you just need to pull main, execute the mono tests and git add -u them.

@HajagosNorbert
Copy link
Collaborator Author

Thanks @Anton-4, I'm waiting for all the tests to pass locally, after including the changes from Sam's review.

@HajagosNorbert
Copy link
Collaborator Author

Thanks for the review @smores56! Everything's in for the PR @Anton-4, can you kick off CI?

Copy link
Collaborator

@smores56 smores56 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 change!

@smores56 smores56 enabled auto-merge January 20, 2025 10:44
@smores56 smores56 merged commit 255a388 into roc-lang:main Jan 20, 2025
19 checks passed
@HajagosNorbert HajagosNorbert deleted the ascii-builtins branch January 20, 2025 12:31
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.

3 participants