[plt-dev] identifier-prune-lexical-context

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun May 17 08:58:50 EDT 2009

Could this be useful for contracts? It expands into a macro definition
and there are generally lots of irrelevant identifiers kept, I think.

You know -- this also makes me wonder if there could be a performance
debugging tool in there. Perhaps something that takes a syntax object
or a .zo file and inspects the information there much like the macro
stepper does, but counts the number of bindings at each subexpression


On Sun, May 17, 2009 at 7:33 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> [File under "obscure macrology" and "macro-expansion performance".]
> The `identifier-prune-lexical-context' function added in strips
> lexical information from an identifier if the information doesn't
> affect the identifier's binding (or, more generally, the binding of
> identifiers derived from a given list of symbols).
> There's also a derived `quote-syntax/prune' form, which is like
> `quote-syntax' on an identifier, but that prunes the lexical
> information from the identifier. Note that `(quote-syntax/prune id)' is
> different from `(identifier-prune-lexical-context (quote-syntax id))';
> the later would wait until the expression is evaluated to prune lexical
> information, while the former prunes it as the expression is expanded
> (so that the lexical information isn't kept in bytecode, etc.).
> You might wonder why irrelevant lexical information would be preserved
> in the first place. The reason is `datum->syntax': The macro system
> doesn't know whether lexical information will be transferred to some
> other datum, where that extra information could become relevant.
> Probably `datum->syntax' is too powerful an operation, but I don't know
> how to get rid of it. So, we've fought the excessive-information
> problem with a lot of encoding, caching, and lazy-initialization
> tricks. These tricks, however, fail for nested internal-definition
> contexts created by `package', especially when `define*'s are used
> within a package to create layers of bindings. I couldn't find new
> tricks that work well enough without a pruning hint from the
> programmer.
> Use `quote-syntax/prune' or `identifier-prune-lexical-context' to
> potentially reduce bytecode size when an identifier's context won't be
> transferred to other syntax objects --- or perhaps only to '#%top,
> which `quote-syntax/prune' excludes from pruning in addition to the
> identifier's symbol. Pruning probably is not worthwhile on a macro
> template, but it can be useful in the expansion of forms like
> `define-struct' and `package' that keep lists of identifiers.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-dev

Posted on the dev mailing list.