chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] * scrutinizer.scm: Fix renaming issue with 'th


From: megane
Subject: [Chicken-hackers] [PATCH] * scrutinizer.scm: Fix renaming issue with 'the'
Date: Sun, 02 Dec 2018 18:02:21 +0200
User-agent: mu4e 1.0; emacs 25.1.1

Hello,

Here's a fix for #1563.

The problem was using the ##core#real-name property for type variables.
The er-macro-transformer would use that to undo the renaming.

Other way to fix this would be to rename type variables while
scrutinizing. This would involve calling simplify-type when walking 'the
and 'compiler-typecase, and when looking up types loaded from type
files.

I think this is a cleaner solution. The printing to user part can be
handled separately when printing the actual messages.

PS.
Personally I feel the best way to handle this would be to remove 'forall
altogether inside the scrutinizer and use, for example, a record for the
typevariables inside the types. For example:

(forall (a) (vector a)) would be converted to:

`(vector ,(make-type-variable 'a (generate-new-tv-id) #f))

The sole purpose of that 'a would be to use it to print the type for the
user.

This way we could get rid of the typeenv too.

The unification trail would have to be changed too. Turns out it's
enough to just push the type-variable record to the trail. When undoing
the unifications just grab a record from the trail and set the type to
#f.

If you have Norvig's book Paradigms of Artificial Intelligence
Programming, there's a short explanation of this in chapter 11.6
"Destructive Unification".

Regards

>From 049c0a7ebe6351377bff8e11c59a81a5da20eb14 Mon Sep 17 00:00:00 2001
From: megane <address@hidden>
Date: Sat, 1 Dec 2018 10:24:16 +0200
Subject: [PATCH] * scrutinizer.scm: Fix renaming issue with 'the'

The 'the macro calls check-and-validate-type which will eventually
call simplify-type on the type. simplify-type renames type variables
with gensym and sets the ##core#real-name property, perhaps because of
prettier messages for the user. Finally the 'the macro expander uses
the property to undo the renaming.

Fixes #1563

* scrutinizer.scm (simplify-type): Don't set the ##core#real-name
  property for renamed tvs

* tests/typematch-tests.scm: Add test

* tests/scrutiny.expected: update
---
 scrutinizer.scm           | 4 +---
 tests/scrutiny.expected   | 2 +-
 tests/typematch-tests.scm | 2 ++
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/scrutinizer.scm b/scrutinizer.scm
index bbc3b5a..ba4c180 100644
--- a/scrutinizer.scm
+++ b/scrutinizer.scm
@@ -1231,9 +1231,7 @@
                     (set! typeenv
                       (append (map (lambda (v)
                                      (let ((v (if (symbol? v) v (first v))))
-                                       (let ((v* (gensym v)))
-                                         (mark-variable v* '##core#real-name v)
-                                         (cons v v*))))
+                                       (cons v (gensym v))))
                                    typevars)
                               typeenv))
                     (set! constraints 
diff --git a/tests/scrutiny.expected b/tests/scrutiny.expected
index 665d700..e445ebb 100644
--- a/tests/scrutiny.expected
+++ b/tests/scrutiny.expected
@@ -40,7 +40,7 @@ Warning: at toplevel:
   (scrutiny-tests.scm:29) in procedure call to `scheme#+', expected argument 
#2 of type `number' but was given an argument of type `symbol'
 
 Warning: at toplevel:
-  assignment of value of type `fixnum' to toplevel variable `scheme#car' does 
not match declared type `(forall (a) (procedure scheme#car ((pair a *)) a))'
+  assignment of value of type `fixnum' to toplevel variable `scheme#car' does 
not match declared type `(forall (a335) (procedure scheme#car ((pair a335 *)) 
a335))'
 
 Warning: at toplevel:
   expected a single result in `let' binding of `g19', but received 2 results
diff --git a/tests/typematch-tests.scm b/tests/typematch-tests.scm
index 97b8328..e86ad58 100644
--- a/tests/typematch-tests.scm
+++ b/tests/typematch-tests.scm
@@ -399,6 +399,8 @@
   (length a) ; refine (or pair null) with list (= (list-of *))
   (infer list a))
 
+;; Issue #1563
+(compiler-typecase (the (forall (a) a) 1) ((forall (a) (list a)) 'ok))
 
 (assert
  (compiler-typecase 1
-- 
2.7.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]