weld-project / weld

High-performance runtime for data analytics applications
https://www.weld.rs
BSD 3-Clause "New" or "Revised" License
2.99k stars 259 forks source link

Add support for Type name aliasing #431

Closed sppalkia closed 5 years ago

sppalkia commented 5 years ago

Adds support for aliases for types ("typename aliases"). Aliases must currently be listed before macros before the expression representing the Weld program:

type int = i32;
type pair = {i32,i32};

# Define macros here.

|v: int, p: pair| v + p.$0 + p.$1

Typename aliases can be used within other typename aliases (as long as they are defined before):

type int = i32;
type pair = {int,int};

|v: int, p: pair| v + p.$0 + p.$1

Macros can also use typename aliases:

type int = i32;

macro addOne(a) = (
  cudf[addOneUdf,int](a)
);

# Expands to |v: i64| cudf[addOneUdf,i64](v)
|v: int| addOne(v)

Currently, typename aliases are treated similarly to macros: when a program is compiled, type typenames are replaced with their true types, and the naming information is lost. This means that dumping code, logging messages, etc. will currently show the actual type rather than the typename. We hope to propagate type name information through the compiler soon.

pratiksha commented 5 years ago

lgtm!