-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
@time
in global while loop causes internal error
#45600
Comments
I think @ianatol had looked into this a few times, and was just deciding how to best fix this? |
Ref: #37154 I haven't really worked on it since last year, but happy to check it out soon |
versioninfo()
while true
@time 1
end
|
CC: @IanButterworth alas, this will never end. Thanks for the careful report, @inkydragon! @IanButterworth: do you have any ideas? That PR was mostly just reopening your old PR; I don't immediately see anything wrong. |
@ianatol from the above I get the impression this is a compiler issue, and so the fix isn't to change the time macro code? |
@IanButterworth I can't confirm for sure, but it looks very similar to the issues in #37154. It may be possible to change the |
MWE: julia> while true
x = try finally end
end |
So what's happening is that we produce IR code where the first instructions are julia> begin
nothing
while true
x = try finally end
end
end With this patch (which probably is not the right thing to do): --- a/base/compiler/ssair/legacy.jl
+++ b/base/compiler/ssair/legacy.jl
@@ -86,7 +86,7 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
elseif isa(stmt, GotoIfNot)
code[i] = GotoIfNot(stmt.cond, first(ir.cfg.blocks[stmt.dest].stmts))
elseif isa(stmt, PhiNode)
- code[i] = PhiNode(Int32[last(ir.cfg.blocks[edge].stmts) for edge in stmt.edges], stmt.values)
+ code[i] = PhiNode(Int32[edge == 0 ? 0 : last(ir.cfg.blocks[edge].stmts) for edge in stmt.edges], stmt.values)
elseif isexpr(stmt, :enter)
stmt.args[1] = first(ir.cfg.blocks[stmt.args[1]::Int].stmts)
code[i] = stmt I obtain the following: julia> f() = while true x = try finally end end
f (generic function with 1 method)
julia> @code_typed f()
CodeInfo(
1 ─ %1 = φ (#1 => false, #9 => %15)::Bool
└── %2 = φ (#1 => #undef, #9 => %16)::Nothing
2 ─ $(Expr(:enter, #5))
3 ─ %4 = ϒ (%1)::Bool
│ %5 = ϒ (%2)::Nothing
│ %6 = ϒ (true)::Bool
│ %7 = ϒ (nothing)::Nothing
└── $(Expr(:leave, 1))
4 ─ goto #7
5 ┄ %10 = φᶜ (%4, %6)::Bool
│ %11 = φᶜ (%5, %7)::Nothing
└── $(Expr(:leave, 1))
6 ─ nothing::Nothing
7 ┄ %14 = φ (#4 => -1, #6 => 1)::Int64
│ %15 = φ (#4 => true, #6 => %10)::Bool
│ %16 = φ (#4 => nothing, #6 => %11)::Nothing
│ %17 = (%14 === 1)::Bool
└── goto #9 if not %17
8 ─ invoke Base.rethrow()::Union{}
└── unreachable
9 ─ $(Expr(:throw_undef_if_not, Symbol(""), :(%15)))::Any
└── goto #1
) => Union{} Can our julia> g() = (nothing; while true x = try finally end end)
g (generic function with 1 method)
julia> @code_typed g()
CodeInfo(
1 ── nothing::Nothing
2 ┄─ %2 = φ (#1 => false, #10 => %16)::Bool
└─── %3 = φ (#1 => #undef, #10 => %17)::Nothing
3 ── $(Expr(:enter, #6))
# ... as above, shifted by one instruction/one block |
... or maybe it is? I do get the same output with |
Seems to have been introduced in 1.7.
The text was updated successfully, but these errors were encountered: