[racket] module-path-index and self-paths

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Wed May 11 00:26:01 EDT 2011

I'm trying to trace down a bug in my code down to a user of
module-path-index-resolve.  I'm somehow getting a hold of a
module-path-index with the following structure:

    (module-path-index-join "private/base.rkt"
                                      (module-path-index-join #f #f))

When given this, module-path-index-resolve errors out and says:

    module-path-index-resolve: "self" index has no resolution:

I'm trying to figure out if I'm misusing module-path-index-resolve.  I
am getting this particular module path index by zo-parsing
collects/racket/base.rkt and looking into its phase-0 requires.

Here is code to demonstrate where the value is coming from:

#lang racket
(require racket/match

(define (run-zo-parse path)
  (parameterize ([current-namespace (make-base-namespace)]
                 [read-accept-reader #t]
                  (let-values ([(base file is-dir)
                                (split-path path)])
    (let ([bc (compile (read (open-input-file path)))]
          [op (open-output-bytes)])
      (write bc op)
      (zo-parse (open-input-bytes (get-output-bytes op))))))

;; Splits up a module path index into its components.
(define (explode-module-path-index mpi)
  (let-values ([(x y) (module-path-index-split mpi)])
      [(module-path-index? y)
       (cons x (explode-module-path-index y))]
       (list x y)])))

(match (run-zo-parse (build-path (find-system-path 'collects-dir)
  [(struct compilation-top (_
                            (struct mod (_ _ _ _ _ requires _ _ _ _ _ _ _))))
   (for ([phase-and-paths requires])
     (when (equal? (car phase-and-paths) 0)
       (displayln (map explode-module-path-index (cdr phase-and-paths)))))])

The second element in the list value that displays:

    ((racket/private/pre-base #f) (private/base.rkt #f #f))

is the module-path-index that I don't quite know how to resolve into a
nice resolved-module-path.

Posted on the users mailing list.