-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
StackOverflowError when adding an structure inside DEDataVector in a Module #526
Comments
In fact, this is a strange behavior related to precompilation. Starting Julia with |
The workaround is to create a generated function inside @generated function RecursiveArrayTools.recursivecopy!(dest::Workspace{T}, src::Workspace{T}) where T
fields = fieldnames(src)
expressions = Vector{Expr}(undef, length(fields))
@inbounds for i = 1:length(fields)
f = fields[i]
Tf = src.types[i]
qf = Meta.quot(f)
if ArrayInterface.ismutable(Tf)
expressions[i] = :( dest.$f = getfield( src, $qf ) )
elseif Tf <: AbstractArray
expressions[i] = :( recursivecopy!(dest.$f, getfield( src, $qf ) ) )
else
expressions[i] = :( dest.$f = deepcopy( getfield( src, $qf ) ) )
end
end
:($(expressions...); dest)
end EDIT: For the general case, the same must be done for EDIT2: After thinking for a while, I have absolutely no idea how this can be fix. In fact, I think it cannot be fixed given the way Julia handles generated functions. If I am right, we need to document that, inside a module, we must have those definitions. EDIT3: Sorry for the long comments and many edits, I am in a middle of a brainstorm here :D @ChrisRackauckas what do you think to have a macro like |
I'm wondering, couldn't we just define |
Well, that will certainly solve everything in the most easy way! In fact, if anyone wants more performance, they can always overload those methods with a more specialize signature. |
Looping over the fields won't be type stable. For small arrays that could be pretty bad for performance. For large DEDataArrays, sure it's fine, but smaller ones is an issue. |
Wouldn't it help if we add a function barrier and replace the |
I cannot reproduce the stack overflow error. |
Did you paste the code inside a module? I tried here with a clean env and I reproduce it every time. |
Hi! Did anyone think about a better workaround than that one I posted? |
Hi! With the following code:
I am getting the following error when calling the function
test()
:I think it is related to the
@generated
functionrecursivecopy!
. Because, this code works outside a module:The text was updated successfully, but these errors were encountered: