Opened 5 years ago

Closed 5 years ago

#1630 closed defect (fixed)

Optimizer sometimes incorrectly drops procedure arguments

Reported by: sjamaan Owned by:
Priority: major Milestone: 5.2
Component: compiler Version: 5.1.0
Keywords: Cc:
Estimated difficulty: hard

Description (last modified by sjamaan)

Found by megane while looking into a patch of mine to improve variable replacements:

(define (foo bindings)                                                                            
  (define (append-map proc lst1)                                                                                                        
    (if lst1                                                                                                                            
        (proc 1)                                                                                                                        
        (proc 1 2)))                                                                                                                    
  (append-map (lambda (b a) (begin)) bindings))

Compile this with -O3 and it will error out with this message:

Error: Arguments to inlined call of `a150' do not match parameter-list (b a)

After fixing this, we can remove the (not captured) test in the 'replaceable code.

Change History (9)

comment:1 Changed 5 years ago by sjamaan

Description: modified (diff)

comment:2 Changed 5 years ago by sjamaan

Summary: Optimizer may incorrectly drop procedure argumentsOptimizer sometimes incorrectly drops procedure arguments

comment:3 Changed 5 years ago by megane

Simpler still:

(define (foo x)
  (let ((bar (lambda (a b) (print a b))))
    (if x
        (bar 1)
        (bar 1 2))))

comment:4 Changed 5 years ago by felix winkelmann

I don't see the problem here. Tha example code is clearly incorrect.

comment:5 Changed 5 years ago by felix winkelmann

Resolution: worksforme
Status: newclosed

comment:6 Changed 5 years ago by megane

Resolution: worksforme
Status: closedreopened

This fails too, but shouldn't. The true branch is never called.

(define (foo x y)
  (define (append-map proc lst1 . lsts)
    (if (null? lsts)
        (proc 1)
        (proc 1 2)))
  (append-map (lambda (a b) (print a b)) x y))

comment:7 Changed 5 years ago by sjamaan

This code seems valid to me but also triggers the error when compiled with -O2:

(define (foo x y)
  (define (append-map proc lst1 . lsts)
    (if (null? lsts)
        (proc 1)
        (proc 1 2)))
  (append-map (lambda (a b) (print a b)) x y)
  (append-map (lambda (a) (print a)) x))

comment:8 Changed 5 years ago by felix winkelmann

Estimated difficulty: mediumhard

Here is another test, submitted by megane. This triggers a compiler error, with the standard CHICKEN:

(define (foo x y)
  (define (append-map proc . lsts)
    (if (null? lsts)
        (proc 1)
        (apply proc lsts)))
  (append-map (lambda (a) (print a)))
  (append-map (lambda (a b) (print a b)) x y))

(foo 3 4)

comment:9 Changed 5 years ago by sjamaan

Resolution: fixed
Status: reopenedclosed

Fixed by cf5d2aed000cfd292708d41b3774321bfec5eb67

Note: See TracTickets for help on using tickets.