
This PR primarily changes how we represent Base types and unions of Base types. Basically, Base types now contain a bits field, which contains an exact-nonnegative-integer? with exactly one bit set to 1. This allows us to represent unions of Base types by simply OR-ing together the various base bits. We store these unions in a new type called a BaseUnion (which contains a field for numeric Base type bits and a field for non-numeric Base type bits). We can perform set operations on BaseUnion types rather quickly (using simple bitwise arithmetic operations). To make Union and BaseUnion work together nicely, the Union type now has a field for non-Base types, and a field which contains any and all Base types placed directly in the Union ( either as a Base if there is only one, or as a BaseUnion if there are more than one). Other changes present in this PR: Base types are now "closed" -- i.e. Base types are only declared in base-types.rkt and numeric-base-types.rkt with a special macro that assigns them their respective bits. The constructor make-Base is no longer provided for miscellaneous usages. Some singleton Value types were moved to Base so all of our common unions of basic types can fit into the new BaseUnion type (namely Null, Void, One, Zero, and the booleans). A new Val-able match expander lets us match on singleton types that used to all be Value types, but, as described above, now some are Base types. Unions contain deterministically ordered, duplicate free lists (in addition to sets for equality and constant time membership checks), so iterating over Unions can be done deterministically (yay!) -- this gets rid of some otherwise problematic behavior in areas like type inference, where the order Unions are iterated over can actually affect the results (i.e. if two valid type inferences are possible, nondeterministic ordering means we can sometimes get one and sometimes get another, which makes for particularly difficult to debug issues and in general has no immediate solution (both substitutions are valid, after all!))
53 lines
2.0 KiB
Racket
53 lines
2.0 KiB
Racket
#lang racket/base
|
|
|
|
(require "test-utils.rkt" (for-syntax racket/base)
|
|
(rep type-rep)
|
|
(types abbrev numeric-tower)
|
|
rackunit)
|
|
|
|
(provide tests)
|
|
(gen-test-main)
|
|
|
|
(define (-opaque x) (make-Opaque x))
|
|
|
|
|
|
(define-syntax (te-tests stx)
|
|
(define (single-test stx)
|
|
(syntax-case stx (FAIL)
|
|
[(FAIL t s) (syntax/loc stx (test-check (format "FAIL ~a" '(t s))
|
|
(lambda (a b) (not (equal? a b))) t s))]
|
|
[(t s) (syntax/loc stx (test-check (format "~a" '(t s)) equal? t s))]))
|
|
(syntax-case stx ()
|
|
[(_ cl ...)
|
|
#`(test-suite "Tests for type equality"
|
|
#,@(map single-test (syntax->list #'(cl ...))))]))
|
|
|
|
(define (fld* t) (make-fld t (datum->syntax #'here 'values) #f))
|
|
|
|
(define tests
|
|
(te-tests
|
|
[-Number -Number]
|
|
[(Un -Number) -Number]
|
|
[(Un -Number -Symbol -Boolean) (Un -Number -Boolean -Symbol)]
|
|
[(Un -Number -Symbol -Boolean) (Un -Symbol -Boolean -Number)]
|
|
[(Un -Number -Symbol -Boolean) (Un -Symbol -Number -Boolean)]
|
|
[(Un -Number -Symbol -Boolean) (Un -Boolean (Un -Symbol -Number))]
|
|
[(Un -Number -Symbol) (Un -Symbol -Number)]
|
|
[(-poly (x) (-> (Un -Symbol -Number) x)) (-poly (xyz) (-> (Un -Number -Symbol) xyz))]
|
|
[(-mu x (Un -Number -Symbol x)) (-mu y (Un -Number -Symbol y))]
|
|
;; found bug
|
|
[FAIL (Un (-mu heap-node
|
|
(-struct #'heap-node #f
|
|
(map fld* (list (-opaque #'comparator)
|
|
-Number
|
|
(-v a)
|
|
(Un heap-node (-opaque #'heap-empty))))))
|
|
(-opaque #'heap-empty))
|
|
(Un (-mu heap-node
|
|
(-struct #'heap-node #f
|
|
(map fld* (list (-opaque #'comparator)
|
|
-Number
|
|
(-pair -Number -Number)
|
|
(Un heap-node (-opaque #'heap-empty))))))
|
|
(-opaque #'heap-empty))]))
|