Calling a NewType type is currently slow. Consider this code: ```py from typing import NewType, cast class C: pass N = NewType("N", C) def f(c: C) -> N: return N(c) # Slow! ``` The IR for the call `N(c)` looks like this: ``` L0: r0 = tt.globals :: static r1 = 'N' r2 = CPyDict_GetItem(r0, r1) if is_error(r2) goto L3 (error at f:10) else goto L1 L1: r3 = [c] r4 = load_address r3 r5 = _PyObject_Vectorcall(r2, r4, 1, 0) dec_ref r2 if is_error(r5) goto L3 (error at f:10) else goto L2 ``` Since calling a NewType type is a no-op at runtime, we can simply compile the call away.
Activity
[mypyc] Compile away NewType type calls (#14398)