-
Notifications
You must be signed in to change notification settings - Fork 161
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
Refactor DeclareAttribute and NewAttribute #2091
Refactor DeclareAttribute and NewAttribute #2091
Conversation
c29f290
to
742f5ae
Compare
I can't think of any reason for this being intentional. I can quite imagine wanting to rank up something like HasMutableStabChain. It makes less sense for something like HasKnownSylowSubgroups (or whatever it's called) because the filter doesn't tell you WHICH Sylow subgroups it has. |
742f5ae
to
f18b162
Compare
Codecov Report
@@ Coverage Diff @@
## master #2091 +/- ##
==========================================
+ Coverage 69.22% 69.23% +0.01%
==========================================
Files 489 489
Lines 256237 256274 +37
==========================================
+ Hits 177369 177436 +67
+ Misses 78868 78838 -30
|
I am also getting the urge to factor the argument checking code into a separate function for |
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.
This looks good, except for one issue I mention. This kind of code is always a bit horrible, so the ultimate test will be to test all packages/library code, and check nothing breaks by doing anything too crazy/unexpected.
hpcgap/lib/oper.g
Outdated
elif LEN_LIST(args) = 2 and args[1] in [ "mutable", true ] and IS_INT(args[2]) then | ||
mutflag := true; | ||
rank := args[2]; | ||
elif LEN_LIST(args) > 2 then |
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.
I think the logic is wrong here.. I think line 1202 should just be "else", otherwise if you get one or two arguments that don't match one of the earlier if/elifs, we silently accept them and do nothing?
hpcgap/lib/oper.g
Outdated
elif LEN_LIST(args) = 2 and args[1] in [ "mutable", true ] and IS_INT(args[2]) then | ||
mutflag := true; | ||
rank := args[2]; | ||
elif LEN_LIST(args) > 2 then |
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.
Same problem as mentioned above
lib/oper.g
Outdated
elif LEN_LIST(args) = 2 and args[1] in [ "mutable", true ] and IS_INT(args[2]) then | ||
mutflag := true; | ||
rank := args[2]; | ||
elif LEN_LIST(args) > 2 then |
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.
same issue as above
lib/oper.g
Outdated
elif LEN_LIST(args) = 2 and args[1] in [ "mutable", true ] and IS_INT(args[2]) then | ||
mutflag := true; | ||
rank := args[2]; | ||
elif LEN_LIST(args) > 2 then |
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.
same issue as above
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.
I'll look some more, but here a few quick comments
hpcgap/lib/oper.g
Outdated
mutflag := true; | ||
rank := args[2]; | ||
elif LEN_LIST(args) > 2 then | ||
Error("Usage: NewAttribute( <name>, <filter>, [<mutable>, <rank>] )"); |
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.
This should match the usage string at the start of the documentation comment, i.e. <name>, <filter>[, <mutable>][, <rank>]
hpcgap/lib/oper.g
Outdated
|
||
if not IS_OPERATION( filter ) then | ||
Error( "<filter> must be an operation" ); | ||
Error( "<filter> must be an operation" ); |
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 also check that name
is a string?
hpcgap/lib/oper.g
Outdated
mutflag := true; | ||
rank := args[2]; | ||
elif LEN_LIST(args) > 2 then | ||
Error("Usage: DeclareAttribute( <name>, <filter>, [<mutable>, <rank>] )"); |
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.
Adjust this to match the doc comment -- and perhaps both should be adjusted to match that of NewAttribute? I.e. <name>, <filter>[, <mutable>][, <rank>]
?
2ce8f3a
to
e86dab0
Compare
Argument checking code rewritten again. I also added tests to convince myself I cover all cases. |
e86dab0
to
b5ec9b2
Compare
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.
I think this is essentially good now. Sure, one could perhaps improve some of the doc comments, but I can easily do that in a future PR myself.
Unfortunately, this now conflicts with recent changes on master, but I think a rebase will go through mostly clean -- if not, I am happy to help if needed.
Also, the HPC-GAP tests now fail?
In any case, I'd like to get this merged ASAP so that I can look into syncing lib/oper.g
and hpcgap/lib/oper.g
.
## <Item> If the argument <A>mutable</A> is the string <C>"mutable"</C> or | ||
## the boolean <C>true</C>, then the values of the attribute are mutable. | ||
## </Item> | ||
## <Item> If the argument <A>mutable</A> is the boolean <C>false</C>, then |
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.
Hmm. I'd rather say: "Otherwise, i.e. if mutable is not given or set to false,"
## mutable.) | ||
## For the optional third and fourth arguments, there are the following | ||
## possibilities. | ||
## <List> |
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.
Why a list? And why talk about 3rd and 4th together? Perhaps this was because it is how one thinks about it when implementing it (i.e. "how do I distinguish which of the two args the user meant?), but somebody reading the docs cares little about it (and can easily guess it anyway, as the types of the two args are distinct).
How about something more like this:
If the argument is given, it must be a positive integer, which is used as incremental rank (see BLA). If not given, then 1 is used.
If the argument is given, and either equal to the string "mutable", or to the boolean true, then ...
If is false or not given, then...
hpcgap/lib/oper.g
Outdated
# The attribute has already been declared. | ||
# If it was not created as an attribute | ||
# then we may be able to convert it | ||
if FLAG2_FILTER( gvar ) = 0 or gvar in FILTERS then |
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.
That line now conflicts with my PR #2096. But I can easily fix that in that PR once this one here has been merged, no problem.
od; | ||
else | ||
# The attribute is new. | ||
attr := NewAttribute(name, filter, mutflag, rank); |
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.
Meta-issue (i.e. not something I expect this PR to address): I think this code (and that of other New/Declare functions) has a race condition in HPC-GAP: If e.g. DeclareAttribute
is called from two threads simultaneously with identical arguments, then it could happen that bother check ISB_GVAR
and decide the var is not bound, then go on to call NewAttribute
, and try to BIND_GLOBAL
at the same time. At this point, one of the two will run into an error.
We probably should open an issue about this to not forget ...
This is the result of trying to fix a bug in DeclareAttribute where if the user called it with the same name but different filters, the attributes would be setup correctly, but the second would not be added to the list ATTRIBUTES. The argument parsing made it impossible to give "mutable" and a rank for the attribute: If one gave "mutable", the rank would be ignored.
b5ec9b2
to
60ad35d
Compare
Added to release notes for GAP 4.10 at https://github.com/gap-system/gap/wiki/GAP-4.10-release-notes |
This PR rearranges the argument parsing code for DeclareAttribute and NewAttribute, and addresses the issue that the rank argument would be ignored if "mutable" was given.
It would be good if @stevelinton could comment whether this might have been intentional (not being able to rank a tester for a mutable attribute).
Most of
oper.g
(DeclareProperty
,DeclareConstructor
,...) could do with a similar treatment.(This PR includes some adjustments made responding to comments on #2080 by @fingolfin)