Skip to content

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 20, 2025

…dings

Currently, even though the binding partition system is implemented, it is largely enabled. New const definitions get magically "backdated" to the first world age in which the binding was undefined.

Additionally, they do not get their own world age and there is currently no latestworld marker after const definitions. This PR changes this situation to give const markers their own world age with appropriate latestworld increments. Both of these are mandatory for const replacement to work.

The other thing this PR does is to remove the automatic "backdating". To see the difference, consider:

function foo($i)
    Core.eval(:(const x = $i))
    x
end

Without an intervening world age increment, this will throw an UndefVarError on this PR. I believe this is the best option for two reasons:

  1. It will allow us infer these to Union{} in the future (thus letting inference prune dead code faster).
  2. I think it is less confusing in terms of the world age semantics for const definitions to become active only after they are defined.

To illustrate the second point, suppose we did keep the automatic backdating. Then we would have:

foo(1) => 1
foo(2) => 1
foo(3) => 2

as opposed to on this PR:

foo(1) => UndefVarError
foo(2) => 1
foo(3) => 2

The semantics are consistent, of course, but I am concerned that an automatic backdating will give users the wrong mental model about world age, since it "fixes itself" the first time, but if you Revise it, it will give an unexpected answer. I think this would encourage accidentally bad code patterns that only break under Revise (where they are hard to debug).

The counterpoint of course is that that not backdating is a more breaking choice. As with the rest of the 1.12-era world age semantics changes, I think taking a look at PkgEval will be helpful.

…dings

Currently, even though the binding partition system is implemented, it is
largely enabled. New `const` definitions get magically "backdated" to the
first world age in which the binding was undefined.

Additionally, they do not get their own world age and there is currently no `latestworld` marker
after `const` definitions. This PR changes this situation to give
const markers their own world age with appropriate `latestworld` increments.
Both of these are mandatory for `const` replacement to work.

The other thing this PR does is to remove  the automatic "backdating".
To see the difference, consider:

```
function foo($i)
    Core.eval(:(const x = $i))
    x
end
```

Without an intervening world age increment, this will throw an
UndefVarError on this PR. I believe this is the best option for
two reasons:

1. It will allow us infer these to `Union{}` in the future (thus
   letting inference prune dead code faster).
2. I think it is less confusing in terms of the world age semantics
   for `const` definitions to become active only after they are defined.

To illustrate the second point, suppose we did keep the automatic backdating.
Then we would have:
```
foo(1) => 1
foo(2) => 1
foo(3) => 2
```
as opposed to on this PR:
```
foo(1) => UndefVarError
foo(2) => 1
foo(3) => 2
```

The semantics are consistent, of course, but I am concerned that
an automatic backdating will give users the wrong mental model
about world age, since it "fixes itself" the first time, but
if you Revise it, it will give an unexpected answer. I think
this would encourage accidentally bad code patterns that only
break under Revise (where they are hard to debug).

The counterpoint of course is that that not backdating is a
more breaking choice. As with the rest of the 1.12-era world
age semantics changes, I think taking a look at PkgEval will
be helpful.
@Keno Keno added this to the 1.12 milestone Jan 20, 2025
@Keno
Copy link
Member Author

Keno commented Jan 21, 2025

Alright, this is probably too breaking as-is. Don't even need to look at pkgeval, since Documenter is unhappy also. That said, I still think the automatic silent backdating is too confusing. As a compromise, I think we can do the backdating, but emit a warning. When and if we turn off that warning (i.e. whether it's a warning or an error in the full 1.12 release or we wait until 1.13 or later), we can decide later. I will update this PR to re-instate the automatic backdating and then I will add the warning in a separate PR.

Keno added 4 commits January 21, 2025 19:19
This doctest is bad, because it tests the internal representation of
the macro, not its behavior. With the additional features added to
the macro, the expansion is no longer as simple, so remove the test.
@Keno Keno merged commit 7f99e95 into master Jan 22, 2025
7 checks passed
@Keno Keno deleted the kf/constminworld branch January 22, 2025 12:40
Keno added a commit that referenced this pull request Jan 22, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 22, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 22, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 23, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 23, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 23, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 24, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 24, 2025
This implements the strategy proposed in #57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated access.
Keno added a commit that referenced this pull request Jan 24, 2025
This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
Keno added a commit that referenced this pull request Jan 24, 2025
This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
xal-0 pushed a commit to xal-0/julia that referenced this pull request Jan 24, 2025
…57102)

Currently, even though the binding partition system is implemented, it
is largely enabled. New `const` definitions get magically "backdated" to
the first world age in which the binding was undefined.

Additionally, they do not get their own world age and there is currently
no `latestworld` marker after `const` definitions. This PR changes this
situation to give const markers their own world age with appropriate
`latestworld` increments. Both of these are mandatory for `const`
replacement to work.

The other thing this PR does is prepare to remove the automatic "backdating". To
see the difference, consider:

```
function foo($i)
    Core.eval(:(const x = $i))
    x
end
```

Without an intervening world age increment, this will throw an
UndefVarError on this PR. I believe this is the best option for two
reasons:

1. It will allow us infer these to `Union{}` in the future (thus letting
inference prune dead code faster).
2. I think it is less confusing in terms of the world age semantics for
`const` definitions to become active only after they are defined.

To illustrate the second point, suppose we did keep the automatic
backdating. Then we would have:
```
foo(1) => 1
foo(2) => 1
foo(3) => 2
```
as opposed to on this PR:
```
foo(1) => UndefVarError
foo(2) => 1
foo(3) => 2
```

The semantics are consistent, of course, but I am concerned that an
automatic backdating will give users the wrong mental model about world
age, since it "fixes itself" the first time, but if you Revise it, it
will give an unexpected answer. I think this would encourage
accidentally bad code patterns that only break under Revise (where they
are hard to debug).

The counterpoint of course is that that not backdating is a more
breaking choice. As with the rest of the 1.12-era world age semantics
changes, I think taking a look at PkgEval will be helpful.
Keno added a commit that referenced this pull request Jan 25, 2025
This implements the strategy proposed in
#57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated
access.
Keno added a commit that referenced this pull request Jan 25, 2025
This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
Keno added a commit that referenced this pull request Jan 28, 2025
This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
Comment on lines +1390 to +1394
!!! note
If `f` is a global, it will be resolved consistently
in the (latest) world as the call target. However, all other arguments
(as well as `f` itself if it is not a literal global) will be evaluated
in the current world age.
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that in invokelatest(f, args...), f itself is not evaluated in the latest world, whereas using @invokelatest f(args...) ensures that both the function binding and the function call are evaluated in the latest world?

I’ve written the following snippet to find the difference, but it seems that invokelatest behaves as expected (i.e. always returns latest result). I’m curious to know in what situations the difference between these two would become significant?

julia> function foo()
           global fg3 = sin
           x = invokelatest(fg3, 42)
           Main.fg3 = cos
           y = invokelatest(fg3, 42)
           x, y
       end
foo (generic function with 1 method)

julia> foo()
(-0.9165215479156338, -0.39998531498835127)

Keno added a commit that referenced this pull request Jan 28, 2025
This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
Keno added a commit that referenced this pull request Jan 29, 2025
)

This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
topolarity added a commit to topolarity/Tracy.jl that referenced this pull request Feb 10, 2025
topolarity added a commit to topolarity/Tracy.jl that referenced this pull request Feb 10, 2025
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 4, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 18, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
serenity4 pushed a commit to serenity4/julia that referenced this pull request May 1, 2025
…57102)

Currently, even though the binding partition system is implemented, it
is largely enabled. New `const` definitions get magically "backdated" to
the first world age in which the binding was undefined.

Additionally, they do not get their own world age and there is currently
no `latestworld` marker after `const` definitions. This PR changes this
situation to give const markers their own world age with appropriate
`latestworld` increments. Both of these are mandatory for `const`
replacement to work.

The other thing this PR does is prepare to remove the automatic "backdating". To
see the difference, consider:

```
function foo($i)
    Core.eval(:(const x = $i))
    x
end
```

Without an intervening world age increment, this will throw an
UndefVarError on this PR. I believe this is the best option for two
reasons:

1. It will allow us infer these to `Union{}` in the future (thus letting
inference prune dead code faster).
2. I think it is less confusing in terms of the world age semantics for
`const` definitions to become active only after they are defined.

To illustrate the second point, suppose we did keep the automatic
backdating. Then we would have:
```
foo(1) => 1
foo(2) => 1
foo(3) => 2
```
as opposed to on this PR:
```
foo(1) => UndefVarError
foo(2) => 1
foo(3) => 2
```

The semantics are consistent, of course, but I am concerned that an
automatic backdating will give users the wrong mental model about world
age, since it "fixes itself" the first time, but if you Revise it, it
will give an unexpected answer. I think this would encourage
accidentally bad code patterns that only break under Revise (where they
are hard to debug).

The counterpoint of course is that that not backdating is a more
breaking choice. As with the rest of the 1.12-era world age semantics
changes, I think taking a look at PkgEval will be helpful.
serenity4 pushed a commit to serenity4/julia that referenced this pull request May 1, 2025
…Lang#57133)

This implements the strategy proposed in
JuliaLang#57102 (comment).
Example:
```
julia> function foo(i)
           eval(:(const x = $i))
           x
       end
foo (generic function with 1 method)

julia> foo(1)
WARNING: Detected access to binding Main.x in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
1
```

The warning is triggered once per binding to avoid spamming for repeated
access.
serenity4 pushed a commit to serenity4/julia that referenced this pull request May 1, 2025
…iaLang#57150)

This is the analog of JuliaLang#57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.
aviatesk pushed a commit to aviatesk/JuliaLowering.jl that referenced this pull request Jun 14, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
aviatesk pushed a commit to aviatesk/JuliaLowering.jl that referenced this pull request Jun 14, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
aviatesk pushed a commit to aviatesk/JuliaLowering.jl that referenced this pull request Jul 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
aviatesk pushed a commit to aviatesk/JuliaLowering.jl that referenced this pull request Jul 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Jul 29, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above (missing world age increments).

Co-authored-by: Claire Foster <[email protected]>
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Jul 29, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above (missing world age increments).

Co-authored-by: Claire Foster <[email protected]>
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Jul 30, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above (missing world age increments).

Co-authored-by: Claire Foster <[email protected]>
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Aug 2, 2025
For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above (missing world age increments).

Co-authored-by: Claire Foster <[email protected]>
mlechu added a commit to c42f/JuliaLowering.jl that referenced this pull request Aug 4, 2025
* Update CodeInfo struct and handling

Co-authored-by: Claire Foster <[email protected]>

* Don't produce raw symbol from globalref

This used to implicitly refer to a module-level name, but lowering is now
expected to wrap it in a `globalref`. Part of JuliaLang/julia#54772

* Updates to const and global lowering; add K"constdecl"; omit `wrap`

JuliaLang/julia#54773, JuliaLang/julia#56713, JuliaLang/julia#57470. Some
     changes omitted from `expand-decls` and `expand-assignment`.

Note that the two-argument IR "const" is K"constdecl", whereas the one-argument
    K"const" only appears in the AST.

