Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: extended --stable-compatible checks #4850

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/codegen/compile_enhanced.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12268,11 +12268,9 @@ and compile_prim_invocation (env : E.t) ae p es at =

| ICStableRead ty, [] ->
SR.Vanilla,
(* IC.compile_static_print env ("ICStableRead" ^ Type.string_of_typ ty) ^^ *)
Persistence.load env ty
| ICStableWrite ty, [] ->
SR.unit,
(* IC.compile_static_print env ("ICStableWrite" ^ Type.string_of_typ ty) ^^ *)
Persistence.save env ty

(* Cycles *)
Expand Down
9 changes: 5 additions & 4 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,12 @@ and build_actor at ts (exp_opt : Ir.exp option) self_id es obj_typ =
(dom_fields @
(List.filter_map
(fun tf ->
match T.lookup_val_field_opt tf.T.lab dom_fields with
| Some t ->
(* ignore overriden *)
match T.lookup_val_field_opt tf.T.lab dom_fields,
T.lookup_val_field_opt tf.T.lab rng_fields with
| Some _, _ (* ignore consumed (overridden) *)
| _, Some _ -> (* ignore produced (provided) *)
None
| None ->
| None, None ->
(* retain others *)
Some tf)
stab_fields))
Expand Down
10 changes: 7 additions & 3 deletions src/mo_frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2645,9 +2645,13 @@ and check_migration env (stab_tfs : T.field list) exp_opt =
dom_tfs @
(List.filter_map
(fun tf ->
match T.lookup_val_field_opt tf.T.lab dom_tfs with
| Some _ -> None
| None -> Some tf)
match T.lookup_val_field_opt tf.T.lab dom_tfs, T.lookup_val_field_opt tf.T.lab rng_tfs with
| _, Some _ (* ignore consumed (overridden) *)
| Some _, _ -> (* ignore produced (provided) *)
None
| None, None ->
(* retain others *)
Some tf)
stab_tfs)
in
(* Check for duplicates and hash collisions in pre-signature *)
Expand Down
6 changes: 6 additions & 0 deletions test/cmp/files/version0.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Version: 1.0.0
actor {
stable var one : [var Nat];
stable var two : [var Text];
stable var zero : Nat
};
9 changes: 9 additions & 0 deletions test/cmp/files/version1.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Version: 2.0.0
actor ({
stable var one : [var Nat];
stable var two : [var Text];
stable var zero : Nat
}, {
stable var three : [var (Nat, Text)];
stable var zero : Nat
}) ;
8 changes: 8 additions & 0 deletions test/cmp/files/version2.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Version: 2.0.0
actor ({
stable var three : [var (Nat, Text)];
stable var zero : Nat
}, {
stable var four : [var (Nat, Text)];
stable var zero : Nat
}) ;
8 changes: 8 additions & 0 deletions test/cmp/files/version3.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Version: 2.0.0
actor ({
stable var four : [var (Nat, Text)];
stable var zero : Nat
}, {
stable var four : [var (Text, Nat)];
stable var zero : Nat
}) ;
8 changes: 8 additions & 0 deletions test/cmp/files/version4.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Version: 2.0.0
actor ({
stable var four : [var (Text, Nat)];
stable var zero : Nat
}, {
stable var four : [var (Text, Nat, Bool)];
stable var zero : Nat
}) ;
5 changes: 5 additions & 0 deletions test/cmp/files/version5.most
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Version: 1.0.0
actor {
stable var four : [var (Text, Nat, Bool)];
stable var zero : Nat
};
1 change: 1 addition & 0 deletions test/cmp/neg-version4-3.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version4.most files/version3.most
1 change: 1 addition & 0 deletions test/cmp/neg-version5-4.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version5.most files/version4.most
5 changes: 5 additions & 0 deletions test/cmp/ok/neg-version4-3.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(unknown location): Compatibility error [M0170], stable variable four of previous type
var [var (Text, Nat, Bool)]
cannot be consumed at new type
var [var (Nat, Text)]
FALSE
5 changes: 5 additions & 0 deletions test/cmp/ok/neg-version5-4.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(unknown location): Compatibility error [M0170], stable variable four of previous type
var [var (Text, Nat, Bool)]
cannot be consumed at new type
var [var (Text, Nat)]
FALSE
1 change: 1 addition & 0 deletions test/cmp/ok/version0-1.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUE
4 changes: 4 additions & 0 deletions test/cmp/ok/version1-0.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(unknown location): warning [M0169], stable variable three of previous type
var [var (Nat, Text)]
will be discarded. This may cause data loss. Are you sure?
TRUE
1 change: 1 addition & 0 deletions test/cmp/ok/version1-2.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUE
4 changes: 4 additions & 0 deletions test/cmp/ok/version2-1.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(unknown location): warning [M0169], stable variable four of previous type
var [var (Nat, Text)]
will be discarded. This may cause data loss. Are you sure?
TRUE
1 change: 1 addition & 0 deletions test/cmp/ok/version2-3.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUE
4 changes: 4 additions & 0 deletions test/cmp/ok/version3-2.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(unknown location): warning [M0169], stable variable four of previous type
var [var (Text, Nat)]
will be discarded. This may cause data loss. Are you sure?
TRUE
1 change: 1 addition & 0 deletions test/cmp/ok/version3-4.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUE
1 change: 1 addition & 0 deletions test/cmp/ok/version4-5.cmp.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRUE
1 change: 1 addition & 0 deletions test/cmp/version0-1.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version0.most files/version1.most
1 change: 1 addition & 0 deletions test/cmp/version1-0.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version1.most files/version0.most
1 change: 1 addition & 0 deletions test/cmp/version1-2.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version1.most files/version2.most
1 change: 1 addition & 0 deletions test/cmp/version2-1.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version2.most files/version1.most
1 change: 1 addition & 0 deletions test/cmp/version2-3.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version2.most files/version3.most
1 change: 1 addition & 0 deletions test/cmp/version3-2.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version3.most files/version2.most
1 change: 1 addition & 0 deletions test/cmp/version3-4.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version3.most files/version4.most
1 change: 1 addition & 0 deletions test/cmp/version4-5.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files/version4.most files/version5.most
4 changes: 0 additions & 4 deletions test/run-drun/ok/upgrade-class-migration.drun.ok
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ debug.print: Version 2
ingress Completed: Reply: 0x4449444c0000
debug.print: {four = [var (1, "1"), (2, "2"), (3, "3"), (4, "4")]; zero = 0}
ingress Completed: Reply: 0x4449444c0000
ingress Err: IC0503: Error from Canister rwlgt-iiaaa-aaaaa-aaaaa-cai: Canister called `ic0.trap` with message: stable variable `three` of type `var [var (Nat, Text)]` expected but not found.
Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly
debug.print: {four = [var (1, "1"), (2, "2"), (3, "3"), (4, "4")]; zero = 0}
ingress Completed: Reply: 0x4449444c0000
debug.print: {migration = {new = {four = [var ("1", 1), ("2", 2), ("3", 3), ("4", 4)]}; old = {four = [var (1, "1"), (2, "2"), (3, "3"), (4, "4")]}}}
debug.print: Version 3
ingress Completed: Reply: 0x4449444c0000
Expand Down
4 changes: 0 additions & 4 deletions test/run-drun/ok/upgrade-migration.drun.ok
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ debug.print: Version 2
ingress Completed: Reply: 0x4449444c0000
debug.print: {four = [var (1, "1"), (2, "2"), (3, "3"), (4, "4")]; zero = 0}
ingress Completed: Reply: 0x4449444c0000
ingress Err: IC0503: Error from Canister rwlgt-iiaaa-aaaaa-aaaaa-cai: Canister called `ic0.trap` with message: stable variable `three` of type `var [var (Nat, Text)]` expected but not found.
Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly
debug.print: {four = [var (1, "1"), (2, "2"), (3, "3"), (4, "4")]; zero = 0}
ingress Completed: Reply: 0x4449444c0000
debug.print: {migration = {new = {four = [var ("1", 1), ("2", 2), ("3", 3), ("4", 4)]}; old = {four = [var (1, "1"), (2, "2"), (3, "3"), (4, "4")]}}}
debug.print: Version 3
ingress Completed: Reply: 0x4449444c0000
Expand Down
2 changes: 0 additions & 2 deletions test/run-drun/upgrade-class-migration.drun
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ upgrade $ID upgrade-class-migration/version1.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-class-migration/version2.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-class-migration/version2.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-class-migration/version3.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-class-migration/version4.mo ""
Expand Down
2 changes: 0 additions & 2 deletions test/run-drun/upgrade-migration.drun
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ upgrade $ID upgrade-migration/version1.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-migration/version2.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-migration/version2.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-migration/version3.mo ""
ingress $ID check "DIDL\x00\x00"
upgrade $ID upgrade-migration/version4.mo ""
Expand Down
Loading