Skip to content

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
Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

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

LGTM. Seems like a pretty straightforward (small) re-factor

unless @JeffBezanson has any feedback, I'll merge this today

mlechu added 5 commits April 22, 2025 09:59
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.
This seems to be more accurate.
@topolarity topolarity merged commit cb10e40 into JuliaLang:master Apr 23, 2025
7 checks passed
@topolarity
Copy link
Member

Thanks @mlechu !

yuyichao added a commit to yuyichao/NLopt.jl that referenced this pull request May 26, 2025
Broken by JuliaLang/julia#58147 . However, this has always been an error outside of a module block so the error is probably consistent
odow pushed a commit to jump-dev/NLopt.jl that referenced this pull request May 26, 2025
Broken by JuliaLang/julia#58147 . However, this has always been an error outside of a module block so the error is probably consistent
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.

3 participants