julia
a8a4686f - [JuliaLowering] Refactor function desugaring (#61342)

Commit
10 days ago
[JuliaLowering] Refactor function desugaring (#61342) A number of fixes that hopefully make up for the large diff. Currently atop https://github.com/JuliaLang/julia/pull/61213 Changes: 1. Handle destructuring (tuple) params first, like flisp does, since it's simpler to assume every param is a single identifier later. 2. Structure "expand function", "method-def-expr", "keyword-method-def-expr", and "optional positional wrappers" to call each other like flisp does. I think it's simpler this way, and it also affects the order of the methods (closure boxes unfortunately depend on this right now; see discussion in #61051). 3. Don't rewrite constructors with callbacks passed to expand_function_def. I think this was originally since matching the function name was too messy, but validation.jl and pattern-matching make this doable (even flisp uses its own pattern-lambda language here) 4. Keep args bundled with their types for longer 5. Keep typevars bundled with their bounds for longer with new `K"_typevar"` (flisp does this with 3-long lists). 6. Set the first argument to `:method` expressions to `nothing` if the function is local. I think flisp does this to remove unnecessary data dependencies. 7. Add `valid_st2` (just for internal use). 8. Push the generated function wrapper (previously `generated_function`, now `_generated_body`) down to wrap the body of the function instead, and introduce it in `est_to_dst` instead of macro expansion. That information needs to travel with the function body anyway to get to the right `method_def_expr` calls. Fixes: - fix https://github.com/JuliaLang/JuliaLowering.jl/issues/158, failure to detect inter-arg static param dependencies. As discussed with @topolarity, we're trying out something slightly different from flisp commented on in `optional_positional_defs` - fix https://github.com/JuliaLang/JuliaLowering.jl/issues/157. - fix https://github.com/JuliaLang/JuliaLowering.jl/issues/156. Destructuring args are now treated the same in function-name position. - fix https://github.com/JuliaLang/JuliaLowering.jl/issues/155, unused args not marked unused. This is part of function desugaring in flisp and I've tried to match that logic within the JL framework. This means `Symbol("#unused#")` becomes `K"Placeholder"` in `est_to_dst`, the reverse happens in `to_lowered_expr`, and generated functions do their own detection for the quoted arglist. - Initial support for method table overlays - fix and test anonymous generated functions https://github.com/JuliaLang/JuliaLowering.jl/issues/152 is also worth checking TODO (later): - Support globalref properly (validator and existing lowering recognize it, but it isn't generally expected as an lvalue in desugaring) - Overlays need more work - Destructured args in generated functions may need to be special-cased, since desugaring pushes statements into the body - Fix `where` expression in function name (https://github.com/JuliaLang/julia/pull/35861). This PR fixes the desugaring part, but scope resolution appears to fail. --------- Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
Author
Parents
Loading