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

Assume :foldable in isuppercase/islowercase for Char #54346

Merged
merged 4 commits into from
May 7, 2024

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented May 3, 2024

With this, isuppercase/islowercase are evaluated at compile-time for Char arguments:

julia> @code_typed (() -> isuppercase('A'))()
CodeInfo(
1return true
) => Bool

julia> @code_typed (() -> islowercase('A'))()
CodeInfo(
1return false
) => Bool

This would be useful in #54303, where the case of the character indicates which triangular half of a matrix is filled, and may be constant-propagated downstream.

@Seelengrab Seelengrab added the compiler:effects effect analysis label May 4, 2024
base/strings/unicode.jl Outdated Show resolved Hide resolved
Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

base/strings/unicode.jl Outdated Show resolved Hide resolved
base/strings/unicode.jl Outdated Show resolved Hide resolved
base/strings/unicode.jl Outdated Show resolved Hide resolved
jishnub and others added 2 commits May 7, 2024 10:41
Annotate `@ccall` macro

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
Annotate `@ccall` macro in `isuppercase`

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
@jishnub
Copy link
Contributor Author

jishnub commented May 7, 2024

Should similar changes me made elsewhere as well, e.g. in category_code? That would let other functions such as isletter be evaluated at compile time.

@aviatesk
Copy link
Member

aviatesk commented May 7, 2024

If you're motivated, that would be helpful. Having said that I don't believe it's necessary for merging this PR.

@KristofferC KristofferC merged commit d2399e6 into master May 7, 2024
7 checks passed
@KristofferC KristofferC deleted the jishnub/isupperlowercase branch May 7, 2024 09:08
aviatesk pushed a commit that referenced this pull request May 8, 2024
Following on from #54346, this
marks the `ccall` in `category_code` as foldable. This lets us compute
the results of several functions at compile time, such as:
```julia
julia> @code_typed (() -> isletter('C'))()
CodeInfo(
1 ─     return true
) => Bool

julia> @code_typed (() -> isnumeric('C'))()
CodeInfo(
1 ─     return false
) => Bool

julia> @code_typed (() -> ispunct('C'))()
CodeInfo(
1 ─     return false
) => Bool
```
xlxs4 pushed a commit to xlxs4/julia that referenced this pull request May 9, 2024
Following on from JuliaLang#54346, this
marks the `ccall` in `category_code` as foldable. This lets us compute
the results of several functions at compile time, such as:
```julia
julia> @code_typed (() -> isletter('C'))()
CodeInfo(
1 ─     return true
) => Bool

julia> @code_typed (() -> isnumeric('C'))()
CodeInfo(
1 ─     return false
) => Bool

julia> @code_typed (() -> ispunct('C'))()
CodeInfo(
1 ─     return false
) => Bool
```
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Jul 12, 2024
…ng#54346)

With this, `isuppercase`/`islowercase` are evaluated at compile-time for
`Char` arguments:
```julia
julia> @code_typed (() -> isuppercase('A'))()
CodeInfo(
1 ─     return true
) => Bool

julia> @code_typed (() -> islowercase('A'))()
CodeInfo(
1 ─     return false
) => Bool
```
This would be useful in JuliaLang#54303,
where the case of the character indicates which triangular half of a
matrix is filled, and may be constant-propagated downstream.

---------

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Jul 12, 2024
Following on from JuliaLang#54346, this
marks the `ccall` in `category_code` as foldable. This lets us compute
the results of several functions at compile time, such as:
```julia
julia> @code_typed (() -> isletter('C'))()
CodeInfo(
1 ─     return true
) => Bool

julia> @code_typed (() -> isnumeric('C'))()
CodeInfo(
1 ─     return false
) => Bool

julia> @code_typed (() -> ispunct('C'))()
CodeInfo(
1 ─     return false
) => Bool
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:effects effect analysis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants