racket / racket/typed-racket

Mutable strings are unsound with (make-predicate "abc")

Open
#487 4 comments 1 reaction 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.7.0.4

What program did you run?
#lang typed/racket
(define s (string #\a #\b #\c))
(if ((make-predicate "abc") s)
      (begin
        (string-set! s 1 #\x)
        (ann s "abc"))
      #f)
What should have happened?

make-predicate should refuse to generate the predicate, as it needs a non-flat contract.

I think it's best to wait until immutable data structures are implemented in TR before fixing this, as this may otherwise break programs which rely on make-predicate (and string mutations are exceedingly rare). Then it will be possible to write (make-predicate (∩ Immutable "abc")) or something similar.

The type of the generated predicate can also be changed to (-> Any Boolean : #:+ "abc" #:- (or (not "abc") Mutable)), although that goes against the general pattern for make-predicate which always generates (-> Any Boolean : T). Maybe it would be interesting in the future to have weaker versions (make-pos-predicate T) which returns a predicate with the type (-> Any Boolean : #:+ T) and (make-neg-predicate T) which returns a predicate with the type (-> Any Boolean : #:- T) ?

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 with the make-predicate entry point and run the Typed Racket reproducer shown in the issue. Resolve which proposed behavior is intended for mutable strings, then add coverage showing that the unsound (ann s "abc") path is no longer accepted; the issue names no source file or test.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.