FunctionType

The signature of a procedure.

Declaration

Syntax

FunctionType(ttype* arg_types, ttype? return_var_type, abi abi,
    deftype deftype, string? bindc_name, bool elemental, bool pure,
    bool module, bool inline, bool static, symbol* restrictions,
    bool is_restriction, exec_space exec_space)

Arguments

Argument

Description

arg_types

the types of the dummy arguments, in order.

return_var_type

the type of the result, or nil for a subroutine.

abi

the ABI of the procedure; see the ABI section of the ASR overview.

deftype

Implementation when the body is present, Interface when only the signature is, ImplicitInterface when neither is known; see deftype.

bindc_name

the linker name given by bind(c, name=...).

elemental

true for an elemental procedure, which applies to each element of an array argument.

pure

true for a pure procedure.

module

true for a module procedure whose interface is declared in a module and whose body is in a submodule.

inline

true when the procedure is marked for inlining.

static

true when the procedure's local variables are allocated statically rather than on the stack.

restrictions

for a procedure of a generic Template, the operations its type parameters must provide.

is_restriction

true when this signature is itself one of those required operations rather than a procedure with an implementation.

exec_space

where the procedure runs; see exec_space.

Return values

None. A type is not evaluated.

Description

Everything about a procedure other than its body and its symbols lives here, so a call site can be checked against the signature without looking at the procedure's symbol table.

exec_space mirrors the execution space qualifiers of CUDA. Host is the default and runs on the CPU. Device runs on the GPU only, and HostDevice is compiled for both, which is what a routine reachable from the host and from a kernel alike becomes. Kernel is the entry point of a GPU kernel, the counterpart of __global__: it runs on the device and the host launches it with a GpuKernelLaunch. The device_partition pass takes the closure of the call graph from the kernels and gives every routine it reaches the space it belongs in.

A subroutine is a signature with no return_var_type. deftype says whether there is a body: an interface, and a procedure loaded from a module file as interface ASR, are Interface. An empty arg_types means the procedure takes no arguments, except under deftype = ImplicitInterface, where it means the arguments are not known here.

Examples

(FunctionType
  :arg_types [
    (Integer
      :kind 4
    )
    (Integer
      :kind 4
    )
  ]
  :return_var_type (Integer
    :kind 4
  )
  :abi :Source
  :deftype :Implementation
  :bindc_name nil
  :elemental false
  :pure false
  :module false
  :inline false
  :static false
  :restrictions []
  :is_restriction false
  :exec_space :Host
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "m" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "add" (Function
              :symtab (SymbolTable
                :id 2
                :symbols {
                  "a" (Variable
                    :parent_symtab 2
                    :name "a"
                    :dependencies []
                    :intent :In
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Integer
                      :kind 4
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                  )
                  "b" (Variable
                    :parent_symtab 2
                    :name "b"
                    :dependencies []
                    :intent :In
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Integer
                      :kind 4
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                  )
                  "c" (Variable
                    :parent_symtab 2
                    :name "c"
                    :dependencies []
                    :intent :ReturnVar
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Integer
                      :kind 4
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                  )
                }
              )
              :name "add"
              :function_signature (FunctionType
                :arg_types [
                  (Integer
                    :kind 4
                  )
                  (Integer
                    :kind 4
                  )
                ]
                :return_var_type (Integer
                  :kind 4
                )
                :abi :Source
                :deftype :Implementation
                :bindc_name nil
                :elemental false
                :pure false
                :module false
                :inline false
                :static false
                :restrictions []
                :is_restriction false
                :exec_space :Host
              )
              :dependencies []
              :args [
                (Var
                  :v (SymbolRef 2 "a")
                )
                (Var
                  :v (SymbolRef 2 "b")
                )
              ]
              :body [
                (Assignment
                  :target (Var
                    :v (SymbolRef 2 "c")
                  )
                  :value (IntegerBinOp
                    :left (Var
                      :v (SymbolRef 2 "a")
                    )
                    :op :Add
                    :right (Var
                      :v (SymbolRef 2 "b")
                    )
                    :type (Integer
                      :kind 4
                    )
                    :value nil
                  )
                  :overloaded nil
                  :realloc_lhs false
                  :move_allocation false
                )
              ]
              :return_var (Var
                :v (SymbolRef 2 "c")
              )
              :access :Public
              :deterministic false
              :side_effect_free false
              :module_file nil
            )
          }
        )
        :name "m"
        :parent_module nil
        :dependencies []
        :loaded_from_mod false
        :intrinsic false
        :has_submodules false
      )
      "main" (Program
        :symtab (SymbolTable
          :id 3
          :symbols {}
        )
        :name "main"
        :dependencies []
        :body []
      )
    }
  )
  :items []
)

See Also

Function, FunctionCall, deftype, abi, exec_space, FunctionParam