@@ -232,22 +232,44 @@ def _quote_embedded_function(self, function):
232
232
quote_function = self ._quote_function )
233
233
return asttyped_rewriter .visit (function_node )
234
234
235
- def _function_def_note (self , function ):
235
+ def _function_loc (self , function ):
236
236
filename = function .__code__ .co_filename
237
237
line = function .__code__ .co_firstlineno
238
238
name = function .__code__ .co_name
239
239
240
240
source_line = linecache .getline (filename , line )
241
241
column = re .search ("def" , source_line ).start (0 )
242
242
source_buffer = source .Buffer (source_line , filename , line )
243
- loc = source .Range (source_buffer , column , column )
243
+ return source .Range (source_buffer , column , column )
244
+
245
+ def _function_def_note (self , function ):
244
246
return diagnostic .Diagnostic ("note" ,
245
247
"definition of function '{function}'" ,
246
- {"function" : name },
247
- loc )
248
+ {"function" : function .__name__ },
249
+ self ._function_loc (function ))
250
+
251
+ def _extract_annot (self , function , annot , kind , call_loc ):
252
+ if not isinstance (annot , types .Type ):
253
+ note = diagnostic .Diagnostic ("note" ,
254
+ "in function called remotely here" , {},
255
+ call_loc )
256
+ diag = diagnostic .Diagnostic ("error" ,
257
+ "type annotation for {kind}, '{annot}', is not an ARTIQ type" ,
258
+ {"kind" : kind , "annot" : repr (annot )},
259
+ self ._function_loc (function ),
260
+ notes = [note ])
261
+ self .engine .process (diag )
262
+
263
+ return types .TVar ()
264
+ else :
265
+ return annot
248
266
249
267
def _type_of_param (self , function , loc , param ):
250
- if param .default is not inspect .Parameter .empty :
268
+ if param .annotation is not inspect .Parameter .empty :
269
+ # Type specified explicitly.
270
+ return self ._extract_annot (function , param .annotation ,
271
+ "argument {}" .format (param .name ), loc )
272
+ elif param .default is not inspect .Parameter .empty :
251
273
# Try and infer the type from the default value.
252
274
# This is tricky, because the default value might not have
253
275
# a well-defined type in APython.
@@ -300,8 +322,14 @@ def _quote_rpc_function(self, function, loc):
300
322
else :
301
323
optarg_types [param .name ] = self ._type_of_param (function , loc , param )
302
324
303
- # Fixed for now.
304
- ret_type = builtins .TInt (types .TValue (32 ))
325
+ if signature .return_annotation is not inspect .Signature .empty :
326
+ ret_type = self ._extract_annot (function , signature .return_annotation ,
327
+ "return type" , loc )
328
+ else :
329
+ diag = diagnostic .Diagnostic ("fatal" ,
330
+ "function must have a return type specified to be called remotely" , {},
331
+ self ._function_loc (function ))
332
+ self .engine .process (diag )
305
333
306
334
rpc_type = types .TRPCFunction (arg_types , optarg_types , ret_type ,
307
335
service = self ._map (function ))
0 commit comments