Skip to content
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

lowering: Don't bother rewrapping bare linenumbers in hygienic-scope #53850

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@
(cdr ranges)
(list ranges))))

(define (just-line? ex)
(and (pair? ex) (eq? (car ex) 'line) (atom? (cadr ex)) (or (atom? (caddr ex)) (nothing? (caddr ex)))))

(define (resolve-expansion-vars- e env m lno parent-scope inarg)
(cond ((or (eq? e 'begin) (eq? e 'end) (eq? e 'ccall) (eq? e 'cglobal) (underscore-symbol? e))
e)
Expand Down Expand Up @@ -417,11 +420,15 @@
((toplevel) ; re-wrap Expr(:toplevel) in the current hygienic-scope(s)
`(toplevel
,@(map (lambda (arg)
(let loop ((parent-scope parent-scope) (m m) (lno lno) (arg arg))
(let ((wrapped `(hygienic-scope ,arg ,m ,@lno)))
(if (null? parent-scope) wrapped
(loop (cdr parent-scope) (cadar parent-scope) (caddar parent-scope) wrapped)))))
(cdr e))))
;; Minor optimization: A lot of toplevel exprs have just bare line numbers in them.
;; don't bother with the full rewrapping in that case (even though
;; this would be semantically legal) - lowering won't touch them anyways.
(if (just-line? arg) arg
(let loop ((parent-scope parent-scope) (m m) (lno lno) (arg arg))
(let ((wrapped `(hygienic-scope ,arg ,m ,@lno)))
(if (null? parent-scope) wrapped
(loop (cdr parent-scope) (cadar parent-scope) (caddar parent-scope) wrapped))))))
(cdr e))))
((using import export meta line inbounds boundscheck loopinfo inline noinline purity) (map unescape e))
((macrocall) e) ; invalid syntax anyways, so just act like it's quoted.
((symboliclabel) e)
Expand Down