fix case-lambda checking when no expected type
Not we will check each clause against the other applicable
arrows that are derived during type synthesis for soundness
sake. At a future date, if we instead compute a more
complete "intersection" of these arrows and then
check against that intersection, that would admit more
correct programs.
Add a case to the static contract optimizer so that contracts
generated from the `Syntax` type disappear in trusted positions.
This restores the "old" behavior for the `Syntax` type --- the behavior
before fixing the 'or/c' unsoundness in issue 598.
<https://github.com/racket/typed-racket/issues/598>
Note: this fix is temporary, until the definition of `Syntax` can
be in terms of _immutable_ vectors & boxes.
Prevent the static contract optimizer from changing constructors under `or/sc`.
i.e., for static contracts of the form `(or/sc other-scs ...)`,
the optimizer cannot optimize any of the `other-scs ...` to `any/sc`
but it can optimize sub-contracts of the `other-scs ...`
Example:
`(or/sc set?/sc (box/sc set?/sc))` in a trusted position now optimizes to itself,
instead of `any/sc`
Optimization can resume under a sub-contract that represents a "heavy" type constructor.
(I mean, `U` is a type constructor but it's not "heavy" like that.)
Adds the following:
+ dependent function Types
+ some existential object support when applying
dependent functions
+ simplify linear arith support
+ add unsafe-require/typed/provide
* Add a test that suites and run-tests work in typed/rackunit
* Fix Seed type
The "seed" parameter of fold-test-results is passed to each test suite but, near as I can tell, never actually interacted with by the suite.
Changing `HashTableTop` from a singleton to the union:
```
(U (Immutable-HashTable Any Any) MutableHashTable WeakHashTable)
```
is a backwards compatibility issue because the type `Any` requires a chaperone,
therefore `HashTableTop` requires a chaperone.
This commit adds a case to make sure `HashTableTop` generates a flat contract.
The contract for `(U (I-Hash k1 v1) (M-Hash k2 v2) (W-Hash k3 v3))`
is now `(hash/c (or/c k1 k2 k3) (or/c v1 v2 v3))`
ONLY WHEN the key and value types are distinct.
The contract should no longer include duplicate key or value types.
The old 'HashTable' type is now the union of the other 3 hash types.
- all operations that used to work on 'HashTable's still work,
but some now have more specific outputs
- `#hash` literals have type `ImmutableHash`
- `immutable?` and `hash-weak?` are filters
- `Mutable-` and `Weak-` hashes have corresponding `Top` types, `HashTableTop` is now a union
- the contact for `(U (Immutable-Hash K1 V1) (Mutable-Hash K2 V2))` is ONE `hash/c`
Minor notes:
- renamed internal identifiers containing 'Hashtable' to all use 'HashTable'
- add Racket guide/reference 'secref' functions
check calls to resolve-once to see if they return #f
(i.e. if a type is not yet defined), and have overlap
only extend its seen list when it is resolving/unfolding
a potentially infinite type
fix intersection bug
intersections with resolvable types would occasionally generate
spurious weird types (e.g. μx.x) when a type name
is not yet fully defined -- this patches that problem by
using resolve-once instead of resolve and checking the result
for #f before proceeding to compute the intersection
This PR adds more support for refinement reasoning, in particular
type inference is now aware of argument objects which allows for
more programs w/ refinements to typecheck. Additionally, working
with vector types and literals that are refined or need to have
properties about their length proven now works.
Since the type-checker can now handle their expansions.
* add typed/racket/flonum and provide typed for/flvector and for*/flvector from it
* add typed/racket/extflonum and provide typed for/extflvector and for*/extflvector from it
The optimizer should only run when the code being compiled could
directly access racket/unsafe/ops. This prevents unsoundness in Typed
Racket from giving untrusted code access to dangerous operations.
Running with-tr-contracts as-is takes an unreasonable
amount of time because the tests are run w/o recompiling
typed racket. We need to find a way to make this more
reasonable (i.e. make sure we recompile before running
the unit tests) before enabling them for DrDr again.
This PR adds about half of the needed primitives and logic for
reasoning about linear integer arithmetic in programs with interesting
dependent types. Things have been added in a way s.t. programs will
still continue to typecheck as they did, but if you want integer literals
and certain operations (e.g. *,+,<,<=,=,>=,>) to include linear inequality
information by default, you need to include the
'#:with-linear-integer-arithmetic' keyword at the top of your module.
The other features needed to get TR to be able to check things like
verified vector operations will be to ajust function types so
dependencies can exist between arguments and a minor tweak to get
type inference to consider the symbolic objects of functions arguments.
These features should be coming shortly in a future pull request.
Keyword functions are a little tricky. This PR addresses issues
checking the body of kw functions.
Basically, a function with keyword arguments such as inc:
(define (inc x #:n [n 1])
(+ x n))
actually expands into a more complex function with 3 arguments that
looks something resembling the following:
(define (inc-expanded n* n-given? x)
(let ([n (if n-given? n* 1)]) (+ x n)))
and calls to inc are converted to match this form:
(inc 42) => (inc-expanded #f #f 42)
(inc 42 #:n 2) => (inc-expanded 2 #t 42)
Note that each optional keyword argument has a boolean flag argument
that signals whether or not the caller provided that keyword argument.
This PR takes advantage of the observation that the value for the n*
argument in inc is only reachable in code when n-given? is #t, and so,
assuming the kw-expansion protocol always only accesses n* if n-given?
is #t, we can actually safely check the body of the function against
the following simple but correct type:
(-> Number Boolean Number Number)
An alternative previous approach expanded the function type into every
possible combination of optional argument and optional argument flag,
but this was prohibitively expensive.
this is an trade-off since dynamically-valued interfaces are almost impossible to typecheck
https://github.com/racket/typed-racket/pull/468
Also, the `SQL-Datum` is now more precision, since `Any` shadows
all opaque types (such as `SQL-Null`) which may lead to contract errors.
An opaque object contract is stronger than another (opaque) object contract if:
- it has stronger field/method contracts on fields/methods common to both
- and it has no more field/method contracts than the other, if the other is opaque
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!))