-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Expand docs for the first arg to syntax-local-make-definition-context #2043
Expand docs for the first arg to syntax-local-make-definition-context #2043
Conversation
As far as I can tell, this is correct and a great improvement. |
I’m pretty certain it’s wrong. The reason I’m bugging you with so many questions on slack is figuring out exactly what the right thing to say is. :) This program demonstrates why this PR is incorrect: #lang racket
(begin-for-syntax
(define x-id #'x)
(define y-id #'y)
(define intdef-ctx-a (syntax-local-make-definition-context))
(syntax-local-bind-syntaxes (list x-id) #'(make-rename-transformer #'values) intdef-ctx-a)
(define intdef-ctx-b (syntax-local-make-definition-context intdef-ctx-a))
(syntax-local-bind-syntaxes (list y-id) #`(make-rename-transformer #'#,x-id) intdef-ctx-b)
(println (local-expand y-id 'expression '() intdef-ctx-b)))
This modified program does not produce any errors: #lang racket
(begin-for-syntax
(define x-id #'x)
(define y-id #'y)
(define intdef-ctx-a (syntax-local-make-definition-context))
(syntax-local-bind-syntaxes (list x-id) #'(make-rename-transformer #'values) intdef-ctx-a)
(define intdef-ctx-b (syntax-local-make-definition-context))
(define x_a-id (internal-definition-context-introduce intdef-ctx-a x-id))
(syntax-local-bind-syntaxes (list y-id) #`(make-rename-transformer #'#,x_a-id) intdef-ctx-b)
(println (local-expand y-id 'expression '() intdef-ctx-b))) However, it prints This would imply that the |
I see – I focused on the part of what the other functions don't do, and not on what Next try: I believe frame IDs are about detecting the situation where a use-site scope needs to be added, where not adding a use-site scope is a useful optimization. A use-site scope is needed when a macro is being used in the same context where the macro is defined. That correspondence is detected by comparing the frame ID of a macro's binding to the current expansion context's frame ID. A definition context needs to carry its frame ID for binding via Now, what happens when you have a definition context immediately within some other definition context? The expander wants to conservatively treat those as the same definition context for the purposes of triggering a use-site scope. If you create a definition context during expansion within an existing definition context, that sameness can be detected automatically; the current context's frame ID is captured as the new context's frame ID. But if a programmer is creating multiple definition contexts and mixing them together at the end (by passing them both to If you don't tell The v6 expander performed that check, but in a different way than using a If all that is right, then the documentation could say that you need to provide a definition-context argument to |
Closing in favor of #2051. |
This expands some of the documentation for
syntax-local-make-definition-context
to clarify the extent to which supplying a parent definition context has an effect. I’m not sure this is the best way of phrasing things, so I’m happy if you’d prefer a different wording; I just spent a lot of time trying to hunt down a bug that stemmed from misunderstanding the existing documentation, so I wanted to try and add some clarification that would have helped me.