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

Testing unstable ssa values useref values in red #55435

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

joseeloren
Copy link

@joseeloren joseeloren commented Aug 9, 2024

I have made some tests to check if unstable ssa values useref values are in red. This address issue #54028 PRs: #54501 and #54441. The last one is #54501, that is waiting for these tests.

@gbaraldi

arhik and others added 16 commits May 28, 2024 16:31
This is partial commit which passes unstable_ssa statements to `show_ir_stmts`.
Central Idea is to show/print type unstable ssa userefs in IR statements in color. To achieve that we need to modify following code segments.
[*] determine unstable_ssa
[*] pass unstable_ssa to `show_ir_stmts`.
[ ] pass unstable_ssa to `show_ir_stmt`.
[ ] pass unstable_ssa to `print_stmt`
[ ] pass unstable_ssa to `show_unquoted`

This PR covers second task alone
This is partial commit which passes unstable_ssa statements to `show_ir_stmts`.
Central Idea is to show/print type unstable ssa userefs in IR statements in color. To achieve that we need to modify following code segments.
[*] determine unstable_ssa
[*] pass unstable_ssa to `show_ir_stmts`.
[*] pass unstable_ssa to `show_ir_stmt`.
[ ] pass unstable_ssa to `print_stmt`
[ ] pass unstable_ssa to `show_unquoted`

This PR covers third task alone
This is partial commit which passes unstable_ssa statements to `show_ir_stmts`.
Central Idea is to show/print type unstable ssa userefs in IR statements in color. To achieve that we need to modify following code segments.
[*] determine unstable_ssa
[*] pass unstable_ssa to `show_ir_stmts`.
[*] pass unstable_ssa to `show_ir_stmt`.
[*] pass unstable_ssa to `print_stmt`
[ ] pass unstable_ssa to `show_unquoted`

This PR covers fourth task alone
This is partial commit which passes unstable_ssa statements to `show_ir_stmts`.
Central Idea is to show/print type unstable ssa userefs in IR statements in color. To achieve that we need to modify following code segments.
[*] determine unstable_ssa
[*] pass unstable_ssa to `show_ir_stmts`.
[*] pass unstable_ssa to `show_ir_stmt`.
[*] pass unstable_ssa to `print_stmt`
[*] pass unstable_ssa to `show_unquoted`

This PR covers finished basic pipeline. Other ssa values appearing in nodes like `return` etc can be easily provided now.
ops like `x + y` are covered.
pass unstable_ssa to show_unquoted

This is partial commit which passes unstable_ssa statements to `show_ir_stmts`.
Central Idea is to show/print type unstable ssa userefs in IR statements in color. To achieve that we need to modify following code segments.
[*] determine unstable_ssa
[*] pass unstable_ssa to `show_ir_stmts`.
[*] pass unstable_ssa to `show_ir_stmt`.
[*] pass unstable_ssa to `print_stmt`
[*] pass unstable_ssa to `show_unquoted`

This PR covers finished basic pipeline. Other ssa values appearing in nodes like `return` etc can be easily provided now.

unstable_ssa as optional in `show_unquoted`

unstable ssa should be highlighted only when appropriate
… tests for unstable SSA values useref values in red
@joseeloren
Copy link
Author

@gbaraldi @Zentrik @fingolfin

@gbaraldi
Copy link
Member

gbaraldi commented Aug 15, 2024

I think it's almost there but looking at it in my terminal it seems we are printing the SSA values in a slightly different colour
image I believe it should use :light_redand also bold. Following emphasize thats used in

function warntype_type_printer(io::IO; @nospecialize(type), used::Bool, show_type::Bool=true, _...)
(show_type && used) || return nothing
str = "::$type"
if !highlighting[:warntype]
print(io, str)
elseif type isa Union && is_expected_union(type)
Base.emphasize(io, str, Base.warn_color()) # more mild user notification
elseif type isa Type && (!Base.isdispatchelem(type) || type == Core.Box)
Base.emphasize(io, str)
else
Base.printstyled(io, str, color=:cyan) # show the "good" type
end
return nothing
end

@joseeloren
Copy link
Author

You are right @gbaraldi Fixed.

base/show.jl Outdated Show resolved Hide resolved
@joseeloren joseeloren requested a review from lgoettgens August 19, 2024 08:48
Copy link
Contributor

@lgoettgens lgoettgens left a comment

Choose a reason for hiding this comment

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

The output now seems fine to me. Furthermore, all comments in #54501 seem to be adapted (already by @arhik in #54501).

To whoever is merging this: please close #54028 and #54501 at the same time

@@ -31,11 +31,17 @@ function Base.show(io::IO, cfg::CFG)
end
end

function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxlength_idx::Int, color::Bool, show_type::Bool)
function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxlength_idx::Int, color::Bool, show_type::Bool,
unstable_ssa::Union{Nothing, BitSet} = nothing)
Copy link
Member

Choose a reason for hiding this comment

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

Why the nothing case instead of BitSet(), or requiring this parameter always?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was changed due to @fingolfin's comment #54501 (comment)

Copy link
Member

@topolarity topolarity Aug 19, 2024

Choose a reason for hiding this comment

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

Hmm.. on second thought, I think this should probably not tie unstable-highlighting to show_type in the first place

I think we want, e.g., π(%26) and return %10 to show the type-unstable SSA usage in red:
image

Copy link
Author

Choose a reason for hiding this comment

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

Maybe we need @fingolfin opinion to continue?

Copy link
Member

Choose a reason for hiding this comment

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

We haven't heard back, but I still feel that every usage of the %26 should be highlighted in red, including the π and return statements

Copy link
Member

Choose a reason for hiding this comment

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

w.r.t. nothing the pattern that I'd reach to (which I believe is compatible with @fingolfin's original request) is:

const EMPTY_BITSET = BitSet()

function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxlength_idx::Int, color::Bool, show_type::Bool,
                    unstable_ssa::BitSet = EMPTY_BITSET)

but I don't think that's a requirement for merging this PR

Copy link
Member

Choose a reason for hiding this comment

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

Hi folks, I never saw the pings for me here (I get dozens and sometimes hundreds of GitHub notifications per day and it is very easy to miss something). If you want to make sure I look at something, I recommend pinging me on Slack or sending me an email.

That said, I am not even sure what I am being asked here. Looking at PR #54501 I made no comments about what parts to show in which color I think? The comment @lgoettgens links to is about a refactoring of the code that should be neutral with respect to behavior. The goal was to avoid unnecessary allocations and code duplication. The suggestion by @topolarity addresses the first point, and the second is not that important. But in any case, I agree with @topolarity that none of this is a reason to hold up the changes (I thought that I already made that clear in my comments on #54501, by stating "Left some minor and optional suggestions, feel free to ignore/disagree" ... :-) )

if idx in used
idx_s = string(idx)
pad = " "^(maxlength_idx - length(idx_s) + 1)
print(io, "%", idx_s, pad, "= ")
if unstable_ssa != nothing && idx in unstable_ssa
printstyled(io, "%", idx_s; color=:light_red, bold=true)
Copy link
Member

Choose a reason for hiding this comment

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

Does this still print correctly for green (i.e. new) nodes?

Seems like it might not be respecting the color::Bool argument

Copy link
Author

Choose a reason for hiding this comment

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

AFAIK, color was not used previously. I think we can remove color::Bool argument

Copy link
Member

Choose a reason for hiding this comment

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

? It's used just below this on line 44/50

Copy link
Author

Choose a reason for hiding this comment

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

I think it is solved, if I understood the issue.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

when color === false, this function is not supposed to print color - it looks to me that it still does

@lgoettgens
Copy link
Contributor

Bump @topolarity @fingolfin @gbaraldi . I think this is just waiting for some reaction from your side to the authors changes and responses to your comments in this PR and in #54501.

And it would be great to get this in 1.12 (aka merged until tomorrow)

Comment on lines +88 to +92
elseif stmt isa ReturnNode
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0, show_type ? unstable_ssa : nothing)
# everything else in the IR, defer to the generic AST printer
elseif stmt isa Expr
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0, 0, show_type ? unstable_ssa : nothing)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
elseif stmt isa ReturnNode
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0, show_type ? unstable_ssa : nothing)
# everything else in the IR, defer to the generic AST printer
elseif stmt isa Expr
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0, 0, show_type ? unstable_ssa : nothing)
elseif stmt isa ReturnNode
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0, unstable_ssa)
# everything else in the IR, defer to the generic AST printer
elseif stmt isa Expr
show_unquoted(io, stmt, indent, show_type ? prec_decl : 0, 0, unstable_ssa)

This is the show_type issue I was referring to in https://github.com/JuliaLang/julia/pull/55435/files/cf84e06513b7a3e0c4aef70e3298713d638c04b7#r1721769973

@@ -1967,7 +1980,7 @@ function show_unquoted_expr_fallback(io::IO, ex::Expr, indent::Int, quote_level:
end

# TODO: implement interpolated strings
function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::Int = 0)
function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::Int = 0, unstable_ssa::Union{Nothing, BitSet} = nothing)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like unstable_ssa is dropped (in this function) for a lot of possible IR statements (e.g. Expr(:tuple, ...))

This makes me wonder if the unstable_ssa should be attached to an IOContext instead of being piped manually through all of the print / show machinery

@fingolfin
Copy link
Member

The main obstacle here seems to be the conflicts this PR has which somebody needs to resolve before merging is an option?

if idx in used
idx_s = string(idx)
pad = " "^(maxlength_idx - length(idx_s) + 1)
print(io, "%", idx_s, pad, "= ")
if unstable_ssa != nothing && idx in unstable_ssa
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if unstable_ssa != nothing && idx in unstable_ssa
if color && unstable_ssa != nothing && idx in unstable_ssa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants