Commit Graph

117 Commits

Author SHA1 Message Date
Andrew Kent
8aa05bebff add dependent function types (#584)
Adds the following:
+ dependent function Types
+ some existential object support when applying
  dependent functions
+ simplify linear arith support
+ add unsafe-require/typed/provide
2017-09-25 12:52:33 -04:00
Jack Firth
6369753c28 Fix typed/rackunit contract exception when using run-tests (#583)
* 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.
2017-07-14 08:58:11 -04:00
Ben Greenman
afa0530b3a backwards-compatibility: make HashTableTop generate a flat contract
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.
2017-07-13 15:13:59 -04:00
Ben Greenman
6c2a7eb512 patch: check duplicates before making an or/c for hash keys
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.
2017-06-27 01:38:18 -04:00
Ben Greenman
fae58e140d add types for Immutable-HashTable, Mutable-HashTable, Weak-HashTable (#559)
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
2017-06-26 18:00:19 -04:00
Andrew Kent
dda8b1da20 fix resolve usage in overlap, allocate less (#555)
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
2017-05-22 22:55:33 +01:00
Vincent St-Amour
c0af5235d2 Add support for #:ps argument in command-line. 2017-05-18 15:50:18 -05:00
Daniel Feltey
764696752d Disarm syntax in typed unit macros
Closes #536
2017-04-27 17:46:23 -05:00
Daniel Feltey
4b35df2c96 Be less rigid about the shape of type annotations in units
Closes #535
2017-04-27 17:24:54 -05:00
Andrew Kent
80d1654dee add more refinement support for inference and literals (#528)
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.
2017-04-22 18:45:22 -04:00
Andrew Kent
5fbf4d30a8 singleton char types if expected type (#527) 2017-03-31 18:04:05 -04:00
Andrew Kent
81b134cbb9 add refinement types, linear expr objs, and ineq props (#510)
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.
2017-03-27 14:32:29 -04:00
Ben Greenman
2804bd4a93 update path-add-extension type with new optional argument (#519) 2017-03-27 10:18:53 -04:00
Benjamin Greenman
ed2cf43a19 regression test for issue #33 (#493)
closes #33
2017-01-14 10:56:20 -05:00
WarGrey Gyoudmon Ju
3077af848b in-query returns a sequence of single value (#468)
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.
2017-01-06 11:34:54 -05:00
WarGrey Gyoudmon Ju
4e02bd44ab Add #lang typed/racket/gui/no-check (#467) 2017-01-06 11:29:04 -05:00
Ben Greenman
3e2d020a19 Implement object/c-opaque-stronger
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
2017-01-06 02:41:59 -05:00
WarGrey Gyoudmon Ju
e72f2506df Add typed/images/compile-time.rkt (#476) 2017-01-04 17:02:42 -05:00
Andrew Kent
be155fa3e3 propagate expected type info further down AST
Previously expected propositions were erased frequently
(at lets and ifs) and checking for logical entailment
was unidirectional instead of bidirectional. In other words,
instead of checking if propositions held at the leaves
of the AST, we would typecheck the AST and blindly propagate
up ALL logical info we learned at each step. This meant that
we would get exponential blow up of propositions even when
we didn't care about their content.

With this commit, instead now we send down expected types
*and* propositions so we can verify expected types and
propisitions are satisfied at leaves, thereby relieving the
need to constantly report up huge amounts of logical info
while typechecking.
2016-12-20 07:43:21 -05:00
Andrew Kent
da30fb6f74 be less eager about bottom propogation
Moving to eager propagating of bottom works for most cases,
but in some cases flattening types such as (Pairof Bottom Any)
to Bottom made things like type inference break for some cases
(since (Listof Nothing) == Null, and (Listof A) did not structurally
like up like it used to). Perhaps w/ a little more effort
inference and any other potential issues could work better
with propagating bottom, but for now we'll be slightly less
aggressive about it.

i.e. this fixes pfds, which commit 8e7f390 broke.
2016-12-19 08:28:49 -05:00
Sam Tobin-Hochstadt
0678743e3d Fix errors in a9ae85d3. 2016-11-05 20:02:15 -04:00
Sam Tobin-Hochstadt
a9ae85d3fd Fix #378 more comprehensively. (#453)
The previous fix relied on finding and manipulating all dead code.
But we missed some; in particular code of the form:

    (begin (error 'x) ...dead...)

So switch to a different strategy that tolerates untraversed
dead code.
2016-11-05 13:11:25 -04:00
Andrew Kent
9c33a54c6a fix intersect, make it (hopefully) commutative 2016-10-25 19:25:28 -04:00
Andrew Kent
9df3a1dab5 fix resolve for names being defined 2016-10-23 21:47:00 -04:00
Andrew Kent
24c64e9de0 new representation scheme for typed racket internals
This is a major to some of the internal representation of things
within Typed Racket (mostly affecting structs that inherited from Rep
(see rep/rep-utils.rkt)), and lots of tweaks and bug fixes that
happened along the way.

This PR includes the following major changes:

A new rep-utils implementation, which uses struct properties for the
generic operations and properties of the various Reps (see
rep-utils.rkt)

More specific Rep inheritance (i.e. arr no longer inherits from Type,
because it is not a Type, etc ...) (see type-rep.rkt, core-rep.rkt,
values-rep.rkt), and thus things like Type/c no longer exist

New Rep's to classify the things that are no longer Type or Prop,
(such as PropSets, SomeValues, Results, etc -- see core-rep.rkt and
values-rep.rkt)

uses of type-case now replaced by uses of Rep-fold and Rep-walk

structural types can specify their fields' variance and operations
like subtyping and free-vars can generically operate over these types
(see type-rep.rkt)

type-mask replaces types key -- types masks are described in detail in
(rep/type-mask.rkt)

Types can specify a predicate to recognize their "top type" via [#:top
pred])

There is an explicit 'Bottom' type now (i.e. neither union or
intersection are used)

subtyping re-organized, slight tweaking to inference

various environments got for-each functions in addition to the map
functions they had (e.g. type-name-env.rkt)

Empty is no longer an Object? -- the OptObject? predicate checks for
either Object or Empty, and so it is easier to be clear about where
Empty makes sense appearing and where it does not

Previously signatures were created with promises in their fields, now
we create a promise around each signature (this way the contracts for
Signature fields are cleaner)

Names for structs now use the args field to describe how many type
arguments they take (Note: this could use further tidying for sure!)

simplified the propositional logic code in several places, got rid of
escape continuations, etc (see prop-ops.rkt, tc-envops.rkt,
tc-metafunctions.rkt)

we now use subsumption more to simplify type results from type
checking, e.g. if the type does not overlap w/ false, it's false
proposition is FalseProp, etc (see tc-expr-unit.rkt and prop-ops.rkt,
the function is called reduce-tc-results/subsumption)

updating along a path will now intersect with the expected structural
type if it is not encountered (e.g. updating Any with (Int @ car) now
produces (Pairof Int Any) instead of Any -- see update.rkt)

lots of tests were tweaked to match up w/ the new prop subsumption
that occurs

remove was renamed subtract (so as to not conflict w/ racket/base's
remove)

a restrict function was added, which acts like intersect but is never
additive (i.e. it will never create an intersection if it can't figure
out how the two types relate -- see intersect.rkt)

tc-subst was modified to substitute out all the variables leaving
scope at once (and I simplified/tweaked some of the logic in there a
little, see tc-subst.rkt)

Type checking function applications now propagates information learned
why type checking the arguments, (e.g. (begin (f (assert x boolean?))
...)) ; the remainder of the begin is aware that x is a boolean)
2016-10-21 14:24:27 -04:00
Alex Knauth
bbb62da731 fix type of non-empty-string? (#427)
fixes #426
2016-09-12 09:17:57 -04:00
Alex Knauth
dfd61642b6 unsafe-require/typed #:opaque doesn't warn about opaque structs passed as Any (#418) 2016-08-31 11:37:05 -04:00
Asumu Takikawa
10eb2542c6 Add syntax for poly structs in require/typed
Currently only works in unsafe requires. In other cases
it will emit an error instead.

Also bump version
2016-07-21 12:00:08 -04:00
Asumu Takikawa
98d0657141 Fix contracts for structs with the same name (PR 15330) (#410)
Fix contracts for structs with the same name

Closes PR 15330
2016-07-21 11:14:05 -04:00
Andrew Kent
a5c4ad2f77 have overlap use a current-seen list 2016-07-13 15:21:17 -04:00
Ben Greenman
2409457930 type for #:limit-prefix? formatting option 2016-07-10 20:42:57 -04:00
Sam Tobin-Hochstadt
27ed39d101 Adjust tests since opaque structs are no longer accepted by Any. 2016-07-09 21:22:08 -04:00
Benjamin Greenman
92c67b16ae add any-wrap test for Environment-Variables (#390) 2016-07-08 20:11:30 -04:00
Alex Knauth
191ec136b6 fix any-wrap/c unsoundness on opaque structures (#385) 2016-07-07 20:58:26 -04:00
Alex Knauth
9f3cf01d26 don't throw internal errors for unreachable cast exprs (#386)
This fills the corresponding entries in the cast table with a Dead-Code
type so that when the contract-generation pass calls the contract-def
thunk, it finds that in the table.
2016-07-07 16:51:08 -04:00
Alex Knauth
a1f8908a29 call compute-constraints instead of sc->constraints in get-max-contract-kind (#382)
* call compute-constraints instead of sc->constraints in get-max-contract-kind

* test cast on an intersection type involving Rec

* remove memory limit on sandboxed-unsafe-ops test
2016-07-07 12:16:15 -04:00
Alex Knauth
583a752954 test (and/c vector? any-wrap/c) -like contracts 2016-06-29 17:04:23 -04:00
Asumu Takikawa
527b233e45 Remove pconvert dependency in tests
The test just tests whether struct properties
work and it's not important what the precise
property is.
2016-06-21 16:43:38 -04:00
Asumu Takikawa
295a4b7e39 Simplify flat contracts for Value types
Potentially speeds up contracts checks for
types like False or Boolean.
2016-06-13 04:08:33 -04:00
AlexKnauth
a846514f28 make cast sound 2016-06-06 13:19:33 -04:00
Asumu Takikawa
b338fc6b64 Be less conservative about struct overlap
Fixes issue #366
2016-06-01 14:23:13 -04:00
Asumu Takikawa
71f17f5cb2 Compute struct intersection more conservatively
Fixes GH issue #205
2016-05-20 16:56:49 -04:00
Andrew Kent
b4a4c174e4 initial intersection types addition
Adds intersection types as a better way to handle the the case
when restrict cannot structurally intersect two types (e.g. when
you learn within a polymorphic function a variable x of type A
is also an Integer, but we dont know how A relates to Integer).
This allows for non-lossy refinements of type info while typechecking.
2016-05-20 11:34:04 -04:00
Asumu Takikawa
af385d6932 Fix issue #336 2016-04-28 11:29:12 -04:00
Vincent St-Amour
b352739131 Always populate type table, regardless of optimizer status.
Closes #343.
2016-04-11 14:43:44 -05:00
Asumu Takikawa
cea5091ee6 Fix struct name in Struct type representation
Closes issue #304
2016-04-07 21:49:50 -04:00
Georges Dupéron
e33c902842 Remove debugging output from test case in typed-racket-test/succeed/define-typed-untyped-identifier-syntax-properties.rkt 2016-04-07 16:47:17 +02:00
Georges Dupéron
4ab256abf2 Fixes GH issue #315 Syntax properties are not forwarded by define-typed/untyped-identifier, following @samth's suggestions. 2016-04-06 12:06:42 -05:00
Sam Tobin-Hochstadt
7572adb9c2 Fix use of simple-result-> to check the domains.
This broke pict3d, but also disabled some contract checks that
should have been kept.
2016-03-28 17:11:37 -04:00
Sam Tobin-Hochstadt
0bfaa75bcf Add test for test-case from typed/rackunit. 2016-02-02 08:21:02 -05:00