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

StackOverflow with operate!! and NonlinearExpr #3469

Closed
blegat opened this issue Aug 31, 2023 · 5 comments
Closed

StackOverflow with operate!! and NonlinearExpr #3469

blegat opened this issue Aug 31, 2023 · 5 comments

Comments

@blegat
Copy link
Member

blegat commented Aug 31, 2023

This should be investigated, I wouldn't expect this to cause a StackOverflow

# We can't use `operate!!` here because in the IsNotMutable case (e.g.,
# NonlinearExpr), it will fallback to this method and cause a StackOverflow.
if _MA.mutability(T) == _MA.IsNotMutable()

@odow
Copy link
Member

odow commented Aug 31, 2023

I think this is expected behavior. See #3106 (comment)

julia> import MutableArithmetics as MA

julia> struct Foo <: MA.AbstractMutable
           x::Int
       end

julia> Base.copy(f::Foo) = Foo(f.x)

julia> function MA.add_mul(lhs::Foo, x::Union{Int,Foo}, y::Union{Int,Foo})
           return MA.operate!!(MA.add_mul, copy(lhs), x, y)
       end

julia> lhs = Foo(2)
Foo(2)

julia> x = Foo(3)
Foo(3)

julia> MA.add_mul(lhs, x, 3)
ERROR: StackOverflowError:
Stacktrace:
     [1] operate_fallback!!(::MutableArithmetics.IsNotMutable, ::typeof(MutableArithmetics.add_mul), ::Foo, ::Foo, ::Int64)
       @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/interface.jl:581
     [2] operate!!(::typeof(MutableArithmetics.add_mul), ::Foo, ::Foo, ::Int64)
       @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/rewrite.jl:89
     [3] add_mul(lhs::Foo, x::Foo, y::Int64)
       @ Main ./REPL[26]:2
     [4] operate(op::typeof(MutableArithmetics.add_mul), x::Foo, y::Foo, args::Int64)
       @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/interface.jl:206
     [5] operate_fallback!!(::MutableArithmetics.IsNotMutable, ::typeof(MutableArithmetics.add_mul), ::Foo, ::Foo, ::Int64)
       @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/interface.jl:586
--- the last 4 lines are repeated 19994 more times ---
 [79982] operate!!(::typeof(MutableArithmetics.add_mul), ::Foo, ::Foo, ::Int64)
       @ MutableArithmetics ~/.julia/dev/MutableArithmetics/src/rewrite.jl:89
 [79983] add_mul(lhs::Foo, x::Foo, y::Int64)
       @ Main ./REPL[26]:2

@blegat
Copy link
Member Author

blegat commented Aug 31, 2023

Oh sorry I missed that comment. It's good the PR is merged and we can now discuss on separate issue, it's going to be easier to keep track of discussions threads ^^

@odow
Copy link
Member

odow commented Aug 31, 2023

I don't understand what there is to discuss here. This is expected behavior. The definition of add_mul ends up calling the same definition of add_mul, which is a recursive loop.

@odow
Copy link
Member

odow commented Sep 2, 2023

What is there to do here?

@blegat blegat closed this as completed Sep 2, 2023
@blegat
Copy link
Member Author

blegat commented Sep 2, 2023

I think it's fine, we could add a link to this issue in the comments in the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants