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

Objectify: warn if Is{Component,Positional}ObjectRep absent #4964

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions lib/type1.g
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,6 @@ BIND_GLOBAL( "FlagsObj", obj -> FlagsType( TypeObj( obj ) ) );
BIND_GLOBAL( "DataObj", obj -> DataType( TypeObj( obj ) ) );


BIND_GLOBAL( "IsNonAtomicComponentObjectRepFlags",
FLAGS_FILTER(IsNonAtomicComponentObjectRep));
BIND_GLOBAL( "IsAtomicPositionalObjectRepFlags",
FLAGS_FILTER(IsAtomicPositionalObjectRep));
BIND_GLOBAL( "IsReadOnlyPositionalObjectRepFlags",
FLAGS_FILTER(IsReadOnlyPositionalObjectRep));

#############################################################################
##
#F Objectify( <type>, <obj> )
Expand All @@ -592,26 +585,40 @@ BIND_GLOBAL( "Objectify", function ( type, obj )
if not IsType( type ) then
Error("<type> must be a type");
fi;
flags := FlagsType(type);
if IsHPCGAP then
flags := FlagsType(type);
if IS_LIST( obj ) then
if IS_SUBSET_FLAGS(flags, IsAtomicPositionalObjectRepFlags) then
if IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsAtomicPositionalObjectRep)) then
FORCE_SWITCH_OBJ( obj, FixedAtomicList(obj) );
fi;
elif IS_REC( obj ) then
if IS_ATOMIC_RECORD(obj) then
if IS_SUBSET_FLAGS(flags, IsNonAtomicComponentObjectRepFlags) then
if IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsNonAtomicComponentObjectRep)) then
FORCE_SWITCH_OBJ( obj, FromAtomicRecord(obj) );
fi;
elif not IS_SUBSET_FLAGS(flags, IsNonAtomicComponentObjectRepFlags) then
elif not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsNonAtomicComponentObjectRep)) then
FORCE_SWITCH_OBJ( obj, AtomicRecord(obj) );
fi;
fi;
fi;
if IS_LIST( obj ) then
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Comment on lines +605 to +606
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe disable this by default, but have it enabled e.g. in most test suites (as long as the use START_TEST)?

Suggested change
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
#Assert(1, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(1, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));

if not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)) then
INFO_DEBUG(1, "Objectify: type does not imply IsPositionalObjectRep ",
INPUT_FILENAME(), ":", STRING_INT(INPUT_LINENUMBER()));
fi;
SET_TYPE_POSOBJ( obj, type );
elif IS_REC( obj ) then
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Comment on lines +613 to +614
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
#Assert(1, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(1, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));

if not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)) then
INFO_DEBUG(1, "Objectify: type does not imply IsComponentObjectRep ",
INPUT_FILENAME(), ":", STRING_INT(INPUT_LINENUMBER()));
fi;
SET_TYPE_COMOBJ( obj, type );
else
Error("<obj> must be a list or a record");
fi;
if not ( IGNORE_IMMEDIATE_METHODS
or IsNoImmediateMethodsObject(obj) ) then
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/kernel/gap.tst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gap> START_TEST("kernel/gap.tst");
# in ViewObj; afterwards everything should still work as before
gap> l := [ ~ ];; r := rec(a:=~);;
gap> cat := NewCategory("IsMockObject", IsObject);;
gap> type := NewType(NewFamily("MockFamily"), cat);;
gap> type := NewType(NewFamily("MockFamily"), cat and IsPositionalObjectRep);;
gap> InstallMethod(ViewObj, [cat], function(s) Error("oops"); end);
gap> InstallMethod(PrintObj, [cat], function(s) Error("uups"); end);
gap> x:=Objectify(type,[]); r; Print(l, "\n");
Expand Down
4 changes: 2 additions & 2 deletions tst/testinstall/kernel/opers.tst
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ gap> CLEAR_CACHE_INFO();
gap> opcheck := OPERS_CACHE_INFO();;
#@if GAPInfo.KernelInfo.KernelDebug and IsHPCGAP
gap> opcheck{[1..11]};
[ 2, 0, 0, 6, 0, 0, 6, 0, 0, 2, 0 ]
[ 2, 0, 0, 6, 0, 0, 10, 0, 0, 2, 0 ]
#@fi

# FIXME: the following code skips entry 4 (OperationHit, which is normally
Expand Down Expand Up @@ -338,7 +338,7 @@ gap> opcheck{[1..11]};
#
#@if GAPInfo.KernelInfo.KernelDebug and not IsHPCGAP
gap> opcheck{Difference([1..11], [4])};
[ 2, 0, 0, 0, 0, 4, 0, 0, 2, 0 ]
[ 2, 0, 0, 0, 0, 8, 0, 0, 2, 0 ]
#@fi
#@if not GAPInfo.KernelInfo.KernelDebug
gap> opcheck{[1..11]};
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/object.tst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gap> START_TEST("object.tst");

# test some standard object types
gap> r := Objectify(TYPE_KERNEL_OBJECT, rec());
gap> r := [];; SET_TYPE_DATOBJ(r,TYPE_KERNEL_OBJECT);
<kernel object>
gap> KnownAttributesOfObject(r);
[ ]
Expand Down
Loading