guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 01/01: -Oresolve-free-vars pass gracefully handles faile


From: Andy Wingo
Subject: [Guile-commits] 01/01: -Oresolve-free-vars pass gracefully handles failed autoloads.
Date: Tue, 11 Jan 2022 15:33:02 -0500 (EST)

wingo pushed a commit to branch main
in repository guile.

commit 1148eb5051e4cbd211554e6a7992a9b9981b1f6f
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Tue Jan 11 21:24:42 2022 +0100

    -Oresolve-free-vars pass gracefully handles failed autoloads.
    
    * module/language/tree-il/resolve-free-vars.scm (make-resolver):
    Gracefully handle failed autoloads.
---
 module/language/tree-il/resolve-free-vars.scm | 36 ++++++++++++++++-----------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/module/language/tree-il/resolve-free-vars.scm 
b/module/language/tree-il/resolve-free-vars.scm
index 3d4eb2bb0..69ee55d9e 100644
--- a/module/language/tree-il/resolve-free-vars.scm
+++ b/module/language/tree-il/resolve-free-vars.scm
@@ -1,5 +1,5 @@
 ;;; Resolving free top-level references to modules
-;;; Copyright (C) 2021
+;;; Copyright (C) 2021-2022
 ;;;   Free Software Foundation, Inc.
 ;;;
 ;;; This library is free software: you can redistribute it and/or modify
@@ -51,20 +51,26 @@
   ;; So instead of using the source program to determine where a binding
   ;; comes from, we use the first-class module interface.
   (define (imported-resolver iface)
-    (let ((public-iface (resolve-interface (module-name iface))))
-      (if (eq? iface public-iface)
-          (lambda (name)
-            (and (module-variable iface name)
-                 (cons (module-name iface) name)))
-          (let ((by-var (make-hash-table)))
-            (module-for-each (lambda (name var)
-                               (hashq-set! by-var var name))
-                             public-iface)
-            (lambda (name)
-              (let ((var (module-variable iface name)))
-                (and var
-                     (cons (module-name iface)
-                           (hashq-ref by-var var)))))))))
+    (let ((by-var (make-hash-table)))
+      ;; When resolving a free variable, Guile visits all used modules
+      ;; to see if there is a binding.  If one of those imports is an
+      ;; autoload, it's possible that the autoload interface fails to
+      ;; load.  In that case Guile will issue a warning and consider the
+      ;; binding not found in that module.  Here we try to produce the
+      ;; same behavior at optimization time that we do at expand time
+      ;; that we would do at run time.
+      (false-if-exception
+       (let ((public-iface (resolve-interface (module-name iface))))
+         (module-for-each (lambda (name var)
+                            (hashq-set! by-var var name))
+                          public-iface))
+       #:warning "Failed to determine exported bindings from module ~a:\n"
+       (module-name iface))
+      (lambda (name)
+        (let ((var (module-variable iface name)))
+          (and var
+               (cons (module-name iface)
+                     (hashq-ref by-var var)))))))
 
   (define the-module (resolve-module mod))
   (define resolvers



reply via email to

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