racket / racket/typed-racket

Bad optimization with (if (pair? rest) …) on polymorphic rest argument (unsound)

Open
#412 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

unsound
Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

What version of Racket are you using?

6.6.0.1

What program did you run?
#lang typed/racket
((λ #:∀ (A ...) [rest : A ... A]
   (if (pair? rest)
       #t
       #f))
 1)
; => #f
What should have happened?

The result should be #t, but the program outputs #f. When typing this expression at the REPL, we can see racket incorrectly inferred the return type is False.

Without the (if … #t #f), the program outputs #t as expected:

#lang typed/racket
((λ #:∀ (A ...) [rest : A ... A]
   (pair? rest))
 1)
; => #t

Also, when using a regular Any * rest argument instead of the polymorphic A ... A, the result is correct:

#lang typed/racket
((λ [rest : Any *]
   (if (pair? rest)
       #t
       #f))
 1)
; => #t

I couldn't find a way to turn this into unsafe behaviour, so the problem is "just" incorrect results.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Typed Racket examples in the issue and compare the inferred return type with the runtime result. Investigate the optimization or type-inference path for polymorphic rest arguments and the pair? test behavior. Done means the example returns #t and is no longer inferred as False, while the existing Any * behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.