From ae2ecaf3ac0d62c0b2e09e16f623c167c70fbb08 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 2 Sep 2026 22:57:05 +0000 Subject: [PATCH] CHOLMOD: Prefer `RefValue` to `Ref` for fields and type-assertions `getcommon` asserted the abstract `Ref{cholmod_common}` on the value it fetches from task-local storage, and `Factor` typed its scratch buffers `X`, `Y` and `E` as the abstract `Ref{Ptr{...}}`. With those abstract types every `common[]`, every wrapper call taking it, and every read of the buffers was a dynamic call, which kept the whole CHOLMOD layer from compiling under juliac's `--trim`. The values are always `RefValue`s; say so. This commit was written with the assistance of generative AI (Claude). Co-Authored-By: Claude Fable 5.1 --- src/solvers/cholmod.jl | 10 +++++----- test/cholmod.jl | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/solvers/cholmod.jl b/src/solvers/cholmod.jl index 9d5ce1dc..d96b7175 100644 --- a/src/solvers/cholmod.jl +++ b/src/solvers/cholmod.jl @@ -173,12 +173,12 @@ end function getcommon(::Type{Int32}) LibSuiteSparse.init_suitesparse() - return get!(newcommon, task_local_storage(), :cholmod_common)::Ref{cholmod_common} + return get!(newcommon, task_local_storage(), :cholmod_common)::Base.RefValue{cholmod_common} end function getcommon(::Type{Int64}) LibSuiteSparse.init_suitesparse() - return get!(newcommon_l, task_local_storage(), :cholmod_common_l)::Ref{cholmod_common} + return get!(newcommon_l, task_local_storage(), :cholmod_common_l)::Base.RefValue{cholmod_common} end getcommon() = getcommon(Int) @@ -264,9 +264,9 @@ mutable struct Factor{Tv<:VTypes, Ti<:ITypes} <: Factorization{Tv} ptr::Ptr{cholmod_factor} dense_x::cholmod_dense_struct dense_b::cholmod_dense_struct - X::Ref{Ptr{cholmod_dense_struct}} - Y::Ref{Ptr{cholmod_dense_struct}} - E::Ref{Ptr{cholmod_dense_struct}} + X::Base.RefValue{Ptr{cholmod_dense_struct}} + Y::Base.RefValue{Ptr{cholmod_dense_struct}} + E::Base.RefValue{Ptr{cholmod_dense_struct}} lock::ReentrantLock function Factor{Tv, Ti}(ptr::Ptr{cholmod_factor}, register_finalizer = true) where {Tv, Ti} if ptr == C_NULL diff --git a/test/cholmod.jl b/test/cholmod.jl index d6b91b1e..b152ee26 100644 --- a/test/cholmod.jl +++ b/test/cholmod.jl @@ -368,6 +368,12 @@ end end #end for Ti ∈ itypes for Tv ∈ (Float32, Float64) +@testset "per-type buffers should be concretely typed" begin + @test @inferred(SparseArrays.CHOLMOD.getcommon()) isa Base.RefValue + F = cholesky(sparse(Tv[2 1; 1 2])) + @test @inferred((F -> getfield(F, :Y)[])(F)) isa Ptr +end + @testset "Issue #9915" begin sparseI = sparse(Tv(1.0)I, 2, 2) @test sparseI \ sparseI == sparseI