Compatibility with FunC
Tact itself compiles to FunC and maps all its entities directly to various FunC and TL-B types.
Convert types
Primitive types in Tact are directly mapped to FunC ones.
All rules about copying variables are the same. One of the big differences is that there are no visible mutation operators in Tact and most Slice
operations mutate variables in place.
Convert serialization
Serialization of Structs and Messages in Tact is automatic, unlike FunC where you need to define serialization logic manually.
Tact’s auto-layout algorithm is greedy. This means that it takes the next variable, calculates its size, and tries to fit it into a current cell. If it doesn’t fit, it creates a new cell and continues. All inner structs for auto-layout are flattened before allocation.
All optional types are serialized as Maybe
in TL-B, except for Address
.
There is no support for Either
since it does not define what to pick during serialization in some cases.
Examples
Convert received messages to op
operations
Tact generates a unique op
for every received typed message, but it can be overwritten.
The following code in FunC:
Becomes this in Tact:
Convert get
-methods
You can express everything except list-style-lists
in Tact that would be compatible with FunC’s get
-methods.
Primitive return type
If a get
-method returns a primitive in FunC, you can implement it the same way in Tact.
The following code in FunC:
Becomes this in Tact:
Tensor return types
In FunC there is a difference between tensor type (int, int)
and (int, (int))
, but for TVM there are no differences, they all represent a stack of two integers.
To convert the tensor that returned from a FunC get
-method, you need to define a Struct that has the same field types as the tensor and in the same order.
The following code in FunC:
Becomes this in Tact:
Tuple return type
In FunC if you are returning a tuple, instead of a tensor you need to follow the process for a tensor type, but define the return type of a get
-method as optional.
The following code in FunC:
Becomes this in Tact:
Mixed tuple and tensor return types
When some of the tensors are a tuple, you need to define a struct as in previous steps and the tuple one must be defined as a separate Struct.
The following code in FunC:
Becomes this in Tact:
Arguments mapping
Conversion of get
-methods arguments is straightforward. Each argument is mapped as-is to FunC one, and each tuple is mapped to a Struct.
The following code in FunC:
Becomes this in Tact: