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

code_warntype now shows unstable SSA useref values in red #54501

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

arhik
Copy link
Sponsor

@arhik arhik commented May 16, 2024

Addresses #54028

reraising previous PR after suggested code changes #54441
Screenshot 2024-05-17 at 8 16 09 AM

@arhik
Copy link
Sponsor Author

arhik commented May 17, 2024

Highlighting ssa values on the left is also useful; specially when Any hint is outside the view. Not part of this PR but can be done after feedback.

Screenshot 2024-05-17 at 9 06 56 AM

@arhik
Copy link
Sponsor Author

arhik commented May 17, 2024

This is without left highlighting for comparison.

Screenshot 2024-05-17 at 9 19 52 AM

@gbaraldi
Copy link
Member

I like the left hightlighting

@arhik
Copy link
Sponsor Author

arhik commented May 18, 2024

Does this need tests ?

@arhik
Copy link
Sponsor Author

arhik commented May 18, 2024

@gbaraldi If this needs more discussion let me know.

@gbaraldi
Copy link
Member

gbaraldi commented May 20, 2024

It's always good to have some tests yeah. You can probably base it on some of the tests in show.jl. Search for IR or code_typed

@fingolfin fingolfin added the needs tests Unit tests are required for this change label May 23, 2024
Copy link
Contributor

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Thank you that looks like a quite helpful improvement!

Left some minor and optional suggestions, feel free to ignore/disagree.

@@ -44,7 +49,7 @@ function print_stmt(io::IO, idx::Int, @nospecialize(stmt), used::BitSet, maxleng
if !color && stmt isa PiNode
# when the outer context is already colored (green, for pending nodes), don't use the usual coloring printer
print(io, "π (")
show_unquoted(io, stmt.val, indent)
show_unquoted(io, stmt.val, indent, 0, (stmt.val.id in unstable_ssa) ? true : false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't ? true : false redundant here and elsewhere?

Suggested change
show_unquoted(io, stmt.val, indent, 0, (stmt.val.id in unstable_ssa) ? true : false)
show_unquoted(io, stmt.val, indent, 0, stmt.val.id in unstable_ssa)

print(io, "φᶜ (")
first = true
for v in stmt.values
first ? (first = false) : print(io, ", ")
show_unquoted(io, v, indent)
if v isa SSAValue
show_unquoted(io, v, indent, prec, (v in unstable_ssa) ? true : false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Option suggestion, but: how about changing this and its many variants in this PR to

Suggested change
show_unquoted(io, v, indent, prec, (v in unstable_ssa) ? true : false)
show_unquoted(io, v, indent, prec, unstable_ssa)

and then deal with it in the show_unquoted(::IO, ::SSAValue, ...) method.

That would then also make it trivial to use unstable_ssa::Union{BitSet,Nothing} = nothing everywhere to avoid creating a BitSet() if it is not needed. Dealing with the nothing case would only have to be done in one place, namely the show_unquoted method for SSAValue

Copy link
Sponsor Author

Choose a reason for hiding this comment

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

I remember I had to do that to avoid stackoverflow. But I will check again. Reasonable suggestion to invest time. Thanks.

Comment on lines 106 to 108
show_unquoted(io′, stmt.values[i], indent, 0, (stmt.values[i].id in unstable_ssa) ? true : false)
else
show_unquoted(io′, stmt.values[i], indent)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
show_unquoted(io′, stmt.values[i], indent, 0, (stmt.values[i].id in unstable_ssa) ? true : false)
else
show_unquoted(io′, stmt.values[i], indent)
show_unquoted(io′, val, indent, 0, (stmt.values[i].id in unstable_ssa) ? true : false)
else
show_unquoted(io′, val, indent)

or even

Suggested change
show_unquoted(io′, stmt.values[i], indent, 0, (stmt.values[i].id in unstable_ssa) ? true : false)
else
show_unquoted(io′, stmt.values[i], indent)
show_unquoted(io′, val, indent, 0, stmt.values[i].id in unstable_ssa)
else
show_unquoted(io′, val, indent)

print(io, "π (")
show_unquoted(io, stmt.val, indent)
show_unquoted(io, stmt.val, indent, prec, (stmt.val.id in unstable_ssa) ? true : false)
Copy link
Contributor

Choose a reason for hiding this comment

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

So previously prec was ignored, now it is passed on. Is this a necessary for this patch? (I am not objecting, just wondering whether this fixes something, resp. where it might break something else)

arhik added 13 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Unit tests are required for this change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants