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

Assertion failure with nested scoped values #53521

Closed
simonbyrne opened this issue Feb 29, 2024 · 1 comment · Fixed by #53630
Closed

Assertion failure with nested scoped values #53521

simonbyrne opened this issue Feb 29, 2024 · 1 comment · Fixed by #53630
Labels
bug Indicates an unexpected problem or unintended behavior compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)

Comments

@simonbyrne
Copy link
Contributor

On current master (77c0672) the following example:

const VALUE = ScopedValue{Int}(1)

x = 0
@with VALUE => 2 begin
    for r = Int[1]
        @with VALUE => 3 begin
            try
                copy(x)
            catch err
                nothing
            end
        end
    end
end

triggers an assertion failure

Internal error: during type inference of
Tuple{}
Encountered unexpected error in runtime:
MethodError(f=Base.string, args=(Expr(:call, :==, :current_mapping, :val),), world=0x0000000000001720)
jl_method_error_bare at /Users/simon/src/julia/src/gf.c:2215
jl_method_error at /Users/simon/src/julia/src/gf.c:2233
jl_lookup_generic_ at /Users/simon/src/julia/src/gf.c:3145 [inlined]
ijl_apply_generic at /Users/simon/src/julia/src/gf.c:3160
macro expansion at ./error.jl:233 [inlined]
update_scope_mapping! at ./compiler/ssair/passes.jl:1162
sroa_pass! at ./compiler/ssair/passes.jl:1230
run_passes_ipo_safe at ./compiler/optimize.jl:958
run_passes_ipo_safe at ./compiler/optimize.jl:973 [inlined]
optimize at ./compiler/optimize.jl:947
jfptr_optimize_40169 at /Users/simon/src/julia/usr/lib/julia/sys.dylib (unknown line)
_typeinf at ./compiler/typeinfer.jl:262
typeinf at ./compiler/typeinfer.jl:216
typeinf_ext at ./compiler/typeinfer.jl:1125
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1179 [inlined]
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1177
jfptr_typeinf_ext_toplevel_37409 at /Users/simon/src/julia/usr/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/simon/src/julia/src/./julia.h:2174 [inlined]
jl_type_infer at /Users/simon/src/julia/src/gf.c:393
jl_toplevel_eval_flex at /Users/simon/src/julia/src/toplevel.c:932
jl_toplevel_eval_flex at /Users/simon/src/julia/src/toplevel.c:886
ijl_toplevel_eval at /Users/simon/src/julia/src/toplevel.c:952 [inlined]
ijl_toplevel_eval_in at /Users/simon/src/julia/src/toplevel.c:994
eval at ./boot.jl:428 [inlined]
include_string at ./loading.jl:2486
_include at ./loading.jl:2546
include at ./Base.jl:557
jfptr_include_43902 at /Users/simon/src/julia/usr/lib/julia/sys.dylib (unknown line)
exec_options at ./client.jl:318
_start at ./client.jl:526
jfptr__start_67460 at /Users/simon/src/julia/usr/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/simon/src/julia/src/./julia.h:2174 [inlined]
true_main at /Users/simon/src/julia/src/jlapi.c:898
jl_repl_entrypoint at /Users/simon/src/julia/src/jlapi.c:1057

Possibly related #52819

cc: @Keno @vchuravy

@oscardssmith oscardssmith added the bug Indicates an unexpected problem or unintended behavior label Mar 3, 2024
@oscardssmith
Copy link
Member

oscardssmith commented Mar 3, 2024

Slightly reduced:

function f()
	VALUE = ScopedValue(1)

	@with VALUE => 2 begin
		for i = 1
			@with VALUE => 3 begin
				try
					foo()
				catch
					nothing
				end
			end
		end
	end
end
@code_typed optimize=false f() # works
@code_typed f()
ERROR: AssertionError: current_mapping == val
Stacktrace:
  [1] update_scope_mapping!(scope_mapping::Vector{Core.SSAValue}, bb::Int64, val::Core.SSAValue)
    @ Core.Compiler ./compiler/ssair/passes.jl:1162
  [2] sroa_pass!(ir::Core.Compiler.IRCode, inlining::Core.Compiler.InliningState{Core.Compiler.NativeInterpreter})
    @ Core.Compiler ./compiler/ssair/passes.jl:1230
  [3] run_passes_ipo_safe(ci::Core.CodeInfo, sv::Core.Compiler.OptimizationState{…}, caller::Core.Compiler.InferenceResult, optimize_until::Nothing)
    @ Core.Compiler ./compiler/optimize.jl:965
  [4] run_passes_ipo_safe
    @ ./compiler/optimize.jl:980 [inlined]
  [5] optimize(interp::Core.Compiler.NativeInterpreter, opt::Core.Compiler.OptimizationState{…}, caller::Core.Compiler.InferenceResult)
    @ Core.Compiler ./compiler/optimize.jl:954
  [6] _typeinf(interp::Core.Compiler.NativeInterpreter, frame::Core.Compiler.InferenceState)
    @ Core.Compiler ./compiler/typeinfer.jl:262
  [7] typeinf(interp::Core.Compiler.NativeInterpreter, frame::Core.Compiler.InferenceState)
    @ Core.Compiler ./compiler/typeinfer.jl:216
  [8] typeinf_frame(interp::Core.Compiler.NativeInterpreter, mi::Core.MethodInstance, run_optimizer::Bool)
    @ Core.Compiler ./compiler/typeinfer.jl:1018
  [9] typeinf_code(interp::Core.Compiler.NativeInterpreter, mi::Core.MethodInstance, run_optimizer::Bool)
    @ Core.Compiler ./compiler/typeinfer.jl:961
 [10] typeinf_code
    @ ./compiler/typeinfer.jl:955 [inlined]
 [11] code_typed_by_type(tt::Type; optimize::Bool, debuginfo::Symbol, world::UInt64, interp::Core.Compiler.NativeInterpreter)
    @ Base ./reflection.jl:1626
 [12] code_typed_by_type
    @ ./reflection.jl:1606 [inlined]
 [13] code_typed(f::Any, types::Any; kwargs::@Kwargs{})
    @ Base ./reflection.jl:1585
 [14] code_typed(f::Any, types::Any)
    @ Base ./reflection.jl:1580
 [15] macro expansion
    @ ~/Documents/Code/julia/usr/share/julia/stdlib/v1.12/InteractiveUtils/src/macros.jl:230 [inlined]
 [16] top-level scope
    @ REPL[4]:1
Some type information was truncated. Use `show(err)` to see complete types.

@oscardssmith oscardssmith added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Mar 3, 2024
Keno added a commit that referenced this issue Mar 7, 2024
Sroa was incorrectly assuming that every :leave leaves exactly one
scope. In reality, it leaves as many scopes as the corresponding
:leave references. Fix that to fix #53521.
Keno added a commit that referenced this issue Mar 7, 2024
Sroa was incorrectly assuming that every :leave leaves exactly one
scope. In reality, it leaves as many scopes as the corresponding
:leave references. Fix that to fix #53521.
Keno added a commit that referenced this issue Mar 8, 2024
Sroa was incorrectly assuming that every :leave leaves exactly one
scope. In reality, it leaves as many scopes as the corresponding :leave
references. Fix that to fix #53521.
KristofferC pushed a commit that referenced this issue Mar 15, 2024
Sroa was incorrectly assuming that every :leave leaves exactly one
scope. In reality, it leaves as many scopes as the corresponding :leave
references. Fix that to fix #53521.

(cherry picked from commit 321fb2c)
mkitti pushed a commit to mkitti/julia that referenced this issue Apr 13, 2024
Sroa was incorrectly assuming that every :leave leaves exactly one
scope. In reality, it leaves as many scopes as the corresponding :leave
references. Fix that to fix JuliaLang#53521.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants