fix module-path-index spec and use related to resolved module paths

svn: r11523
This commit is contained in:
Matthew Flatt 2008-09-02 13:54:43 +00:00
parent 300d1361a1
commit 2b98280729
3 changed files with 32 additions and 15 deletions

View File

@ -154,20 +154,21 @@ the form of a @deftech{module path index}. A @tech{module path index}
is a semi-interned (multiple references to the same relative module
tend to use the same @tech{module path index} value, but not always)
opaque value that encodes a module path (see @scheme[module-path?])
and another @tech{module path index} to which it is relative.
and either a @tech{resolved module path} or another @tech{module path
index} to which it is relative.
A @tech{module path index} that uses both @scheme[#f] for its path and
base @tech{module path index} represents ``self''---i.e., the module
declaration that was the source of the @tech{module path index}---and
such a @tech{module path index} is always used as the root for a chain
of @tech{module path index}. For example, when extracting information
about an identifier's binding within a module, if the identifier is
bound by a definition within the same module, the identifier's source
module is reported using the ``self'' @tech{module path index}. If the
identifier is instead defined in a module that is imported via a
module path (as opposed to a literal module name), then the
identifier's source module will be reported using a @tech{module path
index} that contains the @scheme[require]d module path and the
such a @tech{module path index} can be used as the root for a chain of
@tech{module path index}es at compile time. For example, when
extracting information about an identifier's binding within a module,
if the identifier is bound by a definition within the same module, the
identifier's source module is reported using the ``self'' @tech{module
path index}. If the identifier is instead defined in a module that is
imported via a module path (as opposed to a literal module name), then
the identifier's source module will be reported using a @tech{module
path index} that contains the @scheme[require]d module path and the
``self'' @tech{module path index}.
@ -204,7 +205,7 @@ resolved name can depend on the value of
@defproc[(module-path-index-split [mpi module-path-index?])
(values (or/c module-path? false/c)
(or/c module-path-index? false/c))]{
(or/c module-path-index? resolved-module-path? false/c))]{
Returns two values: a module path, and a base @tech{module path index}
or @scheme[#f] to which the module path is relative.
@ -219,7 +220,7 @@ second result, and means that @scheme[mpi] represents ``self'' (see
above).}
@defproc[(module-path-index-join [path (or/c module-path? false/c)]
[mpi (or/c module-path-index? false/c)])
[mpi (or/c module-path-index? resolved-module-path? false/c)])
module-path-index?]{
Combines @scheme[path] and @scheme[mpi] to create a new @tech{module

View File

@ -263,9 +263,15 @@ Use syntax/modcollapse instead.
(if path
(collapse-module-path
path
(if base
(collapse-module-path-index base relto-mp)
relto-mp))
(cond
[(module-path-index? base)
(collapse-module-path-index base relto-mp)]
[(resolved-module-path? base)
(let ([n (resolved-module-path-name base)])
(if (path? n)
n
relto-mp))]
[else relto-mp]))
relto-mp)))
(provide collapse-module-path

View File

@ -128,6 +128,16 @@
(test-cmp (build-path 'same "x.ss") "x.ss" (build-path 'same))
(test '(lib "bar/foo.ss")
collapse-module-path-index
(module-path-index-join '(lib "foo.ss" "bar") (make-resolved-module-path 'nowhere))
(current-directory))
(test (build-path (find-system-path 'temp-dir) "data.ss")
collapse-module-path-index
(module-path-index-join '"data.ss" (make-resolved-module-path
(build-path (find-system-path 'temp-dir) "prog.ss")))
(current-directory))
;; Try path cases that don't fit UTF-8 (and therefore would go wrong as a string):
(let ([dir (build-path (current-directory) (bytes->path #"\xFF"))])
(test-cmp (build-path dir "x.ss")