From 2b9828072991d6ab2441b1d24bc7108a011d9988 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 2 Sep 2008 13:54:43 +0000 Subject: [PATCH] fix module-path-index spec and use related to resolved module paths svn: r11523 --- .../reference/module-reflect.scrbl | 25 ++++++++++--------- collects/syntax/private/modcollapse-noctc.ss | 12 ++++++--- collects/tests/mzscheme/moddep.ss | 10 ++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/collects/scribblings/reference/module-reflect.scrbl b/collects/scribblings/reference/module-reflect.scrbl index beb1e59952..82a9426dca 100644 --- a/collects/scribblings/reference/module-reflect.scrbl +++ b/collects/scribblings/reference/module-reflect.scrbl @@ -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 diff --git a/collects/syntax/private/modcollapse-noctc.ss b/collects/syntax/private/modcollapse-noctc.ss index bd1957d79e..6149b9fe32 100644 --- a/collects/syntax/private/modcollapse-noctc.ss +++ b/collects/syntax/private/modcollapse-noctc.ss @@ -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 diff --git a/collects/tests/mzscheme/moddep.ss b/collects/tests/mzscheme/moddep.ss index 5b08a70c4d..99a173f59a 100644 --- a/collects/tests/mzscheme/moddep.ss +++ b/collects/tests/mzscheme/moddep.ss @@ -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")