florence / cover

a code coverage tool for racket
MIT License
38 stars 7 forks source link

Internal error on modules with the same `syntax-source` and non-identical expansions #128

Closed SuzanneSoy closed 7 years ago

SuzanneSoy commented 8 years ago

I'm using raco cover for most of my projects, and it is failing on this one:

https://github.com/jsmaniac/repltest/tree/30e68d3a2ca445a8399a4f144d4f438b48bd2ab1

See the travis logs: https://travis-ci.org/jsmaniac/repltest/jobs/152937538#L430

hash-ref: no value found for key
  key: '("/home/travis/build/jsmaniac/repltest/lang/reader.rkt" #f #f 590 6)
  context...:
   /home/travis/.racket/snapshot/pkgs/cover/cover/strace.rkt:93:2: test-coverage-point
   loop
   /home/travis/racket/share/pkgs/errortrace-lib/errortrace/stacktrace.rkt:408:7: try-next
   /home/travis/racket/share/pkgs/errortrace-lib/errortrace/stacktrace.rkt:403:4
   /home/travis/.racket/snapshot/pkgs/cover/cover/strace.rkt:44:4
   .../more-scheme.rkt:261:28
   /home/travis/build/jsmaniac/repltest/lang/reader.rkt:13:0
   standard-module-name-resolver
   /home/travis/.racket/snapshot/pkgs/cover/cover/cover.rkt:93:10: for-loop
   /home/travis/.racket/snapshot/pkgs/cover/cover/cover.rkt:110:4
   /home/travis/.racket/snapshot/pkgs/cover/cover/private/shared.rkt:34:0: with-intercepted-logging/receiver
   /home/travis/.racket/snapshot/pkgs/cover/cover/cover.rkt:73:0: test-files!9
   /home/travis/.racket/snapshot/pkgs/cover/cover/raco.rkt:83:4
   /home/travis/.racket/snapshot/pkgs/cover/cover/private/shared.rkt:28:0: with-intercepted-logging
   (submod /home/travis/.racket/snapshot/pkgs/cover/cover/raco.rkt main): [running body]
   /home/travis/racket/collects/raco/raco.rkt: [running body]
   ...

Given the key, I suspect the error is due to the eval statement – the evaluated expression starts at character 590 in the file:

https://github.com/jsmaniac/repltest/blob/30e68d3a2ca445a8399a4f144d4f438b48bd2ab1/lang/reader.rkt#L18

florence commented 8 years ago

The eval call isn't the only problem here. If you replace the eval call with:

(parameterize ([current-namespace 
                (variable-reference->namespace (#%variable-reference))])
  (expand #'orig-mod))

You get (roughly) the same error.

(syntax-source #'orig-mod) is "../repltest/lang/reader.rkt" regardless of the file being read, which confuses Cover. You can see this if you open tests/doc1.rkt and expand it in the macro stepper. (I think this is whats going on, I'm having trouble creating a small test case).

It will probably take me a little while to fix this, since I need to disentangle the eval issue from this syntax-source issue. But having the module have a different syntax-source than the actual file probably isn't what you want anyways. If you can fix this and replace the call to eval with the parameterize code above that should work around this issue.

When I manage to disentangle the eval issue from the syntax-source issue I'll

florence commented 8 years ago

(Notes for myself)

There are two things to be done to fix this:

1) Cover's internal mapping tables should be using module-path-indexes instead of file paths.

2) If an unknown syntax location is found during expansion of a previously initialized module cover should fall back to a slow path where it copies and grows the coverage vector to accommodate the new expansion.

SuzanneSoy commented 8 years ago

Thanks a lot for taking the time to track down this bug!

I applied the changes you suggested, and it seems to work find except for two issues:

florence commented 8 years ago

A few things might be going on with the debug issue: The namespace might be wrong (maybe make-base-namespace or namespace-anchor->namespace are the right things?) or maybe a namespace-syntax-introduce? Those are shots in the dark though.

This is probably a question for the mailing list, where wiser minds lurk.

florence commented 7 years ago

Fixed by 568823c and 13e3764.