Skip to content

[mypyc] Support ERR_ALWAYS #9073

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

Merged
merged 8 commits into from
Jul 2, 2020
Merged

[mypyc] Support ERR_ALWAYS #9073

merged 8 commits into from
Jul 2, 2020

Conversation

TH3CHARLie
Copy link
Collaborator

@TH3CHARLie TH3CHARLie commented Jun 30, 2020

related mypyc/mypyc#734, with a focus on exceptions related ops.

This PR adds a new error kind: ERR_ALWAYS, which indicates the op always fail.

It adds temporary false value to ensure such behavior and makes the raise op void.

@TH3CHARLie TH3CHARLie marked this pull request as draft June 30, 2020 11:11
@TH3CHARLie
Copy link
Collaborator Author

TH3CHARLie commented Jun 30, 2020

I find the way we deal with negative_int_emit may not work here.

Suppose we build an assignment op following the CallC via the call_c function(just like we build a truncate after a CallC)

r0 = call_c()
r1 = assign 0

However, the exception branch is generated directly following the CallC, so after the transform, it would be:

r0 = call_c()
if !r0 goto .. else goto...
r1 = assign 0

which clearly does not meet our goals. @JukkaL

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 30, 2020

Hmm, the proposal we discussed today doesn't seem to work.

Here's another idea. Update exception transform to generate the Op for tmp = 0, followed by a BOOL_EXPR branch, when seeing ERR_ALWAYS. The temporary assignment will be optimized away. This would happen in split_blocks_at_errors, I think.

@TH3CHARLie TH3CHARLie marked this pull request as ready for review July 1, 2020 12:47
@TH3CHARLie
Copy link
Collaborator Author

I think this is ready for its first-round review @JukkaL

Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Looks great. Couple requests for comment tweaks

from mypyc.ir.rtypes import bool_rprimitive, object_rprimitive, void_rtype, exc_rtuple
from mypyc.primitives.registry import (
simple_emit, call_emit, call_void_emit, call_and_fail_emit, custom_op,
simple_emit, call_emit, call_void_emit, call_and_fail_emit, custom_op, c_custom_op
)

# If the argument is a class, raise an instance of the class. Otherwise, assume
# that the argument is an exception object, and raise it.
#
# TODO: Making this raise conditionally is kind of hokey.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop this TODO comment, since this is fixing it

elif op.error_kind == ERR_ALWAYS:
variant = Branch.BOOL_EXPR
negated = True
tmp = LoadInt(0, rtype=bool_rprimitive)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment that this is kind of a hack?

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 2, 2020

It's nice to finally have this!

@JukkaL JukkaL merged commit a04bdbf into python:master Jul 2, 2020
@TH3CHARLie TH3CHARLie deleted the err-always branch July 22, 2020 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants