-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mypyc] Allow registering implementations for singledispatch function…
…s in different files (#10880) * Add test for singledispatch across multiple files Add a test to make sure that we handle registering a singledispatch function in a different module than the main function correctly. This test uses a pattern similar to the code in mypyc/mypyc#802 (comment) to make sure that we don't accidentally end up dynamically registering functions in other modules and just relying on the normal singledispatch machinery to check the dynamically registered functions. * Move info about a register implementation to type alias Add a type alias for the type that we use for information about a register implementation (which is a tuple of the dispatch type's TypeInfo and the function's FuncDef). * Run register-finding pass over entire SCC Instead of trying to look for singledispatch register implementations in one file at a time and only using the register implementations found in the same file as the singledispatch main function when generating code, look for register implementations across the entire SCC once, and then use that list when compiling every module. That change necessitates adding an extra argument for the PreBuildVisitor constructor so that we can remove any register calls that we found (so we can avoid register trying to access `__annotations__` on a builtin function) and adding an extra argument to IRBuilder so that we can access the list of singledispatch functions when building IR in any module. * Load functions from other modules correctly When we're generating calls to registered implementations in other modules, we need to load those functions by loading the module and accessing the correct attribute, instead of trying to load that function from the globals dict of the current module. That change also necessitates generating imports of any modules with registered implementations that weren't already imported so that we can load those modules in the dispatch function.
- Loading branch information
1 parent
14e06c2
commit 9b10175
Showing
6 changed files
with
216 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.