<div dir="ltr">Our own Sam: one step ahead. :)<div><br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 9, 2013 at 7:55 PM, Sam Tobin-Hochstadt <span dir="ltr">&lt;<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>Not only did our own Sam write about this, but he thought that he changed Typed Racket to do this. Am I missing something here, or are you describing more optimization than we do already or ...?</p>
<span class="HOEnZb"><font color="#888888">
<p>Sam</p></font></span><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On Sep 9, 2013 8:33 PM, &quot;Robby Findler&quot; &lt;<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">FWIW, this is something that&#39;s been studied in small calculi in the literature. Nothing that will have to get thru all of the little details that you have to get right to make it work in a real language design like TR, but maybe you&#39;ll find some useful ways to look at the problem. (Mostly the papers I&#39;m thinking of have Jeremy Siek as a co-author but there are others, including our own Sam.)<div>


<br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 9, 2013 at 7:14 PM, Eric Dobson <span dir="ltr">&lt;<a href="mailto:eric.n.dobson@gmail.com" target="_blank">eric.n.dobson@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have ideas to remove about the contracts from TR code, but currently<br>
that is only prototyped.<br>
<br>
Example:<br>
<br>
#lang typed/racket<br>
(provide f)<br>
(: f (Number -&gt; Number))<br>
(define (f x) x)<br>
<br>
Currently f is exported with the contract (number? . -&gt; . number?),<br>
but this can be safely reduced to (number . -&gt; . any). This is because<br>
the return value contract is checking things we have already ensured<br>
statically. IIRC checking return values of functions is much more<br>
expensive than just arguments, so this should reduce the cost of TR<br>
boundary cost, but I don&#39;t have any numbers.<br>
<div><div><br>
On Mon, Sep 9, 2013 at 10:57 AM, Sam Tobin-Hochstadt<br>
&lt;<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>&gt; wrote:<br>
&gt; On Mon, Sep 9, 2013 at 11:35 AM, Neil Toronto &lt;<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Nice, and thanks for the explanation. Just to make sure I get it: does this<br>
&gt;&gt; mean fully expanded TR modules are smaller?<br>
&gt;<br>
&gt; Yes.<br>
&gt;<br>
&gt;&gt; Does it reduce the number of generated contracts?<br>
&gt;<br>
&gt; No.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On 09/08/2013 12:24 PM, Sam Tobin-Hochstadt wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Typed Racket has to expand into code that registers the type of each<br>
&gt;&gt;&gt; module-top-level identifier in the global environment so that other<br>
&gt;&gt;&gt; modules can find the types to typecheck with.  For example, this<br>
&gt;&gt;&gt; program:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; #lang typed/racket<br>
&gt;&gt;&gt; (provide x)<br>
&gt;&gt;&gt; (define: x : Integer 1)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; expands into (greatly simplified):<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; #lang ...<br>
&gt;&gt;&gt; (#%provide x)<br>
&gt;&gt;&gt; (begin-for-syntax<br>
&gt;&gt;&gt;    (declare #&#39;x Integer-rep))<br>
&gt;&gt;&gt; (define-values (x) 1)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; but what is `Integer-rep`?  It needs to be an expression that<br>
&gt;&gt;&gt; _constructs_ the internal Typed Racket representation of the `Integer`<br>
&gt;&gt;&gt; type. Previously, that looked something like this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;      (make-Union (sort (list Negative-Fixnum-rep Positive-Fixnum-rep<br>
&gt;&gt;&gt; ...)))<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; and so on and so forth for the components, all the way down to base<br>
&gt;&gt;&gt; types.  You can imagine how this gets quite large, especially for<br>
&gt;&gt;&gt; large types.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; However, this is wasteful, because every Typed Racket program, at type<br>
&gt;&gt;&gt; checking time, defines a constant that&#39;s the representation of the<br>
&gt;&gt;&gt; `Integer` type, right here [1]. So instead of serializing an<br>
&gt;&gt;&gt; expression that constructs the same thing as `-Int`, we can just<br>
&gt;&gt;&gt; *reference* `-Int` in the expanded code.  To make that possible, Typed<br>
&gt;&gt;&gt; Racket now builds a hash table [2] mapping types (really, their<br>
&gt;&gt;&gt; representations) to identifiers that denote those types. Then the<br>
&gt;&gt;&gt; serializer just consults this table [3].<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; It turns out that base types (but no others) already used basically<br>
&gt;&gt;&gt; this mechanism, by storing the identifier *in* the type<br>
&gt;&gt;&gt; representation.  But that&#39;s now obsolete, and thus was removed in my<br>
&gt;&gt;&gt; subsequent commit.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; As a result, the type serialization is much smaller.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; [1]<br>
&gt;&gt;&gt; <a href="https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/numeric-tower.rkt#L107" target="_blank">https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/numeric-tower.rkt#L107</a><br>



&gt;&gt;&gt; [2]<br>
&gt;&gt;&gt; <a href="https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/base-abbrev.rkt#L23" target="_blank">https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/base-abbrev.rkt#L23</a><br>



&gt;&gt;&gt; [3]<br>
&gt;&gt;&gt; <a href="https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/env/init-envs.rkt#L51" target="_blank">https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/env/init-envs.rkt#L51</a><br>



&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Sat, Sep 7, 2013 at 3:20 PM, Neil Toronto &lt;<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>&gt;<br>
&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On 09/06/2013 04:14 PM, <a href="mailto:samth@racket-lang.org" target="_blank">samth@racket-lang.org</a> wrote:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; 56b372c Sam Tobin-Hochstadt &lt;<a href="mailto:samth@racket-lang.org" target="_blank">samth@racket-lang.org</a>&gt; 2013-09-06 14:22<br>
&gt;&gt;&gt;&gt;&gt; :<br>
&gt;&gt;&gt;&gt;&gt; | Remember types that are defined, and use them in serialization.<br>
&gt;&gt;&gt;&gt;&gt; |<br>
&gt;&gt;&gt;&gt;&gt; | This extends a facility already available for base types,<br>
&gt;&gt;&gt;&gt;&gt; | making that facility no longer strictly needed.<br>
&gt;&gt;&gt;&gt;&gt; |<br>
&gt;&gt;&gt;&gt;&gt; | Shrinks the zo size for the `math` package by almost 1MB.<br>
&gt;&gt;&gt;&gt;&gt; :<br>
&gt;&gt;&gt;&gt;&gt;     M .../typed-racket/env/init-envs.rkt                |   1 +<br>
&gt;&gt;&gt;&gt;&gt;     M .../typed-racket/typecheck/def-export.rkt         |   7 +-<br>
&gt;&gt;&gt;&gt;&gt;     M .../typed-racket/typecheck/tc-toplevel.rkt        |  31 +++---<br>
&gt;&gt;&gt;&gt;&gt;     M .../typed-racket/types/abbrev.rkt                 |  36 +++----<br>
&gt;&gt;&gt;&gt;&gt;     M .../typed-racket/types/base-abbrev.rkt            |  12 ++-<br>
&gt;&gt;&gt;&gt;&gt;     M .../typed-racket/types/numeric-tower.rkt          | 108<br>
&gt;&gt;&gt;&gt;&gt; +++++++++----------<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Would you mind explaining this a little more? It sounds interesting, and<br>
&gt;&gt;&gt;&gt; the<br>
&gt;&gt;&gt;&gt; commit almost has my name in it. :)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Neil ⊥<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt; _________________________<br>
&gt;   Racket Developers list:<br>
&gt;   <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
<br>
_________________________<br>
  Racket Developers list:<br>
  <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
</div></div></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>