Mutable strings are unsound with (make-predicate "abc")
Nobody has claimed this yet.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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