@@ -23522,7 +23522,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2352223522 \DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
2352323523 if \SubtypeNE{T_1}{T_2}.
2352423524
23525- \commentary{
23525+ \commentary{%
2352623526 In this and in the following cases, both types must be interface types.%
2352723527 }
2352823528\item
@@ -23779,7 +23779,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2377923779 \DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
2378023780\end{itemize}
2378123781
23782- \rationale{
23782+ \rationale{%
2378323783The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
2378423784are somewhat redundant in that they explicitly specify
2378523785a lot of pairs of symmetric cases.
@@ -25583,6 +25583,7 @@ \subsection{Type Promotion}
2558325583}
2558425584
2558525585\LMHash{}%
25586+ \BlindDefineSymbol{\ell, v}%
2558625587Let $\ell$ be a location,
2558725588and let $v$ be a local variable which is in scope at $\ell$.
2558825589Assume that $\ell$ occurs after the declaration of $v$.
@@ -25606,34 +25607,33 @@ \subsection{Type Promotion}
2560625607
2560725608\LMHash{}%
2560825609In particular,
25609- a check of the form \code{$v$\,\,==\,\,\NULL},
25610- \code{\NULL\,\,==\,\,$v$},
25611- or \code{$v$\,\,\IS\,\,Null}
25610+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25611+ \code{\NULL\,\,==\,\,$v$}
2561225612where $v$ has type $T$ at $\ell$
2561325613promotes the type of $v$
25614- to \code{Null} in the \TRUE{} continuation,
25615- and to \NonNullType{$T$} in the \FALSE{} continuation.
25616-
25617- %% TODO(eernst), for review: The null safety spec says that `T?` is
25618- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25619- %% `X & int`. So we may be able to specify something which will yield
25620- %% slightly more precise types, and which is more precisely the implemented
25621- %% behavior.
25622- \LMHash{}%
25623- A check of the form \code{$v$\,\,!=\,\,\NULL},
25624- \code{\NULL\,\,!=\,\,$v$},
25625- or \code{$v$\,\,\IS\,\,$T$}
25626- where $v$ has static type $T?$ at $\ell$
25614+ to \NonNullType{$T$} in the \FALSE{} continuation;
25615+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25616+ \code{\NULL\,\,!=\,\,$v$}
25617+ where $v$ has static type $T$ at $\ell$
25618+ promotes the type of $v$
25619+ to \NonNullType{$T$} in the \TRUE{} continuation.
25620+
25621+ \LMHash{}%
25622+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
2562725623promotes the type of $v$
2562825624to $T$ in the \TRUE{} continuation,
25629- and to \code{Null} in the \FALSE{} continuation.
25625+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25626+ promotes the type of $v$
25627+ to $T$ in the continuation where the expression evaluated to an object
25628+ (\commentary{that is, it did not throw}).
2563025629
2563125630\commentary{%
2563225631 The resulting type of $v$ may be the obvious one, e.g.,
2563325632 \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
2563425633 but it may also give rise to a demotion
25635- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25636- and it may have no effect on the type of $v$
25634+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25635+ and potentially promoting it to some other type of interest).
25636+ It may also have no effect on the type of $v$
2563725637 (e.g., when the static type of $e$ is not a type of interest).
2563825638 These details will be specified in a future version of this specification.
2563925639
@@ -25813,15 +25813,20 @@ \section*{Appendix: Algorithmic Subtyping}
2581325813the one which is specified in Fig.~\ref{fig:subtypeRules}.
2581425814It shows that Dart subtyping relationships can be decided
2581525815with good performance.
25816+ This section is not normative.
2581625817
2581725818\LMHash{}%
2581825819In this algorithm, types are considered to be the same when they have
2581925820the same canonical syntax
2582025821(\ref{theCanonicalSyntaxOfTypes}).
25822+ \commentary{%
25823+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25824+ the two occurrences of \code{C} refer to declarations in different libraries.%
25825+ }
2582125826The algorithm must be performed such that the first case that matches
2582225827is always the case which is performed.
2582325828The algorithm produces results which are both positive and negative
25824- (\commentary{
25829+ (\commentary{%
2582525830 that is, in some situations the subtype relation is determined to be false%
2582625831}),
2582725832which is important for performance because
@@ -25833,16 +25838,18 @@ \section*{Appendix: Algorithmic Subtyping}
2583325838\begin{itemize}
2583425839\item
2583525840 \textbf{Reflexivity:}
25836- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25841+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
2583725842
2583825843 \commentary{%
25839- Note that this check is necessary as the base case for primitive types,
25844+ This check is necessary as the base case for primitive types,
2584025845 and type variables, but not for composite types.
2584125846 In particular, a structural equality check is admissible,
2584225847 but not required here.
25843- Pragmatically, non-constant time identity checks here are
25844- counter-productive.
25845- So this rule should only be used when $T$ is atomic.%
25848+ Non-constant time identity checks here are counter-productive
25849+ because the following rules will yield the same result anyway,
25850+ so we may just perform a full traversal of a large structure twice
25851+ for no reason.
25852+ Hence, this rule is only used when the given type is atomic.%
2584625853 }
2584725854\item
2584825855 \textbf{Right Top:}
@@ -25852,7 +25859,7 @@ \section*{Appendix: Algorithmic Subtyping}
2585225859 if $T_0$ is \DYNAMIC{} or \VOID{}
2585325860 then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
2585425861\item
25855- \textbf{Left Bottom:}
25862+ \textbf{Bottom:}
2585625863 if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
2585725864\item
2585825865 \textbf{Right Object:}
@@ -25905,7 +25912,7 @@ \section*{Appendix: Algorithmic Subtyping}
2590525912 or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
2590625913 then \SubtypeNE{T_0}{T_1}.
2590725914
25908- \commentary{
25915+ \commentary{%
2590925916 Note that this rule is admissible, and can be safely elided if desired.%
2591025917 }
2591125918\item
@@ -25988,7 +25995,7 @@ \section*{Appendix: Algorithmic Subtyping}
2598825995 for $i \in 0 .. q$.
2598925996 \item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
2599025997 \item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25991- have the same canonical syntax , for $i \in 0 .. k$.
25998+ are subtypes of each other , for $i \in 0 .. k$.
2599225999 \end{itemize}
2599326000\item
2599426001 \textbf{Named Function Types:}
@@ -26029,8 +26036,7 @@ \section*{Appendix: Algorithmic Subtyping}
2602926036 \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
2603126038 $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
26032- have the same canonical syntax,
26033- for each $i \in 0 .. k$.
26039+ are subtypes of each other, for each $i \in 0 .. k$.
2603426040 \end{itemize}
2603526041
2603626042 \commentary{%
0 commit comments