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 Apr 23, 2019
1 parent 57c8003 commit 54dec72
Show file tree
Hide file tree
Showing 3 changed files with 340 additions and 59 deletions.
21 changes: 20 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,25 @@ BIND_GLOBAL( "INSTALL_METHOD",
fi;
fi;

if IS_FUNCTION(method) and not HAS_NAME_FUNC(method) then
funcname := SHALLOW_COPY_OBJ(NAME_FUNC(opr));
if info <> false then
APPEND_LIST_INTR(funcname, " ");
APPEND_LIST_INTR(funcname, info);
fi;
SET_NAME_FUNC(method, funcname);
fi;

if IS_FUNCTION(rank) and not HAS_NAME_FUNC(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
189 changes: 160 additions & 29 deletions src/c_oper1.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef AVOID_PRECOMPILED
/* C file produced by GAC */
#include "compiled.h"
#define FILE_CRC "127678438"
#define FILE_CRC "-102102092"

/* global variables used in handlers */
static GVar G_REREADING;
Expand All @@ -16,6 +16,10 @@ static GVar G_IS__FUNCTION;
static Obj GF_IS__FUNCTION;
static GVar G_NAME__FUNC;
static Obj GF_NAME__FUNC;
static GVar G_HAS__NAME__FUNC;
static Obj GF_HAS__NAME__FUNC;
static GVar G_SET__NAME__FUNC;
static Obj GF_SET__NAME__FUNC;
static GVar G_NARG__FUNC;
static Obj GF_NARG__FUNC;
static GVar G_IS__OPERATION;
Expand Down Expand Up @@ -1360,6 +1364,7 @@ static Obj HdlrFunc6 (
Obj l_imp = 0;
Obj l_notmatch = 0;
Obj l_lk = 0;
Obj l_funcname = 0;
Obj t_1 = 0;
Obj t_2 = 0;
Obj t_3 = 0;
Expand Down Expand Up @@ -1392,6 +1397,7 @@ static Obj HdlrFunc6 (
(void)l_imp;
(void)l_notmatch;
(void)l_lk;
(void)l_funcname;
Bag oldFrame;

/* allocate new stack frame */
Expand Down Expand Up @@ -2365,9 +2371,113 @@ static Obj HdlrFunc6 (
}
/* fi */

/* if IS_FUNCTION( method ) and not HAS_NAME_FUNC( method ) then */
t_4 = GF_IS__FUNCTION;
t_3 = CALL_1ARGS( t_4, l_method );
CHECK_FUNC_RESULT( t_3 )
CHECK_BOOL( t_3 )
t_2 = (Obj)(UInt)(t_3 != False);
t_1 = t_2;
if ( t_1 ) {
t_6 = GF_HAS__NAME__FUNC;
t_5 = CALL_1ARGS( t_6, l_method );
CHECK_FUNC_RESULT( t_5 )
CHECK_BOOL( t_5 )
t_4 = (Obj)(UInt)(t_5 != False);
t_3 = (Obj)(UInt)( ! ((Int)t_4) );
t_1 = t_3;
}
if ( t_1 ) {

/* funcname := SHALLOW_COPY_OBJ( NAME_FUNC( opr ) ); */
t_2 = GF_SHALLOW__COPY__OBJ;
t_4 = GF_NAME__FUNC;
t_3 = CALL_1ARGS( t_4, l_opr );
CHECK_FUNC_RESULT( t_3 )
t_1 = CALL_1ARGS( t_2, t_3 );
CHECK_FUNC_RESULT( t_1 )
l_funcname = t_1;

/* if info <> false then */
t_2 = False;
t_1 = (Obj)(UInt)( ! EQ( l_info, t_2 ));
if ( t_1 ) {

/* APPEND_LIST_INTR( funcname, " " ); */
t_1 = GF_APPEND__LIST__INTR;
t_2 = MakeString( " " );
CALL_2ARGS( t_1, l_funcname, t_2 );

/* APPEND_LIST_INTR( funcname, info ); */
t_1 = GF_APPEND__LIST__INTR;
CALL_2ARGS( t_1, l_funcname, l_info );

}
/* fi */

/* SET_NAME_FUNC( method, funcname ); */
t_1 = GF_SET__NAME__FUNC;
CALL_2ARGS( t_1, l_method, l_funcname );

}
/* fi */

/* if IS_FUNCTION( rank ) and not HAS_NAME_FUNC( rank ) then */
t_4 = GF_IS__FUNCTION;
CHECK_BOUND( l_rank, "rank" )
t_3 = CALL_1ARGS( t_4, l_rank );
CHECK_FUNC_RESULT( t_3 )
CHECK_BOOL( t_3 )
t_2 = (Obj)(UInt)(t_3 != False);
t_1 = t_2;
if ( t_1 ) {
t_6 = GF_HAS__NAME__FUNC;
t_5 = CALL_1ARGS( t_6, l_rank );
CHECK_FUNC_RESULT( t_5 )
CHECK_BOOL( t_5 )
t_4 = (Obj)(UInt)(t_5 != False);
t_3 = (Obj)(UInt)( ! ((Int)t_4) );
t_1 = t_3;
}
if ( t_1 ) {

/* funcname := "Priority calculation for "; */
t_1 = MakeString( "Priority calculation for " );
l_funcname = t_1;

/* APPEND_LIST_INTR( funcname, NAME_FUNC( opr ) ); */
t_1 = GF_APPEND__LIST__INTR;
t_3 = GF_NAME__FUNC;
t_2 = CALL_1ARGS( t_3, l_opr );
CHECK_FUNC_RESULT( t_2 )
CALL_2ARGS( t_1, l_funcname, t_2 );

/* if info <> false then */
t_2 = False;
t_1 = (Obj)(UInt)( ! EQ( l_info, t_2 ));
if ( t_1 ) {

/* APPEND_LIST_INTR( funcname, " " ); */
t_1 = GF_APPEND__LIST__INTR;
t_2 = MakeString( " " );
CALL_2ARGS( t_1, l_funcname, t_2 );

/* APPEND_LIST_INTR( funcname, info ); */
t_1 = GF_APPEND__LIST__INTR;
CALL_2ARGS( t_1, l_funcname, l_info );

}
/* fi */

/* SET_NAME_FUNC( rank, funcname ); */
t_1 = GF_SET__NAME__FUNC;
CALL_2ARGS( t_1, l_rank, l_funcname );

}
/* fi */

/* INSTALL_METHOD_FLAGS( opr, info, rel, flags, rank, method ); */
t_1 = GF_INSTALL__METHOD__FLAGS;
CHECK_BOUND( l_rank, "rank" )
CALL_6ARGS( t_1, l_opr, l_info, l_rel, l_flags, l_rank, l_method );

/* return; */
Expand Down Expand Up @@ -2727,8 +2837,8 @@ static Obj HdlrFunc7 (
t_6 = NewFunction( NameFunc[8], 1, ArgStringToList("obj"), HdlrFunc8 );
SET_ENVI_FUNC( t_6, STATE(CurrLVars) );
t_7 = NewFunctionBody();
SET_STARTLINE_BODY(t_7, 671);
SET_ENDLINE_BODY(t_7, 689);
SET_STARTLINE_BODY(t_7, 690);
SET_ENDLINE_BODY(t_7, 708);
SET_FILENAME_BODY(t_7, FileName);
SET_BODY_FUNC(t_6, t_7);
CALL_6ARGS( t_1, t_2, t_3, t_4, t_5, l_rank, t_6 );
Expand Down Expand Up @@ -3293,8 +3403,8 @@ static Obj HdlrFunc11 (
t_1 = NewFunction( NameFunc[12], 1, ArgStringToList("key"), HdlrFunc12 );
SET_ENVI_FUNC( t_1, STATE(CurrLVars) );
t_2 = NewFunctionBody();
SET_STARTLINE_BODY(t_2, 868);
SET_ENDLINE_BODY(t_2, 872);
SET_STARTLINE_BODY(t_2, 887);
SET_ENDLINE_BODY(t_2, 891);
SET_FILENAME_BODY(t_2, FileName);
SET_BODY_FUNC(t_1, t_2);
ASS_LVAR( 2, t_1 );
Expand Down Expand Up @@ -3372,8 +3482,8 @@ static Obj HdlrFunc11 (
t_6 = NewFunction( NameFunc[13], 1, ArgStringToList("D"), HdlrFunc13 );
SET_ENVI_FUNC( t_6, STATE(CurrLVars) );
t_7 = NewFunctionBody();
SET_STARTLINE_BODY(t_7, 889);
SET_ENDLINE_BODY(t_7, 889);
SET_STARTLINE_BODY(t_7, 908);
SET_ENDLINE_BODY(t_7, 908);
SET_FILENAME_BODY(t_7, FileName);
SET_BODY_FUNC(t_6, t_7);
CALL_6ARGS( t_1, t_2, t_3, t_4, t_5, INTOBJ_INT(0), t_6 );
Expand Down Expand Up @@ -3434,8 +3544,8 @@ static Obj HdlrFunc11 (
t_6 = NewFunction( NameFunc[14], 2, ArgStringToList("D,key"), HdlrFunc14 );
SET_ENVI_FUNC( t_6, STATE(CurrLVars) );
t_7 = NewFunctionBody();
SET_STARTLINE_BODY(t_7, 911);
SET_ENDLINE_BODY(t_7, 934);
SET_STARTLINE_BODY(t_7, 930);
SET_ENDLINE_BODY(t_7, 953);
SET_FILENAME_BODY(t_7, FileName);
SET_BODY_FUNC(t_6, t_7);
CALL_6ARGS( t_1, t_2, t_3, t_4, t_5, INTOBJ_INT(0), t_6 );
Expand Down Expand Up @@ -3482,8 +3592,8 @@ static Obj HdlrFunc11 (
t_6 = NewFunction( NameFunc[15], 2, ArgStringToList("D,key"), HdlrFunc15 );
SET_ENVI_FUNC( t_6, STATE(CurrLVars) );
t_7 = NewFunctionBody();
SET_STARTLINE_BODY(t_7, 944);
SET_ENDLINE_BODY(t_7, 952);
SET_STARTLINE_BODY(t_7, 963);
SET_ENDLINE_BODY(t_7, 971);
SET_FILENAME_BODY(t_7, FileName);
SET_BODY_FUNC(t_6, t_7);
CALL_6ARGS( t_1, t_2, t_3, t_4, t_5, INTOBJ_INT(0), t_6 );
Expand Down Expand Up @@ -3543,8 +3653,8 @@ static Obj HdlrFunc11 (
t_6 = NewFunction( NameFunc[16], 3, ArgStringToList("D,key,obj"), HdlrFunc16 );
SET_ENVI_FUNC( t_6, STATE(CurrLVars) );
t_7 = NewFunctionBody();
SET_STARTLINE_BODY(t_7, 961);
SET_ENDLINE_BODY(t_7, 974);
SET_STARTLINE_BODY(t_7, 980);
SET_ENDLINE_BODY(t_7, 993);
SET_FILENAME_BODY(t_7, FileName);
SET_BODY_FUNC(t_6, t_7);
CALL_6ARGS( t_1, t_2, t_3, t_4, t_5, INTOBJ_INT(0), t_6 );
Expand Down Expand Up @@ -3905,8 +4015,8 @@ static Obj HdlrFunc17 (
t_4 = NewFunction( NameFunc[18], -1, ArgStringToList("arg"), HdlrFunc18 );
SET_ENVI_FUNC( t_4, STATE(CurrLVars) );
t_5 = NewFunctionBody();
SET_STARTLINE_BODY(t_5, 1040);
SET_ENDLINE_BODY(t_5, 1056);
SET_STARTLINE_BODY(t_5, 1059);
SET_ENDLINE_BODY(t_5, 1075);
SET_FILENAME_BODY(t_5, FileName);
SET_BODY_FUNC(t_4, t_5);
CALL_6ARGS( t_1, t_2, l_info, l_fampred, t_3, l_val, t_4 );
Expand Down Expand Up @@ -4156,7 +4266,7 @@ static Obj HdlrFunc1 (
AssGVar( G_INSTALL__METHOD, 0 );

/* BIND_GLOBAL( "INSTALL_METHOD", function ( arglist, check )
local len, opr, info, pos, rel, filters, info1, isstr, flags, i, rank, method, oreqs, req, reqs, match, j, k, imp, notmatch, lk;
local len, opr, info, pos, rel, filters, info1, isstr, flags, i, rank, method, oreqs, req, reqs, match, j, k, imp, notmatch, lk, funcname;
;
len := LEN_LIST( arglist );
if len < 3 then
Expand Down Expand Up @@ -4301,6 +4411,23 @@ static Obj HdlrFunc1 (
od;
fi;
fi;
if IS_FUNCTION( method ) and not HAS_NAME_FUNC( method ) then
funcname := SHALLOW_COPY_OBJ( NAME_FUNC( opr ) );
if info <> false then
APPEND_LIST_INTR( funcname, " " );
APPEND_LIST_INTR( funcname, info );
fi;
SET_NAME_FUNC( method, funcname );
fi;
if IS_FUNCTION( rank ) and not HAS_NAME_FUNC( 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_METHOD_FLAGS( opr, info, rel, flags, rank, method );
;
return;
Expand All @@ -4311,7 +4438,7 @@ static Obj HdlrFunc1 (
SET_ENVI_FUNC( t_3, STATE(CurrLVars) );
t_4 = NewFunctionBody();
SET_STARTLINE_BODY(t_4, 378);
SET_ENDLINE_BODY(t_4, 610);
SET_ENDLINE_BODY(t_4, 629);
SET_FILENAME_BODY(t_4, FileName);
SET_BODY_FUNC(t_3, t_4);
CALL_2ARGS( t_1, t_2, t_3 );
Expand Down Expand Up @@ -4368,8 +4495,8 @@ static Obj HdlrFunc1 (
t_2 = NewFunction( NameFunc[7], 6, ArgStringToList("name,filter,getter,setter,tester,mutflag"), HdlrFunc7 );
SET_ENVI_FUNC( t_2, STATE(CurrLVars) );
t_3 = NewFunctionBody();
SET_STARTLINE_BODY(t_3, 629);
SET_ENDLINE_BODY(t_3, 693);
SET_STARTLINE_BODY(t_3, 648);
SET_ENDLINE_BODY(t_3, 712);
SET_FILENAME_BODY(t_3, FileName);
SET_BODY_FUNC(t_2, t_3);
CALL_1ARGS( t_1, t_2 );
Expand All @@ -4382,8 +4509,8 @@ static Obj HdlrFunc1 (
t_2 = NewFunction( NameFunc[9], 6, ArgStringToList("name,filter,getter,setter,tester,mutflag"), HdlrFunc9 );
SET_ENVI_FUNC( t_2, STATE(CurrLVars) );
t_3 = NewFunctionBody();
SET_STARTLINE_BODY(t_3, 696);
SET_ENDLINE_BODY(t_3, 702);
SET_STARTLINE_BODY(t_3, 715);
SET_ENDLINE_BODY(t_3, 721);
SET_FILENAME_BODY(t_3, FileName);
SET_BODY_FUNC(t_2, t_3);
CALL_1ARGS( t_1, t_2 );
Expand All @@ -4410,8 +4537,8 @@ static Obj HdlrFunc1 (
t_3 = NewFunction( NameFunc[10], 2, ArgStringToList("list,elm"), HdlrFunc10 );
SET_ENVI_FUNC( t_3, STATE(CurrLVars) );
t_4 = NewFunctionBody();
SET_STARTLINE_BODY(t_4, 715);
SET_ENDLINE_BODY(t_4, 739);
SET_STARTLINE_BODY(t_4, 734);
SET_ENDLINE_BODY(t_4, 758);
SET_FILENAME_BODY(t_4, FileName);
SET_BODY_FUNC(t_3, t_4);
CALL_2ARGS( t_1, t_2, t_3 );
Expand Down Expand Up @@ -4494,8 +4621,8 @@ static Obj HdlrFunc1 (
t_3 = NewFunction( NameFunc[11], 4, ArgStringToList("name,domreq,keyreq,keytest"), HdlrFunc11 );
SET_ENVI_FUNC( t_3, STATE(CurrLVars) );
t_4 = NewFunctionBody();
SET_STARTLINE_BODY(t_4, 864);
SET_ENDLINE_BODY(t_4, 975);
SET_STARTLINE_BODY(t_4, 883);
SET_ENDLINE_BODY(t_4, 994);
SET_FILENAME_BODY(t_4, FileName);
SET_BODY_FUNC(t_3, t_4);
CALL_2ARGS( t_1, t_2, t_3 );
Expand Down Expand Up @@ -4545,8 +4672,8 @@ static Obj HdlrFunc1 (
t_3 = NewFunction( NameFunc[17], -1, ArgStringToList("arg"), HdlrFunc17 );
SET_ENVI_FUNC( t_3, STATE(CurrLVars) );
t_4 = NewFunctionBody();
SET_STARTLINE_BODY(t_4, 1010);
SET_ENDLINE_BODY(t_4, 1057);
SET_STARTLINE_BODY(t_4, 1029);
SET_ENDLINE_BODY(t_4, 1076);
SET_FILENAME_BODY(t_4, FileName);
SET_BODY_FUNC(t_3, t_4);
CALL_2ARGS( t_1, t_2, t_3 );
Expand Down Expand Up @@ -4587,6 +4714,8 @@ static Int PostRestore ( StructInitInfo * module )
G_GAPInfo = GVarName( "GAPInfo" );
G_IS__FUNCTION = GVarName( "IS_FUNCTION" );
G_NAME__FUNC = GVarName( "NAME_FUNC" );
G_HAS__NAME__FUNC = GVarName( "HAS_NAME_FUNC" );
G_SET__NAME__FUNC = GVarName( "SET_NAME_FUNC" );
G_NARG__FUNC = GVarName( "NARG_FUNC" );
G_IS__OPERATION = GVarName( "IS_OPERATION" );
G_AINV = GVarName( "AINV" );
Expand Down Expand Up @@ -4704,6 +4833,8 @@ static Int InitKernel ( StructInitInfo * module )
InitCopyGVar( "GAPInfo", &GC_GAPInfo );
InitFopyGVar( "IS_FUNCTION", &GF_IS__FUNCTION );
InitFopyGVar( "NAME_FUNC", &GF_NAME__FUNC );
InitFopyGVar( "HAS_NAME_FUNC", &GF_HAS__NAME__FUNC );
InitFopyGVar( "SET_NAME_FUNC", &GF_SET__NAME__FUNC );
InitFopyGVar( "NARG_FUNC", &GF_NARG__FUNC );
InitFopyGVar( "IS_OPERATION", &GF_IS__OPERATION );
InitFopyGVar( "AINV", &GF_AINV );
Expand Down Expand Up @@ -4851,7 +4982,7 @@ static Int InitLibrary ( StructInitInfo * module )
static StructInitInfo module = {
.type = MODULE_STATIC,
.name = "GAPROOT/lib/oper1.g",
.crc = 127678438,
.crc = -102102092,
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.postRestore = PostRestore,
Expand Down
Loading

0 comments on commit 54dec72

Please sign in to comment.