call/cc + letrec + occurrence typing can be unsound

Open
#128 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
compilers

Research direction

Start by running the supplied Typed Racket example and tracing how occurrence typing handles letrec-bound variables and inner defines. Determine how the call/cc mutation reaches bar, then add a regression case covering the example. Done means the unsound program is rejected or its occurrence typing is prevented as described.

Written by the indexing model from the issue text.

Description

unsound

In the following example, the mutation exposed via the combination of call/cc and letrec can lead to unsoundness via occurrence typing; bar has the type (-> False False) but actually is called with #t. The obvious solution is to disable occurrence typing on letreced variables (including inner defines that are not converted to let).

#lang typed/racket

(define (bar [v : False]) : False
  (error "yo" v))

(define-type klk (-> (U klk (List klk Boolean)) (List klk Boolean)))

(define (foo)
  (letrec ((x (call/cc (lambda ([k : klk]) : (List klk Boolean) (list k #f)))))
    (when (list? x)
      (if (false? (second x))
          (begin
            (call/cc
             (lambda ([k : klk])
               ((first x) (list k #t))))
            (bar (second x)))
          ((first x) x)))))

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

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.

More from racket/typed-racket

All issues in racket/typed-racket

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.