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

avoid some invalidations from untyped dict code in TOML print #48908

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stdlib/TOML/src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ function print_table(f::MbyFunc, io::IO, a::AbstractDict,
end
if is_table(value)
push!(ks, String(key))
header = isempty(value) || !all(is_tabular(v) for v in values(value))::Bool
_values = @invokelatest values(value)
Copy link
Member

Choose a reason for hiding this comment

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

this feels semantically wrong to me

header = isempty(value) || !all(is_tabular(v) for v in _values)::Bool
Comment on lines +174 to +175
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be:

header = isempty(value) || !(all(is_tabular(v) for v in @invokelatest values(value))::Bool)

?

Copy link
Member

Choose a reason for hiding this comment

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

::Bool seems to be applied to the result of all even as is, so nvm:

julia> code_typed((Any,); optimize=false) do value
           _values = @invokelatest values(value)
           header = isempty(value) || !all(is_tabular(v) for v in _values)::Bool
           header
       end
1-element Vector{Any}:
 CodeInfo(
1 ─       Core.NewvarNode(:(#52))::Any
│         Core.NewvarNode(:(header))::Any
│         (_values = Base.invokelatest(Main.values, value))::Any%4  = Main.isempty(value)::Any
└──       goto #3 if not %4
2 ─       (@_6 = %4)::Any
└──       goto #4
3 ─       (#52 = %new(Main.:(var"#52#54")))::Core.Const(var"#52#54"())%9  = #52::Core.Const(var"#52#54"())%10 = Base.Generator(%9, _values)::Base.Generator{_A, var"#52#54"} where _A
│   %11 = Main.all(%10)::Union{Missing, Bool}%12 = Core.typeassert(%11, Main.Bool)::Bool
└──       (@_6 = !%12)::Bool
4 ┄       (header = @_6)::Any
└──       return header
) => Any

if header
# print table
first_block || println(io)
Expand Down