-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue #448 (Trie.mergeDisjoint can produce broken tries) * actually forces a trap when Trie.mergeDisjoint tries to merge maps with non disjoint domains (as claimed in the doc). Unfortunately, the test harness isn't set up to test for traps, but you manually verify it by running (in dir test) ``` [nix-shell:~/motoko-base/test]$ moc -c --package base ../src -wasi-system-api traps/issue-448.mo [nix-shell:~/motoko-base/test]$ wasmtime run --disable-cache issue-448.wasm Trie.mergeDisjoint Error: failed to run main module `issue-448.wasm` Caused by: 0: failed to invoke command default 1: wasm trap: wasm `unreachable` instruction executed wasm backtrace: 0: 0x1634 - <unknown>!trap 1: 0x1618 - <unknown>!anon-func-576.15 2: 0x1c73 - <unknown>!rec2 3: 0x1d62 - <unknown>!rec1 4: 0x1586 - <unknown>!disj 5: 0x1732 - <unknown>!rec 6: 0x5eb - <unknown>!mergeDisjoint 7: 0x57e - <unknown>!init 8: 0x1f84 - <unknown>!_start ```
- Loading branch information
Showing
2 changed files
with
97 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Trie "mo:base/Trie"; | ||
import Text "mo:base/Text"; | ||
|
||
func key(t : Text) : Trie.Key<Text> = {key = t; hash = Text.hash(t)}; | ||
|
||
var trie = Trie.empty<Text,Nat>(); | ||
|
||
trie := Trie.put(trie, key "hello", Text.equal, 42).0; | ||
trie := Trie.put(trie, key "bye", Text.equal, 42).0; | ||
// trie2 is a copy of trie | ||
var trie2 = Trie.clone(trie); | ||
// trie2 has a different value for "hello" | ||
trie2 := Trie.put(trie2, key "hello", Text.equal, 33).0; | ||
// mergeDisjoint should signal a dynamic error | ||
// in the case of a collision | ||
Trie.mergeDisjoint(trie, trie2, Text.equal); // should trap |