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

Short circuit bool ops. #264

Merged
merged 4 commits into from
Sep 24, 2021
Merged

Short circuit bool ops. #264

merged 4 commits into from
Sep 24, 2021

Conversation

otrho
Copy link
Contributor

@otrho otrho commented Sep 23, 2021

Closes #226.

I've special cased && and || to no longer be overridden std::ops::... method invocations and have instead created a new Expression::LazyOperator variant. It is type checked into a TypedExpression::LazyOperator which translates to custom ASM gen for the lazy evaluation.

Initially I was thinking it could be a special FunctionApplication which we detected and special-cased in the ASM gen, but I think this approach is nicer.

emilyaherbert
emilyaherbert previously approved these changes Sep 23, 2021
sezna
sezna previously approved these changes Sep 23, 2021
@@ -964,8 +987,8 @@ impl OpVariant {
Divide => "divide",
Multiply => "multiply",
Modulo => "modulo",
Or => "or",
And => "and",
Or => "$or$",
Copy link
Contributor

Choose a reason for hiding this comment

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

this just prevents it from calling the stdlib version?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use && and ||?

A new LazyOperator expression variant is introduced, type-checked and
and converted to fairly simple ASM.

These operators are no longer allowed to be overridden because they must
be evaluated lazily and this can't be enforced with a trait.  Instead,
they're now compiler intrinsics.
`&&` and `||` are no longer overidable method invocations in std::ops,
but rather intrinsic compiler operations.
@otrho otrho dismissed stale reviews from sezna and emilyaherbert via 6a2d592 September 24, 2021 00:03
@otrho otrho force-pushed the otrho/226_short_circuit_bool_ops branch from 8e7106a to 6a2d592 Compare September 24, 2021 00:03
@otrho otrho merged commit 0ecbdf9 into master Sep 24, 2021
@otrho otrho deleted the otrho/226_short_circuit_bool_ops branch September 24, 2021 00:54
@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement short-circuiting && and ||
4 participants