Bytecode problem with fxvector inside a macro

41 views
Skip to first unread message

Dmitry Pavlov

unread,
May 8, 2019, 3:54:56 PM5/8/19
to Racket Users
Hello,

I would like to report something that I see as
inconsistent behavior of the bytecode compiler.
The following short program (an artificial minimal
reproducible example) works at first, but fails
after raco make. My OS is Linux.



$ cat one.rkt
#lang racket

(require (for-syntax syntax/parse racket/fixnum))

(define-syntax (macro stx)
(syntax-parse stx
(({~literal macro})
(let ((v (fxvector 5)))
(with-syntax ((v v))
(quasisyntax/loc stx
(begin
(define v-name v)
'OK)))))))

(macro)

$ racket one.rkt
'OK

$ raco make one.rkt

$ racket one.rkt
read: bad syntax `#fx'
in: compiled/one_rkt.zo
context...:
read-linklet-or-directory
read-dispatch
read
default-load-handler
standard-module-name-resolver
module-path-index-resolve
[repeats 1 more time]
module-declared?


$ racket -v
Welcome to Racket v7.2.


Best regards,

Dmitry

Matthew Flatt

unread,
May 8, 2019, 4:09:07 PM5/8/19
to Dmitry Pavlov, Racket Users
The intended error here is "cannot marshal value that is embedded in
compiled code" at `raco make` time, because fxvectors are not supported
as literals. I'll fix the bytecode writer to check for this case.

Meanwhile, the fact that non-literal values can be coerced to syntax
(as long as they don't have to be marshaled) is troublesome, but it's
useful enough in interactive situations that we haven't yet committed
to closing the loophole.
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/c8d25d54-e69e-ba45-9e78-4bd8366f
> a51f%40iaaras.ru.
> For more options, visit https://groups.google.com/d/optout.

Dmitry Pavlov

unread,
May 8, 2019, 5:04:43 PM5/8/19
to Matthew Flatt, Racket Users
Matthew,


> The intended error here is "cannot marshal value that is embedded in
> compiled code" at `raco make` time, because fxvectors are not supported
> as literals. I'll fix the bytecode writer to check for this case.

OK, thank you. What would you recommend, though, to users who want fxvectors (of "static" kind) to be generated by macros?
Populating fxvectors in runtime will be a loss of performance, maybe not critical, but noticeable.

Best regards,

Dmitry


Dmitry Pavlov

unread,
May 8, 2019, 5:15:47 PM5/8/19
to Matthew Flatt, Racket Users
Ah, I see

#lang racket

(require (for-syntax syntax/parse))
(require  racket/fixnum)

(define-syntax (macro stx)
  (syntax-parse stx
    (({~literal macro})
     (quasisyntax/loc stx
       (begin
         (define v-name (fxvector 5))
         'OK)))))

(macro)


So I should put fxvector non-literals inside the syntax, and everything will be fine.


Best regards,

Dmitry


Matthew Flatt

unread,
May 8, 2019, 5:27:18 PM5/8/19
to Dmitry Pavlov, Racket Users
Yes. Or if the macro is used in a potentially nested expression context
and you want to make sure that the fxvector is created once, you can
use `syntax-local-lift-expression`.

Reply all
Reply to author
Forward
0 new messages