]> gitweb.factorcode.org Git - factor.git/blob - basis/stack-checker/errors/errors-docs.factor
Conflict resolution
[factor.git] / basis / stack-checker / errors / errors-docs.factor
1 USING: help.markup help.syntax kernel effects sequences
2 sequences.private words ;
3 IN: stack-checker.errors
4
5 HELP: literal-expected
6 { $error-description "Thrown when inference encounters a " { $link call } " or " { $link if } " being applied to a value which is not known to be a literal. Such a form can have an arbitrary stack effect, and does not compile." }
7 { $notes "This error will be thrown when compiling any combinator, such as " { $link each } ". However, words calling combinators can compile if the combinator is declared " { $link POSTPONE: inline } " and the quotation being passed in is a literal." }
8 { $examples
9     "In this example, words calling " { $snippet "literal-expected-example" } " will compile, even if " { $snippet "literal-expected-example" } " does not compile itself:"
10     { $code
11         ": literal-expected-example ( quot -- )"
12         "    [ call ] [ call ] bi ; inline"
13     }
14 } ;
15
16 HELP: unbalanced-branches-error
17 { $values { "in" "a sequence of integers" } { "out" "a sequence of integers" } }
18 { $description "Throws an " { $link unbalanced-branches-error } "." }
19 { $error-description "Thrown when inference encounters an " { $link if } " or " { $link dispatch } " where the branches do not all exit with the same stack height." }
20 { $notes "Conditionals with variable stack effects are considered to be bad style and should be avoided since they do not compile."
21 $nl
22 "If this error comes up when inferring the stack effect of a recursive word, check the word's stack effect declaration; it might be wrong." }
23 { $examples
24     { $code
25         ": unbalanced-branches-example ( a b c -- )"
26         "    [ + ] [ dup ] if ;"
27     }
28 } ;
29
30 HELP: too-many->r
31 { $error-description "Thrown if inference notices a quotation pushing elements on the retain stack without popping them at the end." } ;
32
33 HELP: too-many-r>
34 { $error-description "Thrown if inference notices a quotation popping elements from the return stack it did not place there." } ;
35
36 HELP: missing-effect
37 { $error-description "Thrown when inference encounters a word lacking a stack effect declaration. Stack effects of words must be declared, with the exception of words which only push literals on the stack." }
38 { $examples
39     { $code
40         ": missing-effect-example"
41         "    + * ;"
42     }
43 } ;
44
45 HELP: effect-error
46 { $values { "word" word } { "effect" "an instance of " { $link effect } } }
47 { $description "Throws an " { $link effect-error } "." }
48 { $error-description "Thrown when a word's inferred stack effect does not match its declared stack effect." } ;
49
50 HELP: recursive-quotation-error
51 { $error-description "Thrown when a quotation calls itself, directly or indirectly, within the same word. Stack effect inference becomes equivalent to the halting problem if quotation recursion has to be taken into account, hence it is not permitted." }
52 { $examples
53     "Here is an example of quotation recursion:"
54     { $code "[ [ dup call ] dup call ] infer." }
55 } ;
56
57 HELP: undeclared-recursion-error
58 { $error-description "Thrown when an " { $link POSTPONE: inline } " word which is not declared " { $link POSTPONE: recursive } " calls itself, directly or indirectly. The " { $link POSTPONE: recursive } " declaration is mandatory for such words." } ;
59
60 HELP: diverging-recursion-error
61 { $error-description "Thrown when stack effect inference determines that a recursive word might take an arbitrary number of values from the stack." }
62 { $notes "Such words do not have a static stack effect and most likely indicate programmer error." }
63 { $examples
64     { $code
65         ": diverging-recursion-example ( -- )"
66         "    [ diverging-recursion-example f ] when ; inline recursive"
67     }
68 } ;
69
70 HELP: unbalanced-recursion-error
71 { $error-description "Thrown when stack effect inference determines that an inline recursive word has an incorrect stack effect declaration." }
72 { $examples
73     { $code
74         ": unbalanced-recursion-example ( quot: ( -- ? ) -- b )"
75         "    dup call [ unbalanced-recursion-example ] [ drop ] if ;"
76         "    inline recursive"
77     }
78 } ;
79
80 HELP: inconsistent-recursive-call-error
81 { $error-description "Thrown when stack effect inference determines that an inline recursive word calls itself with a different set of quotation parameters than were input." }
82 { $examples
83     { $code
84         ": inconsistent-recursive-call-example ( quot: ( -- ? ) -- b )"
85         "    [ not ] compose inconsistent-recursive-call-example ; inline recursive"
86     }
87 } ;
88
89 ARTICLE: "inference-errors" "Inference warnings and errors"
90 "Main wrapper for all inference warnings and errors:"
91 { $subsection inference-error }
92 "Inference warnings:"
93 { $subsection literal-expected }
94 "Inference errors:"
95 { $subsection recursive-quotation-error }
96 { $subsection unbalanced-branches-error }
97 { $subsection effect-error }
98 { $subsection missing-effect }
99 "Inference errors for inline recursive words:"
100 { $subsection undeclared-recursion-error }
101 { $subsection diverging-recursion-error }
102 { $subsection unbalanced-recursion-error }
103 { $subsection inconsistent-recursive-call-error }
104 "Retain stack usage errors:"
105 { $subsection too-many->r }
106 { $subsection too-many-r> } ;
107
108 ABOUT: "inference-errors"