Skip to content

Commit

Permalink
bugfix: fix tracking of current package in pipeline.ml (#4426)
Browse files Browse the repository at this point in the history
* to suppress unused identifiers in libs
* also, update base doc
  • Loading branch information
crusso authored Mar 5, 2024
1 parent f9a6715 commit 01efc2a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
14 changes: 8 additions & 6 deletions doc/md/base/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ sum // => 3

Runtime: O(size)

Space: O(1)
Space: O(size)

*Runtime and space assumes that `f` runs in O(1) time and space.

## Function `map`
``` motoko no-repl
Expand Down Expand Up @@ -219,6 +221,8 @@ Runtime: O(size)

Space: O(size)

*Runtime and space assumes that `f` runs in O(1) time and space.

## Function `mapFilter`
``` motoko no-repl
func mapFilter<T, U>(l : List<T>, f : T -> ?U) : List<U>
Expand All @@ -245,6 +249,8 @@ Runtime: O(size)

Space: O(size)

*Runtime and space assumes that `f` runs in O(1) time and space.

## Function `mapResult`
``` motoko no-repl
func mapResult<T, R, E>(xs : List<T>, f : T -> Result.Result<R, E>) : Result.Result<List<R>, E>
Expand Down Expand Up @@ -654,7 +660,7 @@ Runtime: O(min(size(xs), size(ys)))

Space: O(min(size(xs), size(ys)))

*Runtime and space assumes that `zip` runs in O(1) time and space.
*Runtime and space assumes that `f` runs in O(1) time and space.

## Function `split`
``` motoko no-repl
Expand All @@ -675,8 +681,6 @@ Runtime: O(n)

Space: O(n)

*Runtime and space assumes that `zip` runs in O(1) time and space.

## Function `chunks`
``` motoko no-repl
func chunks<T>(n : Nat, xs : List<T>) : List<List<T>>
Expand All @@ -703,8 +707,6 @@ Runtime: O(size)

Space: O(size)

*Runtime and space assumes that `zip` runs in O(1) time and space.

## Function `fromArray`
``` motoko no-repl
func fromArray<T>(xs : [T]) : List<T>
Expand Down
7 changes: 7 additions & 0 deletions doc/md/base/Option.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ func isNull(x : ?Any) : Bool

Returns true if the argument is `null`, otherwise returns false.

## Function `equal`
``` motoko no-repl
func equal<A>(x : ?A, y : ?A, eq : (A, A) -> Bool) : Bool
```

Returns true if the optional arguments are equal according to the equality function provided, otherwise returns false.

## Function `assertSome`
``` motoko no-repl
func assertSome(x : ?Any)
Expand Down
4 changes: 2 additions & 2 deletions doc/md/base/Trie.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ Build sequence of two sub-builds

### Function `prod`
``` motoko no-repl
func prod<K1, V1, K2, V2, K3, V3>(tl : Trie<K1, V1>, tr : Trie<K2, V2>, op : (K1, V1, K2, V2) -> ?(K3, V3), k3_eq : (K3, K3) -> Bool) : Build<K3, V3>
func prod<K1, V1, K2, V2, K3, V3>(tl : Trie<K1, V1>, tr : Trie<K2, V2>, op : (K1, V1, K2, V2) -> ?(K3, V3), _k3_eq : (K3, K3) -> Bool) : Build<K3, V3>
```

Like [`prod`](#prod), except do not actually do the put calls, just
Expand Down Expand Up @@ -920,7 +920,7 @@ new trie, and the prior value, if any.

## Function `mergeDisjoint2D`
``` motoko no-repl
func mergeDisjoint2D<K1, K2, V>(t : Trie2D<K1, K2, V>, k1_eq : (K1, K1) -> Bool, k2_eq : (K2, K2) -> Bool) : Trie<K2, V>
func mergeDisjoint2D<K1, K2, V>(t : Trie2D<K1, K2, V>, _k1_eq : (K1, K1) -> Bool, k2_eq : (K2, K2) -> Bool) : Trie<K2, V>
```

Like [`mergeDisjoint`](#mergedisjoint), except instead of merging a
Expand Down
12 changes: 3 additions & 9 deletions src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2857,11 +2857,9 @@ let infer_prog scope pkg_opt async_cap prog : (T.typ * Scope.t) Diag.result =
let env0 = env_of_scope msgs scope in
let env = {
env0 with async = async_cap;
(* suppress usage warning in package code *)
check_unused = pkg_opt = None
} in
let res = infer_block env prog.it prog.at true in
emit_unused_warnings env;
if pkg_opt = None then emit_unused_warnings env;
res
) prog
)
Expand Down Expand Up @@ -2898,11 +2896,7 @@ let check_lib scope pkg_opt lib : Scope.t Diag.result =
(fun msgs ->
recover_opt
(fun lib ->
let env = {
(env_of_scope msgs scope) with
(* suppress usage warning in package code *)
check_unused = pkg_opt = None
} in
let env = env_of_scope msgs scope in
let { imports; body = cub; _ } = lib.it in
let (imp_ds, ds) = CompUnit.decs_of_lib lib in
let typ, _ = infer_block env (imp_ds @ ds) lib.at false in
Expand Down Expand Up @@ -2945,7 +2939,7 @@ let check_lib scope pkg_opt lib : Scope.t Diag.result =
(* this shouldn't really happen, as an imported program should be rewritten to a module *)
error env cub.at "M0000" "compiler bug: expected a module or actor class but found a program, i.e. a sequence of declarations"
in
emit_unused_warnings env;
if pkg_opt = None then emit_unused_warnings env;
Scope.lib lib.note.filename imp_typ
) lib
)
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline/pipeline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ let chase_imports parsefn senv0 imports : (Syntax.lib list * Scope.scope) Diag.r
let* prog, base = parsefn ri.Source.at f in
let* () = Static.prog prog in
let* more_imports = ResolveImport.resolve (resolve_flags ()) prog base in
let pkg_opt' = if lib_pkg_opt <> None then lib_pkg_opt else pkg_opt in
let* () = go_set pkg_opt more_imports in
let cur_pkg_opt = if lib_pkg_opt <> None then lib_pkg_opt else pkg_opt in
let* () = go_set cur_pkg_opt more_imports in
let lib = lib_of_prog f prog in
let* sscope = check_lib !senv pkg_opt' lib in
let* sscope = check_lib !senv cur_pkg_opt lib in
libs := lib :: !libs; (* NB: Conceptually an append *)
senv := Scope.adjoin !senv sscope;
pending := remove ri.Source.it !pending;
Expand Down

0 comments on commit 01efc2a

Please sign in to comment.