Skip to content

Conversation

@gus-massa
Copy link
Contributor

@gus-massa gus-massa commented Oct 21, 2025

Avoid moving predicates from tail position when they may raise an error, in spite the result in known in case of a success.

In particular, in

(lambda (x)
  (when (or (fixnum? x) (list? x))
    (exact? x))))

it's clear that it will be #t if not an error, but it's not possible to replace it with (begin (exact? x) #t) in tail position.

I added a check for (debug-level), but I'm not sure it's correct.

I'm sure this is a bug, but I don't have an example where I can see an incorrect result. It's probably a combination of with-handlers to inspect the continuation marks, but I'm not sure.

Avoid moving predicates from tail position when they may raise
an error, in spite the result in known in case of a success.
@gus-massa
Copy link
Contributor Author

When I detected the bug, I decided to expand the possible contexts to handle a lot of cases like in cp0, perhaps more (tail vs non-tail, single vs multiple value, ignore vs use, boolean). But there are too many cases and after some tries I gave up and decided to send a quick fix that doesn't change the available contexts.

After thinking a bit more, I notice that the fix was correct but too pessimistic and the reduction applied in too few cases. So now I split 'value into 'value and 'tail that is short enough to send the PR now, but increase the number of place that the reduction can be applied, because most of the times it's used in a non-tail position.

@burgerrg burgerrg changed the title Fix non-total predicates in tail possition in cptypes Fix non-total predicates in tail position in cptypes Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant