diff --git a/mypyc/irbuild/for_helpers.py b/mypyc/irbuild/for_helpers.py index 38e75016b26e..65e6f97a7e89 100644 --- a/mypyc/irbuild/for_helpers.py +++ b/mypyc/irbuild/for_helpers.py @@ -386,7 +386,7 @@ def gen_cleanup(self) -> None: # an exception was raised during the loop, then err_reg wil be set to # True. If no_err_occurred_op returns False, then the exception will be # propagated using the ERR_FALSE flag. - self.builder.primitive_op(no_err_occurred_op, [], self.line) + self.builder.call_c(no_err_occurred_op, [], self.line) def unsafe_index( @@ -539,7 +539,7 @@ def gen_step(self) -> None: def gen_cleanup(self) -> None: # Same as for generic ForIterable. - self.builder.primitive_op(no_err_occurred_op, [], self.line) + self.builder.call_c(no_err_occurred_op, [], self.line) class ForDictionaryKeys(ForDictionaryCommon): diff --git a/mypyc/irbuild/generator.py b/mypyc/irbuild/generator.py index e09711b7e1f7..18443c1af3fe 100644 --- a/mypyc/irbuild/generator.py +++ b/mypyc/irbuild/generator.py @@ -114,7 +114,7 @@ def add_raise_exception_blocks_to_generator_class(builder: IRBuilder, line: int) builder.add_bool_branch(comparison, error_block, ok_block) builder.activate_block(error_block) - builder.primitive_op(raise_exception_with_tb_op, [exc_type, exc_val, exc_tb], line) + builder.call_c(raise_exception_with_tb_op, [exc_type, exc_val, exc_tb], line) builder.add(Unreachable()) builder.goto_and_activate(ok_block) diff --git a/mypyc/irbuild/nonlocalcontrol.py b/mypyc/irbuild/nonlocalcontrol.py index 2baacd6f372a..f19c376da4bc 100644 --- a/mypyc/irbuild/nonlocalcontrol.py +++ b/mypyc/irbuild/nonlocalcontrol.py @@ -99,7 +99,7 @@ def gen_return(self, builder: 'IRBuilder', value: Value, line: int) -> None: # StopIteration instead of using RaiseStandardError because # the obvious thing doesn't work if the value is a tuple # (???). - builder.primitive_op(set_stop_iteration_value, [value], NO_TRACEBACK_LINE_NO) + builder.call_c(set_stop_iteration_value, [value], NO_TRACEBACK_LINE_NO) builder.add(Unreachable()) builder.builder.pop_error_handler() @@ -159,7 +159,7 @@ def __init__(self, outer: NonlocalControl, saved: Union[Value, AssignmentTarget] self.saved = saved def gen_cleanup(self, builder: 'IRBuilder', line: int) -> None: - builder.primitive_op(restore_exc_info_op, [builder.read(self.saved)], line) + builder.call_c(restore_exc_info_op, [builder.read(self.saved)], line) class FinallyNonlocalControl(CleanupNonlocalControl): @@ -187,5 +187,5 @@ def gen_cleanup(self, builder: 'IRBuilder', line: int) -> None: target, cleanup = BasicBlock(), BasicBlock() builder.add(Branch(self.saved, target, cleanup, Branch.IS_ERROR)) builder.activate_block(cleanup) - builder.primitive_op(restore_exc_info_op, [self.saved], line) + builder.call_c(restore_exc_info_op, [self.saved], line) builder.goto_and_activate(target) diff --git a/mypyc/irbuild/statement.py b/mypyc/irbuild/statement.py index ac88ecb04858..184458b85f31 100644 --- a/mypyc/irbuild/statement.py +++ b/mypyc/irbuild/statement.py @@ -238,7 +238,7 @@ def transform_continue_stmt(builder: IRBuilder, node: ContinueStmt) -> None: def transform_raise_stmt(builder: IRBuilder, s: RaiseStmt) -> None: if s.expr is None: - builder.primitive_op(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) + builder.call_c(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) builder.add(Unreachable()) return @@ -278,7 +278,7 @@ def transform_try_except(builder: IRBuilder, # exception is raised, based on the exception in exc_info. builder.builder.push_error_handler(double_except_block) builder.activate_block(except_entry) - old_exc = builder.maybe_spill(builder.primitive_op(error_catch_op, [], line)) + old_exc = builder.maybe_spill(builder.call_c(error_catch_op, [], line)) # Compile the except blocks with the nonlocal control flow overridden to clear exc_info builder.nonlocal_control.append( ExceptNonlocalControl(builder.nonlocal_control[-1], old_exc)) @@ -288,7 +288,7 @@ def transform_try_except(builder: IRBuilder, next_block = None if type: next_block, body_block = BasicBlock(), BasicBlock() - matches = builder.primitive_op( + matches = builder.call_c( exc_matches_op, [builder.accept(type)], type.line ) builder.add(Branch(matches, body_block, next_block, Branch.BOOL_EXPR)) @@ -297,7 +297,7 @@ def transform_try_except(builder: IRBuilder, target = builder.get_assignment_target(var) builder.assign( target, - builder.primitive_op(get_exc_value_op, [], var.line), + builder.call_c(get_exc_value_op, [], var.line), var.line ) handler_body() @@ -307,7 +307,7 @@ def transform_try_except(builder: IRBuilder, # Reraise the exception if needed if next_block: - builder.primitive_op(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) + builder.call_c(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) builder.add(Unreachable()) builder.nonlocal_control.pop() @@ -317,14 +317,14 @@ def transform_try_except(builder: IRBuilder, # restore the saved exc_info information and continue propagating # the exception if it exists. builder.activate_block(cleanup_block) - builder.primitive_op(restore_exc_info_op, [builder.read(old_exc)], line) + builder.call_c(restore_exc_info_op, [builder.read(old_exc)], line) builder.goto(exit_block) # Cleanup for if we leave except through a raised exception: # restore the saved exc_info information and continue propagating # the exception. builder.activate_block(double_except_block) - builder.primitive_op(restore_exc_info_op, [builder.read(old_exc)], line) + builder.call_c(restore_exc_info_op, [builder.read(old_exc)], line) builder.primitive_op(keep_propagating_op, [], NO_TRACEBACK_LINE_NO) builder.add(Unreachable()) @@ -402,7 +402,7 @@ def try_finally_entry_blocks(builder: IRBuilder, builder.add(LoadErrorValue(builder.ret_types[-1])) ) ) - builder.add(Assign(old_exc, builder.primitive_op(error_catch_op, [], -1))) + builder.add(Assign(old_exc, builder.call_c(error_catch_op, [], -1))) builder.goto(finally_block) return old_exc @@ -442,7 +442,7 @@ def try_finally_resolve_control(builder: IRBuilder, # Reraise the exception if there was one builder.activate_block(reraise) - builder.primitive_op(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) + builder.call_c(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) builder.add(Unreachable()) builder.builder.pop_error_handler() @@ -520,7 +520,7 @@ def transform_try_body() -> None: def get_sys_exc_info(builder: IRBuilder) -> List[Value]: - exc_info = builder.primitive_op(get_exc_info_op, [], -1) + exc_info = builder.call_c(get_exc_info_op, [], -1) return [builder.add(TupleGet(exc_info, i, -1)) for i in range(3)] @@ -557,7 +557,7 @@ def except_body() -> None: reraise_block ) builder.activate_block(reraise_block) - builder.primitive_op(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) + builder.call_c(reraise_exception_op, [], NO_TRACEBACK_LINE_NO) builder.add(Unreachable()) builder.activate_block(out_block) diff --git a/mypyc/primitives/exc_ops.py b/mypyc/primitives/exc_ops.py index a42f8d3c0aa4..5b48b5bb8752 100644 --- a/mypyc/primitives/exc_ops.py +++ b/mypyc/primitives/exc_ops.py @@ -3,7 +3,7 @@ from mypyc.ir.ops import ERR_NEVER, ERR_FALSE, ERR_ALWAYS 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, c_custom_op + simple_emit, custom_op, c_custom_op ) # If the argument is a class, raise an instance of the class. Otherwise, assume @@ -15,37 +15,33 @@ error_kind=ERR_ALWAYS) # Raise StopIteration exception with the specified value (which can be NULL). -set_stop_iteration_value = custom_op( +set_stop_iteration_value = c_custom_op( arg_types=[object_rprimitive], - result_type=bool_rprimitive, - error_kind=ERR_FALSE, - format_str='set_stop_iteration_value({args[0]}); {dest} = 0', - emit=call_and_fail_emit('CPyGen_SetStopIterationValue')) + return_type=void_rtype, + c_function_name='CPyGen_SetStopIterationValue', + error_kind=ERR_ALWAYS) # Raise exception with traceback. # Arguments are (exception type, exception value, traceback). -raise_exception_with_tb_op = custom_op( +raise_exception_with_tb_op = c_custom_op( arg_types=[object_rprimitive, object_rprimitive, object_rprimitive], - result_type=bool_rprimitive, - error_kind=ERR_FALSE, - format_str='raise_exception_with_tb({args[0]}, {args[1]}, {args[2]}); {dest} = 0', - emit=call_and_fail_emit('CPyErr_SetObjectAndTraceback')) + return_type=void_rtype, + c_function_name='CPyErr_SetObjectAndTraceback', + error_kind=ERR_ALWAYS) # Reraise the currently raised exception. -reraise_exception_op = custom_op( +reraise_exception_op = c_custom_op( arg_types=[], - result_type=bool_rprimitive, - error_kind=ERR_FALSE, - format_str='reraise_exc; {dest} = 0', - emit=call_and_fail_emit('CPy_Reraise')) + return_type=void_rtype, + c_function_name='CPy_Reraise', + error_kind=ERR_ALWAYS) # Propagate exception if the CPython error indicator is set (an exception was raised). -no_err_occurred_op = custom_op( +no_err_occurred_op = c_custom_op( arg_types=[], - result_type=bool_rprimitive, - error_kind=ERR_FALSE, - format_str='{dest} = no_err_occurred', - emit=call_emit('CPy_NoErrOccured')) + return_type=bool_rprimitive, + c_function_name='CPy_NoErrOccured', + error_kind=ERR_FALSE) # Assert that the error indicator has been set. assert_err_occured_op = custom_op( @@ -68,42 +64,37 @@ # handled exception" (by sticking it into sys.exc_info()). Returns the # exception that was previously being handled, which must be restored # later. -error_catch_op = custom_op( +error_catch_op = c_custom_op( arg_types=[], - result_type=exc_rtuple, - error_kind=ERR_NEVER, - format_str='{dest} = error_catch', - emit=call_emit('CPy_CatchError')) + return_type=exc_rtuple, + c_function_name='CPy_CatchError', + error_kind=ERR_NEVER) # Restore an old "currently handled exception" returned from. # error_catch (by sticking it into sys.exc_info()) -restore_exc_info_op = custom_op( +restore_exc_info_op = c_custom_op( arg_types=[exc_rtuple], - result_type=void_rtype, - error_kind=ERR_NEVER, - format_str='restore_exc_info {args[0]}', - emit=call_void_emit('CPy_RestoreExcInfo')) + return_type=void_rtype, + c_function_name='CPy_RestoreExcInfo', + error_kind=ERR_NEVER) # Checks whether the exception currently being handled matches a particular type. -exc_matches_op = custom_op( +exc_matches_op = c_custom_op( arg_types=[object_rprimitive], - result_type=bool_rprimitive, - error_kind=ERR_NEVER, - format_str='{dest} = exc_matches {args[0]}', - emit=call_emit('CPy_ExceptionMatches')) + return_type=bool_rprimitive, + c_function_name='CPy_ExceptionMatches', + error_kind=ERR_NEVER) # Get the value of the exception currently being handled. -get_exc_value_op = custom_op( +get_exc_value_op = c_custom_op( arg_types=[], - result_type=object_rprimitive, - error_kind=ERR_NEVER, - format_str='{dest} = get_exc_value', - emit=call_emit('CPy_GetExcValue')) + return_type=object_rprimitive, + c_function_name='CPy_GetExcValue', + error_kind=ERR_NEVER) # Get exception info (exception type, exception instance, traceback object). -get_exc_info_op = custom_op( +get_exc_info_op = c_custom_op( arg_types=[], - result_type=exc_rtuple, - error_kind=ERR_NEVER, - format_str='{dest} = get_exc_info', - emit=call_emit('CPy_GetExcInfo')) + return_type=exc_rtuple, + c_function_name='CPy_GetExcInfo', + error_kind=ERR_NEVER) diff --git a/mypyc/test-data/analysis.test b/mypyc/test-data/analysis.test index db20f704a875..dde8430f18eb 100644 --- a/mypyc/test-data/analysis.test +++ b/mypyc/test-data/analysis.test @@ -568,49 +568,51 @@ def lol(x): r5 :: bool r6 :: short_int r7 :: int - r8, r9 :: bool - r10 :: short_int - r11, r12 :: int + r8 :: bool + r9 :: short_int + r10, r11 :: int + r12 :: bool L0: L1: r0 = CPyTagged_Id(x) st = r0 goto L10 L2: - r1 = error_catch + r1 = CPy_CatchError() r2 = builtins :: module r3 = unicode_1 :: static ('Exception') r4 = getattr r2, r3 if is_error(r4) goto L8 (error at lol:4) else goto L3 L3: - r5 = exc_matches r4 + r5 = CPy_ExceptionMatches(r4) if r5 goto L4 else goto L5 :: bool L4: r6 = 1 r7 = CPyTagged_Negate(r6) - restore_exc_info r1 + CPy_RestoreExcInfo(r1) return r7 L5: - reraise_exc; r8 = 0 - if not r8 goto L8 else goto L6 :: bool + CPy_Reraise() + r12 = 0 + if not r12 goto L8 else goto L6 :: bool L6: unreachable L7: - restore_exc_info r1 + CPy_RestoreExcInfo(r1) goto L10 L8: - restore_exc_info r1 - r9 = keep_propagating - if not r9 goto L11 else goto L9 :: bool + CPy_RestoreExcInfo(r1) + r8 = keep_propagating + if not r8 goto L11 else goto L9 :: bool L9: unreachable L10: - r10 = 1 - r11 = CPyTagged_Add(st, r10) - return r11 + r9 = 1 + r10 = CPyTagged_Add(st, r9) + return r10 L11: - r12 = :: int - return r12 + r11 = :: int + return r11 (0, 0) {x} {x} (1, 0) {x} {r0} (1, 1) {r0} {st} @@ -626,18 +628,19 @@ L11: (4, 1) {r1, r6} {r1, r7} (4, 2) {r1, r7} {r7} (4, 3) {r7} {} -(5, 0) {r1} {r1, r8} -(5, 1) {r1, r8} {r1} +(5, 0) {r1} {r1} +(5, 1) {r1} {r1, r12} +(5, 2) {r1, r12} {r1} (6, 0) {} {} (7, 0) {r1, st} {st} (7, 1) {st} {st} (8, 0) {r1} {} -(8, 1) {} {r9} -(8, 2) {r9} {} +(8, 1) {} {r8} +(8, 2) {r8} {} (9, 0) {} {} -(10, 0) {st} {r10, st} -(10, 1) {r10, st} {r11} -(10, 2) {r11} {} -(11, 0) {} {r12} -(11, 1) {r12} {} +(10, 0) {st} {r9, st} +(10, 1) {r9, st} {r10} +(10, 2) {r10} {} +(11, 0) {} {r11} +(11, 1) {r11} {} diff --git a/mypyc/test-data/exceptions.test b/mypyc/test-data/exceptions.test index 0848943f8d4d..dd18356e22c4 100644 --- a/mypyc/test-data/exceptions.test +++ b/mypyc/test-data/exceptions.test @@ -202,7 +202,7 @@ L2: dec_ref r2 if is_error(r3) goto L3 (error at g:3) else goto L10 L3: - r4 = error_catch + r4 = CPy_CatchError() r5 = unicode_2 :: static ('weeee') r6 = builtins :: module r7 = unicode_3 :: static ('print') @@ -213,11 +213,11 @@ L4: dec_ref r8 if is_error(r9) goto L6 (error at g:5) else goto L11 L5: - restore_exc_info r4 + CPy_RestoreExcInfo(r4) dec_ref r4 goto L8 L6: - restore_exc_info r4 + CPy_RestoreExcInfo(r4) dec_ref r4 r10 = keep_propagating if not r10 goto L9 else goto L7 :: bool @@ -258,8 +258,9 @@ def a(): r12 :: object r13 :: str r14, r15 :: object - r16, r17 :: bool - r18 :: str + r16 :: bool + r17 :: str + r18 :: bool L0: L1: r0 = builtins :: module @@ -281,7 +282,7 @@ L4: L5: r9 = :: str r5 = r9 - r10 = error_catch + r10 = CPy_CatchError() r6 = r10 L6: r11 = unicode_3 :: static ('goodbye!') @@ -296,8 +297,9 @@ L7: L8: if is_error(r6) goto L11 else goto L9 L9: - reraise_exc; r16 = 0 - if not r16 goto L13 else goto L22 :: bool + CPy_Reraise() + r18 = 0 + if not r18 goto L13 else goto L22 :: bool L10: unreachable L11: @@ -309,18 +311,18 @@ L13: L14: if is_error(r6) goto L16 else goto L15 L15: - restore_exc_info r6 + CPy_RestoreExcInfo(r6) dec_ref r6 L16: - r17 = keep_propagating - if not r17 goto L19 else goto L17 :: bool + r16 = keep_propagating + if not r16 goto L19 else goto L17 :: bool L17: unreachable L18: unreachable L19: - r18 = :: str - return r18 + r17 = :: str + return r17 L20: dec_ref r3 goto L3 @@ -373,9 +375,9 @@ L2: st = r1 goto L4 L3: - r2 = error_catch + r2 = CPy_CatchError() r3 = unicode_4 :: static - restore_exc_info r2 + CPy_RestoreExcInfo(r2) dec_ref r2 inc_ref r3 return r3 @@ -418,9 +420,9 @@ L3: b = r3 goto L6 L4: - r4 = error_catch + r4 = CPy_CatchError() L5: - restore_exc_info r4 + CPy_RestoreExcInfo(r4) dec_ref r4 L6: if is_error(a) goto L17 else goto L9 diff --git a/mypyc/test-data/irbuild-basic.test b/mypyc/test-data/irbuild-basic.test index eac963c9adcc..5eb54b6e3383 100644 --- a/mypyc/test-data/irbuild-basic.test +++ b/mypyc/test-data/irbuild-basic.test @@ -3063,7 +3063,7 @@ L4: L5: goto L1 L6: - r8 = no_err_occurred + r8 = CPy_NoErrOccured() L7: L8: return r0 @@ -3096,7 +3096,7 @@ L4: L5: goto L1 L6: - r9 = no_err_occurred + r9 = CPy_NoErrOccured() L7: L8: return r0 diff --git a/mypyc/test-data/irbuild-dict.test b/mypyc/test-data/irbuild-dict.test index a5a47e0fd3bb..c4e5bfe185c5 100644 --- a/mypyc/test-data/irbuild-dict.test +++ b/mypyc/test-data/irbuild-dict.test @@ -194,7 +194,7 @@ L3: r14 = CPyDict_CheckSize(d, r2) goto L1 L4: - r15 = no_err_occurred + r15 = CPy_NoErrOccured() L5: return d @@ -290,7 +290,7 @@ L5: r13 = CPyDict_CheckSize(d1, r2) goto L1 L6: - r14 = no_err_occurred + r14 = CPy_NoErrOccured() L7: r15 = 0 r16 = r15 @@ -319,7 +319,7 @@ L10: r32 = CPyDict_CheckSize(d2, r17) goto L8 L11: - r33 = no_err_occurred + r33 = CPy_NoErrOccured() L12: r34 = None return r34 diff --git a/mypyc/test-data/irbuild-statements.test b/mypyc/test-data/irbuild-statements.test index 596e6671da5e..16660928f465 100644 --- a/mypyc/test-data/irbuild-statements.test +++ b/mypyc/test-data/irbuild-statements.test @@ -330,7 +330,7 @@ L3: r12 = CPyDict_CheckSize(d, r2) goto L1 L4: - r13 = no_err_occurred + r13 = CPy_NoErrOccured() L5: r14 = None return r14 @@ -404,7 +404,7 @@ L5: r21 = CPyDict_CheckSize(d, r3) goto L1 L6: - r22 = no_err_occurred + r22 = CPy_NoErrOccured() L7: return s @@ -906,7 +906,7 @@ L3: i = r6 goto L1 L4: - r7 = no_err_occurred + r7 = CPy_NoErrOccured() L5: r8 = None return r8 @@ -965,7 +965,7 @@ L6: r1 = r12 goto L1 L7: - r13 = no_err_occurred + r13 = CPy_NoErrOccured() L8: r14 = None return r14 @@ -1020,7 +1020,7 @@ L5: z = r17 goto L1 L6: - r18 = no_err_occurred + r18 = CPy_NoErrOccured() L7: r19 = None return r19 diff --git a/mypyc/test-data/irbuild-try.test b/mypyc/test-data/irbuild-try.test index f5cee4864957..6183ab9de1da 100644 --- a/mypyc/test-data/irbuild-try.test +++ b/mypyc/test-data/irbuild-try.test @@ -24,17 +24,17 @@ L1: r3 = py_call(r2) goto L5 L2: (handler for L1) - r4 = error_catch + r4 = CPy_CatchError() r5 = unicode_2 :: static ('weeee') r6 = builtins :: module r7 = unicode_3 :: static ('print') r8 = getattr r6, r7 r9 = py_call(r8, r5) L3: - restore_exc_info r4 + CPy_RestoreExcInfo(r4) goto L5 L4: (handler for L2) - restore_exc_info r4 + CPy_RestoreExcInfo(r4) r10 = keep_propagating unreachable L5: @@ -79,17 +79,17 @@ L3: L4: goto L8 L5: (handler for L1, L2, L3, L4) - r6 = error_catch + r6 = CPy_CatchError() r7 = unicode_3 :: static ('weeee') r8 = builtins :: module r9 = unicode_4 :: static ('print') r10 = getattr r8, r9 r11 = py_call(r10, r7) L6: - restore_exc_info r6 + CPy_RestoreExcInfo(r6) goto L8 L7: (handler for L5) - restore_exc_info r6 + CPy_RestoreExcInfo(r6) r12 = keep_propagating unreachable L8: @@ -124,14 +124,14 @@ def g(): r16 :: object r17 :: str r18, r19 :: object - r20, r21 :: bool - r22 :: tuple[object, object, object] - r23 :: str - r24 :: object - r25 :: str - r26, r27 :: object - r28 :: bool - r29 :: None + r20 :: bool + r21 :: tuple[object, object, object] + r22 :: str + r23 :: object + r24 :: str + r25, r26 :: object + r27 :: bool + r28 :: None L0: L1: r0 = unicode_1 :: static ('a') @@ -146,14 +146,14 @@ L2: r8 = py_call(r7) goto L8 L3: (handler for L2) - r9 = error_catch + r9 = CPy_CatchError() r10 = builtins :: module r11 = unicode_4 :: static ('AttributeError') r12 = getattr r10, r11 - r13 = exc_matches r12 + r13 = CPy_ExceptionMatches(r12) if r13 goto L4 else goto L5 :: bool L4: - r14 = get_exc_value + r14 = CPy_GetExcValue() e = r14 r15 = unicode_5 :: static ('b') r16 = builtins :: module @@ -162,34 +162,34 @@ L4: r19 = py_call(r18, r15, e) goto L6 L5: - reraise_exc; r20 = 0 + CPy_Reraise() unreachable L6: - restore_exc_info r9 + CPy_RestoreExcInfo(r9) goto L8 L7: (handler for L3, L4, L5) - restore_exc_info r9 - r21 = keep_propagating + CPy_RestoreExcInfo(r9) + r20 = keep_propagating unreachable L8: goto L12 L9: (handler for L1, L6, L7, L8) - r22 = error_catch - r23 = unicode_6 :: static ('weeee') - r24 = builtins :: module - r25 = unicode_2 :: static ('print') - r26 = getattr r24, r25 - r27 = py_call(r26, r23) + r21 = CPy_CatchError() + r22 = unicode_6 :: static ('weeee') + r23 = builtins :: module + r24 = unicode_2 :: static ('print') + r25 = getattr r23, r24 + r26 = py_call(r25, r22) L10: - restore_exc_info r22 + CPy_RestoreExcInfo(r21) goto L12 L11: (handler for L9) - restore_exc_info r22 - r28 = keep_propagating + CPy_RestoreExcInfo(r21) + r27 = keep_propagating unreachable L12: - r29 = None - return r29 + r28 = None + return r28 [case testTryExcept4] def g() -> None: @@ -217,17 +217,17 @@ def g(): r15 :: object r16 :: str r17, r18 :: object - r19, r20 :: bool - r21 :: None + r19 :: bool + r20 :: None L0: L1: goto L9 L2: (handler for L1) - r0 = error_catch + r0 = CPy_CatchError() r1 = builtins :: module r2 = unicode_1 :: static ('KeyError') r3 = getattr r1, r2 - r4 = exc_matches r3 + r4 = CPy_ExceptionMatches(r3) if r4 goto L3 else goto L4 :: bool L3: r5 = unicode_2 :: static ('weeee') @@ -240,7 +240,7 @@ L4: r10 = builtins :: module r11 = unicode_4 :: static ('IndexError') r12 = getattr r10, r11 - r13 = exc_matches r12 + r13 = CPy_ExceptionMatches(r12) if r13 goto L5 else goto L6 :: bool L5: r14 = unicode_5 :: static ('yo') @@ -250,18 +250,18 @@ L5: r18 = py_call(r17, r14) goto L7 L6: - reraise_exc; r19 = 0 + CPy_Reraise() unreachable L7: - restore_exc_info r0 + CPy_RestoreExcInfo(r0) goto L9 L8: (handler for L2, L3, L4, L5, L6) - restore_exc_info r0 - r20 = keep_propagating + CPy_RestoreExcInfo(r0) + r19 = keep_propagating unreachable L9: - r21 = None - return r21 + r20 = None + return r20 [case testTryFinally] def a(b: bool) -> None: @@ -282,8 +282,8 @@ def a(b): r9 :: object r10 :: str r11, r12 :: object - r13, r14 :: bool - r15 :: None + r13 :: bool + r14 :: None L0: L1: if b goto L2 else goto L3 :: bool @@ -302,7 +302,7 @@ L5: r5 = r6 goto L7 L6: (handler for L1, L2, L3) - r7 = error_catch + r7 = CPy_CatchError() r5 = r7 L7: r8 = unicode_3 :: static ('finally') @@ -312,20 +312,20 @@ L7: r12 = py_call(r11, r8) if is_error(r5) goto L9 else goto L8 L8: - reraise_exc; r13 = 0 + CPy_Reraise() unreachable L9: goto L13 L10: (handler for L7, L8) if is_error(r5) goto L12 else goto L11 L11: - restore_exc_info r5 + CPy_RestoreExcInfo(r5) L12: - r14 = keep_propagating + r13 = keep_propagating unreachable L13: - r15 = None - return r15 + r14 = None + return r14 [case testWith] from typing import Any @@ -349,11 +349,11 @@ def foo(x): r15 :: bool r16 :: tuple[object, object, object] r17, r18, r19, r20 :: object - r21, r22, r23 :: bool - r24, r25, r26 :: tuple[object, object, object] - r27, r28 :: object - r29, r30 :: bool - r31 :: None + r21, r22 :: bool + r23, r24, r25 :: tuple[object, object, object] + r26, r27 :: object + r28 :: bool + r29 :: None L0: r0 = py_call(x) r1 = type r0 :: object @@ -374,10 +374,10 @@ L2: r13 = py_call(r12, r9) goto L8 L3: (handler for L2) - r14 = error_catch + r14 = CPy_CatchError() r15 = False r8 = r15 - r16 = get_exc_info + r16 = CPy_GetExcInfo() r17 = r16[0] r18 = r16[1] r19 = r16[2] @@ -385,45 +385,45 @@ L3: (handler for L2) r21 = bool r20 :: object if r21 goto L5 else goto L4 :: bool L4: - reraise_exc; r22 = 0 + CPy_Reraise() unreachable L5: L6: - restore_exc_info r14 + CPy_RestoreExcInfo(r14) goto L8 L7: (handler for L3, L4, L5) - restore_exc_info r14 - r23 = keep_propagating + CPy_RestoreExcInfo(r14) + r22 = keep_propagating unreachable L8: L9: L10: - r25 = :: tuple[object, object, object] - r24 = r25 + r24 = :: tuple[object, object, object] + r23 = r24 goto L12 L11: (handler for L1, L6, L7, L8) - r26 = error_catch - r24 = r26 + r25 = CPy_CatchError() + r23 = r25 L12: if r8 goto L13 else goto L14 :: bool L13: - r27 = builtins.None :: object - r28 = py_call(r3, r0, r27, r27, r27) + r26 = builtins.None :: object + r27 = py_call(r3, r0, r26, r26, r26) L14: - if is_error(r24) goto L16 else goto L15 + if is_error(r23) goto L16 else goto L15 L15: - reraise_exc; r29 = 0 + CPy_Reraise() unreachable L16: goto L20 L17: (handler for L12, L13, L14, L15) - if is_error(r24) goto L19 else goto L18 + if is_error(r23) goto L19 else goto L18 L18: - restore_exc_info r24 + CPy_RestoreExcInfo(r23) L19: - r30 = keep_propagating + r28 = keep_propagating unreachable L20: - r31 = None - return r31 + r29 = None + return r29 diff --git a/mypyc/test-data/refcount.test b/mypyc/test-data/refcount.test index a63474b02766..216454e6d92c 100644 --- a/mypyc/test-data/refcount.test +++ b/mypyc/test-data/refcount.test @@ -885,7 +885,7 @@ L3: r12 = CPyDict_CheckSize(d, r2) goto L1 L4: - r13 = no_err_occurred + r13 = CPy_NoErrOccured() L5: r14 = None return r14