Skip to content

Commit

Permalink
Merge pull request numba#5024 from stuartarchibald/fix/5015
Browse files Browse the repository at this point in the history
Propagate semantic constants ahead of static rewrites.
  • Loading branch information
seibert authored Jan 3, 2020
2 parents 6189435 + 2e48486 commit 88e3dad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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))

0 comments on commit 88e3dad

Please sign in to comment.