@@ -23548,7 +23548,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2354823548 \DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
2354923549 if \SubtypeNE{T_1}{T_2}.
2355023550
23551- \commentary{
23551+ \commentary{%
2355223552 In this and in the following cases, both types must be interface types.%
2355323553 }
2355423554\item
@@ -23805,7 +23805,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2380523805 \DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
2380623806\end{itemize}
2380723807
23808- \rationale{
23808+ \rationale{%
2380923809The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
2381023810are somewhat redundant in that they explicitly specify
2381123811a lot of pairs of symmetric cases.
@@ -25623,6 +25623,7 @@ \subsection{Type Promotion}
2562325623}
2562425624
2562525625\LMHash{}%
25626+ \BlindDefineSymbol{\ell, v}%
2562625627Let $\ell$ be a location,
2562725628and let $v$ be a local variable which is in scope at $\ell$.
2562825629Assume that $\ell$ occurs after the declaration of $v$.
@@ -25646,34 +25647,33 @@ \subsection{Type Promotion}
2564625647
2564725648\LMHash{}%
2564825649In particular,
25649- a check of the form \code{$v$\,\,==\,\,\NULL},
25650- \code{\NULL\,\,==\,\,$v$},
25651- or \code{$v$\,\,\IS\,\,Null}
25650+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25651+ \code{\NULL\,\,==\,\,$v$}
2565225652where $v$ has type $T$ at $\ell$
2565325653promotes the type of $v$
25654- to \code{Null} in the \TRUE{} continuation,
25655- and to \NonNullType{$T$} in the \FALSE{} continuation.
25656-
25657- %% TODO(eernst), for review: The null safety spec says that `T?` is
25658- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25659- %% `X & int`. So we may be able to specify something which will yield
25660- %% slightly more precise types, and which is more precisely the implemented
25661- %% behavior.
25662- \LMHash{}%
25663- A check of the form \code{$v$\,\,!=\,\,\NULL},
25664- \code{\NULL\,\,!=\,\,$v$},
25665- or \code{$v$\,\,\IS\,\,$T$}
25666- where $v$ has static type $T?$ at $\ell$
25654+ to \NonNullType{$T$} in the \FALSE{} continuation;
25655+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25656+ \code{\NULL\,\,!=\,\,$v$}
25657+ where $v$ has static type $T$ at $\ell$
25658+ promotes the type of $v$
25659+ to \NonNullType{$T$} in the \TRUE{} continuation.
25660+
25661+ \LMHash{}%
25662+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
2566725663promotes the type of $v$
2566825664to $T$ in the \TRUE{} continuation,
25669- and to \code{Null} in the \FALSE{} continuation.
25665+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25666+ promotes the type of $v$
25667+ to $T$ in the continuation where the expression evaluated to an object
25668+ (\commentary{that is, it did not throw}).
2567025669
2567125670\commentary{%
2567225671 The resulting type of $v$ may be the obvious one, e.g.,
2567325672 \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
2567425673 but it may also give rise to a demotion
25675- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25676- and it may have no effect on the type of $v$
25674+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25675+ and potentially promoting it to some other type of interest).
25676+ It may also have no effect on the type of $v$
2567725677 (e.g., when the static type of $e$ is not a type of interest).
2567825678 These details will be specified in a future version of this specification.
2567925679
@@ -25853,15 +25853,20 @@ \section*{Appendix: Algorithmic Subtyping}
2585325853the one which is specified in Fig.~\ref{fig:subtypeRules}.
2585425854It shows that Dart subtyping relationships can be decided
2585525855with good performance.
25856+ This section is not normative.
2585625857
2585725858\LMHash{}%
2585825859In this algorithm, types are considered to be the same when they have
2585925860the same canonical syntax
2586025861(\ref{theCanonicalSyntaxOfTypes}).
25862+ \commentary{%
25863+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25864+ the two occurrences of \code{C} refer to declarations in different libraries.%
25865+ }
2586125866The algorithm must be performed such that the first case that matches
2586225867is always the case which is performed.
2586325868The algorithm produces results which are both positive and negative
25864- (\commentary{
25869+ (\commentary{%
2586525870 that is, in some situations the subtype relation is determined to be false%
2586625871}),
2586725872which is important for performance because
@@ -25873,16 +25878,18 @@ \section*{Appendix: Algorithmic Subtyping}
2587325878\begin{itemize}
2587425879\item
2587525880 \textbf{Reflexivity:}
25876- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25881+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
2587725882
2587825883 \commentary{%
25879- Note that this check is necessary as the base case for primitive types,
25884+ This check is necessary as the base case for primitive types,
2588025885 and type variables, but not for composite types.
2588125886 In particular, a structural equality check is admissible,
2588225887 but not required here.
25883- Pragmatically, non-constant time identity checks here are
25884- counter-productive.
25885- So this rule should only be used when $T$ is atomic.%
25888+ Non-constant time identity checks here are counter-productive
25889+ because the following rules will yield the same result anyway,
25890+ so we may just perform a full traversal of a large structure twice
25891+ for no reason.
25892+ Hence, this rule is only used when the given type is atomic.%
2588625893 }
2588725894\item
2588825895 \textbf{Right Top:}
@@ -25892,7 +25899,7 @@ \section*{Appendix: Algorithmic Subtyping}
2589225899 if $T_0$ is \DYNAMIC{} or \VOID{}
2589325900 then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
2589425901\item
25895- \textbf{Left Bottom:}
25902+ \textbf{Bottom:}
2589625903 if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
2589725904\item
2589825905 \textbf{Right Object:}
@@ -25945,7 +25952,7 @@ \section*{Appendix: Algorithmic Subtyping}
2594525952 or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
2594625953 then \SubtypeNE{T_0}{T_1}.
2594725954
25948- \commentary{
25955+ \commentary{%
2594925956 Note that this rule is admissible, and can be safely elided if desired.%
2595025957 }
2595125958\item
@@ -26028,7 +26035,7 @@ \section*{Appendix: Algorithmic Subtyping}
2602826035 for $i \in 0 .. q$.
2602926036 \item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2603026037 \item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26031- have the same canonical syntax , for $i \in 0 .. k$.
26038+ are subtypes of each other , for $i \in 0 .. k$.
2603226039 \end{itemize}
2603326040\item
2603426041 \textbf{Named Function Types:}
@@ -26069,8 +26076,7 @@ \section*{Appendix: Algorithmic Subtyping}
2606926076 \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2607026077 \item
2607126078 $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26072- have the same canonical syntax,
26073- for each $i \in 0 .. k$.
26079+ are subtypes of each other, for each $i \in 0 .. k$.
2607426080 \end{itemize}
2607526081
2607626082 \commentary{%
0 commit comments