Skip to content

Commit 910a05d

Browse files
catamorphismgraydon
authored andcommitted
Update docs to reflect preds
1 parent acf9bd7 commit 910a05d

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

doc/rust.texi

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ The keywords are:
682682
@tab @code{thread}
683683
@item @code{auth}
684684
@tab @code{unsafe}
685+
@tab @code{as}
685686
@tab @code{self}
686687
@tab @code{log}
687688
@item @code{bind}
@@ -711,8 +712,8 @@ The keywords are:
711712
@tab @code{str}
712713
@item @code{fn}
713714
@tab @code{iter}
715+
@tab @code{pred}
714716
@tab @code{obj}
715-
@tab @code{as}
716717
@tab @code{drop}
717718
@item @code{task}
718719
@tab @code{port}
@@ -1785,8 +1786,6 @@ fn main() @{
17851786
@c * Ref.Item.Fn:: Items defining functions.
17861787
@cindex Functions
17871788
@cindex Slots, function input and output
1788-
@cindex Predicate
1789-
17901789

17911790
A @dfn{function item} defines a sequence of statements associated with a name
17921791
and a set of parameters. Functions are declared with the keyword
@@ -1805,16 +1804,37 @@ expression. If a control path lacks a @code{ret} expression in source code, an
18051804
implicit @code{ret} expression is appended to the end of the control path
18061805
during compilation, returning the implicit @code{()} value.
18071806

1808-
Any pure boolean function is also called a @emph{predicate}, and may be used
1809-
as part of the static typestate system. @xref{Ref.Typestate.Constr}.
1810-
18111807
An example of a function:
18121808
@example
18131809
fn add(int x, int y) -> int @{
18141810
ret x + y;
18151811
@}
18161812
@end example
18171813

1814+
@node Ref.Item.Pred
1815+
@subsection Ref.Item.Pred
1816+
@c * Ref.Item.Pred:: Items defining predicates.
1817+
@cindex Predicate
1818+
1819+
Any pure boolean function is called a @emph{predicate}, and may be used
1820+
as part of the static typestate system. @xref{Ref.Typestate.Constr}. A
1821+
predicate declaration is identical to a function declaration, except that it
1822+
is declared with the keyword @code{pred} instead of @code{fn}. In addition,
1823+
the typechecker checks the body of a predicate with a restricted set of
1824+
typechecking rules. A predicate
1825+
@itemize
1826+
@item may not contain a @code{put}, @code{send}, @code{recv}, assignment, or
1827+
self-call expression; and
1828+
@item may only call other predicates, not general functions.
1829+
@end itemize
1830+
1831+
An example of a predicate:
1832+
@example
1833+
pred lt_42(int x) -> bool @{
1834+
ret (x < 42);
1835+
@}
1836+
@end example
1837+
18181838
@node Ref.Item.Iter
18191839
@subsection Ref.Item.Iter
18201840
@c * Ref.Item.Iter:: Items defining iterators.
@@ -2631,14 +2651,14 @@ This implicit graph is called the @dfn{control-flow graph}, or @dfn{CFG}.
26312651
@cindex Predicate
26322652
@cindex Constraint
26332653

2634-
A @dfn{predicate} is any pure boolean function. @xref{Ref.Item.Fn}.
2654+
A @dfn{predicate} is a pure boolean function declared with the keyword @code{pred}. @xref{Ref.Item.Pred}.
26352655

26362656
A @dfn{constraint} is a predicate applied to specific slots.
26372657

26382658
For example, consider the following code:
26392659

26402660
@example
2641-
fn is_less_than(int a, int b) -> bool @{
2661+
pred is_less_than(int a, int b) -> bool @{
26422662
ret a < b;
26432663
@}
26442664
@@ -3543,7 +3563,7 @@ and statically comparing implied states and their
35433563
specifications. @xref{Ref.Typestate}.
35443564

35453565
@example
3546-
fn even(&int x) -> bool @{
3566+
pred even(&int x) -> bool @{
35473567
ret x & 1 == 0;
35483568
@}
35493569

0 commit comments

Comments
 (0)