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

experiment: add persistent/transient keywords as synonyms for stable/flexible #4784

Merged
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
4 changes: 4 additions & 0 deletions doc/md/examples/grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,14 @@
<empty>
'flexible'
'stable'
TRANSIENT
PERSISTENT

<stab_mod> ::=
'flexible'
'stable'
TRANSIENT
PERSISTENT

<pat_plain> ::=
'_'
Expand Down
2 changes: 2 additions & 0 deletions src/mo_frontend/error_reporting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let terminal2token (type a) (symbol : a terminal) : token =
| T_UNDERSCORE -> UNDERSCORE
| T_COMPOSITE -> COMPOSITE
| T_TYPE -> TYPE
| T_TRANSIENT -> TRANSIENT
| T_TRY -> TRY
| T_THROW -> THROW
| T_FINALLY -> FINALLY
Expand Down Expand Up @@ -45,6 +46,7 @@ let terminal2token (type a) (symbol : a terminal) : token =
| T_BANG -> BANG
| T_QUERY -> QUERY
| T_PUBLIC -> PUBLIC
| T_PERSISTENT -> PERSISTENT
| T_PRIVATE -> PRIVATE
| T_PRIM -> PRIM
| T_POWOP -> POWOP
Expand Down
7 changes: 7 additions & 0 deletions src/mo_frontend/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ and objblock s id ty dec_fields =
%token WRAPADDASSIGN WRAPSUBASSIGN WRAPMULASSIGN WRAPPOWASSIGN
%token NULL
%token FLEXIBLE STABLE
%token TRANSIENT PERSISTENT
%token<string> DOT_NUM
%token<string> NAT
%token<string> FLOAT
Expand Down Expand Up @@ -805,10 +806,16 @@ stab :
| (* empty *) { None }
| FLEXIBLE { Some (Flexible @@ at $sloc) }
| STABLE { Some (Stable @@ at $sloc) }
| TRANSIENT { Some (Flexible @@ at $sloc) }
| PERSISTENT { Some (Stable @@ at $sloc) }

%inline stab_mod :
(* we could also forbid flexible/transient,
defining away flexible/transient actor class? {} ... *)
| FLEXIBLE { Some (Flexible @@ at $sloc) }
| STABLE { Some (Stable @@ at $sloc) }
| TRANSIENT { Some (Flexible @@ at $sloc) }
| PERSISTENT { Some (Stable @@ at $sloc) }

(* Patterns *)

Expand Down
2 changes: 2 additions & 0 deletions src/mo_frontend/printers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let string_of_symbol = function
| X (T T_SHRASSIGN) -> binop ">>="
| X (T T_UNDERSCORE) -> "_"
| X (T T_TYPE) -> "type"
| X (T T_TRANSIENT) -> "transient"
| X (T T_TRY) -> "try"
| X (T T_THROW) -> "throw"
| X (T T_FINALLY) -> "finally"
Expand All @@ -50,6 +51,7 @@ let string_of_symbol = function
| X (T T_QUEST) -> "?"
| X (T T_BANG) -> "!"
| X (T T_QUERY) -> "query"
| X (T T_PERSISTENT) -> "persistent"
| X (T T_PUBLIC) -> "public"
| X (T T_PRIVATE) -> "private"
| X (T T_PRIM) -> "prim"
Expand Down
2 changes: 2 additions & 0 deletions src/mo_frontend/source_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ rule token mode = parse
| "label" { LABEL }
| "let" { LET }
| "loop" { LOOP }
| "persistent" { PERSISTENT}
| "private" { PRIVATE }
| "public" { PUBLIC }
| "query" { QUERY }
Expand All @@ -242,6 +243,7 @@ rule token mode = parse
| "stable" { STABLE }
| "switch" { SWITCH }
| "system" { SYSTEM }
| "transient" { TRANSIENT }
| "try" { TRY }
| "throw" { THROW }
| "to_candid" { TO_CANDID }
Expand Down
6 changes: 6 additions & 0 deletions src/mo_frontend/source_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type token =
| RETURN
| SYSTEM
| STABLE
| TRANSIENT
| TRY
| THROW
| WITH
Expand All @@ -45,6 +46,7 @@ type token =
| OBJECT
| ACTOR
| CLASS
| PERSISTENT
| PUBLIC
| PRIVATE
| SHARED
Expand Down Expand Up @@ -162,6 +164,7 @@ let to_parser_token :
| WHILE -> Ok Parser.WHILE
| FOR -> Ok Parser.FOR
| RETURN -> Ok Parser.RETURN
| TRANSIENT -> Ok Parser.TRANSIENT
| TRY -> Ok Parser.TRY
| THROW -> Ok Parser.THROW
| FINALLY -> Ok Parser.FINALLY
Expand All @@ -173,6 +176,7 @@ let to_parser_token :
| OBJECT -> Ok Parser.OBJECT
| ACTOR -> Ok Parser.ACTOR
| CLASS -> Ok Parser.CLASS
| PERSISTENT -> Ok Parser.PERSISTENT
| PUBLIC -> Ok Parser.PUBLIC
| PRIVATE -> Ok Parser.PRIVATE
| SHARED -> Ok Parser.SHARED
Expand Down Expand Up @@ -302,11 +306,13 @@ let string_of_parser_token = function
| Parser.OBJECT -> "OBJECT"
| Parser.ACTOR -> "ACTOR"
| Parser.CLASS -> "CLASS"
| Parser.PERSISTENT -> "PERSISTENT"
| Parser.PUBLIC -> "PUBLIC"
| Parser.PRIVATE -> "PRIVATE"
| Parser.SHARED -> "SHARED"
| Parser.STABLE -> "STABLE"
| Parser.SYSTEM -> "SYSTEM"
| Parser.TRANSIENT -> "TRANSIENT"
| Parser.QUERY -> "QUERY"
| Parser.SEMICOLON -> "SEMICOLON"
| Parser.SEMICOLON_EOL -> "SEMICOLON_EOL"
Expand Down
4 changes: 4 additions & 0 deletions test/run-drun/ok/stable-counter-class.drun.ok
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ debug.print: {pre = 1}
ingress Completed: Reply: 0x4449444c0000
debug.print: 2
ingress Completed: Reply: 0x4449444c00017d02
debug.print: {pre = 2}
ingress Completed: Reply: 0x4449444c0000
debug.print: 3
ingress Completed: Reply: 0x4449444c00017d03
4 changes: 4 additions & 0 deletions test/run-drun/ok/stable-counter.drun.ok
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ debug.print: {pre = 1}
ingress Completed: Reply: 0x4449444c0000
debug.print: 2
ingress Completed: Reply: 0x4449444c00017d02
debug.print: {pre = 2}
ingress Completed: Reply: 0x4449444c0000
debug.print: 3
ingress Completed: Reply: 0x4449444c00017d03
4 changes: 3 additions & 1 deletion test/run-drun/stable-counter-class.drun
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
install $ID stable-counter-class/stable-counter-class.mo ""
ingress $ID inc "DIDL\x00\x00"
upgrade $ID stable-counter-class/stable-counter-class.mo ""
upgrade $ID stable-counter-class/stable-counter-class-1.mo ""
ingress $ID inc "DIDL\x00\x00"
upgrade $ID stable-counter-class/stable-counter-class-2.mo ""
ingress $ID inc "DIDL\x00\x00"
25 changes: 25 additions & 0 deletions test/run-drun/stable-counter-class/stable-counter-class-1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Prim "mo:⛔";

persistent actor class Counter() {

var count : Nat = 0;

public func inc() : async Nat {
count += 1;
Prim.debugPrint (debug_show(count));
count
};

system func preupgrade() {
Prim.debugPrint (debug_show({pre=count}));
};

transient let f = func(){};
func g() {};
class D() {};
type T = ?T;
ignore 1;

}


25 changes: 25 additions & 0 deletions test/run-drun/stable-counter-class/stable-counter-class-2.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Prim "mo:⛔";

actor class Counter() {

persistent var count : Nat = 0;

public func inc() : async Nat {
count += 1;
Prim.debugPrint (debug_show(count));
count
};

system func preupgrade() {
Prim.debugPrint (debug_show({pre=count}));
};

let f = func(){};
func g() {};
class D() {};
type T = ?T;
ignore 1;

}


8 changes: 6 additions & 2 deletions test/run-drun/stable-counter-class/stable-counter-class.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ stable actor class Counter() {

system func preupgrade() {
Prim.debugPrint (debug_show({pre=count}));
}
};

// let f = func(){}; // rejected as unstable
flexible let f = func(){};
func g() {};
class D() {};
type T = ?T;
ignore 1;

}

Expand Down
4 changes: 3 additions & 1 deletion test/run-drun/stable-counter.drun
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
install $ID stable-counter/stable-counter.mo ""
ingress $ID inc "DIDL\x00\x00"
upgrade $ID stable-counter/stable-counter.mo ""
upgrade $ID stable-counter/stable-counter-1.mo ""
ingress $ID inc "DIDL\x00\x00"
upgrade $ID stable-counter/stable-counter-2.mo ""
ingress $ID inc "DIDL\x00\x00"
26 changes: 26 additions & 0 deletions test/run-drun/stable-counter/stable-counter-1.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Prim "mo:⛔";

persistent actor Counter {

var count : Nat = 0;

public func inc() : async Nat {
count += 1;
Prim.debugPrint (debug_show(count));
count
};

system func preupgrade() {
Prim.debugPrint (debug_show({pre=count}));
};

transient let f = func(){};

func g() {};
class D() {};
type T = ?T;
ignore 1;

}


26 changes: 26 additions & 0 deletions test/run-drun/stable-counter/stable-counter-2.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Prim "mo:⛔";

actor Counter {

persistent var count : Nat = 0;

public func inc() : async Nat {
count += 1;
Prim.debugPrint (debug_show(count));
count
};

system func preupgrade() {
Prim.debugPrint (debug_show({pre=count}));
};

let f = func(){};

func g() {};
class D() {};
type T = ?T;
ignore 1;

}


8 changes: 6 additions & 2 deletions test/run-drun/stable-counter/stable-counter.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ stable actor Counter {

system func preupgrade() {
Prim.debugPrint (debug_show({pre=count}));
}
};

// let f = func(){}; // rejected as unstable
flexible let f = func(){};
func g() {};
class D() {};
type T = ?T;
ignore 1;

}

Expand Down
Loading