Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modifying user-expressions in macros #3639

Merged
merged 1 commit into from Dec 20, 2023
Merged

Conversation

odow
Copy link
Member

@odow odow commented Dec 20, 2023

Closes #3638

Looks like this was caused by the new MA.rewrite( ; move_factors_into_sums = false) code path in #3106

julia> JuMP._MA.rewrite(:(e))
(Symbol("##308"), :(var"##308" = begin
          #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:325 =#
          let
              #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:326 =#
              begin
                  var"##310" = MutableArithmetics.Zero()
                  var"##309" = (MutableArithmetics.operate!!)(MutableArithmetics.add_mul, var"##310", $(Expr(:escape, :e)))
              end
              #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:327 =#
              var"##309"
          end
      end))

julia> JuMP._MA.rewrite(:(e); move_factors_into_sums = false)
(Symbol("##311"), :(var"##311" = begin
          #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:325 =#
          let
              #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:326 =#
              begin
                  #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:321 =#
              end
              #= /Users/oscar/.julia/packages/MutableArithmetics/NIXlP/src/rewrite.jl:327 =#
              $(Expr(:escape, :e))
          end
      end))

Note how the latter does not create a copy of the expression.

@odow odow mentioned this pull request Dec 20, 2023
14 tasks
Copy link

codecov bot commented Dec 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f5f07b5) 98.27% compared to head (a493931) 98.27%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3639   +/-   ##
=======================================
  Coverage   98.27%   98.27%           
=======================================
  Files          43       43           
  Lines        5636     5639    +3     
=======================================
+ Hits         5539     5542    +3     
  Misses         97       97           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@odow odow merged commit 868b3d5 into master Dec 20, 2023
12 checks passed
@odow odow deleted the od/fix-modifying-user-data branch December 20, 2023 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Constraint macro modifies expression
1 participant