gap-system / gap

Main development repository for GAP - Groups, Algorithms, Programming, a System for Computational Discrete Algebra
https://www.gap-system.org
GNU General Public License v2.0
805 stars 163 forks source link

DEEP_COPY_OBJ copies Immutable objects #236

Open ChrisJefferson opened 9 years ago

ChrisJefferson commented 9 years ago

In GAP, we get:

gap> DeclareGlobalVariable("xyz");
gap> IsMutable(xyz);
false
gap> IsIdenticalObj(xyz, DEEP_COPY_OBJ(xyz));
true

Whereas in HPC-GAP this returns false.

There doesn't seem to be a good reason to make a new object -- in this case the original and new objects are put in the same region.

I tried diving into the code to find out how to stop this happening, but couldn't easily figure out how to change it.

rbehrends commented 9 years ago

The underlying problem is that DeclareGlobalVariable(xyz) puts an immutable positional object in variable xyz. However, an immutable positional object need not have immutable state. And the HPC-GAP version of DEEP_COPY_OBJ() tries to make a copy of everything where the state isn't shared (e.g. atomic records) or immutable so as to avoid a thread suddenly and unexpectedly trying to read or modify an object that belongs to a different thread; it would still result in an error, but it could cause bugs.

What we probably need in the long term is both an in-region deep copy and a cross-region deep copy.