Commit Graph

37761 Commits

Author SHA1 Message Date
Robby Findler
f7465f81f1 convert stream/c to late-neg-projection
Also, tune the projection to get a few modest performance gains.

This program gets about 20% faster:

  #lang racket
  (define s (contract (stream/c exact-nonnegative-integer?)
                      (in-naturals) 'pos 'neg))
  (time
   (for ([x (in-range 1000)])
     (for/fold ([s s])
               ([x (in-range 100)])
       (stream-rest s))))

and this program gets about 15% faster:

  #lang racket
  (define f (contract (-> (stream/c exact-nonnegative-integer?)
                          any)
                      (λ (x) 1)
                      'pos 'neg))
  (define l (make-list 10000 0))
  (time (for ([x (in-range 1000)])
          (f l) (f l) (f l) (f l) (f l)))
2015-12-28 21:57:03 -06:00
Robby Findler
ff31b01505 add some error checking for custom set type constructors 2015-12-28 16:59:43 -06:00
Robby Findler
50405a2ca9 fix chaperone-hash-set and impersonate-hash-set for custom-set-types 2015-12-28 16:59:42 -06:00
Matthew Flatt
e08188aeda add source for "racket-playsound.exe" 2015-12-28 07:37:29 -06:00
Matthew Flatt
cefcbdf802 Windows: ensure 'kill subprocesses end with Racket
Use a job object to ensure that subprocesses that are meant
to be killed by the current custodian are reliably terminated
if Racket exits for any reason.
2015-12-28 07:37:29 -06:00
Matthew Flatt
afa01fa763 allow optimizations around procedure-specialize
Although `procedure-specialize` should be useful in places where
inlining does not apply, allowing inlining and related optimizations
through it, anyway.
2015-12-28 07:37:29 -06:00
Robby Findler
b3d05de304 improvements to set/c
- use chaperone-hash-set for set/c when the contract allows only hash-sets

- add a #:lazy flag to allow explicit choice of when to use laziness
  (but have a backwards-compatible default that, roughly, eschews laziness
   only when the resulting contract would be flat)
2015-12-27 22:56:04 -06:00
Robby Findler
bc12019af4 allow the interposition procedures to all be #f in chaperone-hash-set and impersonate-hash-set 2015-12-27 21:02:20 -06:00
Robby Findler
8f2874e4b5 fix impersonator properties for chaperone-hash-set and impersonate-hash-set 2015-12-26 22:37:00 -06:00
Robby Findler
daf19869de chaperone-hash-set fixes 2015-12-26 22:09:14 -06:00
Robby Findler
1b6705f3d9 typo 2015-12-26 17:01:22 -06:00
Robby Findler
d927d04efd generalize tail contract checking for function contracts
Specifically, remove reliance on procedure-closure-contents-eq? to
tell when a pending check is stronger in favor of usint
contract-stronger?

Also, tighten up the specification of contract-stronger? to require
that any contract is stronger than itself

With this commit, this program gets about 10% slower:

  #lang racket/base
  (require racket/contract/base)
  (define f
    (contract
     (-> any/c integer?)
     (λ (x) (if (zero? x)
                0
                (f (- x 1))))
     'pos 'neg))
  (time (f 2000000))

becuase the checking is doing work more explicitly now but because the
checking in more general, it identifies the redundant checking in this
program

  #lang racket/base
  (require racket/contract/base)
  (define f
    (contract
     (-> any/c integer?)
     (contract
      (-> any/c integer?)
      (λ (x) (if (zero? x)
                 0
                 (f (- x 1))))
      'pos 'neg)
     'pos 'neg))
  (time (f 200000))

which makes it run about 13x faster than it did before

I'm not sure if this is a win overall, since the checking can be more
significant in the case of "near misses". For example, with this
program, where neither the new nor the old checking detects the
redundancy is about 40% slower after this commit than it was before:

  #lang racket/base
  (require racket/contract/base)
  (define f
    (contract
     (-> any/c (<=/c 0))
     (contract
      (-> any/c (>=/c 0))
      (λ (x) (if (zero? x)
                 0
                 (f (- x 1))))
      'pos 'neg)
     'pos 'neg))

  (time (f 50000))

