]> gitweb.factorcode.org Git - factor.git/commitdiff
help.lint.checks: check for disposable leaks and print more details when $values...
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 14 Apr 2014 00:02:26 +0000 (02:02 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 14 Apr 2014 15:37:52 +0000 (08:37 -0700)
basis/help/lint/checks/checks-docs.factor [new file with mode: 0644]
basis/help/lint/checks/checks.factor
basis/tools/destructors/destructors-docs.factor
basis/tools/destructors/destructors-tests.factor
basis/tools/destructors/destructors.factor

diff --git a/basis/help/lint/checks/checks-docs.factor b/basis/help/lint/checks/checks-docs.factor
new file mode 100644 (file)
index 0000000..640337a
--- /dev/null
@@ -0,0 +1,18 @@
+USING: help.markup help.syntax sequences words ;
+IN: help.lint.checks
+
+HELP: check-example
+{ $values { "element" sequence } }
+{ $description "Throws an error if the expected output from the $example is different from the expected, or if it leaks disposables." } ;
+
+HELP: check-values
+{ $values { "word" word } { "element" sequence } }
+{ $description "Throws an error if the $values pair doesnt match the declared stack effect." }
+{ $examples
+  { $unchecked-example
+    "USING: help.lint.checks math ;"
+    ": foo ( x -- y ) ;"
+    "\\ foo { $values { \"a\" number } { \"b\" number } } check-values"
+    "$values don't match stack effect; expected { \"x\" \"y\" }, got { \"a\" \"b\" }\n\nType :help for debugging help."
+    }
+} ;
index 463b83f2c9e1a2f00883859cc678b0c554a339a4..8a31cac7c553cff59507e98a98b190833c8ef322 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs classes classes.tuple combinators
-combinators.short-circuit debugger definitions effects eval fry
-grouping help help.markup help.topics io io.streams.string
-kernel macros namespaces sequences sequences.deep sets splitting
-strings summary unicode.categories vocabs vocabs.loader words
-words.constant words.symbol ;
+combinators.short-circuit debugger definitions effects eval
+formatting fry grouping help help.markup help.topics io io.streams.string
+kernel macros math namespaces sequences sequences.deep sets splitting
+strings summary threads tools.destructors unicode.categories vocabs vocabs.loader
+words words.constant words.symbol ;
 FROM: sets => members ;
 IN: help.lint.checks
 
@@ -20,14 +20,18 @@ SYMBOL: all-vocabs
 SYMBOL: vocab-articles
 
 : check-example ( element -- )
-    '[
-        _ rest [
-            but-last "\n" join
-            [ (eval>string) ] call( code -- output )
-            "\n" ?tail drop
-        ] keep
-        last assert=
-    ] vocabs-quot get call( quot -- ) ;
+    [
+        '[
+            _ rest [
+                but-last "\n" join
+                [ (eval>string) ] call( code -- output )
+                "\n" ?tail drop
+            ] keep
+            last assert=
+        ] vocabs-quot get call( quot -- )
+    ] leaks members length [
+        "%d disposable(s) leaked in example" sprintf simple-lint-error
+    ] unless-zero ;
 
 : check-examples ( element -- )
     \ $example swap elements [ check-example ] each ;
@@ -39,7 +43,7 @@ SYMBOL: vocab-articles
 
 : extract-value-effects ( element -- seq )
     \ $values swap elements dup empty? [
-        first rest [ 
+        first rest [
             \ $quotation swap elements dup empty? [ drop f ] [
                 first second
             ] if
@@ -77,18 +81,17 @@ SYMBOL: vocab-articles
         [ constant? ]
     } 1|| ;
 
+: skip-check-values? ( word element -- ? )
+    [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
+
 : check-values ( word element -- )
-    {
-        [
-            [ don't-check-word? ]
-            [ contains-funky-elements? ]
-            bi* or
-        ] [
-            [ effect-values ]
-            [ extract-values ]
-            bi* sequence=
-        ]
-    } 2|| [ "$values don't match stack effect" simple-lint-error ] unless ;
+    2dup skip-check-values? [ 2drop ] [
+        [ effect-values ] [ extract-values ] bi* 2dup
+        sequence= [ 2drop ] [
+            "$values don't match stack effect; expected %u, got %u" sprintf
+            simple-lint-error
+        ] if
+    ] if ;
 
 : check-value-effects ( word element -- )
     [ effect-effects ]
index 3491caf46287e2590c5933f1534fa82fba76add7..41e0849052af4f1c661ad8175b125c391a68571d 100644 (file)
@@ -1,25 +1,34 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax help.tips quotations destructors ;
+USING: destructors help.markup help.syntax help.tips quotations sequences ;
 IN: tools.destructors
 
 HELP: disposables.
 { $description "Print the number of disposable objects of each class." } ;
 
-HELP: leaks
+HELP: leaks.
 { $values
     { "quot" quotation }
 }
 { $description "Runs a quotation, printing any increases in the number of disposable objects after the quotation returns. The " { $link debug-leaks? } " variable is also switched on while the quotation runs, recording the current continuation in every newly-created disposable object." } ;
 
-TIP: "Use the " { $link leaks } " combinator to track down resource leaks." ;
+HELP: leaks
+{ $values
+  { "quot" quotation }
+  { "disposables" sequence }
+}
+{ $description
+  "Runs the quotation and collects all disposables leaked by it. Used by " { $link leaks. } "."
+} ;
+
+TIP: "Use the " { $link leaks. } " combinator to track down resource leaks." ;
 
 ARTICLE: "tools.destructors" "Destructor tools"
 "The " { $vocab-link "tools.destructors" } " vocabulary provides words for tracking down resource leaks."
 { $subsections
     debug-leaks?
     disposables.
-    leaks
+    leaks.
 }
 { $see-also "destructors" } ;
 
index 24904f76f63024050657427ea52aa5f2e5a0bd16..788b67133a82b140f02412858c2a3c874cba34c5 100644 (file)
@@ -3,11 +3,10 @@ IN: tools.destructors.tests
 
 f debug-leaks? set-global
 
-[ [ 3 throw ] leaks ] must-fail
+[ [ 3 throw ] leaks. ] must-fail
 
 [ f ] [ debug-leaks? get-global ] unit-test
 
-[ ] [ [ ] leaks ] unit-test
+[ ] [ [ ] leaks. ] unit-test
 
 [ f ] [ debug-leaks? get-global ] unit-test
-
index b923c7ba94371fbf45d38ad2e6c5fabf32678bb1..d76c242ff5d4e2b150570ce3bdfba9c09d4cc408 100644 (file)
@@ -45,10 +45,13 @@ PRIVATE>
     [ disposables get members sort-disposables ] dip
     '[ _ instance? ] filter stack. ;
 
-: leaks ( quot -- )
+: leaks ( quot -- disposables )
     disposables get clone
     t debug-leaks? set-global
     [
         [ call disposables get clone ] dip
     ] [ f debug-leaks? set-global ] [ ] cleanup
-    diff (disposables.) ; inline
+    diff ; inline
+
+: leaks. ( quot -- )
+    leaks (disposables.) ; inline