Skip to content

Conversation

jishnub
Copy link
Member

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

jishnub and others added 2 commits May 7, 2024 10:41
Annotate `@ccall` macro

Co-authored-by: Shuhei Kadowaki <[email protected]>
Annotate `@ccall` macro in `isuppercase`

Co-authored-by: Shuhei Kadowaki <[email protected]>
@jishnub
Copy link
Member 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
@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 <[email protected]>
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