Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-10-19 Thread Peter Bex
On Tue, Sep 09, 2014 at 02:57:17AM -0700, Evan Hanson wrote:
 Hi hackers,
 
 Here are some list-related scrutiny improvements. I started with pair
 walking for the scrutinizer's special cases to fix #759 (patch #2),
 which made adding special cases for drop  tail easy (#3). The other
 special cases (#4, #5) are basically just improving result type accuracy
 for make-list, make-vector and reverse, where possible.
 
 The list-copy types.db fix (#1) speaks for itself, I think. Let me know
 if anything looks off.

Hi, Evan!

Sorry it took so long for me to get around to this set of patches.
This is some great work!  I've pushed these patches, but I had to make
one small modification: the special case for split-at was incorrect.
I'm not sure how to indicate returning multiple values inside the
scrutinizer, but simply wrapping them in a list doesn't seem to work.

With your patch as-is, the following program errors out with a message
that the inlined function doesn't return multiple values:

(use srfi-1)
(print (+ (receive (a b) (split-at (list 1 2 'a 4) 2) a) 2))

I've simply taken out the split-at special case, so we at least get
these patches in.  I've applied them all to chicken-5 *and* master.

Of course, if srfi-1 is ever taken out of core, we'd have to revert some
of these patches.  But chances are that we'll use something similar to
these procedures in core, which can then perhaps be special-cased in the
same way.

Cheers,
Peter
-- 
http://www.more-magic.net

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-10-19 Thread Evan Hanson
Hi Peter, thanks for all the pushes!

On 2014-10-19 14:34, Peter Bex wrote:
 I've pushed these patches, but I had to make one small modification:
 the special case for split-at was incorrect.

Thanks for catching that. Indeed, values should be spliced *out* of
their lists. Not sure what I was doing, there -- buggy thinking on my
part.

Evan

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-10 Thread Jörg F. Wittenberger

Am 09.09.2014 um 15:34 schrieb Moritz Heidkamp:

John Cowan co...@mercury.ccil.org writes:


Thanks, that's helpful.  The trouble is that such a file is an internal
(not publicly documented, unstable) format.  So if I want to ship portable
code along with type information for Chicken, I have to:

1) insert the type declarations in the code

2) compile with the -emit-type-file option

3) strip out the declarations again

4) hope the .types file continues to work with new compiler releases

Wait, what? Why not just something like this:

   (cond-expand
 (chicken
   (include chicken-type-decls.scm))
 (else))


Note also that the type declarations are intentionally compatible to be 
macro-defined away like this


(define-macro (: . rest) '(begin))
(define-macro (the type val) val)






That's really intolerable.  I suppose if I confine myself to : and
define-type, then I could ship my code along with macros that turn them
into (begin).

FTR, there is the type-stubs egg which defines those macros and some
more. It's purpose is to make code compatible with CHICKENS that didn't
yet have the type syntax but could be used for portability purposes,
too.

Moritz

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers



___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


[Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread Evan Hanson
Hi hackers,

Here are some list-related scrutiny improvements. I started with pair
walking for the scrutinizer's special cases to fix #759 (patch #2),
which made adding special cases for drop  tail easy (#3). The other
special cases (#4, #5) are basically just improving result type accuracy
for make-list, make-vector and reverse, where possible.

The list-copy types.db fix (#1) speaks for itself, I think. Let me know
if anything looks off.

Cheers,

Evan
From fd3de2653850806947de6461d3c1db332278e1fc Mon Sep 17 00:00:00 2001
From: Evan Hanson ev...@foldling.org
Date: Sat, 16 Aug 2014 16:16:29 +1200
Subject: [PATCH 1/5] Fix list-copy types.db entry to allow any argument type

list-copy accepts any argument type (returning non-pair arguments
unchanged), so its type should be a - a. This also means it can be
marked pure, and improves the scrutinizer's accuracy on list-copy calls
since the argument type can be preserved as the result type.
---
 tests/typematch-tests.scm |3 +++
 types.db  |2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/typematch-tests.scm b/tests/typematch-tests.scm
index bbd5a3c..6cbcc9a 100644
--- a/tests/typematch-tests.scm
+++ b/tests/typematch-tests.scm
@@ -263,6 +263,9 @@
 (mx fixnum (##sys#vector-ref '#(1 2 3.4) 0))
 (mx (vector fixnum float) (vector 1 2.3))
 (mx (list fixnum float) (list 1 2.3))
+(mx (list fixnum float) (list-copy (list 1 2.3)))
+(mx (pair fixnum float) (list-copy (cons 1 2.3)))
+(mx fixnum (list-copy 1))
 
 (: f1 (forall (a) ((list-of a) - a)))
 (define (f1 x) (car x))
diff --git a/types.db b/types.db
index 2621686..e5c0771 100644
--- a/types.db
+++ b/types.db
@@ -1924,7 +1924,7 @@
 (last (#(procedure #:clean #:enforce) last (pair) *))
 (last-pair (#(procedure #:clean #:enforce) last-pair (pair) *))
 (length+ (#(procedure #:clean #:enforce) length+ (list) *))
-(list-copy (forall (a) (#(procedure #:clean #:enforce) list-copy ((list-of a)) 
(list-of a
+(list-copy (forall (a) (#(procedure #:pure) list-copy (a) a)))
 (list-index (forall (a) (#(procedure #:enforce) list-index ((procedure (a 
#!rest) *) (list-of a) #!rest list) *)))
 (list-tabulate (forall (a) (#(procedure #:enforce) list-tabulate (fixnum 
(procedure (fixnum) a)) (list-of a
 (list= (#(procedure #:clean #:enforce) list= (#!optional (procedure (list 
list) *) #!rest list) boolean)
-- 
1.7.10.4

From 2f96ca6af2cfdb29b10dd00f656fa2a2f22f0e37 Mon Sep 17 00:00:00 2001
From: Evan Hanson ev...@foldling.org
Date: Sat, 16 Aug 2014 16:42:07 +1200
Subject: [PATCH 2/5] Walk nested pair types in special-cased scrutiny for
 list-ref/list-tail

Also, remove the unused ##sys#list-ref alias and its special case.

Fixes #759.
---
 library.scm   |1 -
 scrutinizer.scm   |   86 +++--
 tests/typematch-tests.scm |   16 +++--
 3 files changed, 65 insertions(+), 38 deletions(-)

diff --git a/library.scm b/library.scm
index 74980fb..fb85c86 100644
--- a/library.scm
+++ b/library.scm
@@ -4763,7 +4763,6 @@ EOF
 (define ##sys#list? list?)
 (define ##sys#null? null?)
 (define ##sys#map-n map)
-(define ##sys#list-ref list-ref)
 
 
 ;;; Promises:
diff --git a/scrutinizer.scm b/scrutinizer.scm
index c437933..c756067 100644
--- a/scrutinizer.scm
+++ b/scrutinizer.scm
@@ -2232,42 +2232,60 @@
   (define-special-case vector-ref vector-ref-result-type)
   (define-special-case ##sys#vector-ref vector-ref-result-type))
 
+
+;;; List-related special cases
+;
+; Preserve known element types for list-ref, list-tail.
+
 (let ()
-  (define (list-ref-result-type node args rtypes)
-(or (and-let* ((subs (node-subexpressions node))
-   ((= (length subs) 3))
-   (arg1 (walked-result (second args)))
-   ((pair? arg1))
-   ((eq? 'list (car arg1)))
-   (index (third subs))
-   ((eq? 'quote (node-class index)))
-   (val (first (node-parameters index)))
-   ((fixnum? val))
-   ((= val 0))  ;XXX could warn on failure (but needs 
location)
-   (( val (length (cdr arg1)
-  (list (list-ref (cdr arg1) val)))
-   rtypes))
-  (define-special-case list-ref list-ref-result-type)
-  (define-special-case ##sys#list-ref list-ref-result-type))
 
-(define-special-case list-tail
-  (lambda (node args rtypes)
-(or (and-let* ((subs (node-subexpressions node))
-   ((= (length subs) 3))
-   (arg1 (walked-result (second args)))
-   ((pair? arg1))
-   ((eq? 'list (car arg1)))
-   (index (third subs))
-   ((eq? 'quote (node-class index)))
-   (val (first (node-parameters index)))
-   ((fixnum? val))
-   ((= val 0))
-   ((= val (length (cdr arg1)   ;XXX could warn on 
failure (but needs location)
-  (let ((rest 

Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread Felix Winkelmann
From: Evan Hanson ev...@foldling.org
Subject: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases
Date: Tue, 9 Sep 2014 02:57:17 -0700

 Hi hackers,
 
 Here are some list-related scrutiny improvements. I started with pair
 walking for the scrutinizer's special cases to fix #759 (patch #2),
 which made adding special cases for drop  tail easy (#3). The other
 special cases (#4, #5) are basically just improving result type accuracy
 for make-list, make-vector and reverse, where possible.

Wow, cool. I have to try these patches out. But note that hardcoding
special cases for SRFI-1 procedures is moot, since these will be
thrown of the core system, sooner or later (or in other words: there
will be only internally used variants, possibly with less error
checking).


felix

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread John Cowan
Felix Winkelmann scripsit:

 Wow, cool. I have to try these patches out. But note that hardcoding
 special cases for SRFI-1 procedures is moot, since these will be
 thrown of the core system, sooner or later (or in other words: there
 will be only internally used variants, possibly with less error
 checking).

Eventually, there should be a way for eggs to add types to the scrutinizer
database through a public API of some kind.

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
You're a brave man! Go and break through the lines, and remember while
you're out there risking life and limb through shot and shell,
we'll be in here thinking what a sucker you are!--Rufus T. Firefly

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread Mario Domenech Goulart
Hi John,

On Tue, 9 Sep 2014 08:03:29 -0400 John Cowan co...@mercury.ccil.org wrote:

 Felix Winkelmann scripsit:

 Wow, cool. I have to try these patches out. But note that hardcoding
 special cases for SRFI-1 procedures is moot, since these will be
 thrown of the core system, sooner or later (or in other words: there
 will be only internally used variants, possibly with less error
 checking).

 Eventually, there should be a way for eggs to add types to the
 scrutinizer database through a public API of some kind.

If I understand correctly your comment, that's already supported
(http://wiki.call-cc.org/man/4/Types#using-type-information-in-extensions).

See the new eggs Felix created out of core code for examples
(binary-search, memory-mapped-files, object-evict and queues -- all in
svn).

Best wishes.
Mario
-- 
http://parenteses.org/mario

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread John Cowan
Mario Domenech Goulart scripsit:

 If I understand correctly your comment, that's already supported
 (http://wiki.call-cc.org/man/4/Types#using-type-information-in-extensions).

Thanks, that's helpful.  The trouble is that such a file is an internal
(not publicly documented, unstable) format.  So if I want to ship portable
code along with type information for Chicken, I have to:

1) insert the type declarations in the code

2) compile with the -emit-type-file option

3) strip out the declarations again

4) hope the .types file continues to work with new compiler releases

That's really intolerable.  I suppose if I confine myself to : and
define-type, then I could ship my code along with macros that turn them
into (begin).


-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
One art / There is / No less / No more
To do / All things / With sparks / Galore   --Douglas Hofstadter

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread Moritz Heidkamp
John Cowan co...@mercury.ccil.org writes:

 Thanks, that's helpful.  The trouble is that such a file is an internal
 (not publicly documented, unstable) format.  So if I want to ship portable
 code along with type information for Chicken, I have to:

 1) insert the type declarations in the code

 2) compile with the -emit-type-file option

 3) strip out the declarations again

 4) hope the .types file continues to work with new compiler releases

Wait, what? Why not just something like this:

  (cond-expand
(chicken
  (include chicken-type-decls.scm))
(else))


 That's really intolerable.  I suppose if I confine myself to : and
 define-type, then I could ship my code along with macros that turn them
 into (begin).

FTR, there is the type-stubs egg which defines those macros and some
more. It's purpose is to make code compatible with CHICKENS that didn't
yet have the type syntax but could be used for portability purposes,
too.

Moritz

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH 0/5] List scrutiny special cases

2014-09-09 Thread Evan Hanson
  Felix Winkelmann scripsit:
  Wow, cool. I have to try these patches out. But note that hardcoding
  special cases for SRFI-1 procedures is moot, since these will be
  thrown of the core system, sooner or later (or in other words: there
  will be only internally used variants, possibly with less error
  checking).

Yeah, I thought about that, but once the code was written I figured I'd
put it out there in any case (that's patches #1, #3 and #4). Maybe it'll
be possible to add them to the srfi-1 module when the time comes (either
as a hack or via some future extension to the API -- see below).

 On Tue, 9 Sep 2014 08:03:29 -0400 John Cowan co...@mercury.ccil.org wrote:
  Eventually, there should be a way for eggs to add types to the
  scrutinizer database through a public API of some kind.

There is in general, per Mario's response. However, the reason these are
special cases is because they're trying to preserve information in a
way that can't be expressed with the current type specification
language.

If you call `(reverse (list 1 #\2 3))`, it's clear that the resulting
type should be `(list string char fixnum)`. However, reverse has the
type `((list-of a) - (list-of a))`, so the resulting type will be
`(list-of (or fixnum char string))`. That information loss would be nice
to avoid, but in order to do so a specialization needs programmatic
access to the call's argument types. This is done behind the scenes for
a handful of procedures in the scrutinizer, hence special case.

I don't know what user-level provisions for this would look like.
(Thinking out loud now.) It'd be easiest if we allowed the user to
register a handler procedure at scrutiny time, but that's its own can of
worms. Otherwise, I think you'd have to eval something somewhere.

(: reverse (forall (a) ((list-of a) - (list-of a)))
   (((list . #(a))) ; capture part of the argument type as #(a)
((list [reverse #(a)])) ; refer to #(a) somehow in the result type
#(node)))   ; node = leave the original node unchanged

Evan

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers