diff --git a/Project.toml b/Project.toml index 7de631d5a9e..e0f22d760ef 100644 --- a/Project.toml +++ b/Project.toml @@ -24,7 +24,7 @@ DimensionalData = "0.24, 0.25, 0.26.2, 0.27, 0.28, 0.29" LinearAlgebra = "<0.0.1, 1.6" MacroTools = "0.5" MathOptInterface = "1.34.0" -MutableArithmetics = "1.1" +MutableArithmetics = "1.6" OrderedCollections = "1" Printf = "<0.0.1, 1.6" PrecompileTools = "1" diff --git a/src/JuMP.jl b/src/JuMP.jl index de4ba0189d9..d013f7bc17d 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -20,17 +20,12 @@ module JuMP import LinearAlgebra import MacroTools import MathOptInterface as MOI -import MutableArithmetics +import MutableArithmetics as _MA import OrderedCollections import OrderedCollections: OrderedDict import Printf import SparseArrays -# We can't use import MutableArithmetics as _MA because of a bug in MA. -# Fixed in MutableArithmetics v1.2.3, but would require bumping the compat -# bound so we can keep it as this until necessary. -const _MA = MutableArithmetics - """ MOIU diff --git a/src/macros.jl b/src/macros.jl index c9749d84cc6..f435117ff18 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -251,18 +251,15 @@ expressions. """ function _rewrite_expression(expr::Expr) new_expr = MacroTools.postwalk(_rewrite_to_jump_logic, expr) - new_aff, parse_aff = _MA.rewrite(new_expr; move_factors_into_sums = false) - ret = gensym() - has_copy_if_mutable = Ref(false) - MacroTools.postwalk(parse_aff) do x - if x === MutableArithmetics.copy_if_mutable - has_copy_if_mutable[] = true - end - return x - end - if !has_copy_if_mutable[] + new_aff, parse_aff, is_mutable = _MA.rewrite( + new_expr; + move_factors_into_sums = false, + return_is_mutable = true, + ) + if !is_mutable new_aff = :($_MA.copy_if_mutable($new_aff)) end + ret = gensym() code = quote $parse_aff $ret = $flatten!($new_aff)