chicken-janitors
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-janitors] #874: Compiling some files may cause infinite opt


From: Chicken Trac
Subject: Re: [Chicken-janitors] #874: Compiling some files may cause infinite optimization loops, eating all available memory
Date: Sun, 01 Jul 2012 14:36:09 -0000

#874: Compiling some files may cause infinite optimization loops, eating all
available memory
-----------------------+----------------------------------------------------
  Reporter:  mario     |       Owner:       
      Type:  defect    |      Status:  new  
  Priority:  major     |   Milestone:  4.8.0
 Component:  compiler  |     Version:  4.7.x
Resolution:            |    Keywords:       
-----------------------+----------------------------------------------------

Comment(by sjamaan):

 It's not an infinite loop, but it keeps contracting the same procedure
 more than once.  If you rip out all the tests under "shiver's tests" the
 problem goes away.  Put some of them back, it takes longer. Put more back,
 it takes even longer etc.

 It's not the macro either. Looks like the cond is causing the problem.
 Looks like an O(n^2) behavior with n being the number of branches in the
 cond.

 Here's a simplified case that clearly shows what's going on:

 {{{
 #!scm
 (cond ((not (= 1 2)) (print 2))
       ((not (= 5 6)) (print 4))
       (else (print 'nothing)))
 }}}

 {{{
 csc -debug o test.scm
 Removed `not' forms: 2
 contracted procedure: k31
 folded constant expression: (= (quote 5) (quote 6))
 contracted procedure: k22
 contracted procedure: k31
 folded constant expression: (= (quote 5) (quote 6))
 folded constant expression: (= (quote 1) (quote 2))
 replaced variables: 21
 contracted procedure: k22
 removed binding forms: 2
 substituted constant variable: r23
 contracted procedure: k31
 removed binding forms: 4
 removed conditional forms: 1
 removed binding forms: 1
 }}}

 Note the double occurrance of the folded expression, which is probably a
 result of the fact that the procedure k31  that's generated by cond's
 expansion is contracted twice. Add a line and you get three entries for
 the newly added line:

 {{{
 #!scm
 (cond ((not (= 1 2)) (print 2))
       ((not (= 5 6)) (print 4))
       ((not (= 7 8)) (print 5))
       (else (print 'nothing)))
 }}}

 {{{
 csc -debug o test.scm
 Removed `not' forms: 3
 contracted procedure: k40
 folded constant expression: (= (quote 7) (quote 8))
 contracted procedure: k31
 contracted procedure: k40
 folded constant expression: (= (quote 7) (quote 8))
 folded constant expression: (= (quote 5) (quote 6))
 contracted procedure: k22
 contracted procedure: k40
 folded constant expression: (= (quote 7) (quote 8))
 contracted procedure: k31
 contracted procedure: k40
 folded constant expression: (= (quote 7) (quote 8))
 folded constant expression: (= (quote 5) (quote 6))
 folded constant expression: (= (quote 1) (quote 2))
 replaced variables: 53
 contracted procedure: k22
 removed binding forms: 2
 substituted constant variable: r23
 contracted procedure: k31
 removed binding forms: 4
 removed conditional forms: 1
 removed binding forms: 1
 }}}

 And another line:

 {{{
 #!scm
 (cond ((not (= 1 2)) (print 2))
       ((not (= 5 6)) (print 4))
       ((not (= 7 8)) (print 5))
       ((not (= 9 10)) (print 6))
       (else (print 'nothing)))
 }}}

 {{{
 csc -debug o test.scm
 Removed `not' forms: 4
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 contracted procedure: k40
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 folded constant expression: (= (quote 7) (quote 8))
 contracted procedure: k31
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 contracted procedure: k40
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 folded constant expression: (= (quote 7) (quote 8))
 folded constant expression: (= (quote 5) (quote 6))
 contracted procedure: k22
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 contracted procedure: k40
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 folded constant expression: (= (quote 7) (quote 8))
 contracted procedure: k31
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 contracted procedure: k40
 contracted procedure: k49
 folded constant expression: (= (quote 9) (quote 10))
 folded constant expression: (= (quote 7) (quote 8))
 folded constant expression: (= (quote 5) (quote 6))
 folded constant expression: (= (quote 1) (quote 2))
 replaced variables: 117
 contracted procedure: k22
 removed binding forms: 2
 substituted constant variable: r23
 contracted procedure: k31
 removed binding forms: 4
 removed conditional forms: 1
 removed binding forms: 1
 }}}

 Interestingly, it does ''not'' happen when you remove the "not".

-- 
Ticket URL: <http://bugs.call-cc.org/ticket/874#comment:2>
Chicken Scheme <http://www.call-with-current-continuation.org/>
Chicken Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]