-
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
Reduce immutable/mutable diffs (UPDATE: now ready for merge) #1571
Reduce immutable/mutable diffs (UPDATE: now ready for merge) #1571
Conversation
Just added |
Codecov Report
@@ Coverage Diff @@
## master #1571 +/- ##
==========================================
+ Coverage 73.21% 73.21% +<.01%
==========================================
Files 482 482
Lines 246422 246379 -43
==========================================
- Hits 180411 180395 -16
+ Misses 66011 65984 -27
|
84305e6
to
5bc5c95
Compare
** (i.e., built into GAP), and mutable (i.e., can change due to assignments), | ||
** and 0 otherwise. | ||
*/ | ||
static inline Int IS_MUTABLE_PLAIN_OBJ(Obj obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function IS_MUTABLE_PLAIN_OBJ
was meant to be kind of an optimization, but of course it's mostly redundant with the changes to IS_MUTABLE_OBJ
in PR #1563.
src/plist.h
Outdated
return NewBag(type, (plen + 1) * sizeof(Obj)); | ||
} | ||
|
||
static inline Obj NEW_IMM_PLIST(UInt type, Int plen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps NEW_IMM_PLIST
should be called NewImmutablePlist
, and we also provide a NewMutablePlist
?
I should probably point out that the changes in this PR are not that attractive w/o PR #1563, as I essentially replace dispatch via our TNUM based tables by another layer of |
@markuspf perhaps you want to combine the two PRs? I am not going to work more on this particular PR in the near future, but perhaps you are interested in picking it up -- I see you already made some of the changes I mentioned above in your PR? (Also, several of the commits in this PR probably could be squashed together; I just split them up like that in order to track down the crashes caused by me overlooking that |
5bc5c95
to
e9bd801
Compare
e9bd801
to
aee10be
Compare
aee10be
to
277d927
Compare
I think having something like this would be helpful: static inline Obj NEW_PLIST_WITH_GIVEN_MUTABILITY(UInt type, Int plen, Int mut)
{
GAP_ASSERT(type & IMMUTABLE == 0);
if (!mut)
type |= IMMUTABLE;
return NEW_PLIST(type, plen);
} This could then be used to convert tons of places containing code like this: img = NEW_PLIST( IS_MUTABLE_OBJ(pair) ? T_PLIST : T_PLIST+IMMUTABLE, 2 ); In order to introduce the (im)mutable object flag @markuspf is working on, now only that function has to be changed, instead of all the places calling it. Of course a better name would be nice... ;-). And |
Another potentially useful function, which could be used to gradually migrate our codebase: void MakeImmutablePlist(Obj plist)
{
GAP_ASSERT(IS_PLIST(plist));
#ifdef IMMUTABLE
const UInt tnum = TNUM_OBJ(plist);
RetypeBag( plist, tnum | IMMUTABLE );
#else // (im)mutable object flag
SET_OBJ_FLAG(bag, OBJ_FLAG_IMMUTABLE);
#ifdef HPCGAP
MakeBagPublic(plist);
#endif
#endif
} |
277d927
to
2d9c0eb
Compare
I've lost track of what's up with this PR, and related things. If this one is the best we've got, and we could rebase it, I think it's an improvement. |
2d9c0eb
to
a1cb7de
Compare
I just rebased this. However, I am not so sure it's useful to merge this in isolation, at least right now. The main goal (as you know) was to serve as foundation for a bigger change which gets rid of the So I'd rather delay this until after 4.9, and then perhaps pick up work on the whole IMMUTABLE business. So far, what I feel is missing is a more concrete vision as to how to achieve the transition (incrementally or not). One approach is to start by adding the object flag in addition to the TNUM bit, and then add checks to verify they are in sync. @markuspf did that with the now closed PR #1563, and I think run into some problems (and fixed some, and some remain for now). So we also need to work on those issues (perhaps starting by listing them somewhere). |
This is also still on my radar, but work had stalled, I think I would need to take a fresh look at it. On the upside the work on #1563 shook out the problems with |
Just to add, I think introducing the mutability object flag is quite feasible: the biggest stalling point was making a decision as to whether the flag should reflect mutability or immutability. |
59792f3
to
681b3c9
Compare
681b3c9
to
13c4387
Compare
8d15cdf
to
cf21baa
Compare
I changed my mind and would like to merge this now anyway -- I rebased it and improved it, though. Of course @ChrisJefferson already approved this ages ago, but I believe it would be sensible if he or somebody else had another brief look at this. |
cf21baa
to
a8b0c13
Compare
This was for an older, different version of this PR.
fe79b14
to
d6bd3e6
Compare
Also handle all CONSTANT_TNUMs and IMM_MUT_TNUMs directly
d6bd3e6
to
352fda4
Compare
UPDATE: I believe this could be merged now. Also, I submitted issue #2325 for the general (im)mutability plan.
This PR builds extends PR #1570, and again is motivated by PR #1563: It unifies some code to reduce difference between mutable and immutable cases. The number of word occurrences of
IMMUTABLE
, as counted bygit grep -w IMMUTABLE src | wc -l
goes slightly down from 1328 to 565. But once one runs the script below, it goes down to 309, i.e. a quarter of what we started with.This now makes it much easier to decide how to deal with the rest. Some immediate observations on those:
NEW_IMM_PLIST
function (possibly with a different name) would take care of quite a few of those occurences (and this function could immediately set the newOBJ_FLAG_IMMUTABLE
)RetypeBag
calls to change immutability... it might be useful to have a faster variant ofMakeImmutable
, which is only useful for builtin lists and record, and directly modifies the TNUM (now) resp. object flag (with PR Immutable Object Flag (WIP) #1563)MakeBagTypePublic
cannot be used to automatically migrate immutable list and record bags to the public region. No big deal, though (and I actually like that we can thus remove some logic fromRetypeBag
)IsMutableObjFuncs
likely can and should be removed once we get rid of theIMMUTABLE
bit in the TNUMHere is the script I mentioned above: