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

Add return types to procedures #1197

Merged
merged 46 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e601446
feat(all): `return` keyword and `Return` statement in AST
jubnzv Oct 26, 2022
973658d
feat(all): Add return type to procedures
jubnzv Oct 26, 2022
44acbbb
chore(parser): Return syntax: `procedure p() → String`
jubnzv Oct 27, 2022
6ff412a
feat(tc): Support procedures w/ return types
jubnzv Oct 27, 2022
3fa5d21
fix(tests): Remove a redundant test
jubnzv Oct 28, 2022
18dbf5f
fix(fmt): Correct return syntax w/o extra spaces
jubnzv Oct 28, 2022
34a3ea2
chore(parser): Update ParserFaults.messages
jubnzv Oct 28, 2022
172e45d
chore(makefile): Fix a typo. NFC.
jubnzv Oct 28, 2022
99dd697
wip
jubnzv Nov 5, 2022
8989a07
chore(dcd): Simplify code. NFC.
jubnzv Nov 7, 2022
e03e0a9
feat(all): Support return values in `CallProc` statement
jubnzv Nov 9, 2022
573e670
feat(parser): Disambiguate between functions and procedures
jubnzv Nov 9, 2022
7d466cc
feat(merge,fmt): Support return
jubnzv Nov 10, 2022
5f2f54f
feat(parser): Disambiguate `[Bind(id, Var(proc))]` which are procedur…
jubnzv Nov 11, 2022
719ffb7
feat(eval): Support return values
jubnzv Nov 11, 2022
b5c2e71
chore(checker): Rename, because this may be both `cmod` and `lmod`
jubnzv Nov 17, 2022
24532c7
fix(checker): Disambiguate calls in cmod
jubnzv Nov 17, 2022
e30fb3e
fix(typechecker): Add new binds after procedure call to env
jubnzv Nov 17, 2022
1ce75d4
chore(test): Improve a test for formatter
jubnzv Nov 17, 2022
2c7e056
feat(test): Add runner test for `return`
jubnzv Nov 17, 2022
a578852
chore(cf): Better comment
jubnzv Nov 17, 2022
2464898
fix(dcd): False positive on `return` statement
jubnzv Nov 17, 2022
b9906e4
fix(fmt): `make fmt`
jubnzv Nov 17, 2022
fdcbe02
feat(typecheck): Prohibit procedures w/ return in `forall`
jubnzv Nov 17, 2022
eb7f7d7
chore(gitignore): Rollback local changes
jubnzv Nov 17, 2022
982f548
feat(typecheck): Restrict return types to non-maps, for consistency
jubnzv Nov 22, 2022
4eb8256
fix(cf): Use `NoInfo` instead `NotMoney`
jubnzv Nov 22, 2022
299a34a
fix(typechecker): Text of error
jubnzv Nov 22, 2022
e110e24
fix(tests): Directory structure
jubnzv Nov 22, 2022
5fb80e5
fix(typecheck): Error message; add test
jubnzv Nov 22, 2022
d522245
fix(test): Name of test
jubnzv Nov 22, 2022
fa8d18f
feat(sc): Forbid dead code after returns and inconsistent return in m…
jubnzv Nov 28, 2022
b60b3bb
feat(sc): Improve analysis of nested matches
jubnzv Nov 28, 2022
ed6de9c
feat(tests): Improve tests for matches
jubnzv Nov 28, 2022
d17e642
feat(tests): Improve dynamic behavior tests
jubnzv Nov 28, 2022
84d6807
Merge remote-tracking branch 'zilliqa/master' into 578_return
jubnzv Dec 8, 2022
224a0e3
feat(syntax): Use `_return := x` in concrete syntax
jubnzv Dec 8, 2022
2f282fe
feat(tests): More tests for contract addresses
jubnzv Dec 8, 2022
f8265fa
feat(syntax): Use `procedure x() : type` concrete syntax
jubnzv Dec 9, 2022
c237b09
Merge remote-tracking branch 'zilliqa/master' into 578_return
jubnzv Jan 4, 2023
fe65606
fix(sc): Error message
jubnzv Jan 10, 2023
20ff941
chore(typechecker): Change error message
jubnzv Jan 17, 2023
a0dad49
Merge remote-tracking branch 'zilliqa/master' into 578_return
jubnzv Jan 17, 2023
f483b4c
fix(tests): Formatter test
jubnzv Jan 17, 2023
34337c1
Merge branch 'master' into 578_return
jubnzv Jan 17, 2023
ae3c1c2
Merge branch 'master' into 578_return
jubnzv Jan 17, 2023
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: 1 addition & 3 deletions src/base/Cashflow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1876,9 +1876,7 @@ struct
| AcceptPayment ->
(AcceptPayment, param_env, field_env, local_env, ctr_tag_map, false)
| Return i ->
let i_tag =
lub_tags NotMoney (lookup_var_tag2 i local_env param_env)
in
let i_tag = lub_tags NoInfo (lookup_var_tag2 i local_env param_env) in
let new_i = update_id_tag i i_tag in
let new_local_env, new_param_env =
update_var_tag2 i i_tag local_env param_env
Expand Down
21 changes: 18 additions & 3 deletions src/base/TypeChecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ module ScillaTypechecker (SR : Rep) (ER : Rep) = struct
| None ->
fail
(mk_type_error1
~kind:"Return type for procedure not found"
~kind:"Procedure does not return a value"
~inst:(as_error_string p)
(SR.get_loc (get_rep p))))
in
Expand Down Expand Up @@ -1054,8 +1054,8 @@ module ScillaTypechecker (SR : Rep) (ER : Rep) = struct
fail
(mk_type_error1
~kind:
"Procedure with return type cannot be used in forall \
statement"
"Procedures with a return type cannot be used in forall \
statements"
~inst:(as_error_string p)
(SR.get_loc (get_rep p)))
| _ ->
Expand Down Expand Up @@ -1114,6 +1114,21 @@ module ScillaTypechecker (SR : Rep) (ER : Rep) = struct
| CompTrans -> is_legal_transition_parameter_type
| CompProc -> is_legal_procedure_parameter_type
in
(* Procedure return type has the same restrictions as parameters. *)
let%bind comp_return =
match comp_return with
| Some ret_ty ->
if param_checker ret_ty then pure @@ Some ret_ty
else
fail
(mk_type_error1
~kind:
(sprintf "Type cannot be used as %s return value"
jubnzv marked this conversation as resolved.
Show resolved Hide resolved
component_type_string)
~inst:(pp_typ_error ret_ty)
(SR.get_loc (get_rep comp_name)))
| None -> pure @@ None
in
let%bind typed_cparams =
mapM
~f:(fun (param, t) ->
Expand Down
12 changes: 12 additions & 0 deletions tests/typecheck/contracts.t/typecheck-return-3.scilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
scilla_version 0

library TypecheckReturn3

contract TypecheckReturn3()
field f_m: Map Uint32 (Option Uint32) = Emp Uint32 (Option Uint32)

procedure cannot_return_map() -> (Map String String)
m := f_m;
return m
end

4 changes: 4 additions & 0 deletions tests/typecheck/contracts.t/typecheck-return-3.scilla.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

tests/typecheck/contracts.t/typecheck-return-3.scilla:8:11: error: Type cannot be used as procedure return value: Map (String) (String)

Gas remaining: 8000
14 changes: 14 additions & 0 deletions tests/typecheck/contracts.t/typecheck-return-4.scilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
scilla_version 0

library TypecheckReturn4

contract TypecheckReturn4()

procedure cannot_be_used_in_forall() -> BNum
r = _creation_block;
return r
end

transition foo(l: List BNum)
forall l cannot_be_used_in_forall
end
4 changes: 4 additions & 0 deletions tests/typecheck/contracts.t/typecheck-return-4.scilla.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

tests/typecheck/contracts.t/typecheck-return-4.scilla:13:12: error: Procedures with a return type cannot be used in forall statements: cannot_be_used_in_forall

Gas remaining: 8000