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

getfield codegen for unknown symbol cannot handle tuple inputs #51233

Closed
maleadt opened this issue Sep 7, 2023 · 0 comments · Fixed by #51234
Closed

getfield codegen for unknown symbol cannot handle tuple inputs #51233

maleadt opened this issue Sep 7, 2023 · 0 comments · Fixed by #51234
Assignees
Labels
compiler:codegen Generation of LLVM IR and native code kind:bug Indicates an unexpected problem or unintended behavior

Comments

@maleadt
Copy link
Member

maleadt commented Sep 7, 2023

MWE:

julia> x = (1,)
(1,)

julia> x.x
julia: /home/tim/Julia/src/julia/src/codegen.cpp:3882: bool emit_builtin_call(jl_codectx_t&, jl_cgval_t*, jl_value_t*, const jl_cgval_t*, size_t, jl_value_t*, jl_expr_t*, bool): Assertion `jl_svec_len(fn) == 1' failed.

[3543259] signal (6.-6): Aborted
in expression starting at REPL[2]:1
unknown function (ip: 0x7f865388e83c)
raise at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x7f86538263db)
__assert_fail at /usr/lib/libc.so.6 (unknown line)
emit_builtin_call at /home/tim/Julia/src/julia/src/codegen.cpp:3882
emit_call at /home/tim/Julia/src/julia/src/codegen.cpp:4650
emit_expr at /home/tim/Julia/src/julia/src/codegen.cpp:5572
emit_ssaval_assign at /home/tim/Julia/src/julia/src/codegen.cpp:5162
emit_function at /home/tim/Julia/src/julia/src/codegen.cpp:8517

Looks like the code assumes that the length of jl_field_names equals jl_datatype_nfields, which doesn't hold here: For Tuple{Int}, jl_datatype_nfields (or t->layout->nfields) is 1, while jl_field_names (or t->name->names) returns an empty svec. I guess that's why we specialize Tuple here:

julia/base/reflection.jl

Lines 167 to 172 in 27fa5de

fieldnames(t::DataType) = (fieldcount(t); # error check to make sure type is specific enough
(_fieldnames(t)...,))::Tuple{Vararg{Symbol}}
fieldnames(t::UnionAll) = fieldnames(unwrap_unionall(t))
fieldnames(::Core.TypeofBottom) =
throw(ArgumentError("The empty type does not have field names since it does not have instances."))
fieldnames(t::Type{<:Tuple}) = ntuple(identity, fieldcount(t))

@maleadt maleadt added kind:bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code labels Sep 7, 2023
@maleadt maleadt self-assigned this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant