In Racket Mode I have a cache of fully expanded syntax. Some users of the cache need it to be "enriched", as done by expand
(as opposed to expand-syntax
).
In one case I want to "warm" the cache from a compiled load handler, which uses a compile handler, which expects un-enriched syntax (AFAICT) --- so I need to use expand-syntax
. The question is, for the cache, can I reuse some of that work done by expand-syntax
, i.e. avoid doing a whole other expand
from scratch?
-
One idea is
(expand (expand-syntax stx))
. This seems safest (?). The idea is thatexpand
will avoid expansion work per se (stx
is already fully expanded byexpand-syntax
). Butexpand
might need to navigate a huge fully-expanded syntax object (?). So probably I should thunk that, to do only if/as/when needed. This isn't terribly tricky, but it's a complication. -
I wonder if
(namespace-syntax-introduce (expand-syntax stx))
would suffice (and be faster, so no need to delay thunk etc.) On Slack someone pointed out thatexpand
is really(expand-syntax (namespace-syntax-introduce stx))
, not(namespace-syntax-introduce (expand-syntax stx))
. So this wouldn't be the same order. But does it matter? After all, this seems to be whateval
(as opposed toeval-syntax
) does, in case it gets un-enriched syntax fromexpand-syntax
. Can't I just do the same?
And so I have a commit ready that does the first thing, and "it works" (more testing needed). But I just wonder if I'm needlessly complicating it and the second thing (or some third way?) would suffice.