Commit 79d4bd3d authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Non-ndim buffer indices falls back to Python; stops double-analysing index tuples

parent 3da50c6d
...@@ -1289,29 +1289,40 @@ class IndexNode(ExprNode): ...@@ -1289,29 +1289,40 @@ class IndexNode(ExprNode):
self.is_buffer_access = False self.is_buffer_access = False
self.base.analyse_types(env) self.base.analyse_types(env)
skip_child_analysis = False
buffer_access = False
if self.base.type.buffer_options is not None: if self.base.type.buffer_options is not None:
if isinstance(self.index, TupleNode): if isinstance(self.index, TupleNode):
indices = self.index.args indices = self.index.args
else: else:
indices = [self.index] indices = [self.index]
all_ints = True if len(indices) == self.base.type.buffer_options.ndim:
for x in indices: buffer_access = True
x.analyse_types(env) skip_child_analysis = True
if not x.type.is_int: for x in indices:
all_ints = False x.analyse_types(env)
if all_ints: if not x.type.is_int:
# self.indices = [ buffer_access = False
# x.coerce_to(PyrexTypes.c_py_ssize_t_type, env).coerce_to_simple(env) if buffer_access:
# for x in indices] # self.indices = [
self.indices = indices # x.coerce_to(PyrexTypes.c_py_ssize_t_type, env).coerce_to_simple(env)
self.index = None # for x in indices]
self.type = self.base.type.buffer_options.dtype self.indices = indices
self.is_temp = 1 self.index = None
self.is_buffer_access = True self.type = self.base.type.buffer_options.dtype
self.is_temp = 1
self.is_buffer_access = True
# Note: This might be cleaned up by having IndexNode
# parsed in a saner way and only construct the tuple if
# needed.
if not self.is_buffer_access: if not buffer_access:
self.index.analyse_types(env) # ok to analyse as tuple if isinstance(self.index, TupleNode):
self.index.analyse_types(env, skip_children=skip_child_analysis)
elif not skip_child_analysis:
self.index.analyse_types(env)
if self.base.type.is_pyobject: if self.base.type.is_pyobject:
if self.index.type.is_int: if self.index.type.is_int:
self.original_index_type = self.index.type self.original_index_type = self.index.type
...@@ -2212,10 +2223,10 @@ class SequenceNode(ExprNode): ...@@ -2212,10 +2223,10 @@ class SequenceNode(ExprNode):
for arg in self.args: for arg in self.args:
arg.analyse_target_declaration(env) arg.analyse_target_declaration(env)
def analyse_types(self, env): def analyse_types(self, env, skip_children=False):
for i in range(len(self.args)): for i in range(len(self.args)):
arg = self.args[i] arg = self.args[i]
arg.analyse_types(env) if not skip_children: arg.analyse_types(env)
self.args[i] = arg.coerce_to_pyobject(env) self.args[i] = arg.coerce_to_pyobject(env)
self.type = py_object_type self.type = py_object_type
self.gil_check(env) self.gil_check(env)
...@@ -2320,12 +2331,12 @@ class TupleNode(SequenceNode): ...@@ -2320,12 +2331,12 @@ class TupleNode(SequenceNode):
gil_message = "Constructing Python tuple" gil_message = "Constructing Python tuple"
def analyse_types(self, env): def analyse_types(self, env, skip_children=False):
if len(self.args) == 0: if len(self.args) == 0:
self.is_temp = 0 self.is_temp = 0
self.is_literal = 1 self.is_literal = 1
else: else:
SequenceNode.analyse_types(self, env) SequenceNode.analyse_types(self, env, skip_children)
self.type = tuple_type self.type = tuple_type
def calculate_result_code(self): def calculate_result_code(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment