Do not construct layout passes with no coupling map #14353
Merged
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.
Summary
The builtin plugins fairly frequently construct instances of the layout passes with
coupling_map=None
(or similar), even when this is against the documentation of the passes. A couple of passes, but not all, have defensive code in theirrun
methods to raise a better error in this case, but even so, there is an assumption that passes will not be run withcoupling_map=None
.The preset pass managers do follow this assumption; conditional code prevents those passes from ever being called. However, we know that there's no coupling map ahead of time, so we can simply not even construct the layout passes, let alone add them to the
PassManager
.Details and comments
Input normalisation typically wants to be done in pass initialisation, not deferred to runtime (though expensive properties can still be computed only on first run and cached). The current strategy of silently ignoring invalid inputs until runtime makes it harder to do this; it's clearer to have the pass-manager construction logic never produce objects in invalid states in the first place.