-
Notifications
You must be signed in to change notification settings - Fork 160
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
InstallValue
is broken for (at least) Types
#1637
Comments
We could try duplicating the logic of
|
Stepping back a minute, what would we like |
What we want is, I think, impossible. We want to find every reference to the "ToBeDefined" placeholder anywhere in the workspace and replace it by a reference to the exact object we are trying to install as its value. Since that's too hard, we change the object which is the ToBeDefined placeholder into a clone of the object we are trying to install. Mostly that's OK, but there is a problem when the identity of the value we are installing matters, which it does for a few things like types (because we maintain the invariant that equal types are identical. |
So here is a (nasty) way how we could perhaps resolve this: We add a new TNUM Now we go on in one of several ways:
Both approach are quite problematic and ugly. The first may be difficult to achieve in HPC-GAP (we can't really walk over all objects there, can we? And then there is a locking issue... we'd essentially have to "stop the world" for this). The second approach is problematic regarding the word "anywhere": we'd have to potentially change a lot of code, or else modify some very low level functions to make those checks, adding lots of overhead everywhere; and that just to support a rather obscure feature. That leaves variant 3: My bet is that almost all code using In other words, my guess here is that almost none of the placeholders escape, and thus the big problem we are trying to fix is almost a non-problem. Indeed, other than assigning the placeholder to another variable, there is precious little one can do with them, right? So, we could just make that a rule, and then enforce it, by changing GAP to forbid use of And even if we determine that I am wrong, then at least we'll know a concrete example where I am wrong, and can continue discussing based on that. (I still hope this would be rare, and could be removed by refactoring the code). |
I think tidying this up would be nice. Another possibility would be to just leave the variable unbound, and come up with some way of stopping the error message (although, I can't immediately think of a better way of doing that than something similar to what you describe) |
Although, that would require |
@ChrisJefferson yeah, that sounds like a nice approach, except that we'd have to turn Anyway: Right now, a declared but not installed variable still ...
When we change this, we need to be a bit careful about not breaking things silently (it is OK to break things, it should just be guaranteed that this results in an immediate error, and not some code which silently changes its behavior). So, one approach would be to do what I suggested, and declare a special "placeholder" type. That sounds like quite some work and deeper changes to the kernel The approach suggested by @ChrisJefferson, if I understand it right, would be to, say, keep a list of global variables which are unbound but for which we suppress the "unbound variable" syntax warning. That still sounds like something that requires kernel changes, but much more localized (yay!). Indeed, we could do this: First, we immediately reserve the gvar id for that variable; then, we add it to a list / bitlist (T_BLIST) / OBJ_SET / whatever. Then, in the place that triggers the syntax warning, we ignore any gvar id in that list. Also, once a value gets installed, we can delete it from that list (however, that's not strictly necessary). This approach should work as long as no code does the equivalent of |
I suggest to re-assign this to a future milestone (4.9.1 or even 4.10.0). |
Re-assigned to 4.10.0. This would be a major change, so certainly nothing for a minor bugfix release |
Also: My idea for resolving this unfortunately was way too naive and does not work. So this still needs more work. I thought some more about the idea @ChrisJefferson sketched (i.e. simply not binding the variable upon declaration; instead adding it to a list which then is used to suppress the warnings; and finally a gross but probably simple hack to the interpreter to accept such declared variables as first argument to However, even with that, I worry about problems with flushable variables, as there we cannot avoid redefining a previously bound variable... |
Actually, the way I read the documentation for
i.e., I would not be able to deduce from this that the following example would behave the way it does:
This suggests a very simple solution to this mess:
Of course if we are more ambitious, we could also do something completely different, and introduce a syntax extension which allows changing the usual
With this, Anyway, this is a much more difficult and ambitious solution, and certainly not without controversy (e.g. it is not easily visible for a given function call whether any of the arguments to the function are passed by-sharing or by-reference), so despite personally liking the idea of introducing call-by-reference support, I think in this case the much simple approach I described first is preferable. |
Removing the milestone. Nobody is working on this right now; it only makes sense to set a milestone if we have a clear plan how to solve a given issue, resp. volunteers who promise to take care of it in a given time frame. |
InstallValue is one of a tiny handful of places calling the GAP kernel function CLONE_OBJ. This function is rather dangerous, e.g. for *types* it is not really well-defined, see gap-system/gap#1637. While I am not aware of any ill-effects of the usage here, I think it is best to avoid it (and perhaps we can at some point even phase out support for `InstallValue` used on non-plain objects)
My current plan is to eliminate as many uses of |
For some background, see gap-system/gap#1637
For some background, see gap-system/gap#1637
For some background, see gap-system/gap#1637
For some background, see gap-system/gap#1637
For some background, see gap-system/gap#1637
See gap-system/gap#1637 for some background. The `DeclareGlobalVariable` calls are left in, commented out, so that AutoDoc still "sees" them when generating the manual.
So don't do it, see gap-system/gap#1637 Also remove some unused families.
So don't do it, see gap-system/gap#1637 Also remove some unused families.
Currently GAP handles forward declarations and installations of values for global variables as follows:
DeclareGlobalVariable
registers a global variable name and installs a dummy valueToBeDefined
for itInstallValue
copies the new value over the dummy object usingCLONE_OBJ
Now the following is possible:
This is roughly how the
NEW_TYPE
cache works, which means at the very least we must not install values for types this way.I couldn't come up with a better solution for the
DeclareGlobalVariable
.InstallValue
yet, and we might have to forbidInstallValue
(or rather CLONE_OBJ) for all kinds of objects.Maybe @stevelinton @fingolfin or @ChrisJefferson have a bright idea.
The text was updated successfully, but these errors were encountered: