@@ -3232,11 +3232,7 @@ So far only the second case can actually occur.
3232
3232
(vinf (var-info-for vname vi)))
3233
3233
(if (and vinf
3234
3234
(not (and (pair? code)
3235
- (equal? (car code) `(newvar ,vname))))
3236
- ; ; TODO: remove the following expression to re-null
3237
- ; ; all variables when they are allocated. see issue #1571
3238
- (vinfo:capt vinf)
3239
- )
3235
+ (equal? (car code) `(newvar ,vname)))))
3240
3236
(emit `(newvar ,vname))
3241
3237
#f )))
3242
3238
((newvar)
@@ -3246,10 +3242,41 @@ So far only the second case can actually occur.
3246
3242
#f ))
3247
3243
(else (emit (goto-form e))))))
3248
3244
(compile e '() )
3249
- (cons 'body (reverse! code))))
3245
+ (let* ((stmts (reverse! code))
3246
+ (di (definitely-initialized-vars stmts vi)))
3247
+ (cons 'body (filter (lambda (e )
3248
+ (not (and (pair? e) (eq? (car e) 'newvar )
3249
+ (has? di (cadr e)))))
3250
+ stmts)))))
3250
3251
3251
3252
(define to-goto-form goto-form)
3252
3253
3254
+ ; ; find newvar nodes that are unnecessary because (1) the variable is not
3255
+ ; ; captured, and (2) the variable is assigned before any branches.
3256
+ ; ; this is used to remove newvar nodes that are not needed for re-initializing
3257
+ ; ; variables to undefined (see issue #11065). it doesn't look for variable
3258
+ ; ; *uses*, because any variables used-before-def that also pass this test
3259
+ ; ; are *always* used undefined, and therefore don't need to be *re*-initialized.
3260
+ (define (definitely-initialized-vars stmts vi )
3261
+ (let ((vars (table))
3262
+ (di (table)))
3263
+ (let loop ((stmts stmts))
3264
+ (if (null? stmts)
3265
+ di
3266
+ (begin
3267
+ (let ((e (car stmts)))
3268
+ (cond ((and (pair? e) (eq? (car e) 'newvar ))
3269
+ (let ((vinf (var-info-for (cadr e) vi)))
3270
+ (if (not (vinfo:capt vinf))
3271
+ (put! vars (cadr e) #t ))))
3272
+ ((and (pair? e) (eq? (car e) '= ))
3273
+ (if (has? vars (cadr e))
3274
+ (begin (del! vars (cadr e))
3275
+ (put! di (cadr e) #t ))))
3276
+ ((and (pair? e) (memq (car e) ' (goto gotoifnot)))
3277
+ (set! vars (table)))))
3278
+ (loop (cdr stmts)))))))
3279
+
3253
3280
; ; macro expander
3254
3281
3255
3282
(define (splice-expr? e )
0 commit comments