Skip to content

[RFC] Relay IR Text Format #1782

@joshpoll

Description

@joshpoll

Keyword Proposal

The final keywords are:

  • def for global function definitions
  • fn for local function definitions/anonymous functions
  • if and else for if-else expressions
  • let for let bindings
  • True and False for booleans
  • data types are tvm-style. e.g. float32x4

Loose Ends

There are some elements of the text format that didn't make it into this PR. See #1935 for details.


Please comment on syntax design choices for #1781 here!

Notable Syntax Examples

Functions

Named, Typed

def @foo(%x: int64, %y: int64) -> int64 {
    %x + %y
}

Named, Inferred

def @foo(%x, %y) {
    %x + %y
}

Anonymous, Typed

fn (%x: int64, %y: int64) -> int64 {
    %x + %y
}

Anonymous, Inferred

fn (%x, %y) {
    %x + %y
}

Let Expressions and Mutation

Immutable

let %x = 2;
let %x = 3;
let %y = 4;
%x + %y

Side Effects Only

The following are equivalent

print("hello");
1
let %_ = print("hello");
1

Tuples

()
(0,)
(0, 1)

Types

Base Types

Designed to look like NumPy types.

int32
uint32
float32
bool
int32x4
...

Shape Types

unimplemented

s
(n + 1, 2 * n, 4)

Tensor Annotations

generics unimplemented

def @add(t1: Tensor[s, bt], t2: Tensor[s, bt]) -> Tensor[s,  bt] {
    ...
}

Function Types

fn (int32, int32) -> int32

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions