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

Give human-readable names to functions in InstallMethod #3420

Merged
merged 1 commit into from
May 11, 2019

Conversation

ChrisJefferson
Copy link
Contributor

@ChrisJefferson ChrisJefferson commented Apr 23, 2019

@markusbaumeister pointed out that many library functions show up as "nameless" in profiling output. This turned out to be because InstallMethod does not give the functions a useful name. This is a shame, as it's easy to give them a very informative name in InstallMethod. This PR does that.

This shouldn't cause any problems, apart from using a small amount of extra memory on strings. I decided to also give a useful name to the functions which calculate priority. While these functions are very small, it's still useful to know what they are in a trace.

Text for release notes

  • Give more library methods human-readable names. These are used when profiling.

@codecov
Copy link

codecov bot commented Apr 23, 2019

Codecov Report

Merging #3420 into master will increase coverage by <.01%.
The diff coverage is 91.23%.

@@            Coverage Diff             @@
##           master    #3420      +/-   ##
==========================================
+ Coverage   85.34%   85.35%   +<.01%     
==========================================
  Files         699      699              
  Lines      346091   346427     +336     
==========================================
+ Hits       295373   295676     +303     
- Misses      50718    50751      +33
Impacted Files Coverage Δ
src/c_oper1.c 86.26% <91.23%> (+0.2%) ⬆️
src/hpc/c_oper1.c 85.9% <91.23%> (+0.21%) ⬆️
src/objset.c 85.1% <0%> (+0.22%) ⬆️

@coveralls
Copy link

coveralls commented Apr 23, 2019

Coverage Status

Coverage increased (+0.006%) to 85.16% when pulling 671e5d1 on ChrisJefferson:name_func into 578ea99 on gap-system:master.

@wilfwilson wilfwilson changed the title GIve useful names to functions passed to InstallMethod Give useful names to functions passed to InstallMethod Apr 24, 2019
@wilfwilson wilfwilson added the release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes label Apr 24, 2019
@PaulaHaehndel PaulaHaehndel added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library labels Apr 24, 2019
@fingolfin
Copy link
Member

@ChrisJefferson please assign labels to your PRs.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Looks sensible to me overall, but a comment needs to be adjusted. Also, some musings...

lib/function.g Outdated Show resolved Hide resolved
lib/function.g Outdated Show resolved Hide resolved
lib/function.g Outdated Show resolved Hide resolved
lib/function.g Outdated Show resolved Hide resolved
@olexandr-konovalov
Copy link
Member

@ChrisJefferson I find the description for release notes "Give more library functions descriptive names when profiling" to be misleading. This PR does not seem to change any names - it intends to add ability to do this, and apparently adds new functions to do this, which should be then mentioned in release notes (and linked in their GAPDoc version to appropriate mansections).

@ChrisJefferson ChrisJefferson force-pushed the name_func branch 2 times, most recently from 0f6f3b2 to a6766fa Compare April 27, 2019 17:55
@ChrisJefferson
Copy link
Contributor Author

