Raymond Toy pushed to branch issue-318-add-concrete-standard-char-type at cmucl / cmucl
Commits:
-
65083eba
by Raymond Toy at 2026-05-04T11:26:25-07:00
-
5df4f946
by Raymond Toy at 2026-05-04T11:38:52-07:00
-
c3f6a944
by Raymond Toy at 2026-05-04T11:40:58-07:00
3 changed files:
Changes:
| ... | ... | @@ -3321,14 +3321,15 @@ |
| 3321 | 3321 | (declare (ignore type1 type2))
|
| 3322 | 3322 | (values t t))
|
| 3323 | 3323 | |
| 3324 | -(defconstant +standard-chars+
|
|
| 3324 | +(defconstant +standard-chars+
|
|
| 3325 | 3325 | '(#\NEWLINE #\SPACE #\! #\" #\# #\$ #\% #\& #\' #\( #\) #\* #\+ #\,
|
| 3326 | 3326 | #\- #\. #\/ #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\: #\; #\< #\=
|
| 3327 | 3327 | #\> #\? #\@ #\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
|
| 3328 | 3328 | #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z #\[ #\\ #\]
|
| 3329 | 3329 | #\^ #\_ #\` #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
|
| 3330 | 3330 | #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
|
| 3331 | - #\| #\} #\~))
|
|
| 3331 | + #\| #\} #\~)
|
|
| 3332 | + "The set of characters in the STANDARD-CHAR type")
|
|
| 3332 | 3333 | |
| 3333 | 3334 | (define-type-method (standard-char :simple-union) (type1 type2)
|
| 3334 | 3335 | (declare (ignore type2))
|
| ... | ... | @@ -3362,33 +3363,19 @@ |
| 3362 | 3363 | (t
|
| 3363 | 3364 | (values nil t))))
|
| 3364 | 3365 | |
| 3365 | -#+nil
|
|
| 3366 | -(define-type-method (standard-char :complex-union) (type1 type2)
|
|
| 3367 | - (cond ((csubtypep (specifier-type 'character) type2)
|
|
| 3368 | - ;; STANDARD-CHAR union any super-type of CHARACTER is that
|
|
| 3369 | - ;; super-type. Hence, it's TYPE2.
|
|
| 3370 | - type2)
|
|
| 3371 | - ((and (member-type-p type2)
|
|
| 3372 | - (every #'characterp (member-type-members type2)))
|
|
| 3373 | - ;; STANDARD-CHAR union MEMBER-TYPE whose members are all
|
|
| 3374 | - ;; standard-characters is a STANDARD-CHAR.
|
|
| 3375 | - type1)
|
|
| 3376 | - ((eq (type-intersection (specifier-type 'standard-char)
|
|
| 3377 | - type2)
|
|
| 3378 | - *empty-type*)
|
|
| 3379 | - ;; STANDARD-CHAR union with disjoint type2 has no simplification.
|
|
| 3380 | - nil)
|
|
| 3381 | - (t
|
|
| 3382 | - ;; No simplification
|
|
| 3383 | - nil)))
|
|
| 3384 | - |
|
| 3385 | 3366 | (define-type-method (standard-char :complex-union) (type1 type2)
|
| 3386 | - (let* ((sc (if (standard-char-type-p type1) type1 type2))
|
|
| 3387 | - (other (if (eq sc type1) type2 type1)))
|
|
| 3367 | + ;; The standard-char type could be in type1 or type2. Figure out
|
|
| 3368 | + ;; which one is a standard-char.
|
|
| 3369 | + (multiple-value-bind (sc other)
|
|
| 3370 | + (if (standard-char-type-p type1)
|
|
| 3371 | + (values type1 type2)
|
|
| 3372 | + (values type2 type1))
|
|
| 3388 | 3373 | (cond
|
| 3389 | - ((csubtypep (specifier-type 'character) other) other)
|
|
| 3374 | + ((csubtypep (specifier-type 'character) other)
|
|
| 3375 | + other)
|
|
| 3390 | 3376 | ((and (member-type-p other)
|
| 3391 | - (subsetp (member-type-members other) kernel::+standard-chars+))
|
|
| 3377 | + (subsetp (member-type-members other)
|
|
| 3378 | + +standard-chars+))
|
|
| 3392 | 3379 | sc)
|
| 3393 | 3380 | (t nil))))
|
| 3394 | 3381 | |
| ... | ... | @@ -3420,7 +3407,7 @@ |
| 3420 | 3407 | (cond ((null (members))
|
| 3421 | 3408 | c::*empty-type*)
|
| 3422 | 3409 | ((= (length (members))
|
| 3423 | - (length kernel::+standard-chars+))
|
|
| 3410 | + (length +standard-chars+))
|
|
| 3424 | 3411 | sc)
|
| 3425 | 3412 | (t
|
| 3426 | 3413 | (make-member-type :members (members))))))))))
|
| ... | ... | @@ -13,11 +13,9 @@ |
| 13 | 13 | (:tag :issues)
|
| 14 | 14 | (assert-true (typep #\a 'standard-char))
|
| 15 | 15 | (assert-false (typep #\tab 'standard-char))
|
| 16 | - (assert-true (typep #\a 'standard-char))
|
|
| 17 | 16 | (assert-true (typep #\Z 'standard-char))
|
| 18 | 17 | (assert-true (typep #\Space 'standard-char))
|
| 19 | 18 | (assert-true (typep #\Newline 'standard-char))
|
| 20 | - (assert-false (typep #\Tab 'standard-char))
|
|
| 21 | 19 | (assert-false (typep #\Rubout 'standard-char))
|
| 22 | 20 | (assert-false (typep 5 'standard-char))
|
| 23 | 21 | (assert-false (typep "hello" 'standard-char))
|
| ... | ... | @@ -165,10 +163,7 @@ |
| 165 | 163 | (c::specifier-type '(member #\Tab)))))
|
| 166 | 164 | ;; Should not collapse into a 97-element MEMBER.
|
| 167 | 165 | (assert-false (c::member-type-p result))
|
| 168 | - (assert-true (c::union-type-p result))
|
|
| 169 | - #+nil
|
|
| 170 | - (not (and (c::member-type-p result)
|
|
| 171 | - (>= (length (c::member-type-members result)) 90)))))
|
|
| 166 | + (assert-true (c::union-type-p result))))
|
|
| 172 | 167 | |
| 173 | 168 | (define-test standard-char.complex-intersection
|
| 174 | 169 | (:tag :issues)
|
| ... | ... | @@ -246,17 +241,6 @@ |
| 246 | 241 | :error))))
|
| 247 | 242 | (assert-eql expected actual ch))))
|
| 248 | 243 | |
| 249 | -(define-test standard-char.caching
|
|
| 250 | - (:tag :issues)
|
|
| 251 | - ;; Multiple specifier-type calls on `standard-char` return EQ.
|
|
| 252 | - (assert-eq (c::specifier-type 'standard-char)
|
|
| 253 | - (c::specifier-type 'standard-char))
|
|
| 254 | - |
|
| 255 | - ;; And via the deftype expansion.
|
|
| 256 | - (assert-eq (c::specifier-type 'standard-char)
|
|
| 257 | - (c::specifier-type 'standard-char)))
|
|
| 258 | - ;
|
|
| 259 | - |
|
| 260 | 244 | (define-test standard-char.intersection-character-both-orderings
|
| 261 | 245 | (:tag :issues)
|
| 262 | 246 | ;; Standard-char intersect character = standard-char, regardless of argument order.
|
| ... | ... | @@ -333,17 +317,6 @@ |
| 333 | 317 | (some (complement #'characterp)
|
| 334 | 318 | (kernel::member-type-members m)))))))
|
| 335 | 319 | |
| 336 | -(define-test standard-char.subtypep-bidirectional
|
|
| 337 | - (:tag :issues)
|
|
| 338 | - ;; arg1 path: standard-char subset of X?
|
|
| 339 | - (assert-equal (values t t) (subtypep 'standard-char 'character))
|
|
| 340 | - (assert-equal (values nil t) (subtypep 'standard-char 'integer))
|
|
| 341 | - ;; arg2 path: X subset of standard-char?
|
|
| 342 | - (assert-equal (values nil t) (subtypep 'character 'standard-char))
|
|
| 343 | - (assert-equal (values nil t) (subtypep 'integer 'standard-char))
|
|
| 344 | - ;; Both reflexively
|
|
| 345 | - (assert-equal (values t t) (subtypep 'standard-char 'standard-char)))
|
|
| 346 | - |
|
| 347 | 320 | (defun assert-commutative-union (type-a-spec type-b-spec)
|
| 348 | 321 | "Assert that union(A, B) and union(B, A) produce type= results."
|
| 349 | 322 | (assert-equality #'kernel::type=
|