Also note that the `wrap` parameter is omitted throughout assignment desugaring.
      As far as I'm aware, all this plumbing was just to support `const a,b,c =
     1,2,3` having `b` and `c` inherit the `const`.  TODO: find a better way of
     doing the same thing (a ScopedValue might be a clean solution; we currently
     throw an error).

The check for `let; const x = 1; end`, (which should throw) is in scope
     analysis (lisp has it in `compile`).

Co-authored-by: Claire Foster <[email protected]>

* Add `isdefinedglobal` builtin

JuliaLang/julia#54999, JuliaLang/julia#56985

* :global no longer valid_ir_argument; rm `is_defined_nothrow_global`

JuliaLang/julia#56746.  Also call :slot and :static_parameter valid (for now)

* Fix `is_defined_and_owned_global` (Core.Binding changes)

Adapt to bpart changes in JuliaLang/julia#54788

* Struct desugaring: "Undo decision to publish incomplete types..."

JuliaLang/julia#56497; Add self-referencing struct shim

I have doubts about how long this solution will stay in the base repository, and
     how complete it is (doesn't seem to work with M1.M2.S), but we are testing
     for it here.

Also change the expected value of a test changed in the same PR.

* Emit `latestworld` world age increments

For method defs, `latestworld` is produced in desugaring rather than closure
conversion for now (our closure conversion doesn't seem to cover the same
cases as lisp lowering yet).

Covers JuliaLang/julia#56523, JuliaLang/julia#56509, JuliaLang/julia#57299.

Also includes changes from JuliaLang/julia#57102 (bpart: Start enforcing minimum
world age for const bparts) and JuliaLang/julia#57150 (bpart: Start enforcing
min_world for global variable definitions) since the lowering changes from those
appear to be amendments to the changes above (missing world age increments).

Co-authored-by: Claire Foster <[email protected]>

* bpart changes: `Core._typebody!` signature

`Core._typebody!` now takes a new "prev" argument, which we don't use yet here.
 Changes from JuliaLang/julia#57253

* bpart changes: struct desugaring

Changes from JuliaLang/julia#57253 (bpart: Fully switch to partitioned
     semantics).  This fixes one failing test and realigns struct desugaring to
     match lisp for now.

Also changed: the expected result of redefining a primitive type (now allowed).

* Additional argument in `new_opaque_closure`

Fix segfaulting test.  Thanks for the TODO

* Adapt to different `GeneratedFunctionStub` signature

Signature changed in JuliaLang/julia#57230.  Thanks @aviatesk for the help!

* Fix `public` and `export`

As of JuliaLang/julia#57765, `jl_module_public` is no longer exported.  Change
our runtime to handle it like `public` and `export` like we handle `import`
or `using` for now

* Fix modules.jl test

I believe this was a world age issue

* Regenerate IR tests

Too many to count.

* Update README to known-good julia, JuliaSyntax versions

Latest julia works.  Changes are needed to work with the latest JuliaSyntax, but
     that isn't in base julia yet, and more changes are likely to come.

* Fix small bug from #16 so tests pass

The change lifted the scope of `note`, so it was being changed in the loop

* Changes from code review: const/global lowering

Ping me if you'd like this squashed into the original const/global commit!

Co-authored-by: Claire Foster <[email protected]>

* Remove a special case

No longer needed since we no longer put `global` or `local` forms back into the
     expand_forms machine.  Some error messages change slightly as a result.

* Changes from code review

Co-authored-by: Claire Foster <[email protected]>

* Fix + test for assignment in value but not tail position

* Disallow `static_parameter` as `valid_ir_argument`

See added comment, and discussion at
    #10 (comment)

Co-authored-by: Claire Foster <[email protected]>

* Change printing of `K"latestworld"`

Parens are nice, but it wasn't consistent.

Also make it a leaf (remaining non-leaves are deleted in the next commit.)

* Move most `latestworld`s to linearization

From the docs:
```
The following statements raise the current world age:
    1. An explicit invocation of Core.@latestworld
    2. The start of every top-level statement
    3. The start of every REPL prompt
    4. Any type or struct definition
    5. Any method definition
    6. Any constant declaration
    7. Any global variable declaration (but not a global variable assignment)
    8. Any using, import, export or public statement
    9. Certain other macros like eval (depends on the macro implementation)
```

This commit handles each case as follows:

```
    1. = 9
    2. I'm not sure this actually happens (or needs to happen, unless we're
       being defensive? Doing it after each world-changing operation should
       suffice).  But if we need it, this would just be emitting once at the
       beginning of every lowered output.
    3. = 2
    4. = 6
    5. Emit seeing `method` in linearize
    6. Emit seeing `constdecl` in linearize
    7. Emit seeing `global` or `globaldecl` in linearize
    8. We just defer to `eval`, but should probably go in desugaring later
       - using/import recently became builtin calls, and I haven't
         updated JL to use them yet.  Base._import_using has an expr-based
         API that may change, and our importpath destructuring is worth keeping.
       - export and public (special forms) are handled in toplevel.c
    9. Done for us
```

Other quirks:

- `JuliaLowering.eval_closure_type` calls eval to assign a const, so we still
    need to deal with that in closure conversion.

- The `include` hack isn't mentioned in the docs, but can stay in desugaring.
      I'm not certain why we don't do the same for non-macro `eval`.

---------

Co-authored-by: Claire Foster <[email protected]>
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