cs: fix srcloc path conversion on load with no current-load-relative-directory

Fall back to `current-directory` when `current-load-relative-directory`
is #f.

This change also affects `deserialize` --- not because byte code
loading uses it directly in this case, but because they share a helper
function, which exposes the issue. This implementation change is
worrying (even though it makes the implementation match the
documentation), but unless we discover that some use of serialization
needs absolute paths deseialized as relative, is seems better to be
consistent everywhere about falling back to `currenrt-directory`. This
aspect of the change can be reverted separately (by adding more code)
if needed.

Closes racket/drracket#421
This commit is contained in:
Matthew Flatt 2020-09-18 13:52:02 -06:00
parent 1766cba6c6
commit 8f08a9ee5c
4 changed files with 11 additions and 8 deletions

View File

@ -593,14 +593,14 @@ not normally printed in a way that can be read back in, path literals
can be written and read as part of compiled code. The can be written and read as part of compiled code. The
@racket[current-write-relative-directory] parameter is used to convert @racket[current-write-relative-directory] parameter is used to convert
the path to a relative path as is it written, and then the path to a relative path as is it written, and then
@racket[current-load-relative-directory] parameter is used to convert @racket[current-load-relative-directory] parameter (falling back to
any relative path back as it is read. The relative-path conversion @racket[current-directory]) is used to convert
applies on reading whether the path was originally relative or not. any relative path back as it is read.
For a path in a syntax object's source, if the For a path in a syntax object's source, if the
@racket[current-load-relative-directory] parameter is not set of the @racket[current-write-relative-directory] parameter is not set or the
path is not relative to the value of the path is not relative to the value of the
@racket[current-load-relative-directory] parameter, then the path is @racket[current-write-relative-directory] parameter, then the path is
coerced to a string that preserves only part of the path (an in effort coerced to a string that preserves only part of the path (an in effort
to make it less tied to the build-time filesystem, which can be to make it less tied to the build-time filesystem, which can be
different than the run-time filesystem). different than the run-time filesystem).

View File

@ -717,7 +717,7 @@
(deserialize (serialize root #:relative-directory (build-path root "a")))) (deserialize (serialize root #:relative-directory (build-path root "a"))))
(test (test
(build-path 'same) (build-path (current-directory) 'same)
'this-dir-path 'this-dir-path
(parameterize ([current-load-relative-directory #f]) (parameterize ([current-load-relative-directory #f])
(deserialize (serialize (build-path root 'same) #:relative-directory root))))) (deserialize (serialize (build-path root 'same) #:relative-directory root)))))

View File

@ -4,7 +4,8 @@
make-path->relative-path-elements) make-path->relative-path-elements)
(define (relative-path-elements->path elems) (define (relative-path-elements->path elems)
(define wrt-dir (current-load-relative-directory)) (define wrt-dir (or (current-load-relative-directory)
(current-directory)))
(define rel-elems (for/list ([p (in-list elems)]) (define rel-elems (for/list ([p (in-list elems)])
(if (bytes? p) (bytes->path-element p) p))) (if (bytes? p) (bytes->path-element p) p)))
(cond (cond

View File

@ -48042,7 +48042,9 @@
(lambda (e_0) (xify_0 e_0 hash2610)))) (lambda (e_0) (xify_0 e_0 hash2610))))
(define relative-path-elements->path (define relative-path-elements->path
(lambda (elems_0) (lambda (elems_0)
(let ((wrt-dir_0 (current-load-relative-directory))) (let ((wrt-dir_0
(let ((or-part_0 (current-load-relative-directory)))
(if or-part_0 or-part_0 (current-directory)))))
(let ((rel-elems_0 (let ((rel-elems_0
(reverse$1 (reverse$1
(begin (begin