unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#15540: Circular module imports vs. #:select (2.0.9)
@ 2013-10-06 19:36 Ludovic Courtès
  2013-10-08 20:01 ` Ian Price
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ludovic Courtès @ 2013-10-06 19:36 UTC (permalink / raw)
  To: 15540

[-- Attachment #1: Type: text/plain, Size: 1108 bytes --]

Consider these two modules:

--8<---------------cut here---------------start------------->8---
(define-module (a) #:use-module (b) #:export (from-a))
(define from-a 1)
--8<---------------cut here---------------end--------------->8---

and:

--8<---------------cut here---------------start------------->8---
(define-module (b) #:use-module ((a) #:select (from-a)) #:export (from-b))
(define from-b 2)
--8<---------------cut here---------------end--------------->8---

This fails:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(a)
While executing meta-command:
ERROR: no binding `from-a' in module (a)
--8<---------------cut here---------------end--------------->8---

whereas this succeeds (starting from a fresh Guile):

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(b)
scheme@(guile-user)> from-b
$1 = 2
--8<---------------cut here---------------end--------------->8---

Problem is that ‘define-module*’ processes exports after imports.

What about a patch along these lines:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1545 bytes --]

diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index c825b35..24b8f4c 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -2872,11 +2872,8 @@ VALUE."
               (error "expected list of integers for version"))
           (set-module-version! module version)
           (set-module-version! (module-public-interface module) version)))
-    (let ((imports (resolve-imports imports)))
     (call-with-deferred-observers
      (lambda ()
-         (if (pair? imports)
-             (module-use-interfaces! module imports))
        (if (list-of valid-export? exports)
            (if (pair? exports)
                (module-export! module exports))
@@ -2885,6 +2882,9 @@ VALUE."
            (if (pair? replacements)
                (module-replace! module replacements))
            (error "expected replacements to be a list of symbols or symbol pairs"))
+       (let ((imports (resolve-imports module)))
+         (if (pair? imports)
+             (module-use-interfaces! module imports)))
        (if (list-of valid-export? re-exports)
            (if (pair? re-exports)
                (module-re-export! module re-exports))
@@ -2896,7 +2896,7 @@ VALUE."
        ;; handlers.
        (if (pair? duplicates)
            (let ((handlers (lookup-duplicates-handlers duplicates)))
-               (set-module-duplicates-handlers! module handlers))))))
+             (set-module-duplicates-handlers! module handlers)))))
 
     (if transformer
         (if (and (pair? transformer) (list-of symbol? transformer))

[-- Attachment #3: Type: text/plain, Size: 21 bytes --]


Thanks,
Ludo’.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#15540: Circular module imports vs. #:select (2.0.9)
  2013-10-06 19:36 bug#15540: Circular module imports vs. #:select (2.0.9) Ludovic Courtès
@ 2013-10-08 20:01 ` Ian Price
  2016-06-21 11:08 ` Andy Wingo
  2017-02-28 10:50 ` Andy Wingo
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Price @ 2013-10-08 20:01 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 15540


Looks fine to me. Maybe it's worth adding a comment to the source to
mention why we do it that way. And of course, a test so we don't break
it in the future. :)

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#15540: Circular module imports vs. #:select (2.0.9)
  2013-10-06 19:36 bug#15540: Circular module imports vs. #:select (2.0.9) Ludovic Courtès
  2013-10-08 20:01 ` Ian Price
@ 2016-06-21 11:08 ` Andy Wingo
  2017-02-28 10:50 ` Andy Wingo
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2016-06-21 11:08 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, 15540

Yes!

As Ian notes this needs a test case.  Some kind Guixer should fix up
this patch and send to Guile so that it lands before we release 2.0.12,
which should come any day now :-)

Andy


On Sun 06 Oct 2013 21:36, ludo@gnu.org (Ludovic Courtès) writes:

> Consider these two modules:
>
> (define-module (a) #:use-module (b) #:export (from-a))
> (define from-a 1)
>
> and:
>
> (define-module (b) #:use-module ((a) #:select (from-a)) #:export (from-b))
> (define from-b 2)
>
> This fails:
>
> scheme@(guile-user)> ,use(a)
> While executing meta-command:
> ERROR: no binding `from-a' in module (a)
>
> whereas this succeeds (starting from a fresh Guile):
>
> scheme@(guile-user)> ,use(b)
> scheme@(guile-user)> from-b
> $1 = 2
>
> Problem is that ‘define-module*’ processes exports after imports.
>
> What about a patch along these lines:
>
> diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
> index c825b35..24b8f4c 100644
> --- a/module/ice-9/boot-9.scm
> +++ b/module/ice-9/boot-9.scm
> @@ -2872,11 +2872,8 @@ VALUE."
>                (error "expected list of integers for version"))
>            (set-module-version! module version)
>            (set-module-version! (module-public-interface module) version)))
> -    (let ((imports (resolve-imports imports)))
>      (call-with-deferred-observers
>       (lambda ()
> -         (if (pair? imports)
> -             (module-use-interfaces! module imports))
>         (if (list-of valid-export? exports)
>             (if (pair? exports)
>                 (module-export! module exports))
> @@ -2885,6 +2882,9 @@ VALUE."
>             (if (pair? replacements)
>                 (module-replace! module replacements))
>             (error "expected replacements to be a list of symbols or symbol pairs"))
> +       (let ((imports (resolve-imports module)))
> +         (if (pair? imports)
> +             (module-use-interfaces! module imports)))
>         (if (list-of valid-export? re-exports)
>             (if (pair? re-exports)
>                 (module-re-export! module re-exports))
> @@ -2896,7 +2896,7 @@ VALUE."
>         ;; handlers.
>         (if (pair? duplicates)
>             (let ((handlers (lookup-duplicates-handlers duplicates)))
> -               (set-module-duplicates-handlers! module handlers))))))
> +             (set-module-duplicates-handlers! module handlers)))))
>  
>      (if transformer
>          (if (and (pair? transformer) (list-of symbol? transformer))
>
> Thanks,
> Ludo’.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#15540: Circular module imports vs. #:select (2.0.9)
  2013-10-06 19:36 bug#15540: Circular module imports vs. #:select (2.0.9) Ludovic Courtès
  2013-10-08 20:01 ` Ian Price
  2016-06-21 11:08 ` Andy Wingo
@ 2017-02-28 10:50 ` Andy Wingo
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2017-02-28 10:50 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 15540-done

On Sun 06 Oct 2013 21:36, ludo@gnu.org (Ludovic Courtès) writes:

> Consider these two modules:
>
> (define-module (a) #:use-module (b) #:export (from-a))
> (define from-a 1)
>
>
> and:
>
> (define-module (b) #:use-module ((a) #:select (from-a)) #:export (from-b))
> (define from-b 2)
>
>
> This fails:
>
> scheme@(guile-user)> ,use(a)
> While executing meta-command:
> ERROR: no binding `from-a' in module (a)
>
>
> whereas this succeeds (starting from a fresh Guile):
>
> scheme@(guile-user)> ,use(b)
> scheme@(guile-user)> from-b
> $1 = 2
>
> Problem is that ‘define-module*’ processes exports after imports.

Applied a version of your patch to master.  Making the test was quite
tricky!

Andy





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-28 10:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-06 19:36 bug#15540: Circular module imports vs. #:select (2.0.9) Ludovic Courtès
2013-10-08 20:01 ` Ian Price
2016-06-21 11:08 ` Andy Wingo
2017-02-28 10:50 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).