Skip to content

Commit

Permalink
Canonicalize IR to disallow mutable GlobalRef in value position (#39893)
Browse files Browse the repository at this point in the history
Generally we assume parameters can be duplicated without seeing
side-effects. That is not entirely true of mutable globals and
multi-threading.

Refs: #36450
Fixes: #39508
  • Loading branch information
vtjnash authored Mar 3, 2021
1 parent 0988fcf commit c0f9666
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/compiler/ssair/slot2ssa.jl
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ function fixemup!(cond, rename, ir::IRCode, ci::CodeInfo, idx::Int, @nospecializ
return nothing
end
op[] = x
elseif isa(val, GlobalRef) && !isdefined(val.mod, val.name)
elseif isa(val, GlobalRef) && !(isdefined(val.mod, val.name) && isconst(val.mod, val.name))
op[] = NewSSAValue(insert_node!(ir, idx, Any, val).id - length(ir.stmts))
end
end
2 changes: 1 addition & 1 deletion base/compiler/ssair/verify.jl
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
end
end
elseif isa(op, GlobalRef)
if !isdefined(op.mod, op.name)
if !isdefined(op.mod, op.name) || !isconst(op.mod, op.name)
@verify_error "Unbound GlobalRef not allowed in value position"
error("")
end

11 comments on commit c0f9666

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here. cc @maleadt

@maleadt
Copy link
Member

@maleadt maleadt commented on c0f9666 Mar 3, 2021

Choose a reason for hiding this comment

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

Failures seem to come from FileIO.jl, which now fails to precompile (due to an @assert precompile(Iterators.Pair, ...)) because of the changes in #39593. Revise.jl seems to have the same issue.

@vtjnash
Copy link
Member Author

@vtjnash vtjnash commented on c0f9666 Mar 3, 2021

Choose a reason for hiding this comment

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

This seems to be very bad pattern that has been getting picked up by important packages. There's no reason for these packages to be running test in their loading, for using @assert for @test, nor inferring things that will not be saved.

@maleadt
Copy link
Member

@maleadt maleadt commented on c0f9666 Mar 3, 2021

Choose a reason for hiding this comment

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

It's listed in the SnoopCompile.jl docs, https://github.com/timholy/SnoopCompile.jl/blob/89e75619882c622175dcff9ab50e9d28807789d9/docs/src/snoopi.md; I couldn't find whether it's also generated automatically like that. If anything, it should be some kind of warning not to break PkgEval as it did here. cc @timholy

@timholy
Copy link
Member

@timholy timholy commented on c0f9666 Mar 3, 2021

Choose a reason for hiding this comment

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

It's a way of making sure that the precompiles don't go stale. Otherwise if I refactor the package and change foo(x) to foo(x, y), how am I supposed to know that I'm not successfully precompilling?

julia> foo(x, y) = 1
foo (generic function with 1 method)

julia> precompile(foo, (Int,))
false

@chriselrod
Copy link
Contributor

@chriselrod chriselrod commented on c0f9666 Mar 4, 2021

Choose a reason for hiding this comment

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

julia> foo(x, y) = 1
foo (generic function with 1 method)

julia> precompile(foo, (Int,)) || @warn "Precompilation failed on $(@__LINE__)"
┌ Warning: Precompilation failed on 1
└ @ Main REPL[270]:1

Could probably write a smart macro that creates a much nicer warning actually printing the method and signature that failed to precompile.

@timholy
Copy link
Member

@timholy timholy commented on c0f9666 Mar 4, 2021

Choose a reason for hiding this comment

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

That's essentially what @vtjnash did in #39905.

@timholy
Copy link
Member

@timholy timholy commented on c0f9666 Mar 4, 2021

Choose a reason for hiding this comment

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

Updates:

Let me know if there are others.

@vtjnash
Copy link
Member Author

Choose a reason for hiding this comment

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

@nanosoldier runbenchmarks("string", vs="@3ff44eab64c554b31a87df1b972e99959ad15e54")

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @christopher-dG

Please sign in to comment.