From 32c0d55adce842a9069546769e3a22f4dbf6f426 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Wed, 3 Apr 2024 16:08:31 +0200 Subject: [PATCH 1/2] fix frontend throw_undef when value is non-const --- base/compiler/abstractinterpretation.jl | 2 +- test/compiler/inference.jl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index ce8494b1feff0..51794e9e1eb7c 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -2637,7 +2637,7 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp else t = Union{} end - elseif !hasintersect(windenconst(condt), Bool) + elseif !hasintersect(widenconst(condt), Bool) t = Union{} end elseif ehead === :boundscheck diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 62c134e58c2a6..01c4687a26caa 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -5647,6 +5647,22 @@ end @test Core.Compiler.return_type(has_tuin, Tuple{}) === Union{} @test_throws UndefVarError has_tuin() +function gen_tuin_from_arg(world::UInt, source, _, _) + ci = make_codeinfo(Any[ + Expr(:throw_undef_if_not, :x, Core.Argument(2)), + ReturnNode(true), + ]; slottypes=Any[Any, Bool]) + ci.slotnames = Symbol[:var"#self#", :def] + ci +end + +@eval function has_tuin2(def) + $(Expr(:meta, :generated, gen_tuin_from_arg)) + $(Expr(:meta, :generated_only)) +end +@test_throws UndefVarError has_tuin2(false) +@test has_tuin2(true) + # issue #53585 let t = ntuple(i -> i % 8 == 1 ? Int64 : Float64, 4000) @test only(Base.return_types(Base.promote_typeof, t)) == Type{Float64} From 534283d778428b29730347942db733fcf53dbd05 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Wed, 3 Apr 2024 18:30:43 +0200 Subject: [PATCH 2/2] don't resolve tuin symbol to global ref --- src/method.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/method.c b/src/method.c index a97dccf53e1e2..e3b19a5007b58 100644 --- a/src/method.c +++ b/src/method.c @@ -212,7 +212,7 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve jl_exprargset(e, 0, resolve_globals(jl_exprarg(e, 0), module, sparam_vals, binding_effects, 1)); i++; } - if (e->head == jl_method_sym || e->head == jl_module_sym) { + if (e->head == jl_method_sym || e->head == jl_module_sym || e->head == jl_throw_undef_if_not_sym) { i++; } for (; i < nargs; i++) {