julia
3e744a78 - bootstrap: Add isa check to inner constructors generated by _defaultctors

Commit
22 days ago
bootstrap: Add isa check to inner constructors generated by _defaultctors Fix a regression introduced in be15e12bf6 (#61036) where the inner constructor body generated by `_defaultctors` was missing the `isa` typecheck that the old flisp `convert-for-type-decl` pattern provided. The old flisp code generated inner constructors with the pattern: isa(arg, fieldtype(self, i)) ? arg : convert(fieldtype(self, i), arg) The new Julia code in `_defaultctors` generated: convert(fieldtype(self, i), arg) This is fragile because the optimizer must inline `convert(Any, x)` to eliminate the call and produce a `:new` expression. When user code defines ambiguous convert methods such as `Base.convert(::Any, v::T) = v` (as test/misc.jl does at line ~581), this creates a method ambiguity for `convert(::Type{Any}, ::Any)` since `Type{Any} <: Any`. The compiler cannot prove the call is unambiguous when `x::Any`, so it refuses to inline it. Without inlining, the constructor remains as a function call instead of being optimized to `:new`. The old code was resilient because `isa(x, Any)` is trivially `true`, so the `convert` branch is dead code that the optimizer eliminates regardless of method table state. This caused the Compiler/EscapeAnalysis test to fail intermittently on CI (Buildkite builds 55100, 55101) when `misc.jl` ran on the same worker before `EscapeAnalysis`, leaving the ambiguous convert method in the process's method table. The test at EscapeAnalysis.jl:598 calls `only(findall(isnew, result.ir.stmts.stmt))` which expects exactly one `:new` expression in the optimized IR for `SafeRef{Any}(a)`, but finds none. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
Committer
Parents
Loading