Skip to content

Commit

Permalink
When tracing immediates, print location of definition
Browse files Browse the repository at this point in the history
For now, we print the location of the *method*. Ideally, we should
instead track the location of the InstallImmediateMethod call. See also
issue #2239.

Before:

    gap> TraceImmediateMethods( );
    gap> g:= Group( (1,2,3), (1,2) );;
    #I  immediate: Size
    #I  immediate: IsCyclic
    #I  immediate: IsCommutative
    #I  immediate: IsTrivial

After:

    gap> TraceImmediateMethods( );
    gap> g:= Group( (1,2,3), (1,2) );;
    #I RunImmediateMethods
    #I  immediate: Size at GAPROOT/lib/coll.gi:174
    #I  immediate: IsCyclic at GAPROOT/lib/grp.gi:34
    #I  immediate: IsCommutative at GAPROOT/lib/magma.gi:190
    #I  immediate: IsTrivial at GAPROOT/lib/magma.gi:124
  • Loading branch information
fingolfin committed Apr 23, 2018
1 parent b03bc7b commit 6d3fff5
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 92 deletions.
5 changes: 3 additions & 2 deletions lib/oper.g
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,10 @@ end );
## <Ref Func="UntraceImmediateMethods"/>, or <Ref Func="TraceImmediateMethods"/>
## with <A>flag</A> equal <K>false</K> turns tracing off.
## (There is no facility to trace <E>specific</E> immediate methods.)
## <Example><![CDATA[
## <Log><![CDATA[
## gap> TraceImmediateMethods( );
## gap> g:= Group( (1,2,3), (1,2) );;
## #I RunImmediateMethods
## #I immediate: Size
## #I immediate: IsCyclic
## #I immediate: IsCommutative
Expand All @@ -574,7 +575,7 @@ end );
## 6
## gap> UntraceImmediateMethods( );
## gap> UntraceMethods( [ Size ] );
## ]]></Example>
## ]]></Log>
## <P/>
## This example gives an explanation for the two calls of the
## <Q>system getter</Q> for <Ref Func="Size"/>.
Expand Down
28 changes: 23 additions & 5 deletions lib/oper1.g
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## have been discovered recently.
## So possible consequences of other filters are not checked.
##
RUN_IMMEDIATE_METHODS_RUNS := 0;
RUN_IMMEDIATE_METHODS_CHECKS := 0;
RUN_IMMEDIATE_METHODS_HITS := 0;

Expand All @@ -31,7 +32,9 @@ BIND_GLOBAL( "RunImmediateMethods", function ( obj, flags )
j, # loop over `flagspos'
imm, # immediate methods for filter `j'
i, # loop over `imm'
meth,
res, # result of an immediate method
loc,
newflags; # newly found filters

# Avoid recursive calls from inside a setter,
Expand All @@ -49,6 +52,11 @@ BIND_GLOBAL( "RunImmediateMethods", function ( obj, flags )
type := TYPE_OBJ( obj );
flags := type![2];

RUN_IMMEDIATE_METHODS_RUNS := RUN_IMMEDIATE_METHODS_RUNS + 1;
if TRACE_IMMEDIATE_METHODS then
Print( "#I RunImmediateMethods\n");
fi;

# Check the immediate methods for all in `flagspos'.
# (Note that new information is handled via appending to that list.)
for j in flagspos do
Expand All @@ -71,16 +79,26 @@ BIND_GLOBAL( "RunImmediateMethods", function ( obj, flags )
then

# Call the method, and store that it was used.
res := IMMEDIATE_METHODS[ imm[i+6] ]( obj );
meth := IMMEDIATE_METHODS[ imm[i+6] ];
res := meth( obj );
ADD_LIST( tried, imm[i+6] );
RUN_IMMEDIATE_METHODS_CHECKS :=
RUN_IMMEDIATE_METHODS_CHECKS+1;
if TRACE_IMMEDIATE_METHODS then
if imm[i+7] = false then
Print( "#I immediate: ", NAME_FUNC( imm[i+1] ), "\n");
else
Print( "#I immediate: ", NAME_FUNC( imm[i+1] ), ": ", imm[i+7], "\n" );
Print( "#I immediate: ", NAME_FUNC( imm[i+1] ));
if imm[i+7] <> false then
Print( ": ", imm[i+7] );
fi;
if IsBound(LocationFunc) then
loc := VALUE_GLOBAL("LocationFunc")( meth );
if loc <> "" then
Print(" at ", loc);
fi;
fi;
if NAME_FUNC(meth) <> "unknown" then
Print(" via ", NAME_FUNC(meth));
fi;
Print("\n");
fi;

if res <> TRY_NEXT_METHOD then
Expand Down
Loading

0 comments on commit 6d3fff5

Please sign in to comment.