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

Remove drop order twist of && and || and make them associative #103293

Merged
merged 3 commits into from
Dec 4, 2022

Commits on Dec 3, 2022

  1. Remove drop order twist of && and || and make them associative

    Previously a short circuiting && chain would drop the
    first element after all the other elements, and otherwise
    follow evaluation order, so code like:
    
    f(1).g() && f(2).g() && f(3).g() && f(4).g()
    
    would drop the temporaries in the order 2,3,4,1. This made
    && and || non-associative regarding drop order, so
    adding ()'s to the expression would change drop order:
    
    f(1).g() && (f(2).g() && f(3).g()) && f(4).g()
    
    for example would drop in the order 3,2,4,1.
    
    As, except for the bool result, there is no data returned
    by the sub-expressions of the short circuiting binops,
    we can safely discard of any temporaries created by the
    sub-expr. Previously, code was already putting the rhs's
    into terminating scopes, but missed it for the lhs's.
    
    This commit addresses this "twist". In the expression,
    we now also put the lhs into a terminating scope.
    The drop order for the above expressions is 1,2,3,4
    now.
    est31 committed Dec 3, 2022
    Configuration menu
    Copy the full SHA
    8cf521d View commit details
    Browse the repository at this point in the history

Commits on Dec 4, 2022

  1. Improve comments

    est31 committed Dec 4, 2022
    Configuration menu
    Copy the full SHA
    a2076dc View commit details
    Browse the repository at this point in the history
  2. Also avoid creating a terminating scope in mixed chains

    This avoids creation of a terminating scope in
    chains that contain both && and ||, because
    also there we know that a terminating scope is
    not neccessary: all the chain members are already
    in such terminating scopes.
    
    Also add a mixed && / || test.
    est31 committed Dec 4, 2022
    Configuration menu
    Copy the full SHA
    a59a2d3 View commit details
    Browse the repository at this point in the history