Commit Graph

322 Commits

Author SHA1 Message Date
Andrew Kent
aa1d36f44e add type syntax for Union/Intersection 2016-12-19 20:16:36 -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
Andrew Kent
8e7f39025a remove interning for most Reps in TR
Prior to this change (which was Typed Racket PR 469) all internal TR
objects (Reps) were interned and kept around for the entire duration
of type checking.  Because of this, frequent operations that rebuilt
types were particularly costly (e.g. various forms of
substitution). To recoup some of this cost, caching was being used in
a lot of places. This PR sought to remove interning as the default
behavior for Reps and allow for more flexibility in how we approach
time/space performance needs going forward.

The following changes were included in this overhaul:

Interning: All Reps are no longer interned. Right now we only intern
unions and some propositions.

Rep generic operations: we now use racket/generic so we're not
reinventing this wheel.

Singletons: Reps (e.g. TrueProp, Univ, etc) can be declared singleton,
which creates a single instance of the rep that all visible operations
(even within the declaring module) are defined in terms of
(e.g. predicates are defined as (λ (x) (eq? x singleton-instance)),
etc).

Custom constructors: Custom constructors can be specified for Reps,
which allows for simple normalization, interning, or other invariants
to be enfored whenever a Rep is created.

Union: Unions used to try to ensure no obviously overlaping types
would inhabit the same Union (e.g. (U String (Pairof Any Any) (Pairof
Int Int)) would be simplified to (U String (Pairof Any Any))). This,
however, required frequent calls to subtyping every time a Union was
modified and working with Unions thus had a high cost (another thing
that caching was used to reduce). Instead of this, Unions now enforce
a much simpler set of invariants on their members: (1) No duplicates
(by virtue of using a hash-based set), (2) Any and Nothing do not
appear in unions, and (3) Nested unions are flattened. Also, using a
hashset as the internal data structure meant that we could easily
intern unions w.r.t. equal? equality. NOTE: we do reduce unions to not
contain obviously overlapping terms when printing to users and when
generating contracts (so obviously and avoidable inneficient contracts
are not generated – See union.rkt for 'normalize-type').

Subtyping changes: Subtyping has been designed to reduce dispatch time
w/ a switch since we no longer cache _all_ subtyping calls (we only
cache subtyping results for unions since they have some costly
subtyping).

prop-ops changes: AndProps now are careful to sort OrProps by length
before building the resulting proposition. This is done because
OrProp implication only checks if one Or is a subset of another Or.
By ordering Or props by size, we only ever check if an OrProp implies
another if its size is <= the other OrProp. This also makes the
smart constructor '-and' more robust, since the order the props
appear does not affect if some Ors are kept or not.

Testing: More subtype tests have been added (we are still probably
relying too much on typecheck-tests.rkt and not the more granular unit
tests in general).  Also, typecheck-tests.rkt has been changed to
check for type-equivalence (i.e. subtyping in both directions)
instead of equal? equivalence.
2016-12-16 15:18:50 -05:00
Vincent St-Amour
859d9f9eee Fix another test for new for expansion.
The new expansion actually helps us avoid a spurious unboxing.
2016-12-14 15:19:42 -06:00
Vincent St-Amour
60ba1c4447 Fix tests for new expansion of for. 2016-12-14 14:36:15 -06:00
Vincent St-Amour
67bf3db5b8 Fix test for improved syntax-parse optimization. 2016-12-13 14:23:34 -06:00
Andrew Kent
f9385af461 clean up tc-let-unit
This commit cleans up some helper functions that have been
pretty awful for a while. The code is (hopefully) more readable
and it does less work (i.e. unneeded substitutions are no longer
performed).
2016-11-21 19:49:33 -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
Vincent St-Amour
4773283f8f Extend type of vector->list.
Closes #436.
2016-10-08 18:33:39 -05: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
Vincent St-Amour
c256e47e27 Have literal-related optimizations see through ann. 2016-08-04 13:05:27 -05:00
Vincent St-Amour
3b488c1f13 Update test for new syntax-parse behavior.
Sees something twice that it used to see once.
2016-08-04 12:54:11 -05:00
Asumu Takikawa
164b22de59 Add and document row-inst form, Row syntax
Before this, row instantiation was done with an ad-hoc
and undocumented syntax. Adding a new form works better
because rows should not be parsed as types.
2016-07-21 18:29:30 -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
Sam Tobin-Hochstadt
3f372c3b04 Try removing more limits on this test so it succeeds on Travis.
Suggestion from @mflatt.
2016-07-12 10:41:18 -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
e3f56c8a25 check for free-vars in types of casted-exprs (#384) 2016-07-07 14:45:07 -04:00
Andrew Kent
39d6a6047a better rec type intersection 2016-07-07 12:53:31 -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
Sam Tobin-Hochstadt
a10fd9ef45 Fix accidentally-committed debugging code. 2016-06-24 09:15:28 -04:00
Sam Tobin-Hochstadt
8bcfc71fa8 Avoid overlap with sequences of the wrong arity.
Fixes #371.
2016-06-23 12:00:53 -04:00
Asumu Takikawa
ee02c26020 Fix bug in init-envs (need to generate Rows too)
Also simplified Class case a bit
2016-06-22 17:47:46 -04:00
Asumu Takikawa
ca26d22d1c Fix optimizer fix
Fixed spurious syntax quoting and a test
2016-06-22 00:24:31 -04:00
Sam Tobin-Hochstadt
34ff91b3ca Avoid misoptimizing vector-set! of immutable vectors. 2016-06-21 18:05:38 -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
5f311d00c7 Add more init-env tests 2016-06-21 16:37:17 -04:00
Asumu Takikawa
773dab2c24 Reimplement environment initialization
Avoids using mzlib/pconvert in favor of a few big match
clauses. This lets us cut out a package dependency and
makes the code easier to understand.

This commit also removes the use of mzlib/pconvert
in the debug printer in favor of just using the type
serialization performed in init-envs.rkt.

In addition, a few optimizations for type serialization
were implemented that cut a few percent off of zo sizes.

Note that this commit regresses for zo sizes for modules
that heavily use GUI classes, but that is fixed in a
future commit.
2016-06-21 16:37:17 -04:00
Brian Lachance
ec0c8516c2 Add types for combinations, in-combinations 2016-06-15 09:58:36 -04:00
Asumu Takikawa
bc6e9e80cc Don't use number literal types as contracts
Using = for the comparison doesn't work for TR

Fixes bug in 295a4b7e39
2016-06-13 13:25:51 -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
Vincent St-Amour
1ba8e5ba33 Fix test that relied on broken mcons printing. 2016-06-11 16:34:23 -05:00
Sam Tobin-Hochstadt
e3863149f5 Increase timeout again. 2016-06-11 15:20:02 -04:00
AlexKnauth
a846514f28 make cast sound 2016-06-06 13:19:33 -04:00
Asumu Takikawa
a984281cdc Add first-order checks to simple-result-> contract
Fixes issue #368
2016-06-03 13:49:26 -04:00
Asumu Takikawa
7aea90242a Adjust contract tests to allow first-order checks 2016-06-03 13:46:00 -04:00
Asumu Takikawa
b338fc6b64 Be less conservative about struct overlap
Fixes issue #366
2016-06-01 14:23:13 -04:00
Andrew Kent
d66816cf76 use match*/no-order to reduce manual code duplication 2016-05-23 18:13:28 -04:00
Asumu Takikawa
71f17f5cb2 Compute struct intersection more conservatively
Fixes GH issue #205
2016-05-20 16:56:49 -04:00