Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes mypyc/mypyc#1248.
Fixes mypyc/mypyc#1240.
Fixes mypyc/mypyc#1162.
native_args_to_positional()can pass a*args/**kwargsargument on to a*args/**kwargsparameter, but it can't unpack one. Most native call sites check for this and use a Python-level call instead (call_refexpr_with_args(),gen_method_call(),gen_glue_method(), andClass.method(...)since #18228).translate_super_method_call()and thecls.method(...)case intranslate_method_call()didn't.The check is now in
LowLevelIRBuilder.call(), which all of these go through.can_pass_args_natively()uses the same argument mapping asnative_args_to_positional()and reports whether a*args/**kwargsargument is mapped to a parameter of another kind. If so,call()calls the method through its wrapper function, which parses arguments like a call from interpreted code.CPy_GetMethodWrapper()gets a callable for the wrapper fromtp_methodsof the class that defines the method (CPy_SetupObject()readstp_methodsin the same way).The method table had
METH_FASTCALL | METH_KEYWORDSfor every method, but__init__and__new__have legacy wrappers that take a tuple and a dict, and the wrapper of__new__takes the class asself.CPy_GetMethodWrapper()needs the real flags, so these two now haveMETH_VARARGS | METH_KEYWORDS, and__new__hasMETH_CLASS. CPython doesn't use these entries when it sets up the type, since the slot wrappers get into the type dict first, and the type dict is unchanged. The exception is__new__of a class with a built-in base class, which has notp_new: there the entry is in the type dict, and calling it from interpreted code crashed before and raisesTypeErrornow. That needs its own fix.is_fastcall_supported()moves fromemitmodule.pytoemitwrapper.pyso thatemitclass.pycan use it.Calls without
*args/**kwargs, and calls that pass them on to*args/**kwargsof the method, are native calls as before. An unpacked argument that no parameter of the method can take is still ignored, as before.The wrapper call is much slower than a native call, a bit faster than the same call in interpreted code. It only replaces calls that didn't work.