Improved code (although I haven't switched to an attribute). Linked up docs, and also linked up the unused doc for SetNameFunction.

I put two things in the release notes, as I feel the better names are important (and this PR does add better names, that's the point). Adding "HasNameFunction" doesn't feel like something most people would care about, so it should probably be mentioned in some kind of "minor" section (or it can be put with all the other release notes, don't mind).

@ChrisJefferson
Copy link
Contributor Author

I'm happy to rebase this, is this PR fine as it is? (I don't mind if someone else wants to add #3430 on top later).

@fingolfin
Copy link
Member

@ChrisJefferson as @alex-konovalov noted, the title of this PR is misleading, and unsuitable for release notes.

lib/oper1.g Show resolved Hide resolved
@fingolfin
Copy link
Member

OK, so this now obviously needs to be rebased... sorry for the hassle.

@ChrisJefferson
Copy link
Contributor Author

ChrisJefferson commented May 7, 2019

I can't fix this, as I can't call HasNameFunction in oper.g, and I can't figure out where it is declared to know what/if it's "internal" name is.

@fingolfin
Copy link
Member

@ChrisJefferson TESTER_FILTER(NAME_FUNC)

@ChrisJefferson
Copy link
Contributor Author

Nope, segfaults

@fingolfin
Copy link
Member

Ahh, of course: As long as HasNameFunction is not yet defined, also the type objects of functions ( TYPE_FUNCTION, TYPE_FUNCTION_WITH_NAME, TYPE_OPERATION and TYPE_OPERATION_WITH_NAME) are not yet defined. But to test the filter, we need the type object. Hence this can't work.

@fingolfin
Copy link
Member

So one quick fix would be to check for IsBound(TYPE_FUNCTION) or IsBound(HasNameFunction), and only call the tests in that case. This way, only very early method installations won't be covered (we are talking about a single digit number of them), but everything else later one should work.

@ChrisJefferson
Copy link
Contributor Author

Nope, still segfaults (see my pushed version, I check for IsBound(HasNameFunction) and IsBound(TYPE_FUNCTION) and IsBound(TYPE_FUNCTION_WITH_NAME) and IsBound(TYPE_OPERATION_WITH_NAME) and VAL_GVAR("HasNameFunction")(method))

@fingolfin
Copy link
Member

Interesting. I can't reproduce a segfault here with your branch. I do get a strange error, though:

$ ./gap -A
#W Static module lib/oper1.g has CRC mismatch, ignoring
 ┌───────┐   GAP 4.10dev-2036-gae0e26a of today
 │  GAP  │   https://www.gap-system.org
 └───────┘   Architecture: x86_64-apple-darwin18.5.0-default64-kv6
 Configuration:  gmp 6.1.2, GASMAN, readline
 Loading the library and packages ...
Error, Record Element: '<rec>.GeneratorsOfMagmaWithInverses' must have an assigned value in
  GeneratorsOfGroup( F ) at /Users/mhorn/Projekte/GAP/gap.github/lib/grpfp.gi:1583 called from
<function "/ for a free group and an empty list of relators">( <arguments> )
 called from read-eval loop at /Users/mhorn/Projekte/GAP/gap.github/lib/grpfp.gi:5666
type 'quit;' to quit to outer loop
brk>

@fingolfin
Copy link
Member

I guess the cause for the error is that w/o your patch, I get this:

gap> NameFunction(GeneratorsOfMagmaWithInverses);
"GeneratorsOfMagmaWithInverses"

but with it, I get this, which then breaks stuff:

brk> NameFunction(GeneratorsOfMagmaWithInverses);
"FreeGeneratorsOfFpGroup for a free group"

I don't have time to track it down further right now, sorry.

@ChrisJefferson ChrisJefferson force-pushed the name_func branch 2 times, most recently from 323d279 to ff2c1fd Compare May 8, 2019 13:27
@ChrisJefferson ChrisJefferson changed the title Give useful names to functions passed to InstallMethod Give human-readable names to functions in InstallMethod May 8, 2019
@ChrisJefferson
Copy link
Contributor Author

Hopefully now all updated + cleaned up.

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.
@@ -601,6 +601,31 @@ BIND_GLOBAL( "INSTALL_METHOD",
fi;
fi;

if IS_FUNCTION(method) and IsBound(HasNameFunction) and
IsBound(TYPE_FUNCTION_WITH_NAME) and IsBound(TYPE_OPERATION_WITH_NAME) and
not VAL_GVAR("HasNameFunction")(method) then
Copy link
Member

Choose a reason for hiding this comment

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

So, I am in principle fine with keeping this as is, but here's an alternative that might perhaps be a bit easier to read, and which would ensure that the handful of methods which are installed before HasNameFunction is defined properly get names, too: Right before this function, insert HasNameFunction := ReturnFalse;, possibly with a comment explaining what's going on. Then Unbind(HasNameFunction); right before HasNameFunction is actually defined. And here, we can then simply return to the original form, i.e.:

     if IS_FUNCTION(method) and HasNameFunction(method) then

and of course similar for the rank function

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

To be clear, I am OK with this is merged as-is, though you may wish to at least ponder my suggestion :-).

@fingolfin fingolfin merged commit 0479b40 into gap-system:master May 11, 2019
@ChrisJefferson ChrisJefferson deleted the name_func branch May 21, 2019 08:20
@DominikBernhardt DominikBernhardt added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Aug 21, 2019
@olexandr-konovalov olexandr-konovalov added this to the GAP 4.11.0 milestone Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants