-
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
Extend BindConstant
, MakeConstantGlobal
to all object types.
#4142
Extend BindConstant
, MakeConstantGlobal
to all object types.
#4142
Conversation
Currently we only support these on integer and boolean values. This patch extends this to all object types. This would then simply be a "non-reversible" version of `MakeReadOnlyGlobal`; i.e., unlike that, a "constant global variables" can never be turned into a non-constant one. That is, it will always refer to the same object. Semantically this interpretation of `constness` is in line with other languages, such as Julia, where `const` refers to the (re)assignability of a variable identifier, *not* to the mutability of the object it refers to. (Note that this is admittedly somewhat confusing in GAP, with `MakeReadOnlyGlobal`/`MakeReadOnlyGVar` doing one thing and `MakeReadOnlyObj` doing something orthogonal (and for now only in HPC-GAP.... Note that no further use is made of this for now; in particular, unlike for small integer values, `true` and `false`, no attempt is made to "inline" constant object in function definitions. However, interfaces to other languages (such as the GAP-Julia interface) could exploit constness for various optimizations.
I'm happy with this -- the original restriction to bools and ints was because we can make those more efficient, and I wanted to check there were no unpleasent surpries before extending. I haven't checked how this interacts with SwapMasterPoint -- I imagine it will be fine, but certainly people who want to use this for other stuff should be aware of that (or choose explictly to ignore it). |
Good point! Of course |
@ChrisJefferson if you are happy with this, does that mean you approve (hint, hint ;-) ) or perhaps you'd like us to get a third opinion? |
BindConstant
, MakeConstantGlobal
to all object types.
Currently we only support these on integer and boolean values. This patch
extends this to all object types. This would then simply be a "non-reversible"
version of
MakeReadOnlyGlobal
; i.e., unlike that, a "constant globalvariables" can never be turned into a non-constant one. That is, it will
always refer to the same object.
Semantically this interpretation of
constness
is in line with otherlanguages, such as Julia, where
const
refers to the (re)assignability of avariable identifier, not to the mutability of the object it refers to. (Note
that this is admittedly somewhat confusing in GAP, with
MakeReadOnlyGlobal
/MakeReadOnlyGVar
doing one thing andMakeReadOnlyObj
doing something orthogonal (and for now only in HPC-GAP....
Note that no further use is made of this for now; in particular, unlike for
small integer values,
true
andfalse
, no attempt is made to "inline"constant object in function definitions. However, interfaces to other
languages (such as the GAP-Julia interface) could exploit constness for
various optimizations (cc @rfourquet).