no-leaf-env.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. Return-Path: <kelsey@ccs.neu.edu>
  2. Date: Mon, 14 Jun 93 14:34:40 -0400
  3. To: jar@cs.cornell.edu
  4. Subject: environments for leaf procedures
  5. From: kelsey@flora.ccs.neu.edu
  6. Sender: kelsey@ccs.neu.edu
  7. I merged the no-leaf-environments code back into the system, and this
  8. time it may be worth it. Loading pp.scm sped up by 2%, even though
  9. the compiler is doing more work. Benchmark times (in seconds):
  10. old new speedup
  11. quicksort 1.48 1.39 6%
  12. towers 1.05 1.05 0%
  13. matrix-multiply 3.32 3.10 7%
  14. matrix-multiply2 1.94 1.80 7%
  15. Local variable names are screwed up:
  16. > (define (f x) (let ((y 4)) (+ x y)))
  17. > (f 'a)
  18. Error: exception
  19. (+ 'a 4)
  20. 1> ,debug
  21. '#{Continuation (pc 13) f}
  22. [0] 4
  23. [1: y] 'a
  24. inspect:
  25. There is probably a simple fix for this.
  26. Here is the diff:
  27. % diff comp.scm comp.scm.save
  28. 26d25
  29. < (define $compiling-leaf (make-fluid 'no))
  30. 28,33d26
  31. < (define (note-not-leaf!)
  32. < (set-fluid! $compiling-leaf 'no))
  33. <
  34. < (define (compiling-leaf?)
  35. < (eq? 'yes (fluid $compiling-leaf)))
  36. <
  37. 63,82c56,66
  38. < (deliver-value (if (env-ref? den)
  39. < (local-variable den cenv depth #f)
  40. < (instruction-with-variable op/global exp den #f))
  41. < cont)))
  42. <
  43. < (define (local-variable den cenv depth set?)
  44. < (let ((back (env-ref-back den cenv))
  45. < (over (env-ref-over den)))
  46. < (if (and (compiling-leaf?)
  47. < (= back 0))
  48. < (instruction (if set? op/stack-set! op/stack-ref)
  49. < (+ (- over 1) depth))
  50. < (let ((back (if (compiling-leaf?) (- back 1) back)))
  51. < (if set?
  52. < (instruction op/set-local! back over)
  53. < (case back
  54. < ((0) (instruction op/local0 over)) ;+++
  55. < ((1) (instruction op/local1 over)) ;+++
  56. < ((2) (instruction op/local2 over)) ;+++
  57. < (else (instruction op/local back over))))))))
  58. ---
  59. > (if (env-ref? den)
  60. > (let ((back (env-ref-back den cenv))
  61. > (over (env-ref-over den)))
  62. > (deliver-value (case back
  63. > ((0) (instruction op/local0 over)) ;+++
  64. > ((1) (instruction op/local1 over)) ;+++
  65. > ((2) (instruction op/local2 over)) ;+++
  66. > (else (instruction op/local back over)))
  67. > cont))
  68. > (deliver-value (instruction-with-variable op/global exp den #f)
  69. > cont))))
  70. 143,145c127,132
  71. < (if (env-ref? den)
  72. < (local-variable den cenv depth #t)
  73. < (instruction-with-variable op/set-global! name den #t)))
  74. ---
  75. > (cond ((env-ref? den)
  76. > (instruction op/set-local!
  77. > (env-ref-back den cenv)
  78. > (env-ref-over den)))
  79. > (else
  80. > (instruction-with-variable op/set-global! name den #t))))
  81. 203d189
  82. < (note-not-leaf!) ; this isn't strictly necessary, but it keeps things simpler
  83. 222,231c208,215
  84. < (cond ((return-cont? cont)
  85. < code)
  86. < (else
  87. < (note-not-leaf!) ; this isn't strictly necessary, but it keeps things simpler
  88. < (sequentially (instruction-with-offset&byte op/make-cont
  89. < (segment-size code)
  90. < depth)
  91. < (note-source-code (cont-source-info cont)
  92. < code)
  93. < (cont-segment cont)))))
  94. ---
  95. > (if (return-cont? cont)
  96. > code
  97. > (sequentially (instruction-with-offset&byte op/make-cont
  98. > (segment-size code)
  99. > depth)
  100. > (note-source-code (cont-source-info cont)
  101. > code)
  102. > (cont-segment cont))))
  103. 264d247
  104. < (note-not-leaf!)
  105. 280,315c263,284
  106. < (let-fluids $compiling-leaf 'maybe
  107. < (lambda ()
  108. < (let ((code (really-compile-lambda-code formals body cenv name)))
  109. < (if (eq? (fluid $compiling-leaf) 'maybe)
  110. < (let-fluids $compiling-leaf 'yes
  111. < (lambda ()
  112. < (really-compile-lambda-code formals body cenv name)))
  113. < code)))))
  114. <
  115. < (define (really-compile-lambda-code formals body cenv name)
  116. < (let* ((nargs (number-of-required-args formals))
  117. < (vars (normalize-formals formals))
  118. < (cenv (if (null? formals)
  119. < cenv ;+++
  120. < (bind-vars vars cenv))))
  121. < (sequentially
  122. < (cond ((n-ary? formals)
  123. < (sequentially
  124. < (instruction op/make-rest-list nargs)
  125. < (instruction op/push)
  126. < (if (compiling-leaf?)
  127. < empty-segment
  128. < (instruction op/make-env (+ nargs 1)))))
  129. < ((null? formals)
  130. < (note-not-leaf!) ; no point if no variables
  131. < empty-segment)
  132. < ((compiling-leaf?)
  133. < empty-segment)
  134. < (else
  135. < (instruction op/make-env nargs)))
  136. < (note-environment
  137. < vars
  138. < (compile-body body
  139. < cenv
  140. < 0
  141. < (return-cont name))))))
  142. ---
  143. > (if (null? formals)
  144. > (compile-body body ;+++ Don't make null environment
  145. > cenv
  146. > 0
  147. > (return-cont name))
  148. > (sequentially
  149. > (let ((nargs (number-of-required-args formals)))
  150. > (if (n-ary? formals)
  151. > (sequentially
  152. > (instruction op/make-rest-list nargs)
  153. > (instruction op/push)
  154. > (instruction op/make-env (+ nargs 1)))
  155. > (instruction op/make-env nargs)))
  156. > (let* ((vars (normalize-formals formals))
  157. > (cenv (bind-vars vars cenv)))
  158. > (note-environment
  159. > vars
  160. > (compile-body body
  161. > cenv
  162. > 0
  163. > (return-cont name)))))))
  164. >