Releases: dfinity/motoko
0.16.1
- motoko (
moc
)-
bugfix: fix compile-time exception showing
???
type when using 'improved type inference' (#5423). -
Allow inference of invariant type parameters, but only when the bound/solution is an 'isolated' type (meaning it has no proper subtypes nor supertypes other than
Any
/None
) (#5359).
This addresses the limitation mentioned in #5180.
Examples of isolated types include all primitive types exceptNat
andInt
, such asBool
,Text
,Blob
,Float
,Char
,Int32
, etc.
Nat
andInt
are not isolated becauseNat
is a subtype ofInt
(Nat <: Int
).For example, the following code now works without explicit type arguments:
import VarArray "mo:core/VarArray"; let varAr = [var 1, 2, 3]; let result = VarArray.map(varAr, func x = debug_show (x) # "!"); // [var Text]
-
ignore
now warns when its argument has typeasync*
, as it will have no effect (#5419). -
bugfix: fix rare compiler crash when using a label and identifier of the same name in the same scope (#5283, #5412).
-
bugfix:
moc
now warns about parentheticals onasync*
calls, and makes sure that they get discarded (#5415).
-
0.16.0
-
motoko (
moc
)-
Breaking change: add new type constructor
weak T
for constructing weak references.Prim.allocWeakRef: <T>(value : T) -> weak T Prim.weakGet: <T>weak T -> ?(value : T) Prim.isLive: weak Any -> Bool
A weak reference can only be allocated from a value whose type representation is always a heap reference;
allowWeakRef
will trap on values of other types.
A weak reference does not count as a reference to its value and allows the collector to collect the value once no other references to it remain.
weakGet
will returnnull
, andisLive
will return false once the value of the reference has been collected by the garbage collector.
The type constructorweak T
is covariant.Weak reference operations are only supported with --enhanced-orthogonal-persistence and cannot be used with the classic compiler.
-
bugfix: the EOP dynamic stable compatibility check incorrectly rejected upgrades from
Null
to?T
(#5404). -
More explanatory upgrade error messages with detailing of cause (#5391).
-
Improved type inference for calling generic functions (#5180).
This means that type arguments can be omitted when calling generic functions in most common cases.
For example:let ar = [1, 2, 3]; Array.map(ar, func x = x * 2); // Needs no explicit type arguments anymore!
Previously, type arguments were usually required when there was an anonymous not annotated function in arguments.
The reason being that the type inference algorithm cannot infer the type offunc
s in general,
e.g.func x = x * 2
cannot be inferred without knowing the type ofx
.Now, the improved type inference can handle such
func
s when there is enough type information from other arguments.
It works by splitting the type inference into two phases:- In the first phase, it infers part of the instantiation from the non-
func
arguments.
The goal is to infer all parameters of thefunc
arguments, e.g.x
in the example above.
Thear
argument in the example above is used to infer the partial instantiationArray.map<Nat, O>
, leaving the second type argumentO
to be inferred in the second phase.
With this partial instantiation, it knows thatx : Nat
. - In the second phase, it completes the instantiation by inferring the bodies of the
func
arguments; assuming that all parameters were inferred in the first phase.
In the example above, it knows thatx : Nat
, so inferring the bodyx * 2
will infer the typeO
to beNat
.
With this, the full instantiationArray.map<Nat, Nat>
is inferred, and the type arguments can be omitted.
Limitations:
-
Invariant type parameters must be explicitly provided in most cases.
e.g.VarArray.map
must have the return type annotation:let result = VarArray.map<Nat, Nat>(varAr, func x = x * 2);
Or the type of the result must be explicitly provided:
let result : [var Nat] = VarArray.map(varAr, func x = x * 2);
-
When there is not enough type information from the non-
func
arguments, the type inference will not be able to infer thefunc
arguments.
However this is not a problem in most cases.
- In the first phase, it infers part of the instantiation from the non-
-
0.15.1
-
motoko (
moc
)-
bugfix:
persistent
imported actor classes incorrectly rejected as non-persistent
(#5667). -
Allow matching type fields of modules and objects in patterns (#5056)
This allows importing a type from a module without requiring an indirection or extra binding.// What previously required indirection, ... import Result "mo:core/Result"; type MyResult<Ok> = Result.Result<Ok, Text>; // or rebinding, ... import Result "mo:core/Result"; type Result<Ok, Err> = Result.Result<Ok, Err>; type MyResult<Ok> = Result<Ok, Text>; // can now be written more concisely as: import { type Result } "mo:core/Result"; type MyResult<Ok> = Result<Ok, Text>;
-
0.15.0
-
motoko (
moc
)-
Breaking change: the
persistent
keyword is now required on actors and actor classes (#5320, #5298).
This is a transitional restriction to force users to declare transient declarations astransient
and actor/actor classes aspersistent
.
New error messages and warnings will iteratively guide you to inserttransient
andpersistent
as required, after which anystable
keywords can be removed. Use the force.In the near future, the
persistent
keyword will be made optional again, andlet
andvar
declarations within actor and actor classes will bestable
(by default) unless declaredtransient
, inverting the previous default for non-persistent
actors.
The goal of this song and dance is to always default actor declarations to stable unless declaredtransient
and make thepersistent
keyword redundant. -
Breaking change: enhanced orthogonal persistence is now the default compilation mode for
moc
(#5305).
Flag--enhanced-orthogonal-persistence
is on by default.
Users not willing or able to migrate their code can opt in to the behavior of moc prior to this release with the new flag--legacy-persistence
.
Flag--legacy-persistence
is required to select the legacy--copying-gc
(the previous default),--compacting-gc
, orgenerational-gc
.As a safeguard, to protect users from unwittingly, and irreversibly, upgrading from legacy to enhanced orthogonal persistence, such upgrades will fail unless the new code is compiled with flag
--enhanced-orthogonal-persistence
explicitly set.
New projects should not require the flag at all (#5308) and will simply adopt enhanced mode.To recap, enhanced orthogonal persistence implements scalable and efficient orthogonal persistence (stable variables) for Motoko:
- The Wasm main memory (heap) is retained on upgrade with new program versions directly picking up this state.
- The Wasm main memory has been extended to 64-bit to scale as large as stable memory in the future.
- The runtime system checks that data changes of new program versions are compatible with the old state.
Implications:
- Upgrades become extremely fast, only depending on the number of types, not on the number of heap objects.
- Upgrades will no longer hit the IC instruction limit, even for maximum heap usage.
- The change to 64-bit increases the memory demand on the heap, in worst case by a factor of two.
- For step-wise release handling, the IC initially only offers a limited capacity of the 64-bit space (e.g. 4GB or 6GB), that will be gradually increased in future to the capacity of stable memory.
- There is moderate performance regression of around 10% for normal execution due to combined related features (precise tagging, change to incremental GC, and handling of compile-time-known data).
- The garbage collector is fixed to incremental GC and cannot be chosen.
Float.format(#hex prec, x)
is no longer supported (expected to be very rarely used in practice).- The debug print format of
NaN
changes (originallynan
).
-
Fixed file indices in the DWARF encoding of the
debug_line
section. This change is only relevant when using the-g
flag (#5281). -
Improved large array behavior under the incremental GC (#5314)
-
0.14.14
0.14.13
-
motoko (
moc
)-
Introduce
await?
to synchronizeasync
futures, avoiding the commit point when already fulfilled (#5215). -
Adds a
Prim.Array_tabulateVar
function, that allows faster initialization of mutable arrays (#5256). -
optimization: accelerate IR type checking with caching of sub, lub and check_typ tests (#5260).
Reduces need for-no-check-ir
flag.
-
0.14.12
-
motoko (
moc
)- optimization: for
--enhanced-orthogonal-persistence
, reduce code-size and compile-time by sharing more static allocations (#5233, #5242). - bugfix: fix
-fshared-code
bug (#5230). - bugfix: avoid stack overflow and reduce code complexity for large eop canisters (#5218).
- Added the
rootKey
primitive (#4994).
- optimization: for