Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate semantic constants ahead of static rewrites. #5024

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion numba/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ def define_nopython_pipeline(state, name='nopython'):

# pre typing
if not state.flags.no_rewrites:
pm.add_pass(GenericRewrites, "nopython rewrites")
pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants")
pm.add_pass(DeadBranchPrune, "dead branch pruning")
pm.add_pass(GenericRewrites, "nopython rewrites")

pm.add_pass(InlineClosureLikes,
"inline calls to locally defined closures")
Expand Down
11 changes: 11 additions & 0 deletions numba/tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,14 @@ def impl(fa):
FakeArrayType = types.NamedUniTuple(types.int64, 1, FakeArray)
self.assert_prune(impl, (FakeArrayType,), [None], fa,
flags=enable_pyobj_flags)

def test_semantic_const_propagates_before_static_rewrites(self):
# see issue #5015, the ndim needs writing in as a const before
# the rewrite passes run to make e.g. getitems static where possible
@njit
def impl(a, b):
return a.shape[:b.ndim]

args = (np.zeros((5, 4, 3, 2)), np.zeros((1, 1)))

self.assertPreciseEqual(impl(*args), impl.py_func(*args))