提交 30126992 authored 作者: James Bergstra's avatar James Bergstra

gof/cc - added code to handle non-hashable constant signatures by returning a

Null key. This can happen for constants with type 'generic'.
上级 695bcad0
...@@ -858,6 +858,7 @@ class CLinker(link.Linker): ...@@ -858,6 +858,7 @@ class CLinker(link.Linker):
if config.gcc.cxxflags: if config.gcc.cxxflags:
sig.append(config.gcc.cxxflags) sig.append(config.gcc.cxxflags)
error_on_play = [False]
def in_sig(i, topological_pos, i_idx): def in_sig(i, topological_pos, i_idx):
# assert that every input to every node is one of' # assert that every input to every node is one of'
# - an env input # - an env input
...@@ -868,8 +869,15 @@ class CLinker(link.Linker): ...@@ -868,8 +869,15 @@ class CLinker(link.Linker):
# yield a 'position' that reflects its role in code_gen() # yield a 'position' that reflects its role in code_gen()
if isinstance(i, graph.Constant): #orphans if isinstance(i, graph.Constant): #orphans
if id(i) not in constant_ids: if id(i) not in constant_ids:
constant_ids[id(i)] = (i.signature(), topological_pos, i_idx) isig = (i.signature(), topological_pos, i_idx)
isig = constant_ids[id(i)] try:
hash(isig)
except: #generic constants don't have a hashable signature
error_on_play[0] = True
return None
constant_ids[id(i)] = isig
else:
isig = constant_ids[id(i)]
#print 'SIGNATURE', i.signature() #print 'SIGNATURE', i.signature()
#return i.signature() #return i.signature()
elif i in env_inputs_dict: #inputs elif i in env_inputs_dict: #inputs
...@@ -903,6 +911,12 @@ class CLinker(link.Linker): ...@@ -903,6 +911,12 @@ class CLinker(link.Linker):
for ipos,i in enumerate(node.inputs)), for ipos,i in enumerate(node.inputs)),
tuple(o in no_recycling for o in node.outputs))) tuple(o in no_recycling for o in node.outputs)))
if error_on_play[0]:
# if one of the signatures is not hashable
# then bypass the cache mechanism and
# compile fresh every time
return None
op_pos[node] = node_pos op_pos[node] = node_pos
env_computed_set.update(node.outputs) env_computed_set.update(node.outputs)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论