Summary
Issue with matchable and the module system
Metadata
- Id: 07640ce45130e72e19931d74e22bb8dfbe3411b5
- Trac id: 1145
- Type: defect
- Reporter: mario
- Owner: sjamaan
- Cc: ashinn
- Status: assigned
- Component: extensions
- Estimated difficulty: hard
- Resolution:
- Priority: major
- Milestone: someday
- Version: 4.9.x
- Changetime: 2016-08-25 21:36:06 UTC
- Created: 2014-08-05 16:15:36 UTC
- Keywords: matchable, module system
Description
Here are some cases that illustrate the problem: http://paste.call-cc.org/paste?id=4d676dd966a3e3c5b5a3d216014d07a7fa746c6f
Changes and comments
[2014-08-05 16:34:08 UTC] mario wrote:
Peter commented on IRC:
<sjamaan> mario-goulart: I believe the problem lies in the match-gen-or-step, fk2 receives only q,
whereas g+s contain getters and setters for both q and p; so p is not in scope
<sjamaan> The getters and setters should probably be generated in match-one. I'm not 100% sure
though
[2014-08-05 16:36:17 UTC] sjamaan changed status from new to assigned
[2014-08-05 16:36:17 UTC] sjamaan set owner to ashinn
[2014-08-05 16:36:17 UTC] sjamaan wrote:
I believe this is an issue in the expansion of the matchable macro. ie, it's a bug in the egg, not in the expander or module system.
[2014-08-05 16:36:40 UTC] sjamaan changed component from unknown to extensions
[2014-08-05 16:39:36 UTC] ashinn wrote:
The problem is unlikely directly in matchable, since it works on many other implementations.
[2014-08-05 16:44:17 UTC] sjamaan wrote:
Have you tested my trivial test under other implementations? It's the following:
#!scm
(match 'some-form
((or ('x a) ('y b))
'a-macro)
(else #f))
[2014-08-05 16:48:48 UTC] ashinn wrote:
Yes, I test that and variations under chibi and scheme48 (which is about as strict as you get), and couldn't find any errors. The test suite also already has similar cases.
Mario's example that fails depending on the imports suggests it's definitely an interaction with Chicken's module system and/or expander.
[2014-08-05 16:52:26 UTC] sjamaan wrote:
OK, thanks. I'll take a another, closer look then!
[2014-08-05 16:52:26 UTC] sjamaan changed owner from ashinn to sjamaan
[2014-08-05 16:52:32 UTC] sjamaan changed component from extensions to expander
[2015-08-27 09:06:15 UTC] sjamaan changed milestone from someday to 4.11.0
[2015-08-27 09:06:15 UTC] sjamaan wrote:
OK, I never took a look at it; let's move it up to the 4.11 milestone
[2015-11-20 13:50:50 UTC] sjamaan wrote:
Alex, I tried it under Chibi just now, and it seems to indicate the bug really is in matchable:
$ ./chibi-scheme
> (import (chibi match))
> (match 'some-form
((or ('x a) ('y b))
'a-macro)
(else #f))
WARNING: reference to undefined variable: a
WARNING: reference to undefined variable: b
#f
So this seems exactly the same message that CHICKEN gives, except in CHICKEN, a module can't be resolved when you have undefined variables.
[2015-11-20 13:52:00 UTC] sjamaan wrote:
I don't know how to make Matchable work under Scheme48
[2015-11-20 13:58:05 UTC] sjamaan wrote:
If you want to debug this, see the generated source, you can try putting the match expression outside of a module, and then compile with csc -debug 2 test.scm. It will output something like:
#!scm
[canonicalized]
(##core#callunit "library")
(##core#callunit "eval")
(##core#callunit "chicken_2dsyntax")
(##core#undefined)
(let ((t11 (let ((t10 (##sys#require 'matchable))) (##core#undefined))))
(##core#undefined))
(let ((v1316 'some-form))
(let ((failure1927
(##core#lambda
()
(let ((failure3038
(##core#lambda () (error 'match '"no matching pattern"))))
(let ((else97 v1316)) '#f)))))
(let ((sk2587591 (##core#lambda (b592 a593) 'a-macro)))
(let ((fk2595599
(##core#lambda
()
(if (pair? v1316)
(let ((w680687 (car v1316)) (x682688 (cdr v1316)))
(if (equal? w680687 'y)
(if (if (pair? x682688) (null? (cdr x682688)) '#f)
(let ((w770775 (car x682688)))
;; The "a" in the expression below is clearly unbound
(let ((b831 w770775)) (sk2587591 b831 a)))
(failure1927))
(failure1927)))
(failure1927)))))
(if (pair? v1316)
(let ((w911918 (car v1316)) (x913919 (cdr v1316)))
(if (equal? w911918 'x)
(if (if (pair? x913919) (null? (cdr x913919)) '#f)
(let ((w10011006 (car x913919)))
;; The "b" in the expression below is clearly unbound
(let ((a1062 w10011006)) (sk2587591 b a1062)))
(fk2595599))
(fk2595599)))
(fk2595599))))))
((##sys#implicit-exit-handler))
(##core#undefined)
There's a bit of a problem with CHICKEN in that it bails out early when a module is unresolved, so you can't see exactly how it's compiled inside a module, but I think the problem is clear in the code above, where I put the comments.
[2015-11-20 19:18:37 UTC] sjamaan changed component from expander to extensions
[2015-11-20 19:18:37 UTC] sjamaan changed milestone from 4.11.0 to someday
[2015-11-20 19:18:37 UTC] sjamaan wrote:
After pointing this out to Alex on IRC, he agreed that it's a problem with the code emitted by matchable, not so much with CHICKEN itself. Moving this to "someday" and "extensions".