971
971
(sparam-name-bounds params '() '() )
972
972
`(block
973
973
(const ,name)
974
- ,@(map (lambda (v ) `(local ,v)) params)
975
- ,@(map make-assignment params (symbols->typevars params bounds #f ))
976
- (abstract_type ,name (call (top svec) ,@params) ,super))))
974
+ (scope-block
975
+ (block
976
+ ,@(map (lambda (v ) `(local ,v)) params)
977
+ ,@(map make-assignment params (symbols->typevars params bounds #f ))
978
+ (abstract_type ,name (call (top svec) ,@params) ,super))))))
977
979
978
980
(define (bits-def-expr n name params super )
979
981
(receive
980
982
(params bounds)
981
983
(sparam-name-bounds params '() '() )
982
984
`(block
983
985
(const ,name)
984
- ,@(map (lambda (v ) `(local ,v)) params)
985
- ,@(map make-assignment params (symbols->typevars params bounds #f ))
986
- (bits_type ,name (call (top svec) ,@params) ,n ,super))))
986
+ (scope-block
987
+ (block
988
+ ,@(map (lambda (v ) `(local ,v)) params)
989
+ ,@(map make-assignment params (symbols->typevars params bounds #f ))
990
+ (bits_type ,name (call (top svec) ,@params) ,n ,super))))))
987
991
988
992
; take apart a type signature, e.g. T{X} <: S{Y}
989
993
(define (analyze-type-sig ex )
@@ -2569,15 +2573,6 @@ The first one gave something broken, but the second case works.
2569
2573
So far only the second case can actually occur.
2570
2574
|#
2571
2575
2572
- (define (declared-global-vars e )
2573
- (if (or (not (pair? e)) (quoted? e))
2574
- '()
2575
- (case (car e)
2576
- ((lambda scope-block) '() )
2577
- ((global) (cdr e))
2578
- (else
2579
- (apply append (map declared-global-vars e))))))
2580
-
2581
2576
(define (check-dups locals )
2582
2577
(if (and (pair? locals) (pair? (cdr locals)))
2583
2578
(or (and (memq (car locals) (cdr locals))
@@ -2604,26 +2599,27 @@ So far only the second case can actually occur.
2604
2599
(apply append! (map (lambda (x ) (find-assigned-vars x env))
2605
2600
e))))))
2606
2601
2607
- (define (find-decls kind e env )
2602
+ (define (find-decls kind e )
2608
2603
(if (or (not (pair? e)) (quoted? e))
2609
2604
'()
2610
2605
(cond ((or (eq? (car e) 'lambda ) (eq? (car e) 'scope-block ))
2611
2606
'() )
2612
2607
((eq? (car e) kind)
2613
2608
(list (decl-var (cadr e))))
2614
2609
(else
2615
- (apply append! (map (lambda (x ) (find-decls kind x env ))
2610
+ (apply append! (map (lambda (x ) (find-decls kind x))
2616
2611
e))))))
2617
2612
2618
- (define (find-local-decls e env ) (find-decls 'local e env))
2619
- (define (find-local!-decls e env ) (find-decls 'local! e env))
2613
+ (define (find-local-decls e ) (find-decls 'local e))
2614
+ (define (find-local!-decls e ) (find-decls 'local! e))
2615
+ (define (find-global-decls e ) (find-decls 'global e))
2620
2616
2621
2617
(define (find-locals e env glob )
2622
2618
(delete-duplicates
2623
- (append! (check-dups (find-local-decls e env ))
2619
+ (append! (check-dups (find-local-decls e))
2624
2620
; ; const decls on non-globals also introduce locals
2625
- (diff (find-decls 'const e env ) glob)
2626
- (find-local!-decls e env )
2621
+ (diff (find-decls 'const e) glob)
2622
+ (find-local!-decls e)
2627
2623
(find-assigned-vars e env))))
2628
2624
2629
2625
(define (remove-local-decls e )
@@ -2643,22 +2639,30 @@ So far only the second case can actually occur.
2643
2639
; ; 2. (const x) expressions in a scope-block where x is not declared global
2644
2640
; ; 3. variables assigned inside this scope-block that don't exist in outer
2645
2641
; ; scopes
2646
- (define (add-local-decls e env )
2642
+ (define (add-local-decls e env implicitglobals )
2647
2643
(if (or (not (pair? e)) (quoted? e)) e
2648
2644
(cond ((eq? (car e) 'lambda )
2649
2645
(let* ((env (append (lam:vars e) env))
2650
- (body (add-local-decls (caddr e) env)))
2646
+ (body (add-local-decls (caddr e) env
2647
+ ; ; don't propagate implicit globals
2648
+ ; ; issue #7234
2649
+ '() )))
2651
2650
(list 'lambda (cadr e) body)))
2652
2651
2653
2652
((eq? (car e) 'scope-block )
2654
- (let* ((glob (declared-global-vars (cadr e)))
2653
+ (let* ((iglo (find-decls 'implicit-global (cadr e)))
2654
+ (glob (diff (find-global-decls (cadr e)) iglo))
2655
2655
(vars (find-locals
2656
2656
; ; being declared global prevents a variable
2657
2657
; ; assignment from introducing a local
2658
- (cadr e) (append env glob) glob))
2659
- (body (add-local-decls (cadr e) (append vars glob env)))
2660
- (lineno (if (and (length> body 1 )
2661
- (pair? (cadr body))
2658
+ (cadr e)
2659
+ (append env glob implicitglobals iglo)
2660
+ (append glob iglo)))
2661
+ (body (add-local-decls (cadr e)
2662
+ (append vars glob env)
2663
+ (append iglo implicitglobals)))
2664
+ (lineno (if (and (length> body 1 )
2665
+ (pair? (cadr body))
2662
2666
(eq? 'line (car (cadr body))))
2663
2667
(list (cadr body))
2664
2668
'() ))
@@ -2678,10 +2682,10 @@ So far only the second case can actually occur.
2678
2682
; ; form (local! x) adds a local to a normal (non-scope) block
2679
2683
(let ((newenv (append (declared-local!-vars e) env)))
2680
2684
(map (lambda (x )
2681
- (add-local-decls x newenv))
2685
+ (add-local-decls x newenv implicitglobals ))
2682
2686
e))))))
2683
2687
2684
- (define (identify-locals e ) (add-local-decls e '() ))
2688
+ (define (identify-locals e ) (add-local-decls e '() '() ))
2685
2689
2686
2690
(define (declared-local-vars e )
2687
2691
(map (lambda (x ) (decl-var (cadr x)))
@@ -2719,10 +2723,10 @@ So far only the second case can actually occur.
2719
2723
(case (car e)
2720
2724
((lambda)
2721
2725
(append (lambda-all-vars e)
2722
- (declared -global-vars (cadddr e))))
2726
+ (find -global-decls (cadddr e))))
2723
2727
((scope-block)
2724
2728
(append (declared-local-vars e)
2725
- (declared -global-vars (cadr e))))
2729
+ (find -global-decls (cadr e))))
2726
2730
(else '() )))))
2727
2731
(cons (car e)
2728
2732
(map (lambda (x )
@@ -2959,7 +2963,7 @@ So far only the second case can actually occur.
2959
2963
(if vi (free-vars (vinfo:type vi)) '() )))
2960
2964
fv))))
2961
2965
(append (diff dv fv) fv)))
2962
- (glo (declared -global-vars (lam:body e)))
2966
+ (glo (find -global-decls (lam:body e)))
2963
2967
; ; make var-info records for vars introduced by this lambda
2964
2968
(vi (nconc
2965
2969
(map (lambda (decl ) (make-var-info (decl-var decl)))
@@ -3194,6 +3198,7 @@ So far only the second case can actually occur.
3194
3198
))
3195
3199
3196
3200
((global) #f ) ; remove global declarations
3201
+ ((implicit-global) #f )
3197
3202
((local!) #f )
3198
3203
((jlgensym) #f )
3199
3204
((local)
0 commit comments