Skip to content

Commit

Permalink
Give useful names to installed methods
Browse files Browse the repository at this point in the history
This makes these methods easier to understand when profiling.
We add a name both to the installed method, and the function
which calculates their rank, where present.
  • Loading branch information
ChrisJefferson committed May 8, 2019
1 parent 4a3108e commit 323d279
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/oper1.g
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ BIND_GLOBAL( "INSTALL_METHOD",
rank,
method,
oreqs,
req, reqs, match, j, k, imp, notmatch, lk;
req, reqs, match, j, k, imp, notmatch, lk, funcname;

if IsHPCGAP then
# TODO: once the GAP compiler supports 'atomic', use that
Expand Down Expand Up @@ -601,6 +601,27 @@ BIND_GLOBAL( "INSTALL_METHOD",
fi;
fi;

if IS_FUNCTION(method) and IsBound(HasNameFunction) and IsBound(TYPE_FUNCTION) and IsBound(TYPE_FUNCTION_WITH_NAME) and IsBound(TYPE_OPERATION_WITH_NAME) and not VAL_GVAR("HasNameFunction")(method) then
funcname := SHALLOW_COPY_OBJ(NAME_FUNC(opr));
APPEND_LIST_INTR(funcname, " ");
if info <> false then
APPEND_LIST_INTR(funcname, info);
else
APPEND_LIST_INTR(funcname, "method");
fi;
SET_NAME_FUNC(method, funcname);
fi;

if IS_FUNCTION(rank) and IsBound(HasNameFunction) and IsBound(TYPE_FUNCTION) and IsBound(TYPE_FUNCTION_WITH_NAME) and IsBound(TYPE_OPERATION_WITH_NAME) and not VAL_GVAR("HasNameFunction")(rank) then
funcname := "Priority calculation for ";
APPEND_LIST_INTR(funcname, NAME_FUNC(opr));
if info <> false then
APPEND_LIST_INTR(funcname, " ");
APPEND_LIST_INTR(funcname, info);
fi;
SET_NAME_FUNC(rank, funcname);
fi;

# Install the method in the operation.
INSTALL_METHOD_FLAGS( opr, info, rel, flags, rank, method );

Expand Down
18 changes: 18 additions & 0 deletions tst/testinstall/method.tst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,22 @@ Error, required filters [ "IsInt", "IsRat", "IsCyc", "IsExtAElement",
, "IsMultiplicativeElementWithInverse", "IsZDFRE", "IsAssociativeElement",
"IsAdditivelyCommutativeElement", "IsCommutativeElement", "IsCyclotomic" ]
for 1st argument do not match a declaration of Size

# Check names are set correctly
gap> cheese := NewOperation("cheese", [IsObject]);
<Operation "cheese">

# These are in lists as assignments of the form 'f := x -> x' set the name
# of the function to 'f'
gap> funcs := [x -> x, x -> x, x -> x];;;
gap> ranks := [{} -> 10, {} -> 10, {} -> 10];;
gap> SetNameFunction(funcs[3], "func3");
gap> SetNameFunction(ranks[3], "rank3");
gap> InstallMethod(cheese, [IsInt], ranks[1], funcs[1]);
gap> InstallMethod(cheese, "for a list", [IsList], ranks[2], funcs[2]);
gap> InstallMethod(cheese, "for a string", [IsString], ranks[3], funcs[3]);
gap> List(Concatenation(funcs, ranks), NameFunction);
[ "cheese method", "cheese for a list", "func3",
"Priority calculation for cheese",
"Priority calculation for cheese for a list", "rank3" ]
gap> STOP_TEST("method.tst", 1);

0 comments on commit 323d279

Please sign in to comment.