OLD | NEW |
---|---|
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{color} | 3 \usepackage{color} |
4 \usepackage{dart} | 4 \usepackage{dart} |
5 \usepackage{bnf} | 5 \usepackage{bnf} |
6 \usepackage{hyperref} | 6 \usepackage{hyperref} |
7 \usepackage{lmodern} | 7 \usepackage{lmodern} |
8 \newcommand{\code}[1]{{\sf #1}} | 8 \newcommand{\code}[1]{{\sf #1}} |
9 \title{Dart Programming Language Specification \\ | 9 \title{Dart Programming Language Specification \\ |
10 {\large Version 1.9}} | 10 {\large Version 1.9}} |
(...skipping 3074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3085 | 3085 |
3086 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k]) => e$ | 3086 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k]) => e$ |
3087 is | 3087 is |
3088 | 3088 |
3089 $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow T _0$, where $T_0$ is the static type of $e$. | 3089 $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarrow T _0$, where $T_0$ is the static type of $e$. |
3090 | 3090 |
3091 \LMHash{} | 3091 \LMHash{} |
3092 The static type of a function literal of the form | 3092 The static type of a function literal of the form |
3093 | 3093 |
3094 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k])$ \ASYNC{} $=> e$ | 3094 $(T_1$ $a_1, \ldots, T_n$ $a_n, [T_{n+1}$ $x_{n+1} = d_1, \ldots, T_{n+k}$ $x_{ n+k} = d_k])$ \ASYNC{} $=> e$ |
3095 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future<flatten(T_0)>$, where $T_0$ is the static type of $e$ and $flatten(T) = flatten(S)$ if $T = Future<S>$, and $T$ otherwise. | 3095 is $(T_1 \ldots, T_n, [T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}]) \rightarro w Future<flatten(T_0)>$, where $T_0$ is the static type of $e$ and $flatten(T)$ is defined as follows: |
3096 | |
3097 If $T <: Future$ then let $S$ be a type such that $T << Future<S>$ and for all $ R$, if $T << Future<R>$ then $S << R$. | |
3098 | |
3099 \rationale{ | |
3100 This ensures that $Future<S>$ is the most specific instantiation of \cd{Future} that is a super type of $T$. | |
3101 } | |
3102 | |
3103 Then $flatten(T) = flatten(S)$ iff $S \ne T$. | |
3104 | |
3105 In any other circumstance, $flatten(T) = T$. | |
Paul Berry
2015/03/17 01:51:51
I don't think this addresses the infinite regress
| |
3106 | |
3107 | |
3096 | 3108 |
3097 \rationale{ | 3109 \rationale{ |
3098 We collapse multiple layers of futures into one. If $e$ evaluates to a future $f $, the future will not invoke its \code{then()} callback until f completes to a non-future value, and so the result of an await is never a future, and the resul t of an async function will never have type \code{Future$<X>$} where $X$ itself is an invocation of \code{Future}. | 3110 We collapse multiple layers of futures into one. If $e$ evaluates to a future $f $, the future will not invoke its \code{then()} callback until f completes to a non-future value, and so the result of an await is never a future, and the resul t of an async function will never have type \code{Future$<X>$} where $X$ itself is an invocation of \code{Future}. |
3111 | |
3112 The sole exception to that would be a type $X$ that extended or implemented \cod e{Future$<X>$}. In that case, the result type is $X$ and no further unwrapping t akes place. As an example of why this is necessary, consider | |
3113 | |
3114 \cd{\CLASS{} C$<$T$>$ \IMPLEMENTS{} C$<$C$<$T$>>$ \ldots } | |
Paul Berry
2015/03/17 01:51:51
This is an illegal definition (a class cannot impl
| |
3115 | |
3116 Here, a naive definition of $flatten$ diverges; there is not even a fixed point. | |
3117 | |
3099 } | 3118 } |
3100 | 3119 |
3101 | 3120 |
3102 \LMHash{} | 3121 \LMHash{} |
3103 The static type of a function literal of the form | 3122 The static type of a function literal of the form |
3104 | 3123 |
3105 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\}) => e$ | 3124 $(T_1$ $a_1, \ldots, T_n$ $a_n, \{T_{n+1}$ $x_{n+1} : d_1, \ldots, T_{n+k}$ $x_ {n+k} : d_k\}) => e$ |
3106 is | 3125 is |
3107 | 3126 |
3108 $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightarrow T_0$, where $T_0$ is the static type of $e$. | 3127 $(T_1 \ldots, T_n, \{T_{n+1}$ $x_{n+1}, \ldots, T_{n+k}$ $x_{n+k}\}) \rightarrow T_0$, where $T_0$ is the static type of $e$. |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3521 } | 3540 } |
3522 | 3541 |
3523 \LMHash{} | 3542 \LMHash{} |
3524 The iterable implementation must comply with the contract of \code{Iterable} and should not take any steps identified as exceptionally efficient in that contrac t. | 3543 The iterable implementation must comply with the contract of \code{Iterable} and should not take any steps identified as exceptionally efficient in that contrac t. |
3525 | 3544 |
3526 \commentary { | 3545 \commentary { |
3527 The contract explicitly mentions a number of situations where certain iterables could be more efficient than normal. For example, by precomputing their length. Normal iterables must iterate over their elements to determine their length. Thi s is certainly true in the case of a synchronous generator, where each element i s computed by a function. It would not be acceptable to pre-compute the results of the generator and cache them, for example. | 3546 The contract explicitly mentions a number of situations where certain iterables could be more efficient than normal. For example, by precomputing their length. Normal iterables must iterate over their elements to determine their length. Thi s is certainly true in the case of a synchronous generator, where each element i s computed by a function. It would not be acceptable to pre-compute the results of the generator and cache them, for example. |
3528 } | 3547 } |
3529 | 3548 |
3530 \LMHash{} | 3549 \LMHash{} |
3531 When iteration over the iterable is started, by getting an iterator $j$ from the iterable and calling \code{moveNext()} on it, execution of the body of $f$ will begin. When $f$ terminates, $j$ is positioned after its last element, so that i ts current value is \NULL{} and the current call to \code{moveNext()} on $j$ ret urns false, as will all further calls. | 3550 When iteration over the iterable is started, by getting an iterator $j$ from the iterable and calling \code{moveNext()}, execution of the body of $f$ will begin . When $f$ terminates, $j$ is positioned after its last element, so that its cur rent value is \NULL{} and the current call to \code{moveNext()} on $j$ returns f alse, as will all further calls. |
3532 | 3551 |
3533 Each iterator starts a separate computation. If the \SYNC* function is impure, t he sequence of values yielded by each iterator may differ. | 3552 Each iterator starts a separate computation. If the \SYNC* function is impure, t he sequence of values yielded by each iterator may differ. |
3534 | 3553 |
3535 \commentary{ | 3554 \commentary{ |
3536 One can derive more than one iterator from a given iterable. Note that operati ons on the iterable itself can create distinct iterators. An example would be \c ode{length}. It is conceivable that different iterators might yield sequences o f different length. The same care needs to be taken when writing \SYNC* function s as when | 3555 One can derive more than one iterator from a given iterable. Note that operati ons on the iterable itself can create distinct iterators. An example would be \c ode{length}. It is conceivable that different iterators might yield sequences o f different length. The same care needs to be taken when writing \SYNC* function s as when |
3537 writing an \code{Iterator} class. In particular, it should handle multiple | 3556 writing an \code{Iterator} class. In particular, it should handle multiple |
3538 simultaneous iterators gracefully. If the iterator depends on external state | 3557 simultaneous iterators gracefully. If the iterator depends on external state |
3539 that might change, it should check that the state is still valid after every | 3558 that might change, it should check that the state is still valid after every |
3540 yield (and maybe throw a \code{ConcurrentModificationError} if it isn't). | 3559 yield (and maybe throw a \code{ConcurrentModificationError} if it isn't). |
3541 } | 3560 } |
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5906 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function. | 5925 Next, $o$ is added to the iterable or stream associated with the immediately enc losing function. |
5907 | 5926 |
5908 \LMHash{} | 5927 \LMHash{} |
5909 If the enclosing function $m$ is marked \ASYNC* and the stream $u$ associated wi th $m$ has been canceled, then let $c$ be the \FINALLY{} clause (\ref{try}) of t he innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$ . If $h$ is undefined, the immediately enclosing function terminates. | 5928 If the enclosing function $m$ is marked \ASYNC* and the stream $u$ associated wi th $m$ has been canceled, then let $c$ be the \FINALLY{} clause (\ref{try}) of t he innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is defined, control is transferred to $h$ . If $h$ is undefined, the immediately enclosing function terminates. |
5910 | 5929 |
5911 \rationale{ | 5930 \rationale{ |
5912 The stream associated with an asynchronous generator could be canceled by any co de with a reference to that stream at any point where the generator was passivat ed. Such a cancellation constitutes an irretrievable error for the generator. A t this point, the only plausible action for the generator is to clean up after i tself via its \FINALLY{} clauses. | 5931 The stream associated with an asynchronous generator could be canceled by any co de with a reference to that stream at any point where the generator was passivat ed. Such a cancellation constitutes an irretrievable error for the generator. A t this point, the only plausible action for the generator is to clean up after i tself via its \FINALLY{} clauses. |
5913 } | 5932 } |
5914 | 5933 |
5915 \LMHash{} | 5934 \LMHash{} |
5935 Otherwise, if the enclosing function $m$ is marked \ASYNC* (\ref{functions}) the n the enclosing function may suspend. | |
5936 | |
5937 \rationale { | |
5938 If a \YIELD{} occurred inside an infinite loop and the enclosing function never suspended, there might not be an opportunity for consumers of the enclosing str eam to run and access the data in the stream. The stream might then accumulate an unbounded number of elements. Such a situation is untenable. Therefore, we al low the enclosing function to be suspended when a new value is added to its asso ciated stream. However, it is not essential (and in fact, can be quite costly) t o suspend the function on every \YIELD{}. The implementation is free to decide h ow often to suspend the enclosing function. The only requirement is that consume rs are not blocked indefinitely. | |
5939 } | |
5940 | |
5941 | |
5942 \LMHash{} | |
5916 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then: | 5943 If the enclosing function $m$ is marked \SYNC* (\ref{functions}) then: |
5917 \begin{itemize} | 5944 \begin{itemize} |
5918 \item | 5945 \item |
5919 Execution of the function $m$ immediately enclosing $s$ is suspended until the m ethod \code{moveNext()} is invoked upon the iterator used to initiate the curren t invocation of $m$. | 5946 Execution of the function $m$ immediately enclosing $s$ is suspended until the n ullary method \code{moveNext()} is invoked upon the iterator used to initiate th e current invocation of $m$. |
5920 \item | 5947 \item |
5921 The current call to \code{moveNext()} returns \TRUE. | 5948 The current call to \code{moveNext()} returns \TRUE. |
5922 \end{itemize} | 5949 \end{itemize} |
5923 | 5950 |
5924 \LMHash{} | 5951 \LMHash{} |
5925 It is a compile-time error if a yield statement appears in a function that is no t a generator function. | 5952 It is a compile-time error if a yield statement appears in a function that is no t a generator function. |
5926 | 5953 |
5927 \LMHash{} | 5954 \LMHash{} |
5928 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if either: | 5955 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if either: |
5929 \begin{itemize} | 5956 \begin{itemize} |
(...skipping 10 matching lines...) Expand all Loading... | |
5940 \LMHash{} | 5967 \LMHash{} |
5941 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}). | 5968 The {\em yield-each statement} adds a series of values to the result of a gener ator function (\ref{functions}). |
5942 | 5969 |
5943 \begin{grammar} | 5970 \begin{grammar} |
5944 {\bf yieldEachStatement:} | 5971 {\bf yieldEachStatement:} |
5945 \YIELD* expression `{\escapegrammar ;}' | 5972 \YIELD* expression `{\escapegrammar ;}' |
5946 . | 5973 . |
5947 \end{grammar} | 5974 \end{grammar} |
5948 | 5975 |
5949 \LMHash{} | 5976 \LMHash{} |
5950 Execution of a statement s of the form \code{\YIELD* $e$;} proceeds as follows: | 5977 Execution of a statement $s$ of the form \code{\YIELD* $e$;} proceeds as follow s: |
5951 | 5978 |
5952 \LMHash{} | 5979 \LMHash{} |
5953 First, the expression $e$ is evaluated to an object $o$. If the immediately encl osing function $m$ is synchronous, then it is a dynamic error if the class of $o $ does not implement \code{Iterable}. If $m$ asynchronous, then it is a dynamic error if the class of $o$ does not implement \code{Stream}. Next, for each elem ent $x$ of $o$: | 5980 First, the expression $e$ is evaluated to an object $o$. |
5981 | |
5982 \LMHash{} | |
5983 If the immediately enclosing function $m$ is marked \SYNC* (\ref{functions}), th en: | |
5984 \begin{enumerate} | |
5985 \item It is a dynamic error if the class of $o$ does not implement \code{Iterabl e}. Otherwise | |
5986 \item The method \cd{iterator} is invoked upon $o$ returning an object $i$. | |
5987 \item \label{moveNext} The \cd{moveNext} method of $i$ is invoked on it with no arguments. If \cd{moveNext} returns \FALSE{} execution of $s$ is complete. Other wise | |
5988 \item An element $x$ is extracted from $i$ and $x$ is added to the iterable or s tream associated with $m$. | |
5989 Execution of the function $m$ immediately enclosing $s$ is suspended until the n ullary method \code{moveNext()} is invoked upon the iterator used to initiate th e current invocation of $m$, at which point execution of $s$ continues at \ref{m oveNext}. | |
5990 \item | |
5991 The current call to \code{moveNext()} returns \TRUE. | |
5992 \end{enumerate} | |
5993 | |
5994 \LMHash{} | |
5995 If $m$ is marked \ASYNC* (\ref{functions}), then: | |
5996 \begin{itemize} | |
5997 \item It is a dynamic error if the class of $o$ does not implement \code{Stream }. Otherwise | |
5998 \item For each element $x$ of $o$: | |
5954 \begin{itemize} | 5999 \begin{itemize} |
5955 \item | 6000 \item |
5956 If $m$ is marked \ASYNC* (\ref{functions}) and the stream $u$ associated with $m $ has been paused, then execution of $m$ is suspended until $u$ is resumed or c anceled. | 6001 If the stream $u$ associated with $m$ has been paused, then execution of $m$ is suspended until $u$ is resumed or canceled. |
6002 \item | |
6003 If the stream $u$ associated with $m$ has been canceled, then let $c$ be the \FI NALLY{} clause (\ref{try}) of the innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induced by $c$. If $h$ is define d, control is transferred to $h$. If $h$ is undefined, the immediately enclosing function terminates. | |
5957 \item | 6004 \item |
5958 $x$ is added to the iterable or stream associated with $m$ in the order it appe ars in $o$. | 6005 Otherwise, $x$ is added to the stream associated with $m$ in the order it appea rs in $o$. The function $m$ may suspend. |
5959 \item | 6006 \end{itemize} |
5960 If $m$ is marked \ASYNC* and the stream $u$ associated with $m$ has been cancele d, then let $c$ be the \FINALLY{} clause (\ref{try}) of the innermost enclosing try-finally statement, if any. If $c$ is defined, let $h$ be the handler induce d by $c$. If $h$ is defined, control is transferred to $h$. If $h$ is undefined, the immediately enclosing function terminates. | 6007 \item If the stream $o$ is done, execution of $s$ is complete. |
5961 \end{itemize} | 6008 \end{itemize} |
5962 | 6009 |
5963 \LMHash{} | |
5964 If the enclosing function is marked \SYNC* (\ref{functions}) then: | |
5965 \begin{itemize} | |
5966 \item | |
5967 Execution of the function $m$ immediately enclosing $s$ is suspended until the m ethod \code{moveNext()} is invoked upon the iterator used to initiate the curren t invocation of $m$. | |
5968 \item | |
5969 The current call to \code{moveNext()} returns \TRUE. | |
5970 \end{itemize} | |
5971 | 6010 |
5972 \LMHash{} | 6011 \LMHash{} |
5973 It is a compile-time error if a yield-each statement appears in a function that is not a generator function. | 6012 It is a compile-time error if a yield-each statement appears in a function that is not a generator function. |
5974 | 6013 |
5975 \LMHash{} | 6014 \LMHash{} |
5976 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if $T$ may not be assigned to the declared ret urn type of $f$. If $f$ is synchronous it is a static type warning if $T$ may not be assigned to \code{Iterable}. If $f$ is asynchronous it is a static type warning if $T$ may not be assigned to \code{Stream}. | 6015 Let $T$ be the static type of $e$ and let $f$ be the immediately enclosing funct ion. It is a static type warning if $T$ may not be assigned to the declared ret urn type of $f$. If $f$ is synchronous it is a static type warning if $T$ may not be assigned to \code{Iterable}. If $f$ is asynchronous it is a static type warning if $T$ may not be assigned to \code{Stream}. |
5977 | 6016 |
5978 | 6017 |
5979 \subsection{ Assert} | 6018 \subsection{ Assert} |
5980 \LMLabel{assert} | 6019 \LMLabel{assert} |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7383 | 7422 |
7384 The invariant that each normative paragraph is associated with a line | 7423 The invariant that each normative paragraph is associated with a line |
7385 containing the text \LMHash{} should be maintained. Extra occurrences | 7424 containing the text \LMHash{} should be maintained. Extra occurrences |
7386 of \LMHash{} can be added if needed, e.g., in order to make | 7425 of \LMHash{} can be added if needed, e.g., in order to make |
7387 individual \item{}s in itemized lists addressable. Each \LM.. command | 7426 individual \item{}s in itemized lists addressable. Each \LM.. command |
7388 must occur on a separate line. \LMHash{} must occur immediately | 7427 must occur on a separate line. \LMHash{} must occur immediately |
7389 before the associated paragraph, and \LMLabel must occur immediately | 7428 before the associated paragraph, and \LMLabel must occur immediately |
7390 after the associated \section{}, \subsection{} etc. | 7429 after the associated \section{}, \subsection{} etc. |
7391 | 7430 |
7392 ---------------------------------------------------------------------- | 7431 ---------------------------------------------------------------------- |
OLD | NEW |