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

Optimize true/false conditions when coding if-statements #2199

Merged
merged 1 commit into from
Feb 27, 2018

Commits on Feb 22, 2018

  1. Optimize true/false conditions when coding if-statements

    We already had some code which "optimized" some if-statements
    with one or two conditions, where one or both were constant equal
    to `true` or `false`. We skipped branches whose condition was
    always `false`. However, we did not use the `IntrIgnoring` mechanism
    for that. Thus, such code would still trigger warnings if it contained
    undefined globals, e.g.
    
        gap> f:=function()  if false then undefined_global(); fi; end;;
        Syntax warning: Unbound global variable
        f:=function()  if false then undefined_global(); fi; end;;
                                                     ^
    
    This can be viewed as a feature, or as a bug, depending on view point.
    A reason to consider it a "bug" (or at least an undesirable feature)
    is when using global constants to only conditionally execute code, such
    as this:
    
        if IsHPCGAP then
            UNLOCK(lock);
        fi;
    
    This code is optimized away in regular GAP, but still triggers a warning
    during parsing.
    
    With this commit, we change how we deal with true/false conditions in
    if-statements, by making use of the `IntrIgnoring` mechanism. This avoids
    the warnings about globals in the examples above. It also has the side
    effect of being "better" at optimizing away branches of an if-statement
    which can never be executed.
    fingolfin committed Feb 22, 2018
    Configuration menu
    Copy the full SHA
    a06694c View commit details
    Browse the repository at this point in the history