Skip to content
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

Expr consistency and stability #53531

Closed
aplavin opened this issue Feb 29, 2024 · 4 comments
Closed

Expr consistency and stability #53531

aplavin opened this issue Feb 29, 2024 · 4 comments

Comments

@aplavin
Copy link
Contributor

aplavin commented Feb 29, 2024

Many packages rely on the structure of parsed Exprs, mostly to implement transformations in macros.
Sometimes, Expr parsing results aren't too consistent. And I wonder if they are considered stable/public in Julia 1.x or not. Can parsing results of expressions change? Would be nice to clarify that, especially given the recent history of backwards incompatible changes in Julia, some of which aren't acknowledged as breaking even when they lead to failures in popular packages.

@aplavin
Copy link
Contributor Author

aplavin commented Feb 29, 2024

To be more concrete, this is an example of an inconsistency I noticed recently.
Same structure for regular calls:

julia> :(f(x, y)) |> dump
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol f
    2: Symbol x
    3: Symbol y

julia> :(+(x, y)) |> dump
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol +
    2: Symbol x
    3: Symbol y

But very different with broadcasting:

julia> :(f.(x, y)) |> dump
Expr
  head: Symbol .
  args: Array{Any}((2,))
    1: Symbol f
    2: Expr
      head: Symbol tuple
      args: Array{Any}((2,))
        1: Symbol x
        2: Symbol y

julia> :(.+(x, y)) |> dump
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol .+
    2: Symbol x
    3: Symbol y

The last one isn't just inconsistent, but also generally weird: it claims to be a call to a function named .+, but it doesn't exit:

julia> Main.:.+
ERROR: UndefVarError: `.+` not defined in `Main`

Can this or other example parse in a different way in a new Julia version?

@vtjnash
Copy link
Member

vtjnash commented Feb 29, 2024

IIRC, the .+ is a legacy parsing behavior specifically for maintaining backwards compatibility, even though it is a bit awkward to handle. Refs #37583 and #40858

@aplavin
Copy link
Contributor Author

aplavin commented Feb 29, 2024

So, can we rely on existing parsing rules, are they considered stable?

@ararslan
Copy link
Member

ararslan commented Mar 2, 2024

To Jameson's point, significant effort has been put into ensuring and maintaining stability. The last breaking change I can recall to expression parsing was when we started preserving do in the AST in 0.7. I'm not the authority here but that seems pretty stable to me; I'd personally consider the existing rules stable and, like all maintainers of packages that define macros, I rely on that stability.

@aplavin aplavin closed this as completed Mar 2, 2024
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

No branches or pull requests

3 participants