From c41be1179b5ce7912a64022d382a09ccf857c304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 5 Jun 2026 17:41:25 +0100 Subject: [PATCH] Don't copy ScalarNonlinearFunction in VectorOfConstraints --- src/Utilities/vector_of_constraints.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Utilities/vector_of_constraints.jl b/src/Utilities/vector_of_constraints.jl index b12b97bd85..d02459083d 100644 --- a/src/Utilities/vector_of_constraints.jl +++ b/src/Utilities/vector_of_constraints.jl @@ -103,7 +103,14 @@ function MOI.get( ) where {F,S} MOI.throw_if_not_valid(v, ci) f, _ = v.constraints[ci]::Tuple{F,S} - return copy(f) + # Since `MA.mutability(MOI.ScalarNonlinearFunction)` is `MA.IsNotMutable`, + # this does not copy `MOI.ScalarNonlinearFunction`. This is important if the + # function share aliases of the same subexpression at different parts of + # it's expression graph or the expression graph of other functions of the + # model. If we `copy`, they won't be aliases of the same subexpression + # anymore hence `MOI.Nonlinear.ReverseAD` won't detect them as common + # subexpressions. + return MA.copy_if_mutable(f) end function MOI.get(