fix compilation manager for machine-independent conversion

When recompiling modules from machine-independent mode to
machine-specific mode, dependencies of the module to be recompiled
must be checked explicitly, but using `module-path-index-resolve` is
not a good strategy, because it doesn't load transitive dependencies.
That can create a failure later when a transitive dependency is needed
for compilation and it isn't loaded because the dependent module was
already loaded.

Relevant to #2928
This commit is contained in:
Matthew Flatt 2019-12-19 17:35:22 -07:00
parent 6a023cddfa
commit 53d7387f6c

View File

@ -432,7 +432,10 @@
#:assume-compiled-sha1 (and recompile-from-exists? #:assume-compiled-sha1 (and recompile-from-exists?
(force assume-compiled-sha1)) (force assume-compiled-sha1))
#:use-existing-deps (and recompile-from-exists? #:use-existing-deps (and recompile-from-exists?
use-existing-deps))) use-existing-deps)
#:compile-dependency
(lambda (path)
(compile-root path->mode roots path up-to-date collection-cache read-src-syntax seen))))
(trace-printf "~acompiled ~a" (if recompile-from-exists? "re" "") actual-path)]))) (trace-printf "~acompiled ~a" (if recompile-from-exists? "re" "") actual-path)])))
(lambda () (lambda ()
(log-compile-event path (if (or (not lc) locked?) (log-compile-event path (if (or (not lc) locked?)
@ -548,7 +551,8 @@
up-to-date collection-cache up-to-date collection-cache
#:recompile-from recompile-from #:recompile-from recompile-from
#:assume-compiled-sha1 assume-compiled-sha1 #:assume-compiled-sha1 assume-compiled-sha1
#:use-existing-deps use-existing-deps) #:use-existing-deps use-existing-deps
#:compile-dependency compile-dependency)
(when (and (not recompile-from) (when (and (not recompile-from)
(managed-recompile-only)) (managed-recompile-only))
(error 'compile-zo (error 'compile-zo
@ -563,7 +567,8 @@
(compile-zo* path->mode (list target-root) path src-sha1 read-src-syntax #f up-to-date collection-cache (compile-zo* path->mode (list target-root) path src-sha1 read-src-syntax #f up-to-date collection-cache
#:recompile-from recompile-from #:recompile-from recompile-from
#:assume-compiled-sha1 assume-compiled-sha1 #:assume-compiled-sha1 assume-compiled-sha1
#:use-existing-deps use-existing-deps)) #:use-existing-deps use-existing-deps
#:compile-dependency compile-dependency))
(define mi-dep-path (path-replace-extension mi-zo-name #".dep")) (define mi-dep-path (path-replace-extension mi-zo-name #".dep"))
(define mi-deps (call-with-input-file* mi-dep-path read)) (define mi-deps (call-with-input-file* mi-dep-path read))
(define mi-sha1 (or (deps-assume-compiled-sha1 mi-deps) (define mi-sha1 (or (deps-assume-compiled-sha1 mi-deps)
@ -574,21 +579,24 @@
(compile-zo* path->mode (list running-root) path src-sha1 read-src-syntax #f up-to-date collection-cache (compile-zo* path->mode (list running-root) path src-sha1 read-src-syntax #f up-to-date collection-cache
#:recompile-from mi-zo-name #:recompile-from mi-zo-name
#:assume-compiled-sha1 mi-sha1 #:assume-compiled-sha1 mi-sha1
#:use-existing-deps mi-deps))) #:use-existing-deps mi-deps
#:compile-dependency compile-dependency)))
(when (cross-system-type 'target-machine) (when (cross-system-type 'target-machine)
;; Recompile to cross-compile target form: ;; Recompile to cross-compile target form:
(parameterize ([current-compile-target-machine (cross-system-type 'target-machine)]) (parameterize ([current-compile-target-machine (cross-system-type 'target-machine)])
(compile-zo* path->mode (list target-root) path src-sha1 read-src-syntax #f up-to-date collection-cache (compile-zo* path->mode (list target-root) path src-sha1 read-src-syntax #f up-to-date collection-cache
#:recompile-from mi-zo-name #:recompile-from mi-zo-name
#:assume-compiled-sha1 mi-sha1 #:assume-compiled-sha1 mi-sha1
#:use-existing-deps mi-deps))) #:use-existing-deps mi-deps
#:compile-dependency compile-dependency)))
running-zo] running-zo]
[else [else
;; Regular mode, just [re]compile: ;; Regular mode, just [re]compile:
(compile-zo* path->mode roots path src-sha1 read-src-syntax orig-zo-name up-to-date collection-cache (compile-zo* path->mode roots path src-sha1 read-src-syntax orig-zo-name up-to-date collection-cache
#:recompile-from recompile-from #:recompile-from recompile-from
#:assume-compiled-sha1 assume-compiled-sha1 #:assume-compiled-sha1 assume-compiled-sha1
#:use-existing-deps use-existing-deps)])) #:use-existing-deps use-existing-deps
#:compile-dependency compile-dependency)]))
;; For communication within `compile-zo*`: ;; For communication within `compile-zo*`:
(define-struct ext-reader-guard (proc top) (define-struct ext-reader-guard (proc top)
@ -600,7 +608,8 @@
(define (compile-zo* path->mode roots path src-sha1 read-src-syntax orig-zo-name up-to-date collection-cache (define (compile-zo* path->mode roots path src-sha1 read-src-syntax orig-zo-name up-to-date collection-cache
#:recompile-from recompile-from #:recompile-from recompile-from
#:assume-compiled-sha1 assume-compiled-sha1 #:assume-compiled-sha1 assume-compiled-sha1
#:use-existing-deps use-existing-deps) #:use-existing-deps use-existing-deps
#:compile-dependency compile-dependency)
;; The `path' argument has been converted to .rkt or .ss form, ;; The `path' argument has been converted to .rkt or .ss form,
;; as appropriate. ;; as appropriate.
;; External dependencies registered through reader guard and ;; External dependencies registered through reader guard and
@ -682,13 +691,15 @@
;; We don't actually need to do anything, so ;; We don't actually need to do anything, so
;; avoid updating the file. ;; avoid updating the file.
(check-recompile-module-dependencies use-existing-deps (check-recompile-module-dependencies use-existing-deps
collection-cache) collection-cache
compile-dependency)
#f] #f]
[recompile-from [recompile-from
(recompile-module-code recompile-from (recompile-module-code recompile-from
path path
use-existing-deps use-existing-deps
collection-cache)] collection-cache
compile-dependency)]
[else [else
(get-module-code path (path->mode path) compile (get-module-code path (path->mode path) compile
#:choose (lambda (src zo so) 'src) #:choose (lambda (src zo so) 'src)
@ -776,8 +787,8 @@
zo-name) zo-name)
;; Recompile an individual file ;; Recompile an individual file
(define (recompile-module-code recompile-from src-path deps collection-cache) (define (recompile-module-code recompile-from src-path deps collection-cache compile-dependency)
(check-recompile-module-dependencies deps collection-cache) (check-recompile-module-dependencies deps collection-cache compile-dependency)
;; Recompile the module: ;; Recompile the module:
(define-values (base name dir?) (split-path src-path)) (define-values (base name dir?) (split-path src-path))
(parameterize ([current-load-relative-directory (parameterize ([current-load-relative-directory
@ -924,11 +935,11 @@
;; Force potential recompilation of dependencies. Otherwise, we ;; Force potential recompilation of dependencies. Otherwise, we
;; end up relying on cross-module optimization demands, which might ;; end up relying on cross-module optimization demands, which might
;; not happen and are unlikely to cover everything. ;; not happen and are unlikely to cover everything.
(define (check-recompile-module-dependencies deps collection-cache) (define (check-recompile-module-dependencies deps collection-cache compile-dependency)
(for ([d (in-list (deps-imports deps))] (for ([d (in-list (deps-imports deps))]
#:unless (external-dep? d)) #:unless (external-dep? d))
(define path (collects-relative*->path (dep->encoded-path d) collection-cache)) (define path (collects-relative*->path (dep->encoded-path d) collection-cache))
(module-path-index-resolve (module-path-index-join path #f) #t))) (compile-dependency path)))
;; Gets a multi-sha1 string that represents the compiled code ;; Gets a multi-sha1 string that represents the compiled code
;; as well as its dependencies: ;; as well as its dependencies: