Skip to content

Commit

Permalink
compiler: don't crash when quoting builtin functions.
Browse files Browse the repository at this point in the history
Fixes #1051.
  • Loading branch information
whitequark committed Jun 5, 2018
1 parent c28fe47 commit 38dac16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,8 @@ def _quote_attributes():
lleltsptr = llglobal.bitcast(lleltsary.type.element.as_pointer())
llconst = ll.Constant(llty, [lleltsptr, ll.Constant(lli32, len(llelts))])
return llconst
elif types.is_rpc(typ) or types.is_c_function(typ):
# RPC and C functions have no runtime representation.
elif types.is_rpc(typ) or types.is_c_function(typ) or types.is_builtin_function(typ):
# RPC, C and builtin functions have no runtime representation.
return ll.Constant(llty, ll.Undefined)
elif types.is_function(typ):
try:
Expand Down
8 changes: 8 additions & 0 deletions artiq/compiler/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,14 @@ def is_builtin(typ, name=None):
return isinstance(typ, TBuiltin) and \
typ.name == name

def is_builtin_function(typ, name=None):
typ = typ.find()
if name is None:
return isinstance(typ, TBuiltinFunction)
else:
return isinstance(typ, TBuiltinFunction) and \
typ.name == name

def is_constructor(typ, name=None):
typ = typ.find()
if name is not None:
Expand Down
5 changes: 5 additions & 0 deletions artiq/test/coredevice/test_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def numpy_things(self):
def numpy_full(self):
return numpy.full(10, 20)

@kernel
def numpy_nan(self):
return numpy.full(10, numpy.nan)

@kernel
def builtin(self):
sleep(1.0)
Expand All @@ -229,6 +233,7 @@ def test_args(self):
self.assertEqual(exp.numpy_things(),
(numpy.int32(10), numpy.int64(20), numpy.array([42,])))
self.assertTrue((exp.numpy_full() == numpy.full(10, 20)).all())
self.assertTrue(numpy.isnan(exp.numpy_nan()).all())
exp.builtin()


Expand Down

0 comments on commit 38dac16

Please sign in to comment.