racket/enter: another submodule repair

When a submodule is required from the load handler and no such
module is available, the load handler is not supposed to raise
an exception.
This commit is contained in:
Matthew Flatt 2013-02-14 19:44:03 -07:00
parent b22ac3b990
commit 6a218e196a

View File

@ -15,6 +15,8 @@
(define orig-namespace (current-namespace)) (define orig-namespace (current-namespace))
(define-logger enter!)
(define (check-flags flags) (define (check-flags flags)
;; check that all flags are known, that at most one of the noise flags is ;; check that all flags are known, that at most one of the noise flags is
;; present, and add #:verbose-reload if none are (could be done at the macro ;; present, and add #:verbose-reload if none are (could be done at the macro
@ -34,7 +36,8 @@
(let ([flags (check-flags flags)]) (let ([flags (check-flags flags)])
(if mod (if mod
(let* ([none "none"] (let* ([none "none"]
[exn (with-handlers ([void values]) [exn (with-handlers ([void (lambda (exn)
(log-enter!-error "~a" (exn-message exn)))])
(enter-require mod flags) (enter-require mod flags)
none)] none)]
[ns (module->namespace mod)]) [ns (module->namespace mod)])
@ -67,28 +70,35 @@
(if (and name (if (and name
(not (and (pair? name) (not (and (pair? name)
(not (car name))))) (not (car name)))))
;; Module load: ;; Module load:
(let* ([code (get-module-code (with-handlers ([(lambda (exn)
path "compiled" (and (pair? name)
(lambda (e) (exn:get-module-code? exn)))
(parameterize ([compile-enforce-module-constants #f]) (lambda (exn)
(compile e))) ;; Load-handler protocol: quiet failure when a
(lambda (ext loader?) (load-extension ext) #f) ;; submodule is not found
#:notify notify)] (void))])
[dir (or (current-load-relative-directory) (current-directory))] (let* ([code (get-module-code
[path (path->complete-path path dir)] path "compiled"
[path (normal-case-path (simplify-path path))]) (lambda (e)
;; Record module timestamp and dependencies: (parameterize ([compile-enforce-module-constants #f])
(define-values (ts actual-path) (get-timestamp path)) (compile e)))
(let ([a-mod (mod name (lambda (ext loader?) (load-extension ext) #f)
ts #:notify notify)]
(if code [dir (or (current-load-relative-directory) (current-directory))]
(append-map cdr (module-compiled-imports code)) [path (path->complete-path path dir)]
null))]) [path (normal-case-path (simplify-path path))])
(hash-set! loaded path a-mod)) ;; Record module timestamp and dependencies:
;; Evaluate the module: (define-values (ts actual-path) (get-timestamp path))
(parameterize ([current-module-declare-source actual-path]) (let ([a-mod (mod name
(eval code))) ts
(if code
(append-map cdr (module-compiled-imports code))
null))])
(hash-set! loaded path a-mod))
;; Evaluate the module:
(parameterize ([current-module-declare-source actual-path])
(eval code))))
;; Not a module, or a submodule that we shouldn't load from source: ;; Not a module, or a submodule that we shouldn't load from source:
(begin (notify path) (orig path name))))) (begin (notify path) (orig path name)))))