-
Notifications
You must be signed in to change notification settings - Fork 12
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
function to print StaticString does not compile #65
Comments
At first glance, it looks to me like the code for “message” in f2 probably does not do what it looks like it’s supposed to do, (since comparison operators have very low priority in Julia) and as a result is type-unstable — try instead
```
message = ((n_args == 0) ? c"____0" : (n_args == 1) : c"____1" : c"other")::StaticTools.StaticString{6}
```
If that doesn’t fix it, then I’d try falling back to regular if-else syntax instead of the extended ternary.
… On Dec 3, 2024, at 1:21 PM, sadish ***@***.***> wrote:
The function f1 below compiles but f2 does not.
function f1(n_args::Int64, ::Ptr{Ptr{UInt8}})
message = (n_args == 0 ? c"____0" : c"other")::StaticTools.StaticString{6}
StaticTools.print(message)
return zero(Int64)
end
function f2(n_args::Int64, ::Ptr{Ptr{UInt8}})
message = (n_args == 0 ? c"____0" : n_args == 1 : c"____1" : c"other")::StaticTools.StaticString{6}
StaticTools.print(message)
return zero(Int64)
end
StaticCompiler.compile_executable(f1, (Int64, Ptr{Ptr{UInt8}}), "./")
StaticCompiler.compile_executable(f2, (Int64, Ptr{Ptr{UInt8}}), "./")
versioninfo:
Julia Version 1.10.3
Commit 0b4590a5507 (2024-04-30 10:59 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU: 8 × Apple M1
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
—
Reply to this email directly, view it on GitHub <#65>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ACENNQ44BHPXNNPRSTYX3WD2DXZDLAVCNFSM6AAAAABS6MYCMWVHI2DSMVQWIX3LMV43ASLTON2WKOZSG4YTKNZRGU3DANA>.
You are receiving this because you are subscribed to this thread.
|
I'm not sure that's the issue. function f3(n_args::Int64, ::Ptr{Ptr{UInt8}})
message =
if n_args == 0
c"____0"
elseif n_args == 1
c"____1"
else
c"other"
end::StaticTools.StaticString{6}
StaticTools.print(message)
return zero(Int64)
end
function f4(n_args::Int64, ::Ptr{Ptr{UInt8}})
message = ifelse(n_args == 0, c"____0", ifelse(n_args == 1, c"____1", c"other"))::StaticTools.StaticString{6}
StaticTools.print(message)
return zero(Int64)
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The function
f1
below compiles butf2
does not.versioninfo:
The text was updated successfully, but these errors were encountered: