Skip to content

Commit

Permalink
Merge pull request #2 from dfinity/ryan/publish-mops-merge
Browse files Browse the repository at this point in the history
Fix merge conflicts in dfinity#618
  • Loading branch information
ZenVoich authored Feb 21, 2024
2 parents 8a384da + 9e582d9 commit 8ce22a5
Show file tree
Hide file tree
Showing 24 changed files with 35 additions and 81 deletions.
2 changes: 0 additions & 2 deletions src/Array.mo
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,6 @@ module {
/// *Runtime and space assumes that `f` runs in O(1) time and space.
public func mapResult<X, Y, E>(array : [X], f : X -> Result.Result<Y, E>) : Result.Result<[Y], E> {
let size = array.size();
var target : [var Y] = [var];
var isInit = false;

var error : ?Result.Result<[Y], E> = null;
let results = Prim.Array_tabulate<?Y>(
Expand Down
4 changes: 2 additions & 2 deletions src/Char.mo
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module {
public let toText : (c : Char) -> Text = Prim.charToText;

// Not exposed pending multi-char implementation.
private let toUpper : (c : Char) -> Char = Prim.charToUpper;
private let _toUpper : (c : Char) -> Char = Prim.charToUpper;

// Not exposed pending multi-char implementation.
private let toLower : (c : Char) -> Char = Prim.charToLower;
private let _toLower : (c : Char) -> Char = Prim.charToLower;

/// Returns `true` when `c` is a decimal digit between `0` and `9`, otherwise `false`.
public func isDigit(c : Char) : Bool {
Expand Down
2 changes: 1 addition & 1 deletion src/HashMap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module {
public func get(key : K) : (value : ?V) {
let h = Prim.nat32ToNat(keyHash(key));
let m = table.size();
let v = if (m > 0) {
if (m > 0) {
AssocList.find<Key<K>, V>(table[h % m], keyHash_(key), keyHashEq)
} else {
null
Expand Down
2 changes: 1 addition & 1 deletion src/Iter.mo
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module {
/// ```
public func toArray<A>(xs : Iter<A>) : [A] {
let buffer = Buffer.Buffer<A>(8);
iterate(xs, func(x : A, ix : Nat) { buffer.add(x) });
iterate(xs, func(x : A, _ix : Nat) { buffer.add(x) });
return Buffer.toArray(buffer)
};

Expand Down
4 changes: 2 additions & 2 deletions src/RBTree.mo
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ module {
///
/// Note: Creates `O(log(n))` temporary objects that will be collected as garbage.
public func put(key : K, value : V) {
let (t, res) = insert(tree, compare, key, value);
let (t, _res) = insert(tree, compare, key, value);
tree := t
};

Expand All @@ -235,7 +235,7 @@ module {
///
/// Note: Creates `O(log(n))` temporary objects that will be collected as garbage.
public func delete(key : K) {
let (res, t) = removeRec(key, compare, tree);
let (_res, t) = removeRec(key, compare, tree);
tree := t
};

Expand Down
10 changes: 4 additions & 6 deletions src/Trie.mo
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ module {
let len = List.size(l.keyvals);
len <= MAX_LEAF_SIZE and len == l.size and List.all(
l.keyvals,
func((k : Key<K>, v : V)) : Bool { ((k.hash & mask) == bits) }
func((k : Key<K>, _v : V)) : Bool { ((k.hash & mask) == bits) }
)
};
case (#branch b) {
Expand Down Expand Up @@ -483,7 +483,7 @@ module {
func splitAssocList<K, V>(al : AssocList<Key<K>, V>, bitpos : Nat) : (AssocList<Key<K>, V>, AssocList<Key<K>, V>) =
List.partition(
al,
func((k : Key<K>, v : V)) : Bool = not Hash.bit(k.hash, bitpos)
func((k : Key<K>, _v : V)) : Bool = not Hash.bit(k.hash, bitpos)
);

func splitList<K, V>(l : AssocList<Key<K>, V>, bitpos : Nat) : (Nat, AssocList<Key<K>, V>, Nat, AssocList<Key<K>, V>) {
Expand Down Expand Up @@ -585,8 +585,6 @@ module {
/// var mergedTrie = Trie.mergeDisjoint(trie, trie2, Text.equal);
/// ```
public func mergeDisjoint<K, V>(tl : Trie<K, V>, tr : Trie<K, V>, k_eq : (K, K) -> Bool) : Trie<K, V> {
let key_eq = equalKey(k_eq);

func rec(bitpos : Nat, tl : Trie<K, V>, tr : Trie<K, V>) : Trie<K, V> =
switch (tl, tr) {
case (#empty, _) { return tr };
Expand Down Expand Up @@ -964,7 +962,7 @@ module {
tl : Trie<K1, V1>,
tr : Trie<K2, V2>,
op : (K1, V1, K2, V2) -> ?(K3, V3),
k3_eq : (K3, K3) -> Bool
_k3_eq : (K3, K3) -> Bool
) : Build<K3, V3> {

func bin(a : Build<K3, V3>, b : Build<K3, V3>) : Build<K3, V3> = seq(a, b);
Expand Down Expand Up @@ -1565,7 +1563,7 @@ module {
/// trie.
public func mergeDisjoint2D<K1, K2, V>(
t : Trie2D<K1, K2, V>,
k1_eq : (K1, K1) -> Bool,
_k1_eq : (K1, K1) -> Bool,
k2_eq : (K2, K2) -> Bool
) : Trie<K2, V> =
foldUp(
Expand Down
1 change: 0 additions & 1 deletion test/Array.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Int "../src/Int";
import Char "../src/Char";
import Nat "../src/Nat";
import Text "../src/Text";
import Result "../src/Result";
import Suite "mo:matchers/Suite";
import T "mo:matchers/Testable";
import M "mo:matchers/Matchers";
Expand Down
2 changes: 0 additions & 2 deletions test/Buffer.test.mo
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Prim "mo:⛔";
import B "../src/Buffer";
import Iter "../src/Iter";
import Option "../src/Option";
import Nat "../src/Nat";
import Hash "../src/Hash";
import Nat32 "../src/Nat32";
Expand Down
1 change: 0 additions & 1 deletion test/Char.test.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Debug "../src/Debug";
import Char "../src/Char";
import Prim "mo:⛔";

Expand Down
10 changes: 5 additions & 5 deletions test/Float.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func isNegativeZero(number : Float) : Bool {
};

class PositiveZeroMatcher() : M.Matcher<Float> {
public func describeMismatch(number : Float, description : M.Description) {
public func describeMismatch(number : Float, _description : M.Description) {
Debug.print(debug_show (number) # " should be '0.0' (positive zero)")
};

Expand All @@ -73,7 +73,7 @@ class PositiveZeroMatcher() : M.Matcher<Float> {
};

class NegativeZeroMatcher() : M.Matcher<Float> {
public func describeMismatch(number : Float, description : M.Description) {
public func describeMismatch(number : Float, _description : M.Description) {
Debug.print(debug_show (number) # " should be '-0.0' (negative zero)")
};

Expand All @@ -86,7 +86,7 @@ let noEpsilon = 0.0;
let smallEpsilon = 1e-6;

class NaNMatcher() : M.Matcher<Float> {
public func describeMismatch(number : Float, description : M.Description) {
public func describeMismatch(number : Float, _description : M.Description) {
Debug.print(debug_show (number) # " should be 'nan' or '-nan'")
};

Expand All @@ -96,7 +96,7 @@ class NaNMatcher() : M.Matcher<Float> {
};

class PositiveNaNMatcher() : M.Matcher<Float> {
public func describeMismatch(number : Float, description : M.Description) {
public func describeMismatch(number : Float, _description : M.Description) {
Debug.print(debug_show (number) # " should be 'nan' (positive)")
};

Expand All @@ -106,7 +106,7 @@ class PositiveNaNMatcher() : M.Matcher<Float> {
};

class NegativeNaNMatcher() : M.Matcher<Float> {
public func describeMismatch(number : Float, description : M.Description) {
public func describeMismatch(number : Float, _description : M.Description) {
Debug.print(debug_show (number) # " should be '-nan' (negative)")
};

Expand Down
5 changes: 0 additions & 5 deletions test/HashMap.test.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import Prim "mo:⛔";
import HashMap "../src/HashMap";
import Hash "../src/Hash";
import Text "../src/Text";
import Nat "../src/Nat";
import Array "../src/Array";
import Iter "../src/Iter";
import Debug "../src/Debug";
import Order "../src/Order";
import Char "../src/Char";

import Suite "mo:matchers/Suite";
import T "mo:matchers/Testable";
Expand Down
1 change: 0 additions & 1 deletion test/LenClamp.test.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import List "../src/List";
import Trie "../src/Trie";
import Debug "../src/Debug";

type List<T> = List.List<T>;
Expand Down
18 changes: 10 additions & 8 deletions test/List.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ func opnatEq(a : ?Nat, b : ?Nat) : Bool {
case (_, _) { false }
}
};
func opnat_isnull(a : ?Nat) : Bool {
switch a {
case (null) { true };
case (?aaa) { false }
}
};

// Temporarily unused because of the comment-disabled test cases below.
// func opnat_isnull(a : ?Nat) : Bool {
// switch a {
// case (null) { true };
// case (?aaa) { false }
// }
// };

// ## Construction
let l1 = List.nil<X>();
Expand All @@ -69,9 +71,9 @@ assert (opnatEq(List.get<X>(l3, 2), null));
*/

// ## Deconstruction
let (a1, t1) = List.pop<X>(l3);
let (a1, _t1) = List.pop<X>(l3);
assert (opnatEq(a1, ?3));
let (a2, t2) = List.pop<X>(l2);
let (a2, _t2) = List.pop<X>(l2);
assert (opnatEq(a2, ?2));
let (a3, t3) = List.pop<X>(l1);
assert (opnatEq(a3, null));
Expand Down
4 changes: 2 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

STDLIB ?= ../src
MOC ?= moc
WASMTIME_OPTIONS = --disable-cache --enable-cranelift-nan-canonicalization --wasm-features multi-memory,bulk-memory
WASMTIME_OPTIONS = -C cache=n -W nan-canonicalization=y -W multi-memory -W bulk-memory

OUTDIR=_out

Expand All @@ -22,7 +22,7 @@ $(OUTDIR):
$(OUTDIR)/import_all.mo: $(STDLIB_FILES) | $(OUTDIR)
> $@
for f in $(patsubst $(STDLIB)/%.mo,%,$(STDLIB_FILES)); do \
echo "import Import_$$f \"mo:base/$$f\";" >> $@; \
echo "import _Import_$$f \"mo:base/$$f\";" >> $@; \
done

$(OUTDIR)/%.wasm: %.mo | $(OUTDIR)
Expand Down
1 change: 0 additions & 1 deletion test/None.test.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Array "../src/Array";
import None "../src/None";
import Debug "../src/Debug";

Expand Down
10 changes: 3 additions & 7 deletions test/RBTree.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let { run; test; suite } = Suite;
let entryTestable = T.tuple2Testable(T.natTestable, T.textTestable);

class TreeMatcher(expected : [(Nat, Text)]) : M.Matcher<RBTree.RBTree<Nat, Text>> {
public func describeMismatch(actual : RBTree.RBTree<Nat, Text>, description : M.Description) {
public func describeMismatch(actual : RBTree.RBTree<Nat, Text>, _description : M.Description) {
Debug.print(debug_show (Iter.toArray(actual.entries())) # " should be " # debug_show (expected))
};

Expand Down Expand Up @@ -72,12 +72,6 @@ func insert(tree : RBTree.RBTree<Nat, Text>, key : Nat) {
checkTree(tree)
};

func remove(tree : RBTree.RBTree<Nat, Text>, key : Nat) {
let value = tree.remove(key);
assert (value == ?debug_show (key));
checkTree(tree)
};

func getAll(tree : RBTree.RBTree<Nat, Text>, keys : [Nat]) {
for (key in keys.vals()) {
let value = tree.get(key);
Expand Down Expand Up @@ -209,6 +203,7 @@ run(
do {
let tree = buildTestTree();
ignore tree.remove(0);
checkTree(tree);
tree
},
TreeMatcher([])
Expand Down Expand Up @@ -443,6 +438,7 @@ run(
let tree = buildTestTree();
let result = tree.remove(1);
assert (result == ?"1");
checkTree(tree);
tree.remove(1)
},
M.equals(T.optional(T.textTestable, null : ?Text))
Expand Down
17 changes: 1 addition & 16 deletions test/RBTreeMore.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import M "mo:matchers/Matchers";

let { run; test; suite } = Suite;

let entryTestable = T.tuple2Testable(T.natTestable, T.natTestable);

class TreeMatcher(expected : [(Nat, Nat)]) : M.Matcher<RBTree.RBTree<Nat, Nat>> {
public func describeMismatch(actual : RBTree.RBTree<Nat, Nat>, description : M.Description) {
public func describeMismatch(actual : RBTree.RBTree<Nat, Nat>, _description : M.Description) {
Debug.print(debug_show (Iter.toArray(actual.entries())) # " should be " # debug_show (expected))
};

Expand Down Expand Up @@ -76,19 +74,6 @@ func insert(tree : RBTree.RBTree<Nat, Nat>, key : Nat) {
checkTree(tree)
};

func remove(tree : RBTree.RBTree<Nat, Nat>, key : Nat) {
let value = tree.remove(key);
assert (value == ?key);
checkTree(tree)
};

func getAll(tree : RBTree.RBTree<Nat, Nat>, keys : [Nat]) {
for (key in keys.vals()) {
let value = tree.get(key);
assert (value == ?key)
}
};

func clear(tree : RBTree.RBTree<Nat, Nat>) {
for ((key, value) in tree.entries()) {
// stable iteration
Expand Down
1 change: 0 additions & 1 deletion test/Random.test.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Prim "mo:prim";
import Random "../src/Random";
import Nat8 "../src/Nat8";
import Nat16 "../src/Nat16";
Expand Down
1 change: 0 additions & 1 deletion test/Result.test.mo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Result "../src/Result";
import Int "../src/Int";
import Array "../src/Array";
import List "../src/List";

import Suite "mo:matchers/Suite";
import M "mo:matchers/Matchers";
Expand Down
2 changes: 0 additions & 2 deletions test/Stack.test.mo
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Stack "../src/Stack";
import Iter "../src/Iter";
import O "../src/Option";

import Suite "mo:matchers/Suite";
import T "mo:matchers/Testable";
Expand Down
7 changes: 0 additions & 7 deletions test/Text.test.mo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @testmode wasi

import Debug "../src/Debug";
import Text "../src/Text";
import Blob "../src/Blob";
import Iter "../src/Iter";
Expand All @@ -15,12 +14,6 @@ import T "mo:matchers/Testable";

let { run; test; suite } = Suite;

func charT(c : Char) : T.TestableItem<Char> = {
item = c;
display = Text.fromChar;
equals = Char.equal
};

func blobT(b : Blob) : T.TestableItem<Blob> = {
item = b;
display = func(b : Blob) : Text { debug_show (b) };
Expand Down
3 changes: 0 additions & 3 deletions test/Trie.test.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Trie "../src/Trie";
import List "../src/List";
import Nat "../src/Nat";
import Hash "../src/Hash";
import Option "../src/Option";
Expand All @@ -13,8 +12,6 @@ import Suite "mo:matchers/Suite";
import T "mo:matchers/Testable";
import M "mo:matchers/Matchers";

let test = Suite;

func compare (kv1 : (Nat, Nat), kv2 : (Nat, Nat)) : Order.Order {
Nat.compare(kv1.0, kv2.0)
};
Expand Down
2 changes: 1 addition & 1 deletion test/TrieMap.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func sortedEntries(trie : TrieMap.TrieMap<Nat, Text>) : [(Nat, Text)] {
};

class TrieMatcher(expected : [(Nat, Text)]) : M.Matcher<TrieMap.TrieMap<Nat, Text>> {
public func describeMismatch(actual : TrieMap.TrieMap<Nat, Text>, description : M.Description) {
public func describeMismatch(actual : TrieMap.TrieMap<Nat, Text>, _description : M.Description) {
Prim.debugPrint(debug_show (sortedEntries(actual)) # " should be " # debug_show (expected))
};

Expand Down
Loading

0 comments on commit 8ce22a5

Please sign in to comment.