Skip to content

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Sep 30, 2025

Backported PRs:

Need manual backport:

Contains multiple commits, manual intervention needed:

Non-merged PRs with backport label:

@KristofferC KristofferC added the release Release management and versioning. label Sep 30, 2025
serenity4 and others added 2 commits September 30, 2025 17:28
…59631)

Setting world bounds on the created `CodeInfo` allows us to interpret
opaque closures faster.

Taking the following example:

```julia
julia> f(x, y) = x + y
f (generic function with 1 method)

julia> ir = Base.code_ircode_by_type(Tuple{typeof(f), Int, Int})[1][1]
1 1 ─ %1 = intrinsic Base.add_int(_2, _3)::Int64                                                                                                                                                                                 │╻ +
  └──      return %1                                                                                                                                                                                                             ││

julia> ir.argtypes[1] = Tuple{}
Tuple{}

julia> oc = Core.OpaqueClosure(ir; do_compile=true)
(::Int64, ::Int64)->◌::Int64
```

this is what we emitted before
```julia
julia> @code_typed oc(1, 2)
Pair{Core.CodeInfo, Any}(CodeInfo(
    @ REPL[8]:1 within `f`
   ┌ @ int.jl:87 within `+`
1 ─│ %1 =   dynamic Base.add_int(none@_2, none@_3)::Int64
└──│      return %1
   └
), Int64)

julia> using BenchmarkTools; @Btime $oc(1, 2)
  39.765 ns (0 allocations: 0 bytes)
```

and now:
```julia
julia> @code_typed oc(1, 2)
Pair{Core.CodeInfo, Any}(CodeInfo(
    @ REPL[93]:1 within `f`
   ┌ @ int.jl:87 within `+`
1 ─│ %1 = intrinsic Base.add_int(none@_2, none@_3)::Int64
└──│      return %1
   └
), Int64)

julia> using BenchmarkTools; @Btime $oc(1, 2)
  2.678 ns (0 allocations: 0 bytes)
```

The overhead notably adds more and more with every statement, which for
~20 statements led to > 1 µs of overhead, and multiple allocations. This
overhead is observed on 1.12+ only (1.11 evaluates as fast as with this
change), which may have been surfaced by the partitioned bindings
feature.

(cherry picked from commit a5576b4)
Add `gcdx(a::Signed, b::Unsigned)` and `gcdx(a::Unsigned, b::Signed)`
methods to fix #58025:
```julia
julia> gcdx(UInt16(100), Int8(-101))  # pr
(0x0001, 0xffff, 0xffff)

julia> gcdx(UInt16(100), Int8(-101))  # master, incorrect result
(0x0005, 0xf855, 0x0003)
```

Also add the equivalent methods for `lcm` to fix the systematic
`InexactError` when one argument is a negative `Signed` and the other is
any `Unsigned`:
```julia
julia> lcm(UInt16(100), Int8(-101))  # pr
0x2774

julia> lcm(UInt16(100), Int8(-101))  # master, error
ERROR: InexactError: trunc(UInt16, -101)
Stacktrace:
 [1] throw_inexacterror(func::Symbol, to::Type, val::Int8)
   @ Core ./boot.jl:866
 [2] check_sign_bit
   @ ./boot.jl:872 [inlined]
 [3] toUInt16
   @ ./boot.jl:958 [inlined]
 [4] UInt16
   @ ./boot.jl:1011 [inlined]
 [5] convert
   @ ./number.jl:7 [inlined]
 [6] _promote
   @ ./promotion.jl:379 [inlined]
 [7] promote
   @ ./promotion.jl:404 [inlined]
 [8] lcm(a::UInt16, b::Int8)
   @ Base ./intfuncs.jl:152
 [9] top-level scope
   @ REPL[62]:1
```

Inspired by
#59487 (comment).
The difference is that the solution proposed in this PR keeps the
current correct result type for inputs such as `(::Int16, ::UInt8)`.

(cherry picked from commit 4f1e471)
@KristofferC KristofferC force-pushed the backports-release-1.12 branch from 2e71e44 to 2907ebd Compare September 30, 2025 15:28
@OlivierHnt
Copy link
Contributor

Can #59063 be added to this list? The changes made in the PR are minimal and fix a rounding bug when converting Rational to BigFloat.

@aviatesk
Copy link
Member

aviatesk commented Oct 1, 2025

I think we can backport it, if there are no particular objections from cc @adienes @oscardssmith.

@adienes
Copy link
Member

adienes commented Oct 1, 2025

none here

@oscardssmith
Copy link
Member

none

@aviatesk aviatesk force-pushed the backports-release-1.12 branch from acdc210 to 3c7e88b Compare October 1, 2025 16:29
aviatesk and others added 7 commits October 2, 2025 16:26
…59722)

Following up #58872.
Since `e` is potentially arbitrary runtime value, we should not
specialize on it.
Previously, add_ptr and sub_ptr intrinsics were incorrectly inferred as
potentially throwing because they fell through to the general primitive
type check, which was incorrect after #53687 changed them. This adds
explicit handling in intrinsic_exct to return Union{} (nothrow) when
given correct argument types (Ptr and UInt), similar to #57398.

Fixes #57557

Written by Claude
the comment claims:

> When the concrete type of p is signed and has the lowest value,
>   `p != 0 && p == -p` is equivalent to `p == typemin(typeof(p))`

this is true, but fails to consider that `p == -p` is also true when `p
= div(typemax(UInt), 2) + 1`, and that `p` is not necessarily signed

leading to incorrect results on inputs like

```
julia> powermod(0x03, 0x80, 0x07)
0x01
```

which should be `0x02`

(cherry picked from commit bb3be0d)
Fixes #44679

Co-authored-by: KristofferC <[email protected]>
(cherry picked from commit 65ef689)
This was correct prior to changing closures to use Core.Typeof, but was
not corrected when that PR was merged.

This doesn't seem to quite fix issue #56861, since we used to have a
precompile workload for this, and now REPL is a separate package.

(cherry picked from commit 9c8886c)
maxsize is usually typemax, so need to be careful to not do comparisons
after adding to it. Substracting from it should normally be perfectly
fine. At worst we should compute a negative amount of space remaining.

(cherry picked from commit 85687b5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release Release management and versioning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants