[mypyc] Make compilation order with multiple files consistent#21419
Open
p-sawicki wants to merge 2 commits intopython:masterfrom
Open
[mypyc] Make compilation order with multiple files consistent#21419p-sawicki wants to merge 2 commits intopython:masterfrom
p-sawicki wants to merge 2 commits intopython:masterfrom
Conversation
af4d296 to
656cd4f
Compare
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.
The
mypycplugin sets all modules inside a group as dependent on each other so they are part of a single SCC. When we compile the SCC, we compile its modules according to the order inscc.mod_ids.mod_idsis asetso the order is non-deterministic.This might result in random failures when multiple files are compiled together and we have a bug in mypyc caused by relying on data that is dependent on the compilation order. For example if we are compiling two files
a.pyandb.pyeach with a single class and an attribute ofClassIRrepresenting the classAthat is not set during the preparation phase is used when compiling the classB, the result will depend on whethera.pywas compiled beforeb.py.To fix, make the order deterministic based on module names by sorting them first. Also sort the source files and groups passed to
mypycifyso that invokingmypyc a.py b.pyandmypyc b.py a.pyproduces identical results.