@@ -23323,7 +23323,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23323
23323
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23324
23324
if \SubtypeNE{T_1}{T_2}.
23325
23325
23326
- \commentary{
23326
+ \commentary{%
23327
23327
In this and in the following cases, both types must be interface types.%
23328
23328
}
23329
23329
\item
@@ -23580,7 +23580,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23580
23580
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23581
23581
\end{itemize}
23582
23582
23583
- \rationale{
23583
+ \rationale{%
23584
23584
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23585
23585
are somewhat redundant in that they explicitly specify
23586
23586
a lot of pairs of symmetric cases.
@@ -25372,6 +25372,7 @@ \subsection{Type Promotion}
25372
25372
}
25373
25373
25374
25374
\LMHash{}%
25375
+ \BlindDefineSymbol{\ell, v}%
25375
25376
Let $\ell$ be a location,
25376
25377
and let $v$ be a local variable which is in scope at $\ell$.
25377
25378
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25395,34 +25396,33 @@ \subsection{Type Promotion}
25395
25396
25396
25397
\LMHash{}%
25397
25398
In particular,
25398
- a check of the form \code{$v$\,\,==\,\,\NULL},
25399
- \code{\NULL\,\,==\,\,$v$},
25400
- or \code{$v$\,\,\IS\,\,Null}
25399
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25400
+ \code{\NULL\,\,==\,\,$v$}
25401
25401
where $v$ has type $T$ at $\ell$
25402
25402
promotes the type of $v$
25403
- to \code{Null} in the \TRUE{} continuation,
25404
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25405
-
25406
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25407
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25408
- %% `X & int`. So we may be able to specify something which will yield
25409
- %% slightly more precise types, and which is more precisely the implemented
25410
- %% behavior.
25411
- \LMHash{}%
25412
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25413
- \code{\NULL\,\,!=\,\,$v$},
25414
- or \code{$v$\,\,\IS\,\,$T$}
25415
- where $v$ has static type $T?$ at $\ell$
25403
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25404
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25405
+ \code{\NULL\,\,!=\,\,$v$}
25406
+ where $v$ has static type $T$ at $\ell$
25407
+ promotes the type of $v$
25408
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25409
+
25410
+ \LMHash{}%
25411
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25416
25412
promotes the type of $v$
25417
25413
to $T$ in the \TRUE{} continuation,
25418
- and to \code{Null} in the \FALSE{} continuation.
25414
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25415
+ promotes the type of $v$
25416
+ to $T$ in the continuation where the expression evaluated to an object
25417
+ (\commentary{that is, it did not throw}).
25419
25418
25420
25419
\commentary{%
25421
25420
The resulting type of $v$ may be the obvious one, e.g.,
25422
25421
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25423
25422
but it may also give rise to a demotion
25424
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25425
- and it may have no effect on the type of $v$
25423
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25424
+ and potentially promoting it to some other type of interest).
25425
+ It may also have no effect on the type of $v$
25426
25426
(e.g., when the static type of $e$ is not a type of interest).
25427
25427
These details will be specified in a future version of this specification.
25428
25428
@@ -25602,15 +25602,20 @@ \section*{Appendix: Algorithmic Subtyping}
25602
25602
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25603
25603
It shows that Dart subtyping relationships can be decided
25604
25604
with good performance.
25605
+ This section is not normative.
25605
25606
25606
25607
\LMHash{}%
25607
25608
In this algorithm, types are considered to be the same when they have
25608
25609
the same canonical syntax
25609
25610
(\ref{theCanonicalSyntaxOfTypes}).
25611
+ \commentary{%
25612
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25613
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25614
+ }
25610
25615
The algorithm must be performed such that the first case that matches
25611
25616
is always the case which is performed.
25612
25617
The algorithm produces results which are both positive and negative
25613
- (\commentary{
25618
+ (\commentary{%
25614
25619
that is, in some situations the subtype relation is determined to be false%
25615
25620
}),
25616
25621
which is important for performance because
@@ -25622,16 +25627,18 @@ \section*{Appendix: Algorithmic Subtyping}
25622
25627
\begin{itemize}
25623
25628
\item
25624
25629
\textbf{Reflexivity:}
25625
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25630
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25626
25631
25627
25632
\commentary{%
25628
- Note that this check is necessary as the base case for primitive types,
25633
+ This check is necessary as the base case for primitive types,
25629
25634
and type variables, but not for composite types.
25630
25635
In particular, a structural equality check is admissible,
25631
25636
but not required here.
25632
- Pragmatically, non-constant time identity checks here are
25633
- counter-productive.
25634
- So this rule should only be used when $T$ is atomic.%
25637
+ Non-constant time identity checks here are counter-productive
25638
+ because the following rules will yield the same result anyway,
25639
+ so we may just perform a full traversal of a large structure twice
25640
+ for no reason.
25641
+ Hence, this rule is only used when the given type is atomic.%
25635
25642
}
25636
25643
\item
25637
25644
\textbf{Right Top:}
@@ -25641,7 +25648,7 @@ \section*{Appendix: Algorithmic Subtyping}
25641
25648
if $T_0$ is \DYNAMIC{} or \VOID{}
25642
25649
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25643
25650
\item
25644
- \textbf{Left Bottom:}
25651
+ \textbf{Bottom:}
25645
25652
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25646
25653
\item
25647
25654
\textbf{Right Object:}
@@ -25694,7 +25701,7 @@ \section*{Appendix: Algorithmic Subtyping}
25694
25701
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25695
25702
then \SubtypeNE{T_0}{T_1}.
25696
25703
25697
- \commentary{
25704
+ \commentary{%
25698
25705
Note that this rule is admissible, and can be safely elided if desired.%
25699
25706
}
25700
25707
\item
@@ -25777,7 +25784,7 @@ \section*{Appendix: Algorithmic Subtyping}
25777
25784
for $i \in 0 .. q$.
25778
25785
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25779
25786
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25780
- have the same canonical syntax , for $i \in 0 .. k$.
25787
+ are subtypes of each other , for $i \in 0 .. k$.
25781
25788
\end{itemize}
25782
25789
\item
25783
25790
\textbf{Named Function Types:}
@@ -25818,8 +25825,7 @@ \section*{Appendix: Algorithmic Subtyping}
25818
25825
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25819
25826
\item
25820
25827
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25821
- have the same canonical syntax,
25822
- for each $i \in 0 .. k$.
25828
+ are subtypes of each other, for each $i \in 0 .. k$.
25823
25829
\end{itemize}
25824
25830
25825
25831
\commentary{%
0 commit comments