(The redundancy isn't detected here because the contract system only
looks at the first pending contract check.)

Overall, despite the fact that it slows down some programs and speeds
up others, my main thought is that it is worth doing because it
eliminates a (painful) reliance on procedure-closure-contents-eq? that
inhibits other approaches to optimizing these contracts we might try.
2015-12-25 22:58:56 -06:00
Robby Findler
f0f85549ce add impersonate-hash-set and chaperone-hash-set 2015-12-25 22:58:55 -06:00
Robby Findler
c9d192f09b make more explicit that define-custom-set-types produces hash sets. 2015-12-25 22:58:55 -06:00
Robby Findler
badf2bd19e audit requires of files that require misc.rkt in racket/contract 2015-12-25 22:58:55 -06:00
Robby Findler
7708b2056a use specialize-procedure on predicate portion or or/c
This seems to give about a 10% speedup on this program:

 #lang racket/base
(require racket/contract/base)
(define f (contract
           (-> (or/c number? symbol?) any)
           (λ (x) 0)
           'pos 'neg))

(time
 (for ([_ (in-range 1000000)])
   (f 'x) (f 'x) (f 'x) (f 'x)))
2015-12-25 14:17:03 -06:00
Matthew Flatt
0840fcd6c8 JIT: avoid assertion failures due to a full buffer 2015-12-25 08:04:22 -06:00
Matthew Flatt
f0d09dbef1 make JIT recognize literal struct predicatates, etc.
Mka the closure specializer handle literal struct operations
(as opposed to just references to struct operations).
2015-12-25 07:14:40 -06:00
Matthew Flatt
843992d0c7 use specialization opportunity for #%apply-values 2015-12-24 12:17:31 -06:00
Matthew Flatt
144da5abd4 Merge pull request #1178 from vendethiel/patch-1
Fix small typo in jit.h
2015-12-24 05:30:35 -07:00
ven
c1950f1ae3 Fix small typo in jit.h
Just noticed it while reading db0a6de1d2
2015-12-24 10:11:56 +01:00
Matthew Flatt
ba2eb6487c restore precision for procedure-closure-contents-eq?
After adding `procedure-specialize`, making
`procedure-closure-contents-eq?` work as before involves
a little extra tracking. I'd prefer to weaken or
even get rid of `procedure-closure-contents-eq?`, but
this adjustment keeps some contract tests passing.
2015-12-23 22:06:18 -07:00
Matthew Flatt
44e1262648 unbreak no-JIT build 2015-12-23 21:51:14 -07:00
Matthew Flatt
db0a6de1d2 add procedure-specialize
The `procedure-specialize` function is the identity function, but it
provides a hint to the JIT to compile the body of a closure
specifically for the values in the closure (as opposed to compiling
the body generically for all closure instances).

This hint is useful to the contract system, where a predicate
is coerced to a projection with

 (lambda (p?)
   (procedure-specialize
    (lambda (v)
      (if (p? v)
          v
          ....))))

Specializing the projection to a given `p?` allows primitive
predicates to be JIT-inlined in the projection's body.
2015-12-23 17:46:56 -07:00
Matthew Flatt
592ae853e3 JIT: fast path for procedure impersonator w/o wrapper proc
Make the JIT-generated function-call dispatch recognize a call to
an impersonator that wraps a procedure only to hold properties.

