racket / racket/racket

questions about local-expand and local-apply-transformer

Open
#2,212 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
5.2k
Forks
698
Avg merge
18h 34m
Merged PRs (30d)
5

Description

I found in racket 'expression is always used as the context argument of local-apply-tranformer, but, if I understand correctly, 'expression and 'top-level are excluded from generating use-site scopes for local-expand in racket 7
(from https://github.com/racket/racket/blob/41fd4f3a5e0c6d4ca0ef822b168bf33a5c9068a6/racket/src/expander/expand/definition-context.rkt#L245-L250 ).
This program(derived from #2069 ):

#lang racket

(module a racket
  (require (for-syntax racket/syntax))
  (provide use-expander)
  (define-syntax (use-expander stx)
    (syntax-case stx ()
      [(_ id arg)
       (let* ([intdef-ctx (syntax-local-make-definition-context #f #f)]
              [transformer-id (internal-definition-context-introduce
                               intdef-ctx
                               (generate-temporary 'a))])
         (syntax-local-bind-syntaxes
          (list transformer-id)
          #`(quote #,(syntax-local-value #'id))
          intdef-ctx)
         (local-expand #`(#,transformer-id arg) 'expression '() (list intdef-ctx)))])))

(require 'a)

(define x 1)

(define-syntax (expander1 stx)
  (syntax-case stx ()
    [(_ an-x)
     (begin
       (displayln (hash-ref (syntax-debug-info #'an-x) 'context))
       #'(let ([an-x 3])
           x))]))

(use-expander expander1 x)

produce

(#(60778 module) #(60785 module anonymous-module) #(61088 macro))
3

but in 6.12, there will be a use-site scope

(#(110355 module) #(110356 module anonymous-module 0) #(111968 macro) #(111969 use-site))
1

I'm not clear why the behavior is changed in the new expander. Is it intended?
If so, how to use local-apply-transformer or local-expand with internal-definition-context properly? Is generate-expand-context sufficient?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced definition-context.rkt section around lines 245–250 and the local-expand and local-apply-transformer entry points. Reproduce the supplied program on Racket 7 and 6.12, then inspect how internal-definition-context and generate-expand-context affect use-site scopes. Done means explaining whether the changed scope behavior is intentional and documenting the proper API usage.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.