Skip to content

Conversation

@c42f
Copy link
Member

@c42f c42f commented Jan 22, 2025

Make all updating assignment operators like += be represented with a single K"op=" head, with the operator itself in infix position. For example, x += 1 is now parsed as

[op=]
  x    :: Identifier
  +    :: Identifier
  y    :: Identifier

This greatly reduces the number of distinct forms here from a rather big list ($= %= &= *= += -= //= /= <<= >>= >>>= \= ^= |= ÷= ⊻=) and makes the operator itself appear in the AST as kind K"Identifier", as it should. It also makes it possible to add further unicode updating operators while keeping the AST stable.

The need for this was highlighted when working on JuliaLowering. When using K"+=" as a head, one needs to look up the appropriate operator from the list of updating operators or use string munging on the Kind itself. This is quite awkward especially as it needs special rules for inferring the macro scope of the + identifier. In addition, having a single head for this form means update operator semantics only need to be dealt with in one place.

Make all updating assignment operators like `+=` be represented with a
single `K"op="` head, with the operator itself in infix position.
For example, `x += 1` is now parsed as

    [op=]
      x    :: Identifier
      +    :: Identifier
      y    :: Identifier

This greatly reduces the number of distinct forms here from a rather big
list (`$=` `%=` `&=` `*=` `+=` `-=` `//=` `/=` `<<=` `>>=` `>>>=` `\=`
`^=` `|=` `÷=` `⊻=`) and makes the operator itself appear in the AST as
kind `K"Identifier"`, as it should. It also makes it possible to add
further unicode updating operators while keeping the AST stable.

The need for this was highlighted when working on JuliaLowering. When
using `K"+="` as a head, one needs to look up the appropriate operator
from the list of updating operators or use string munging on the Kind
itself. This is quite awkward especially as it needs special rules for
inferring the macro scope of the `+` identifier. In addition, having a
single head for this form means update operator semantics only need to
be dealt with in one place.
c42f added a commit to JuliaLang/JuliaLowering.jl that referenced this pull request Jan 22, 2025
@c42f c42f merged commit 820b646 into main Jan 22, 2025
36 checks passed
@c42f c42f deleted the caf/update-assignments-with-op=-kind branch January 22, 2025 06:09
c42f added a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
…uliaSyntax.jl#530)

Make all updating assignment operators like `+=` be represented with a
single `K"op="` head, with the operator itself in infix position.
For example, `x += 1` is now parsed as

    [op=]
      x    :: Identifier
      +    :: Identifier
      y    :: Identifier

This greatly reduces the number of distinct forms here from a rather big
list (`$=` `%=` `&=` `*=` `+=` `-=` `//=` `/=` `<<=` `>>=` `>>>=` `\=`
`^=` `|=` `÷=` `⊻=`) and makes the operator itself appear in the AST as
kind `K"Identifier"`, as it should. It also makes it possible to add
further unicode updating operators while keeping the AST stable.

The need for this was highlighted when working on JuliaLowering. When
using `K"+="` as a head, one needs to look up the appropriate operator
from the list of updating operators or use string munging on the Kind
itself. This is quite awkward especially as it needs special rules for
inferring the macro scope of the `+` identifier. In addition, having a
single head for this form means update operator semantics only need to
be dealt with in one place.
c42f added a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
topolarity pushed a commit to JuliaLang/julia that referenced this pull request Nov 14, 2025
…uliaSyntax.jl#530)

Make all updating assignment operators like `+=` be represented with a
single `K"op="` head, with the operator itself in infix position.
For example, `x += 1` is now parsed as

    [op=]
      x    :: Identifier
      +    :: Identifier
      y    :: Identifier

This greatly reduces the number of distinct forms here from a rather big
list (`$=` `%=` `&=` `*=` `+=` `-=` `//=` `/=` `<<=` `>>=` `>>>=` `\=`
`^=` `|=` `÷=` `⊻=`) and makes the operator itself appear in the AST as
kind `K"Identifier"`, as it should. It also makes it possible to add
further unicode updating operators while keeping the AST stable.

The need for this was highlighted when working on JuliaLowering. When
using `K"+="` as a head, one needs to look up the appropriate operator
from the list of updating operators or use string munging on the Kind
itself. This is quite awkward especially as it needs special rules for
inferring the macro scope of the `+` identifier. In addition, having a
single head for this form means update operator semantics only need to
be dealt with in one place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant