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

New command line option --alwaystrace #2551

Merged

Conversation

ssiccha
Copy link
Contributor

@ssiccha ssiccha commented Jun 14, 2018

Also introduces a new global variable AlwaysPrintTracebackOnError.

Funtionality and documentation yet to be implemented.

@ssiccha ssiccha added the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Jun 14, 2018
@codecov
Copy link

codecov bot commented Jun 14, 2018

Codecov Report

Merging #2551 into master will decrease coverage by 0.21%.
The diff coverage is 44.89%.

@@            Coverage Diff             @@
##           master    #2551      +/-   ##
==========================================
- Coverage   75.12%    74.9%   -0.22%     
==========================================
  Files         478      478              
  Lines      242221   246757    +4536     
==========================================
+ Hits       181965   184834    +2869     
- Misses      60256    61923    +1667
Impacted Files Coverage Δ
lib/system.g 67.13% <ø> (ø) ⬆️
hpcgap/lib/hpc/stdtasks.g 63.93% <0%> (-1.03%) ⬇️
lib/init.g 71.76% <100%> (+0.37%) ⬆️
lib/error.g 38.75% <36.58%> (+0.61%) ⬆️
src/compiler.c 58.92% <0%> (-28.33%) ⬇️
src/set.c 90.32% <0%> (-0.7%) ⬇️
src/plist.c 93.72% <0%> (-0.2%) ⬇️
src/read.c 95.03% <0%> (+0.18%) ⬆️
src/objset.c 84.82% <0%> (+0.22%) ⬆️
... and 9 more

@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch from 4361ace to b042e10 Compare June 14, 2018 23:13
Copy link
Contributor

@ChrisJefferson ChrisJefferson left a comment

Choose a reason for hiding this comment

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

Oh, I'm sorry, but I really don't like the naming here, it's confusing how it relates to -T.

Maybe make --nobreakloop just the long name for -T, then add --backtraceonbreak , which modifies --nobreakloop/-T to keep the backtrack?

@ssiccha ssiccha changed the title WIP: New command line option nobreakloop WIP: New command line option alwaystrace Jun 28, 2018
@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch from b042e10 to 85c24bb Compare June 28, 2018 23:44
@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 28, 2018

I improved the naming (I hope). The new option is now called --alwaystrace. --nobreakloop now is the long version of -T.

@ChrisJefferson
Copy link
Contributor

Out of interest, do you want to merge this then implement the functionality (which would be a little unusual), or carry on working on the function in this PR?

@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 29, 2018

I want to finish this over the next few days. :)

@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch 2 times, most recently from 5207e21 to 5e33302 Compare July 5, 2018 00:09
@ssiccha
Copy link
Contributor Author

ssiccha commented Jul 5, 2018

I added a new commit which implements the new behaviour. I'll have to think about whether this is correct tomorrow again.

Still missing: documentation of the new global variable AlwaysPrintTracebackOnError

@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch from 5e33302 to 973ff34 Compare July 5, 2018 19:17
@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch from 973ff34 to c378bac Compare July 5, 2018 20:55
@ssiccha ssiccha removed the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Jul 5, 2018
@ssiccha ssiccha changed the title WIP: New command line option alwaystrace New command line option --alwaystrace Jul 5, 2018
@ssiccha
Copy link
Contributor Author

ssiccha commented Jul 5, 2018

Let's see whether tests pass on travis. :)

lib/error.g Outdated
# start an interactive break loop or whether we use JUMP_TO_CATCH
# to exit this function.
# BreakOnError is defined by the `-T` command line flag in init.g.
doBreakLoop := BreakOnError and not QUITTING;
Copy link
Member

Choose a reason for hiding this comment

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

BreakOnError is initialised depending on whether (and how many times?) -T is given on the command line, the user can (unfortunately) set it as well.

Copy link
Member

Choose a reason for hiding this comment

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

I think it is quite fortunate that the user can do this, it has been crucial for some code I wrote, esp. for testing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll change it to initialize.

Copy link
Member

Choose a reason for hiding this comment

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

The unfortunate bit is that the user can set this to, say, a function which makes GAP crash when an error is hit.

lib/error.g Outdated
doBreakLoop := BreakOnError and not QUITTING;
# If we do not start a break loop, the variables SilentErrors and
# AlwaysPrintTracebackOnError determine whether any messages or
# respectively tracebacks are printed.
Copy link
Member

Choose a reason for hiding this comment

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

How?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll expand on that. 👍

lib/error.g Outdated
if IsHPCGAP then
LastErrorMessage := "";
lastErrorStream := OutputTextString(LastErrorMessage, true);
for x in earlyMessage do
PrintTo(lastErrorStream, x);
od;
# FIXME: Also make HPCGAP work with AlwaysPrintTracebackOnError
Copy link
Member

Choose a reason for hiding this comment

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

What needs to be done to achieve this? I see some code added for HPC-GAP, is this comment obsolete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't obsolete. IMO if AlwaysPrintTracebackOnError is true, the traceback should also be put into LastErrorMessage. To do this there needs to be a way to put the output of Where() into lastErrorStream.

I'll add a comment to the source.

lib/init.g Outdated
@@ -248,10 +250,15 @@ CallAndInstallPostRestore( function()

if IsHPCGAP then
BindThreadLocal( "BreakOnError", not GAPInfo.CommandLineOptions.T );
Copy link
Member

Choose a reason for hiding this comment

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

Not really relevant to this PR: We should comment here why these variables are thread local (I suppose we don't want a break look in a worker thread; I have had students trying to debug task-based code, which was a big pain becuase of no break loops or error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did that too.

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.

Please don't merge this quite yet, I'd like to understand this PR properly first.

lib/error.g Outdated
if SHOULD_QUIT_ON_BREAK() then
FORCE_QUIT_GAP(1);
fi;

if IsBound(OnBreak) and IsFunction(OnBreak) then
OnBreak();
fi;
Copy link
Member

Choose a reason for hiding this comment

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

Huh, so OnBreak is now called beforethe test forSHOULD_QUIT_ON_BREAK`? That's quite a change in semantics, one which I am quite concerned about. I'll need to look at your whole PR with a bit more time to understand what is going on.
(It might help if the refactoring did not happen at the same time as the changes in behavior -- note that to me, "refactoring" means a change which does not change behavior (or at most changes in a very minimalistic way, which then however should be documented in the commit message)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right. I'll make separate commits out of that. Note to myself: never mix refactoring and behaviour changes in a single commit.

I realize that I forgot to check for SHOULD_QUIT_ON_BREAK() in the if-clause that controls whether OnBreak() is called. That change in semantics was not on purpose.

@fingolfin
Copy link
Member

In the commit message, you write:

This commit also refactors ErrorInner a bit. Otherwise the code duplication would have been unbearable.

I can't judge if this is really code refactoring or not, as it is mixed with actual code changes, some of which match what you describe, but some I don't see reflected in your descriptions, so I wonder if they are intentational. If the refactoring was done in a separate commit, this would be far easier to evaluate.

As to avoiding code duplication: Another technique in this case that might work is to put the code being duplicatated into an inner function (which thus has access to all local vars), and simply call that from all the places that need to call it. That's a change which is fairly easy to review, too.

@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch 2 times, most recently from 3251a8f to 3071c3f Compare July 6, 2018 13:16
@ssiccha
Copy link
Contributor Author

ssiccha commented Jul 6, 2018

@fingolfin @markuspf I addressed your comments. I split the refactoring into a seperate commit and changed it so that it introduces new local functions. I think this makes this PR a lot clearer.

Copy link
Member

@markuspf markuspf left a comment

Choose a reason for hiding this comment

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

Looks good to me now.

lib/error.g Outdated
od;
end;

printEarlyTraceback := function(stream, context, printThisStatement)
Copy link
Member

Choose a reason for hiding this comment

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

drop context, printThisStatement arguments

lib/error.g Outdated
for x in earlyMessage do
PrintTo(lastErrorStream, x);
od;
printEarlyMessage(lastErrorStream, earlyMessage);
Copy link
Member

Choose a reason for hiding this comment

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

Here you change the behaviour slightly, now Error, is printed to lastErrorStream (I am not sure if this matter for anything, just observing).

Copy link
Member

Choose a reason for hiding this comment

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

I dug a bit, and as far as I can tell, this only affects the TaskError() function (and of course the LastErrorMessage global). I'd still prefer if the redundant arguments were dropped, as they are rather "un-GAPish", but if this is merged with it, I can also fix it myself shrug

lib/error.g Outdated
# Again, the default is to not print the rest of the traceback.
# If AlwaysPrintTracebackOnError is true we do so anyways.
if
AlwaysPrintTracebackOnError
Copy link
Member

Choose a reason for hiding this comment

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

This is a weird line break, please merge the two preceding lines into one.

lib/error.g Outdated


# Local functions that print the user feedback.
printEarlyMessage := function(stream, earlyMessage)
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to pass earlyMessage as an argument, it is available automatically in this closure. I.e. just drop the second argument here and in calls, no other change, and things will work just fine.

BindThreadLocal( "LastErrorMessage", "" );
else
ASS_GVAR( "BreakOnError", not GAPInfo.CommandLineOptions.T );
ASS_GVAR( "SilentErrors", false );
ASS_GVAR( "AlwaysPrintTracebackOnError", GAPInfo.CommandLineOptions.alwaystrace );
ASS_GVAR( "SilentNonInteractiveErrors", false );
Copy link
Member

Choose a reason for hiding this comment

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

Note a change request, just a remark: if the renaming of SilentErrors to SilentNonInteractiveErrors were in a separate commit, that'd make things even easier to review. But it's fine to keep it now as it is.

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.

I've pushed two commits which fix my complaints. Feel free to squash these commits into your other commits; or we can also just merge this PR as-is.

lib/error.g Outdated
for x in earlyMessage do
PrintTo(lastErrorStream, x);
od;
printEarlyMessage(lastErrorStream, earlyMessage);
Copy link
Member

Choose a reason for hiding this comment

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

I dug a bit, and as far as I can tell, this only affects the TaskError() function (and of course the LastErrorMessage global). I'd still prefer if the redundant arguments were dropped, as they are rather "un-GAPish", but if this is merged with it, I can also fix it myself shrug

@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch from 817589e to 1a9f76c Compare July 11, 2018 11:29
ssiccha and others added 4 commits July 11, 2018 13:30
This commit introduces some local functions to print the different
parts of the user feedback.

It also adds some source comments and renames the undocumented
variable SilentErrors to SilentNonInteractiveErrors.

The refactoring is done to e.g. also print a traceback from other
parts of ErrorInner without having to duplicate the printing code.
The option --alwaystrace sets a new global variable
AlwaysPrintTracebackOnError. If set to true `OnBreak()` is always
called before exiting `ErrorInner`.
@ssiccha ssiccha force-pushed the ss/always-print-traceback-on-error branch from 1a9f76c to c80941d Compare July 11, 2018 11:30
@ssiccha
Copy link
Contributor Author

ssiccha commented Jul 11, 2018

I've rebased the commits. I squashed Remove redundant arguments to inner functions into the refactoring commit but left the reformatting in its own commit.

@ChrisJefferson ChrisJefferson merged commit 364cc08 into gap-system:master Jul 15, 2018
@fingolfin fingolfin added the release notes: added PRs introducing changes that have since been mentioned in the release notes label Sep 28, 2018
@ssiccha ssiccha deleted the ss/always-print-traceback-on-error branch August 7, 2019 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: added PRs introducing changes that have since been mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants