Skip to content

Commit

Permalink
Update to [email protected] and use return_is_mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 18, 2024
1 parent fc0409a commit 1285829
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 1 addition & 6 deletions src/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1285829

Please sign in to comment.