racket / racket/typed-racket

infinite loop caused by (ann v t), where t uses polymorphic recursion

Open
#174 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The typechecker goes into an infinite loop when checking if a value of a polymorphically recursive type t1 belongs to a type t2 with a identical declaration (except the recursive reference, which is renamed).

The types use polymorphic recursion, overwriting their argument with a ∀ X type parameter.

  • If we change their definition to (define-type (t1 A) (∀ (X) (→ X (t1 String)))) (replacing X with String at the end, same thing for t2), the problem does not occur.
  • If we change their definition to (define-type (t1 A) (∀ (X) (→ X (t1 A)))) (replacing X with A at the end, same thing for t2), the problem does not occur.
#lang typed/racket

(define-type (t1 A) (∀ (X) (→ X (t1 X))))
(define-type (t2 A) (∀ (X) (→ X (t2 X))))

;; Use the type in some way
(: f (∀ (A) (→ (t1 A) Any)))
(define (f a) 'dummy)
(define f-number (inst f Number))

(ann f-number (→ (t1 Number) Any)) ; This works
;(ann f-number (→ (t2 Number) Any)) ; This line makes the typechecker go in an infinite loop

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 reproducer in the issue, especially the final annotation involving t2, and inspect the typechecker path for ann and polymorphic recursive types. Done means the example terminates without looping while the existing working cases remain valid.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.