racket / ChezScheme

Chez Scheme
Apache License 2.0
110 stars 8 forks source link

Reduce (if <boolean> #t #f) in cp0 #16

Closed gus-massa closed 4 years ago

gus-massa commented 4 years ago

The first commit adds a reduction in cp0 of (if <boolean> #t #f) . It may help to reduce expressions like (and <boolean> <obviously-true>), for example (and (pair? x) (pair? y) where the compiler knows that y is a pair.

The second commit is unrelated. It's a fix to https://github.com/racket/racket/issues/2865 . I've send it as a PR upstream, but it is not merged yet and it would be nice to fix this in Racket7.6.

mflatt commented 4 years ago

I think the conversion probably needs something like a call to safe-single-valuemake-nontail to avoid moving a test expression into tail position.

gus-massa commented 4 years ago

Fixed. Do I merge this?

mflatt commented 4 years ago

LGTM

In retrospect, make-nontail isn't going to do anything because the transformation is only in a 'test context. But it seems nicer to have for future reference.

gus-massa commented 4 years ago

It's applied in a 'test context or when the test expression is boolean-valued?.

I'm never sure about the details, but I think that something like

(lambda () (if (box? (car (current-continuation-attachments))) #t #f))

can cause a problem without make-nontail.

mflatt commented 4 years ago

Yes, you're right. I misread the or around (eq? ctxt 'test) as and (which wouldn't make as much sense).