Skip to content

Commit

Permalink
Merge branch 'master' into gabor/parentheticals
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreif authored Jan 23, 2025
2 parents f1e37a1 + 5f39141 commit ccff46a
Show file tree
Hide file tree
Showing 50 changed files with 492 additions and 131 deletions.
24 changes: 19 additions & 5 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Motoko compiler changelog

## 0.13.6 (2025-01-21)

* motoko (`moc`)

* Support the low Wasm memory hook: `system func lowmemory() : async* () { ... }` (#4849).

* Breaking change (minor) (#4854):

* For enhanced orthogonal persistence: The Wasm persistence modes used internally for canister upgrades have been changed to lower case names,
`keep` and `replace` and instead of `Keep` and `Replace`:

If using actor class instances with enhanced orthogonal persistence, you would need to recompile the program and upgrade with latest `moc` and `dfx`.
Otherwise, no action is needed.

* bugfix: Checks and mitigations that timer servicing works (#4846).

* bugfix: Some valid upgrades deleting a stable variable could fail the `--enhanced-orthogonal-persistence` stable compatibility check due to a bug (#4855).

## 0.13.5 (2024-12-06)

* motoko (`moc`)

* Breaking change (minor):
* Breaking change (minor) (#4786):

* Add new keyword `transient` with exactly the same meaning as the old keyword `flexible` (but a more familiar reading).

Expand All @@ -14,10 +32,8 @@
`let` or `var` declaration is `stable` (not `flexible` or `transient`).

For example, a stateful counter can now be declared as:

``` motoko
persistent actor {
// counts increments since last upgrade
transient var invocations = 0;
Expand All @@ -28,10 +44,8 @@
value += 1;
invocations += 1;
}
}
```
On upgrade, the transient variable `invocations` will be reset to `0` and `value`, now implicitly `stable`, will retain its current value.
Legacy actors and classes declared without the `persistent` keyword have the same semantics as before.
Expand Down
5 changes: 3 additions & 2 deletions doc/md/base/Debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ func print(text : Text)

Prints `text` to output stream.

NOTE: The output is placed in the replica log. When running on mainnet,
this function has no effect.
NOTE: When running on an ICP network, all output is written to the [canister log](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/logs) with the exclusion of any output
produced during the execution of non-replicated queries and composite queries.
In other environments, like the interpreter and stand-alone wasm engines, the output is written to standard out.

```motoko include=import
Debug.print "Hello New World!";
Expand Down
10 changes: 10 additions & 0 deletions doc/md/base/ExperimentalInternetComputer.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ let c1 = IC.performanceCounter(1);
work();
let diff : Nat64 = IC.performanceCounter(1) - c1;
```

## Function `replyDeadline`
``` motoko no-repl
func replyDeadline() : Nat
```

Returns the time (in nanoseconds from the epoch start) by when the update message should
reply to the best effort message so that it can be received by the requesting canister.
Queries and non-best-effort update messages return zero.

2 changes: 1 addition & 1 deletion doc/md/base/OrderedMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Credits:
The core of this implementation is derived from:

* Ken Friis Larsen's [RedBlackMap.sml](https://github.com/kfl/mosml/blob/master/src/mosmllib/Redblackmap.sml), which itself is based on:
* Stefan Kahrs, "Red-black trees with types", Journal of Functional Programming, 11(4): 425-432 (2001), [version 1 in web appendix](https://www.cs.ukc.ac.uk/people/staff/smk/redblack/rb.html).
* Stefan Kahrs, "Red-black trees with types", Journal of Functional Programming, 11(4): 425-432 (2001), [version 1 in web appendix](http://www.cs.ukc.ac.uk/people/staff/smk/redblack/rb.html).

## Type `Map`
``` motoko no-repl
Expand Down
2 changes: 1 addition & 1 deletion doc/md/base/OrderedSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Credits:
The core of this implementation is derived from:

* Ken Friis Larsen's [RedBlackMap.sml](https://github.com/kfl/mosml/blob/master/src/mosmllib/Redblackmap.sml), which itself is based on:
* Stefan Kahrs, "Red-black trees with types", Journal of Functional Programming, 11(4): 425-432 (2001), [version 1 in web appendix](https://www.cs.ukc.ac.uk/people/staff/smk/redblack/rb.html).
* Stefan Kahrs, "Red-black trees with types", Journal of Functional Programming, 11(4): 425-432 (2001), [version 1 in web appendix](http://www.cs.ukc.ac.uk/people/staff/smk/redblack/rb.html).

## Type `Set`
``` motoko no-repl
Expand Down
2 changes: 1 addition & 1 deletion doc/md/base/RBTree.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Credits:
The core of this implementation is derived from:

* Ken Friis Larsen's [RedBlackMap.sml](https://github.com/kfl/mosml/blob/master/src/mosmllib/Redblackmap.sml), which itself is based on:
* Stefan Kahrs, "Red-black trees with types", Journal of Functional Programming, 11(4): 425-432 (2001), [version 1 in web appendix](https://www.cs.ukc.ac.uk/people/staff/smk/redblack/rb.html).
* Stefan Kahrs, "Red-black trees with types", Journal of Functional Programming, 11(4): 425-432 (2001), [version 1 in web appendix](http://www.cs.ukc.ac.uk/people/staff/smk/redblack/rb.html).

## Type `Color`
``` motoko no-repl
Expand Down
58 changes: 58 additions & 0 deletions doc/md/base/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ Converts the given `Char` to a `Text` value.
let text = Text.fromChar('A'); // "A"
```

## Function `fromArray`
``` motoko no-repl
func fromArray(a : [Char]) : Text
```

Converts the given `[Char]` to a `Text` value.

```motoko include=import
let text = Text.fromArray(['A', 'v', 'o', 'c', 'a', 'd', 'o']); // "Avocado"
```

Runtime: O(a.size())
Space: O(a.size())

## Function `fromVarArray`
``` motoko no-repl
func fromVarArray(a : [var Char]) : Text
```

Converts the given `[var Char]` to a `Text` value.

```motoko include=import
let text = Text.fromVarArray([var 'E', 'g', 'g', 'p', 'l', 'a', 'n', 't']); // "Eggplant"
```

Runtime: O(a.size())
Space: O(a.size())

## Function `toIter`
``` motoko no-repl
func toIter(t : Text) : Iter.Iter<Char>
Expand Down Expand Up @@ -105,6 +133,36 @@ Creates a `Text` value from a `Char` iterator.
let text = Text.fromIter(['a', 'b', 'c'].vals()); // "abc"
```

## Function `fromList`
``` motoko no-repl
func fromList(cs : List.List<Char>) : Text
```

Create a text from a character list.
Example:
```motoko include=initialize
fromList(?('H', ?('e', ?('l', ?('l', ?('o', null))))));
// => "Hello"
```

Runtime: O(size cs)
Space: O(size cs)

## Function `toList`
``` motoko no-repl
func toList(t : Text) : List.List<Char>
```

Create a character list from a text.
Example:
```motoko include=initialize
toList("Hello");
// => ?('H', ?('e', ?('l', ?('l', ?('o', null)))))
```

Runtime: O(t.size())
Space: O(t.size())

## Function `size`
``` motoko no-repl
func size(t : Text) : Nat
Expand Down
26 changes: 26 additions & 0 deletions doc/md/canister-maintenance/memory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
sidebar_position: 5
---

# Memory diagnostics

## Low memory hook

The IC allows to implement a low memory hook, which is a warning trigger when main memory is becoming scarce.

For this purpose, a Motoko actor or actor class instance can implement the system function `lowmemory()`. This system function is scheduled when canister's free main memory space has fallen below the defined threshold `wasm_memory_threshold`, that is is part of the canister settings. In Motoko, `lowmemory()` implements the `canister_on_low_wasm_memory` hook defined in the IC specification.

Example of using the low memory hook:
```
actor {
system func lowmemory() : async* () {
Debug.print("Low memory!");
}
}
```

The following properties apply to the low memory hook:
* The execution of `lowmemory` happens with a certain delay, as it is scheduled as a separate asynchronous message that runs after the message in which the threshold was crossed.
* Once executed, `lowmemory` is only triggered again when the main memory free space first exceeds and then falls below the threshold.
* Traps or unhandled errors in `lowmemory` are ignored. Traps only revert the changes done in `lowmemory`.
* Due to its `async*` return type, the `lowmemory` function may send further messages and `await` results.
10 changes: 5 additions & 5 deletions doc/md/getting-started/dev-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ Here are some starter projects for online Motoko canister development:
* [ICP Hello World Motoko](https://github.com/dfinity/icp-hello-world-motoko#readme)
* [Vite + React + Motoko](https://github.com/rvanasa/vite-react-motoko#readme)

Learn more about [Gitpod](/docs/current/developer-docs/developer-tools/ide/gitpod) and [GitHub Codespaces](/docs/current/developer-docs/developer-tools/ide/codespaces) for Motoko development.
Learn more about [Gitpod](https://internetcomputer.org/docs/current/developer-docs/developer-tools/ide/gitpod) and [GitHub Codespaces](https://internetcomputer.org/docs/current/developer-docs/developer-tools/ide/codespaces) for Motoko development.

## Container environments

Developers may want to setup a containerized environment for Motoko and other ICP-related development. Container environments are especially useful for Windows-based systems, since `dfx` is not natively supported on Windows.

Learn more about [developer containers](/docs/current/developer-docs/developer-tools/ide/dev-containers) and [Docker containers](/docs/current/developer-docs/developer-tools/ide/dev-containers#using-docker-directly) for Motoko development.
Learn more about [developer containers](https://internetcomputer.org/docs/current/developer-docs/developer-tools/ide/dev-containers) and [Docker containers](https://internetcomputer.org/docs/current/developer-docs/developer-tools/ide/dev-containers#using-docker-directly) for Motoko development.

## Motoko playground

[Motoko playground](https://play.motoko.org/) is a browser-based developer environment that allows for temporary deployment and testing of canister smart contracts. Motoko playground can also be utilized through the `dfx deploy --playground` command via the CLI.

Canisters deployed to the Motoko playground use borrowed resources from a canister pool and are limited to a deployment length of 20 minutes. Therefore, the playground is not recommended for long-term development.

Learn more about the [Motoko playground](/docs/current/developer-docs/developer-tools/ide/playground).
Learn more about the [Motoko playground](https://internetcomputer.org/docs/current/developer-docs/developer-tools/ide/playground).

## Local developer environment

Expand All @@ -44,7 +44,7 @@ Before you start developing Motoko, verify the following:

- [x] You have a command line interface (CLI) window open. This window is also referred to as the 'terminal' window.

- [x] You have downloaded and installed the IC SDK package as described in the [installing the IC SDK](/docs/current/developer-docs/getting-started/install) page.
- [x] You have downloaded and installed the IC SDK package as described in the [installing the IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install) page.

- [x] You have a code editor installed. The [VS Code IDE](https://code.visualstudio.com/download) (with the [Motoko extension](https://marketplace.visualstudio.com/items?itemName=dfinity-foundation.vscode-motoko)) is a popular choice.

Expand Down Expand Up @@ -116,7 +116,7 @@ mops add [email protected]

### Specifying a custom version of `dfx`

To specify a custom version of `dfx`, you can use the [`dfxvm` tool](/docs/current/developer-docs/developer-tools/cli-tools/dfxvm/docs/cli-reference/dfxvm/dfxvm-default). To set a default `dfx` version to be used in your project, run the command:
To specify a custom version of `dfx`, you can use the [`dfxvm` tool](https://internetcomputer.org/docs/current/developer-docs/developer-tools/cli-tools/dfxvm/docs/cli-reference/dfxvm/dfxvm-default). To set a default `dfx` version to be used in your project, run the command:

```
$ dfxvm default 0.7.2
Expand Down
15 changes: 2 additions & 13 deletions nix/drun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pkgs:
outputHashes = {
"build-info-0.0.27" = "sha256-SkwWwDNrTsntkNiCv6rsyTFGazhpRDnKtVzPpYLKF9U=";
"cloudflare-0.12.0" = "sha256-FxCAK7gUKp/63fdvzI5Ufsy4aur74fO4R/K3YFiUw0Y=";
"ic-bn-lib-0.1.0" = "sha256-wqWfF70B+YQWg63yiEvIxOq+LN1AasrNXcyPkDM4/jw=";
"ic-canister-sig-creation-1.1.0" = "sha256-c47Fh4kZbmezWCYVHMci2BMXJfESaOGsyNlWh8YR6oU=";
"icrc1-test-env-0.1.1" = "sha256-2PB7e64Owin/Eji3k8UoeWs+pfDfOOTaAyXjvjOZ/4g=";
"jsonrpc-0.12.1" = "sha256-3FtdZlt2PqVDkE5iKWYIp1eiIELsaYlUPRSP2Xp8ejM=";
"lmdb-rkv-0.14.99" = "sha256-5WcUzapkrc/s3wCBNCuUDhtbp17n67rTbm2rx0qtITg=";
Expand All @@ -42,19 +44,6 @@ pkgs:
EOF
cd -
# static linking of libunwind fails under nix Linux
patch rs/monitoring/backtrace/build.rs << EOF
@@ -1,8 +1,2 @@
fn main() {
- if std::env::var("TARGET").unwrap() == "x86_64-unknown-linux-gnu" {
- println!("cargo:rustc-link-lib=static=unwind");
- println!("cargo:rustc-link-lib=static=unwind-ptrace");
- println!("cargo:rustc-link-lib=static=unwind-x86_64");
- println!("cargo:rustc-link-lib=dylib=lzma");
- }
}
EOF
mkdir -p .cargo
cat > .cargo/config.toml << EOF
[target.x86_64-apple-darwin]
Expand Down
20 changes: 10 additions & 10 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"homepage": "",
"owner": "dfinity",
"repo": "candid",
"rev": "87f42eefb1070381565d8de3235628a674641fbd",
"sha256": "1kfchlrfwk5b6ahhkkrkf9iby9znjri4jcjwbm3kwiqx8g9v97dp",
"rev": "f7269bc25acf1691411ff91840efe0247ddf6d53",
"sha256": "1bs5jbljjwr9g8qz6crfr5iicmlrary28lhkziqcm1cxz15kb6r4",
"type": "tarball",
"url": "https://github.com/dfinity/candid/archive/87f42eefb1070381565d8de3235628a674641fbd.tar.gz",
"url": "https://github.com/dfinity/candid/archive/f7269bc25acf1691411ff91840efe0247ddf6d53.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"esm": {
Expand All @@ -21,15 +21,15 @@
"version": "3.2.25"
},
"ic": {
"branch": "luc/adjust-drun",
"branch": "luc/latest-drun",
"description": "Internet Computer blockchain source: the client/replica software run by nodes",
"homepage": "",
"owner": "luc-blaeser",
"repo": "ic",
"rev": "bebe89514a6abd26e940b295323823169911a965",
"sha256": "1g68fyi5acbcgs2kjribk97fj8ki5g6pd99nwl5azz1rw1b0xycx",
"rev": "01c8dfda47126bb5f688302e0161f17c2c0cfe6f",
"sha256": "16h037xagxwf00k13y3h0gvfs7f3c45z2ml0j1pgvzg2fx5pzahy",
"type": "tarball",
"url": "https://github.com/luc-blaeser/ic/archive/bebe89514a6abd26e940b295323823169911a965.tar.gz",
"url": "https://github.com/luc-blaeser/ic/archive/01c8dfda47126bb5f688302e0161f17c2c0cfe6f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"ic-hs": {
Expand Down Expand Up @@ -75,10 +75,10 @@
"homepage": "",
"owner": "dfinity",
"repo": "motoko-base",
"rev": "bf3b522b3e2dab992c9d2544cb438e10ef2fac1a",
"sha256": "0pyqwv7af6ccd3imwbnww64959k56vl8r9dsr2g25spmnfsnrl7a",
"rev": "243dc5efc38a183eb3c5615427ab349e7d79d46e",
"sha256": "000vzsfpp24ircvzav3i3sry9vj19373hnx3sab4iqkfbw5acvh7",
"type": "tarball",
"url": "https://github.com/dfinity/motoko-base/archive/bf3b522b3e2dab992c9d2544cb438e10ef2fac1a.tar.gz",
"url": "https://github.com/dfinity/motoko-base/archive/243dc5efc38a183eb3c5615427ab349e7d79d46e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"motoko-matchers": {
Expand Down
Loading

0 comments on commit ccff46a

Please sign in to comment.