Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling a module that refers to a binding created by a use of local-expand in a 'module-begin context causes an unhelpful internal error #2458

Closed
lexi-lambda opened this issue Feb 3, 2019 · 2 comments
Labels
macro system Expander, Syntax Parse, other #lang racket macros

Comments

@lexi-lambda
Copy link
Member

Here’s a Racket program:

#lang racket

(begin-for-syntax
  (local-expand
   #'(#%plain-module-begin
      (begin-for-syntax
        (define x 42)))
   'module-begin
   '()))

(begin-for-syntax
  (println x))

This program is arguably evil, I’m not sure, but whether it is or it isn’t, it currently fails with a pretty unhelpful error if you try to run it:

$ racket modbeg-effects.rkt
42
hash-ref: no value found for key
  key: 'x

Curiously, the error does not occur during expansion, since raco expand expands the module happily, without errors:

$ raco expand modbeg-effects.rkt
42
(module modbeg-effects racket
  (#%module-begin
   (module configure-runtime '#%kernel
     (#%module-begin (#%require racket/runtime-config) (#%app configure '#f)))
   (begin-for-syntax
    (#%app
     local-expand
     (quote-syntax (#%plain-module-begin (begin-for-syntax (define x 42))))
     'module-begin
     '()))
   (begin-for-syntax (#%app println x))))

However, the error is a compile-time error, not a runtime error, since it fails if the program is compiled with raco make:

$ raco make modbeg-effects.rkt
42
hash-ref: no value found for key
  key: 'x
  compilation context...:
   /private/tmp/modbeg-effects.rkt
@mflatt mflatt closed this as completed in f80c71e Feb 25, 2019
@mflatt
Copy link
Member

mflatt commented Feb 25, 2019

Thanks for the report!

@lexi-lambda
Copy link
Member Author

Thank you for the fix!

pmatos pushed a commit to pmatos/racket that referenced this issue Feb 28, 2019
Avoids internal errors (including unsafe behavior) in an example like

```
  #lang racket

  (begin-for-syntax
    (local-expand
     #'(#%plain-module-begin
        (begin-for-syntax
          (define x 42)))
     'module-begin
     '()))

  (begin-for-syntax
    (println x))
```

This example is weird, because it creates an `x` binding that doesn't
survive to the full expansion. Before the repair, the disappearing
binding created trouble for the expanded-to-linklet pass.

The example is weird for a second reason, which is that it uses uses
`local-expand` in a place where it will be triggered by visiting the
module. It turns out that raising a syntax error at that time (from
`#%plain-module-begin`) did not work correctly due to lazy
instantiation of the expansion context.

Closes racket#2458
@shhyou shhyou added the macro system Expander, Syntax Parse, other #lang racket macros label Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macro system Expander, Syntax Parse, other #lang racket macros
Projects
None yet
Development

No branches or pull requests

3 participants