This change also repairs handling for a arity-reducing wrapper
on a primitive, where the fast path incorrecty treated the
primitive as a JIT-generated function.
2015-12-22 15:05:14 -07:00
Matthew Flatt
b794404333 faster path for a procedure impersonator w/o wrapper proc
Make the call path faster when an impersontor is present
on a procedure only to add impersonator properties.
2015-12-22 15:04:53 -07:00
Matthew Flatt
e8073e699e restore a fast path for a procedure chaperone
When the representation of a redirect changed, the fast
path wasn't updated.
2015-12-22 15:04:53 -07:00
Matthew Flatt
c73bcceafe avoid a string pointer needed only for error reporting 2015-12-22 15:04:53 -07:00
Robby Findler
d2233f95e2 make vectorof also try less hard during or/c checking 2015-12-22 16:02:48 -06:00
Robby Findler
8a9408306b have a better strategy for or/c to determine which clause to commit to
in particular, when there is a recursive contract, then we check only
some part of the first-order checks and see if that was enough to
distinguish the branches. if it was, we don't continue and otherwise we do
2015-12-22 16:02:44 -06:00
Robby Findler
31cf0bdbc3 remove the error-prone except-out's from racket/contract
and take the opportunity to move some things around
internally to more reasonable places
2015-12-22 15:51:40 -06:00
Robby Findler
d2bf335212 use the correct accessor for subcontracts 2015-12-22 15:51:39 -06:00
Matthew Flatt
2b10262258 get-module-suffixes: put "rkt" first
Putting "rkt" first in the list makes it likely to act as
a default, such as for a `put-file` dialog.
2015-12-22 11:03:09 -07:00
Matthew Flatt
9bdbd14b96 sync version numbers 2015-12-22 08:03:26 -07:00
Matthew Flatt
c01ced6e1d add syntax-transforming-with-lifts? 2015-12-22 08:02:44 -07:00
Robby Findler
b221e00937 Revert " clean up exports of racket/contract/combinator"
I didn't intend to push that commit
2015-12-21 22:56:34 -06:00
Robby Findler
aeb0509f3a fix performance bug in late-neg projection for cons/c
the first-order check and the projection itself
can duplicate work (potentailly lots of work
in a non-constant factor sort of a way when
recursive-contract is involved)

this seems also to be a potential problem for other
uses of or/c too
2015-12-21 22:53:02 -06:00
Robby Findler
99d7ad56d9 clean up exports of racket/contract/combinator
It used to have a (provide (except-out (all-from-out <private-file>) ...))
    and various private functions leaked to the outside over the years.

    None of the ones removed in this commit were documented, so hopefully
    they weren't being used. But this is definitely not backwards compatible,
    so this commit is mostly about testing the waters
2015-12-21 10:32:41 -06:00
Robby Findler
3a4ba9a1ca fix parametric->/c for the keyword case 2015-12-21 10:32:08 -06:00
Robby Findler
261a5cb1f4 port rename-contract to late-neg projection and add some tests 2015-12-21 09:32:14 -06:00
Robby Findler
e4ffa6c97c port if/c to late-neg, add tests, and fix some (minor) bugs 2015-12-21 09:20:45 -06:00
Robby Findler
8776ab7686 remove implementations of non-late-neg projections from bunch of combinators 2015-12-21 09:20:45 -06:00
Robby Findler
7d02f4c7b1 port parametric->/c to late-neg 2015-12-21 08:06:14 -06:00
Robby Findler
35b2320730 add more warning logging for contracts that don't have late-neg projections 2015-12-21 07:27:38 -06:00
Robby Findler
efc8bcc2fd update contract in comment 2015-12-20 21:17:53 -06:00
Matthew Flatt
0553f191d7 adjust PLT_INCREMENTAL_GC so it can disable generational GC
A value that starts "1", "y", or "Y" enabled incremental mode
permanently (any value was allowed formerly), while a value that
starts "0", "n", or "N" causes incremental-mode requests to be
ignored.
2015-12-20 08:58:21 -07:00
Matthew Flatt
3a99a19c56 reduce double major GCs
When a major GC triggers finalization, another major
GC is scheduled immediately on the grounds that the
finalizer may release other values. That was important
at once time, but the finalization and weak-reference
implementation has improved to the point where the
extra ful GC no longer seems necessary or useful.
2015-12-20 08:58:21 -07:00
Matthew Flatt
513849c1e3 incremental GC: make accounting incremental for the root custodian 2015-12-20 08:58:21 -07:00
Matthew Flatt
9711000b70 drop generation 1/2 except in incremental mode
Originally, generation 1/2 was intended to delay major
collections when the heap is especially large. It doesn't
seem to be effective in that case, and it can slow down
minor GCs, so continue to use it only in incremental
mode (where it helps significantly with fragmentation).
2015-12-20 08:58:21 -07:00
Matthew Flatt
6957780cd5 incremental GC: tune departure from incremental mode
At the completion of an incremental major GC, if incremental
mode wasn't requested recently, schedule an immediate major
GC to reduce the heap back to its normal footprint.
2015-12-20 08:58:21 -07:00