Skip to content

Commit

Permalink
Merge branch 'master' into claudio/sha224
Browse files Browse the repository at this point in the history
  • Loading branch information
crusso authored Feb 23, 2024
2 parents 1911318 + 200acb8 commit 0787ce8
Show file tree
Hide file tree
Showing 557 changed files with 1,990 additions and 3,163 deletions.
12 changes: 11 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Motoko compiler changelog


## Unreleased

* motoko (`moc`)

* Warn on detection of unused identifiers (code `M0194`) (#4377).

- By design, warnings are not emitted for code imported from a package.
- A warning can be suppressed by replacing the identifier entirely by a wildcard `_`,
or by prefixing it with an `_`, e.g. replace `x` by `_x`.

**Limitations**: recursive and mutually recursive definitions are considered used,
even if never referenced outside the recursive definition.

* Remove `__get_candid_interface_tmp_hack` endpoint. Candid interface is already stored as canister metadata, this temporary endpoint is redundant, thus removed. (#4386)

## 0.10.4 (2024-01-10)
Expand All @@ -12,7 +22,7 @@

* Officializing the new **incremental garbage collector** after a successful beta testing phase.
The incremental GC can be enabled by the `moc` flag `--incremental-gc` (#3837) and is designed to scale for large program heap sizes.

**Note**: While resolving scalability issues with regard to the instruction limit of the GC work, it is now possible to hit other scalability limits:
- _Out of memory_: A program can run out of memory if it fills the entire memory space with live objects.
- _Upgrade limits_: When using stable variables, the current mechanism of serialization and deserialization to and from stable memory can exceed the instruction limit or run out of memory.
Expand Down
4 changes: 2 additions & 2 deletions doc/md/language-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ If `<exp>` in `label <id> (: <typ>)? <exp>` is a looping construct:

the body, `<exp1>`, of the loop is implicitly enclosed in `label <id_continue> (…​)` allowing early continuation of the loop by the evaluation of expression `continue <id>`.

`<id_continue>` is fresh identifier that can only be referenced by `continue <id>` (through its implicit expansion to `break <id_continue>`).
`<id_continue>` is a fresh identifier that can only be referenced by `continue <id>` (through its implicit expansion to `break <id_continue>`).

### Break

Expand All @@ -2317,7 +2317,7 @@ The expression `break <id> <exp>` has type `None` provided:

- `<exp>` has type `T`.

The evaluation of `break <id> <exp>` evaluates exp to some result `r`. If `r` is `trap`, the result is `trap`. If `r` is a value `v`, the evaluation abandons the current computation up to dynamically enclosing declaration `label <id> …​` using the value `v` as the result of that labelled expression.
The evaluation of `break <id> <exp>` evaluates `<exp>` to some result `r`. If `r` is `trap`, the result is `trap`. If `r` is a value `v`, the evaluation abandons the current computation up to the dynamically enclosing declaration `label <id> …​` using the value `v` as the result of that labelled expression.

### Continue

Expand Down
6 changes: 3 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
"homepage": null,
"owner": "dfinity",
"repo": "motoko-base",
"rev": "b772c9e49d94e725fcca64fc1c891ec1fb1baab3",
"sha256": "1ci0nink9sqrx4317svaz0y22cargfvlqqsnzi9vylafh0a76yg5",
"rev": "712d0587b0c8d2958adf450bd2e1554f2b0ff258",
"sha256": "17ghrfgzwlz7hbapy4sq9wbckxqy4xmcj8jpqv68bng9s83zvvvn",
"type": "tarball",
"url": "https://github.com/dfinity/motoko-base/archive/b772c9e49d94e725fcca64fc1c891ec1fb1baab3.tar.gz",
"url": "https://github.com/dfinity/motoko-base/archive/712d0587b0c8d2958adf450bd2e1554f2b0ff258.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"motoko-matchers": {
Expand Down
2 changes: 1 addition & 1 deletion rts/cargo-vendor-tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cargo-vendor-tools"
version = "0.1.0"
authors = ["dfinity <sdk@dfinity.org>"]
authors = ["dfinity <team-motoko@dfinity.org>"]
edition = "2018"

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion rts/motoko-rts-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "motoko-rts-macros"
version = "0.1.0"
authors = ["dfinity <sdk@dfinity.org>"]
authors = ["dfinity <team-motoko@dfinity.org>"]
edition = "2018"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion rts/motoko-rts-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "motoko-rts-tests"
version = "0.1.0"
authors = ["dfinity <sdk@dfinity.org"]
authors = ["dfinity <team-motoko@dfinity.org"]
edition = "2018"

[features]
Expand Down
2 changes: 1 addition & 1 deletion rts/motoko-rts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "motoko-rts"
version = "0.1.0"
authors = ["dfinity <sdk@dfinity.org>"]
authors = ["dfinity <team-motoko@dfinity.org>"]
edition = "2018"

# For rlib use native/Cargo.toml
Expand Down
2 changes: 1 addition & 1 deletion rts/motoko-rts/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "motoko-rts"
version = "0.1.0"
authors = ["dfinity <sdk@dfinity.org>"]
authors = ["dfinity <team-motoko@dfinity.org>"]
edition = "2018"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion src/exes/candid_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let mo_of_test tenv test : (string * expected_behaviour, string) result =

try
let defs =
"import Prim \"mo:⛔\";" ^
"import _Prim \"mo:⛔\";" ^
String.concat "" (List.map (fun (n,candid_typ) ->
let mo_typ = Idl_to_mo.check_typ tenv candid_typ in
"type " ^ n ^ " = " ^ Pretty.string_of_typ mo_typ ^ ";\n"
Expand Down
1 change: 1 addition & 0 deletions src/lang_utils/error_codes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,5 @@ let error_codes : (string * string option) list =
"M0191", None; (* Code requires Wasm features ... to execute *)
"M0192", None; (* Object/Actor/Module body type mismatch *)
"M0193", None; (* Can't declare actor class to have `async*` result *)
"M0194", Some([%blob "lang_utils/error_codes/M0194.md"]); (* Unused identifier warning *)
]
31 changes: 31 additions & 0 deletions src/lang_utils/error_codes/M0194.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# M0194

This warning means that you defined an identifier without
referencing it later, a good indicator of dead code.

Dubious code example:

```motoko
let nickname = "klutz";
// code that never uses `nickname`
```

If you encounter this warning, you can either delete the definition (if the code has no other side-effect),

```motoko
// code that never uses `nickname`
```

replace it by a wildcard pattern:

```motoko
let _ = "klutz";
// code that never uses `nickname`
```

or just prefix the identifier with an underscore:

```motoko
let _nickname = "klutz";
// code that never uses `nickname`
```
9 changes: 5 additions & 4 deletions src/languageServer/declaration_index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,14 @@ let list_files_recursively dir =
in
loop [] [ dir ]

let scan_packages : unit -> string list =
let scan_packages : unit -> lib_path list =
fun _ ->
let scan_package path =
let scan_package p path =
list_files_recursively path
|> List.filter (fun f -> Filename.extension f = ".mo")
|> List.map (fun f -> { package = Some p; path = f })
in
Flags.M.fold (fun _ v acc -> scan_package v @ acc) !Flags.package_urls []
Flags.M.fold (fun p v acc -> scan_package p v @ acc) !Flags.package_urls []

let scan_actors : unit -> string list =
fun _ ->
Expand Down Expand Up @@ -347,7 +348,7 @@ let index_from_scope : string -> t -> Syntax.lib list -> Scope.t -> t =

let make_index_inner project_root vfs entry_points : t Diag.result =
let package_paths =
List.map (fun f -> LibPath f @@ Source.no_region) (scan_packages ())
List.map (fun lp -> LibPath lp @@ Source.no_region) (scan_packages ())
in
let package_env =
Pipeline.chase_imports
Expand Down
2 changes: 1 addition & 1 deletion src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ let transform_import (i : S.import) : import_declaration =
assert (t <> T.Pre);
let rhs = match !ir with
| S.Unresolved -> raise (Invalid_argument ("Unresolved import " ^ f))
| S.LibPath fp ->
| S.LibPath {path = fp; _} ->
varE (var (id_of_full_path fp) t)
| S.PrimPath ->
varE (var (id_of_full_path "@prim") t)
Expand Down
8 changes: 5 additions & 3 deletions src/mo_def/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ let empty_typ_note = {note_typ = Type.Pre; note_eff = Type.Triv}

(* Resolved imports (filled in separately after parsing) *)

type lib_path = {package : string option; path : string}
type resolved_import =
| Unresolved
| LibPath of string
| LibPath of lib_path
| IDLPath of (string * string) (* filepath * bytes *)
| PrimPath (* the built-in prim module *)

Expand Down Expand Up @@ -125,6 +126,7 @@ and vis' =
| System

let is_public vis = match vis.Source.it with Public _ -> true | _ -> false
let is_private vis = match vis.Source.it with Private -> true | _ -> false

type stab = stab' Source.phrase
and stab' = Stable | Flexible
Expand Down Expand Up @@ -296,8 +298,8 @@ open Source

(* Identifiers *)

let anon_id sort at = "anon-" ^ sort ^ "-" ^ string_of_pos at.left
let is_anon_id id = Lib.String.chop_prefix "anon-" id.it <> None
let anon_id sort at = "@anon-" ^ sort ^ "-" ^ string_of_pos at.left
let is_anon_id id = Lib.String.chop_prefix "@anon-" id.it <> None

(* Types & Scopes *)

Expand Down
Loading

0 comments on commit 0787ce8

Please sign in to comment.