Skip to content

Core.Box optimization regression versus flisp #147

@topolarity

Description

@topolarity

Calling one closure from another works fine in flisp, without boxing:

julia> Meta.@lower function versioninfo(io::IO=stdout; verbose::Bool=false)
           s = ""
           function foo(s::String)
               return s == ""
           end
           function bar(s::String)
               return foo(k)
           end
           return bar(s)
       end
:($(Expr(:thunk, CodeInfo(
...%3  = Main.:(var"#foo#14")
│         foo = %new(%3)
│   @ REPL[9]:6 within `unknown scope`%5  = Main.:(var"#bar#15")
│   %6  = foo
│   %7  =   dynamic Core._typeof_captured_variable(%6)
│   %8  =   builtin Core.apply_type(%5, %7)
│   %9  = foo
│         bar = %new(%8, %9)
...
))))

In JuliaLowering this introduces a (quite severe) Core.Box:

julia> JuliaLowering.include_string(Main, raw"""
       function versioninfo(io::IO=stdout; verbose::Bool=false)
                  s = ""
                  function foo(s::String)
                      return s == ""
                  end
                  function bar(s::String)
                      return foo(k)
                  end
                  return bar(s)
              end
       """; expr_compat_mode=true)
# printed from eval.jl just before returning the thunk:
:($(Expr(:thunk, CodeInfo(
...
1 ─       foo = Core.Box()
│         $(Expr(:meta, :nkw, 1))
│   @ string:2 within `unknown scope`
│         s = ""
│   @ string:3 within `unknown scope`%4  = Main.:(var"##versioninfo#3#foo##0")
│   %5  = %new(%4)
│   %6  = foo
│           builtin Core.setfield!(%6, :contents, %5)
│   @ string:6 within `unknown scope`%8  = Main.:(var"##versioninfo#3#bar##0")
│   @ string:3 within `unknown scope`%9  = foo
│   @ string:6 within `unknown scope`%10 = %new(%8, %9)
│         bar = %10
...
))))

causes several stdlib test failures, as of JuliaLang/julia#60848

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions