Opened 3 years ago

Last modified 15 months ago

#1145 assigned defect

Issue with matchable and the module system

Reported by: mario Owned by: sjamaan
Priority: major Milestone: someday
Component: extensions Version: 4.9.x
Keywords: matchable, module system Cc: ashinn
Estimated difficulty: hard

Description

Change History (14)

comment:1 Changed 3 years ago by mario

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

comment:2 Changed 3 years ago by sjamaan

  • Owner set to ashinn
  • Status changed from new to assigned

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.

comment:3 Changed 3 years ago by sjamaan

  • Component changed from unknown to extensions

comment:4 Changed 3 years ago by ashinn

The problem is unlikely directly in matchable, since it works on many other implementations.

comment:5 Changed 3 years ago by sjamaan

Have you tested my trivial test under other implementations? It's the following:

(match 'some-form
  ((or ('x a) ('y b))
   'a-macro)
  (else #f))

comment:6 Changed 3 years ago by ashinn

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.

comment:7 Changed 3 years ago by sjamaan

  • Owner changed from ashinn to sjamaan

OK, thanks. I'll take a another, closer look then!

comment:8 Changed 3 years ago by sjamaan

  • Component changed from extensions to expander

comment:9 Changed 2 years ago by sjamaan

  • Milestone changed from someday to 4.11.0

OK, I never took a look at it; let's move it up to the 4.11 milestone

comment:10 Changed 2 years ago by sjamaan

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.

comment:11 Changed 2 years ago by sjamaan

I don't know how to make Matchable work under Scheme48

comment:12 Changed 2 years ago by sjamaan

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:

[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.

comment:13 Changed 2 years ago by sjamaan

  • Component changed from expander to extensions
  • Milestone changed from 4.11.0 to someday

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".

comment:14 Changed 15 months ago by sjamaan

  • Estimated difficulty set to hard
Note: See TracTickets for help on using tickets.