Skip to content
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

Immutable Object Flag (WIP) #1563

Closed
wants to merge 8 commits into from

Conversation

markuspf
Copy link
Member

@markuspf markuspf commented Aug 4, 2017

This PR a work-in-progress to introduce an object flag OBJ_FLAG_IMMUTABLE instead of using TNUMs to determine mutability of objects.

This will make #1520 obsolete.

@markuspf markuspf added the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Aug 4, 2017
@codecov
Copy link

codecov bot commented Aug 4, 2017

Codecov Report

Merging #1563 into master will increase coverage by <.01%.
The diff coverage is 87.09%.

@@            Coverage Diff             @@
##           master    #1563      +/-   ##
==========================================
+ Coverage   63.97%   63.98%   +<.01%     
==========================================
  Files         993      993              
  Lines      325125   325147      +22     
  Branches    12986    12993       +7     
==========================================
+ Hits       208011   208032      +21     
+ Misses     114324   114322       -2     
- Partials     2790     2793       +3
Impacted Files Coverage Δ
src/gasman.c 81.7% <100%> (+0.14%) ⬆️
src/hpc/threadapi.c 35.22% <100%> (+0.19%) ⬆️
src/plist.c 88.34% <100%> (ø) ⬆️
src/boehm_gc.c 91.95% <100%> (+0.23%) ⬆️
src/objects.h 78.43% <66.66%> (-1.57%) ⬇️
src/objects.c 74.96% <75%> (-0.2%) ⬇️
hpcgap/lib/hpc/stdtasks.g 38.61% <0%> (-0.26%) ⬇️
src/hpc/thread.c 46.64% <0%> (-0.2%) ⬇️
... and 1 more

src/objects.c Outdated
@@ -809,10 +809,13 @@ void (*MakeImmutableObjFuncs[LAST_REAL_TNUM+1])( Obj );
void MakeImmutable(Obj obj)
{
if (IS_MUTABLE_OBJ(obj)) {
SET_OBJ_FLAG(obj, OBJ_FLAG_IMMUTABLE);
if (!IS_INTOBJ(obj) && !IS_FFE(obj)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither INTOBJ not FFE can ever be mutable, so I'm not sure what this check is for.

Copy link
Member Author

@markuspf markuspf Aug 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a consequence of me introducing a bug in IS_MUTABLE_OBJ which meant that SET_OBJ_FLAG would be called on FFEs or INTOBJs. This is something I fixed on the train yesterday (but didn't push yet, since I break HPC-GAP in interesting ways which I want to understand first).

@markuspf
Copy link
Member Author

markuspf commented Aug 7, 2017

As also pointed out by @fingolfin on the slack channel there might be a point in introducing a mutability flag.

This would mean more changes initially, but it is probably more sane to have immutable objects as a default and having to make things mutable explicitly.

I'll have a look at the required changes.

{
if(IS_INTOBJ(obj) || IS_FFE(obj)) {
return 0;
} else if (TEST_OBJ_FLAG(obj, OBJ_FLAG_IMMUTABLE) == OBJ_FLAG_IMMUTABLE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be more like

  } else if (FIRST_IMM_MUT_TNUM <= type && type <= LAST_IMM_MUT_TNUM) {
    return TEST_OBJ_FLAG(obj, OBJ_FLAG_IMMUTABLE) != OBJ_FLAG_IMMUTABLE;
  } else {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on whether you want the immutable flag to only be valid for those TNUMs I suppose?
Admittedly it makes little sense to start allowing making permutations mutable...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As they are set up OBJ_FLAGS are universal -- the meaning or value of a flag is not bound to specific TNUMs for which it makes sense.

So it would seem logical to make sure each flag is set appropriately even for those TNUMs where there is only one appropriate setting. So all permutations would have the immutable flag, for instance (or not have the mutable flag). Unless this creates some run-time overhead I haven't thought of, then it seems simpler. The only problem would be if we ran out of flag bits.

That leaves T_INTOBJ and T_FFE. I think the nicest way to handle those (and the most consistent with what is done for those objects elsewhere) is to distinguish BAG_FLAGS from OBJ_FLAGS and deal with the two immediate types in the OBJ_FLAGS code. So Gasman never has to worry about those types and higher level code sees flags consistently on every object.

@fingolfin
Copy link
Member

Another idea: how about adjusting ASS_LIST and ASSS_LIST to check for the (im)mutable object flag, and reject any assignments early on, with a uniform error message ("cannot assign to immutable objects")?

@markuspf
Copy link
Member Author

Never going to be finished, anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants