racket / ChezScheme

Chez Scheme
Apache License 2.0
110 stars 8 forks source link

Fix record? reduction in cptypes #19

Closed gus-massa closed 4 years ago

gus-massa commented 4 years ago

The first commit fix an error in the reduction of record? in cptypes, hat was not checking that the rtd expression was single valued. For example in

(record? 7 (values 1 2)) ; ==> (begin 7 (values 1 2) #f)

To check if it single value, it use the type of the rtd expression, that has more information.

Long comment:

I was considering to use a simplified version of the single-valued? in cp0, but the problem is that it assume that references are single valued. For example in

(let ([r (values 1 2)]) (record? 7 r))
==alternative-cptypes==> (let ([r (values 1 2)]) (begin 7 r #f))
                         ; because r is a reference so it is "single valued"
==cp0==> (begin 7 (values 1 2) #f)
==cp0==> #f

I think that this doesn't cause a problem in cp0 because in cp0 when the expression is moved to an ignored position, it is immediately reduced

(let ([r (values 1 2)]) (#3%map r '()))
==cp0==> (let ([r (values 1 2)]) (begin <cp0 r> '()))
==cp0==> (let ([r (values 1 2)]) (begin (void) '()))
==cp0==> (let ([r (values 1 2)]) '())

So I think it is correct, but it is not as foolproof as I like.

I was thinking about using single-valued? to reduce the first expression in make-seq in cptypes (and cp0) in caases where there is no information about the subexpressions, but I must take a more carefully look.


The second commit allows the types to remember the reference that have a 'ptr, so it distinguish them from the ones with #f. This is only a difference because 'ptr implies that the expression is single valued. This may increase the memory requirement, but I expect that the difference is not too much. Also, I don't expect it to be very useful now, but it may be helpful in the near future. [I have to update a few comments here and there.]

gus-massa commented 4 years ago

After more testing, I realized my comment was wrong,. The correct reduction order is:

(let ([r (values 1 2)]) (record? 7 r))
==cp0==> (record? 7 (values 1 2))
==wrong-cptypes==> (begin 7 (values 1 2) #f)
==cptypes-or-cp0==> #f

so, fixing the error in cptypes is enough and there is no problem with single-valued?.

gus-massa commented 4 years ago

I removed the second commit, but I added a special case to the reduction of ref so if it has a missing type it use 'ptr, so the expression is marked as single valued. cptypes.ss#diff-L1304-R1307

mflatt commented 4 years ago

LGTM