Skip to content

Clean up lowering API #58147

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Clean up lowering API #58147

wants to merge 5 commits into from

Conversation

mlechu
Copy link
Member

@mlechu mlechu commented Apr 16, 2025

This is preparatory work for experimental integration with JuliaLowering, which
happened to be separable into its own PR.

We currently have three lowering entry points doing slightly different things:
jl-expand-to-thunk, jl-expand-to-thunk-warn (for complaining about ambiguous
soft scope assignments during non-interactive use), and
jl-expand-to-thunk-stmt (which wraps the expression in a block returning
nothing before lowering it) and a bunch of C wrappers on top of those (see red
nodes in the call graphs below).

In this PR:

  • Make all lowering calls go through jl_lower, which just calls out to lisp
    for now, but will probably function like jl_parse does in a future PR.
    • Handle warn with an extra parameter
    • Delete most of the lowering wrappers, which were mainly a result of the
      three entry points
  • While we're breaking things in ast.c, take the opportunity to rename
    "expand"-prefixed functions to "lower"-prefixed ones (excluding macro
    expansion functions, which are called as the first part of lowering).

Here's a call graph before this change, made by looking for callers
of each lowering entry point and tracing back one or more steps (expect
mistakes...). Macro expansion functions are mostly omitted for clarity.
Blue is scheme, red is ast.c, and green is toplevel.c.

graph

After this change:
graph(3)

todo?

@topolarity topolarity requested a review from JeffBezanson April 16, 2025 22:17
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the stmt arg form was mainly a hack to change the meaning of an expression for a deprecation, which isn't necessarily applicable anymore

@mlechu mlechu force-pushed the lowering-api branch 2 times, most recently from 5dc7870 to e994dba Compare April 17, 2025 15:46
mlechu added 5 commits April 20, 2025 09:20
and redirect all calls to lowering through it.  `jl_fl_lower` is essentially a
     renamed `jl_expand_with_loc_warn`, but change the structure of the return
     value of its callee `jl-expand-to-thunk-warn` so we can ignore the warnings
     if they aren't relevant.
`jl_expand_stmt`, `jl_expand_stmt_with_loc`, `jl_expand_with_loc`
This function has always been a convenience wrapper providing default arguments
     to another lowering function.  We can give it a more accurate name now that
     there aren't five other wrappers we would also need to rename in a
     consistent way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants