@@ -23140,7 +23140,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23140
23140
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23141
23141
if \SubtypeNE{T_1}{T_2}.
23142
23142
23143
- \commentary{
23143
+ \commentary{%
23144
23144
In this and in the following cases, both types must be interface types.%
23145
23145
}
23146
23146
\item
@@ -23397,7 +23397,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23397
23397
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23398
23398
\end{itemize}
23399
23399
23400
- \rationale{
23400
+ \rationale{%
23401
23401
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23402
23402
are somewhat redundant in that they explicitly specify
23403
23403
a lot of pairs of symmetric cases.
@@ -25189,6 +25189,7 @@ \subsection{Type Promotion}
25189
25189
}
25190
25190
25191
25191
\LMHash{}%
25192
+ \BlindDefineSymbol{\ell, v}%
25192
25193
Let $\ell$ be a location,
25193
25194
and let $v$ be a local variable which is in scope at $\ell$.
25194
25195
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25212,34 +25213,33 @@ \subsection{Type Promotion}
25212
25213
25213
25214
\LMHash{}%
25214
25215
In particular,
25215
- a check of the form \code{$v$\,\,==\,\,\NULL},
25216
- \code{\NULL\,\,==\,\,$v$},
25217
- or \code{$v$\,\,\IS\,\,Null}
25216
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25217
+ \code{\NULL\,\,==\,\,$v$}
25218
25218
where $v$ has type $T$ at $\ell$
25219
25219
promotes the type of $v$
25220
- to \code{Null} in the \TRUE{} continuation,
25221
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25222
-
25223
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25224
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25225
- %% `X & int`. So we may be able to specify something which will yield
25226
- %% slightly more precise types, and which is more precisely the implemented
25227
- %% behavior.
25228
- \LMHash{}%
25229
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25230
- \code{\NULL\,\,!=\,\,$v$},
25231
- or \code{$v$\,\,\IS\,\,$T$}
25232
- where $v$ has static type $T?$ at $\ell$
25220
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25221
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25222
+ \code{\NULL\,\,!=\,\,$v$}
25223
+ where $v$ has static type $T$ at $\ell$
25224
+ promotes the type of $v$
25225
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25226
+
25227
+ \LMHash{}%
25228
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25233
25229
promotes the type of $v$
25234
25230
to $T$ in the \TRUE{} continuation,
25235
- and to \code{Null} in the \FALSE{} continuation.
25231
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25232
+ promotes the type of $v$
25233
+ to $T$ in the continuation where the expression evaluated to an object
25234
+ (\commentary{that is, it did not throw}).
25236
25235
25237
25236
\commentary{%
25238
25237
The resulting type of $v$ may be the obvious one, e.g.,
25239
25238
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25240
25239
but it may also give rise to a demotion
25241
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25242
- and it may have no effect on the type of $v$
25240
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25241
+ and potentially promoting it to some other type of interest).
25242
+ It may also have no effect on the type of $v$
25243
25243
(e.g., when the static type of $e$ is not a type of interest).
25244
25244
These details will be specified in a future version of this specification.
25245
25245
@@ -25412,15 +25412,20 @@ \section*{Appendix: Algorithmic Subtyping}
25412
25412
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25413
25413
It shows that Dart subtyping relationships can be decided
25414
25414
with good performance.
25415
+ This section is not normative.
25415
25416
25416
25417
\LMHash{}%
25417
25418
In this algorithm, types are considered to be the same when they have
25418
25419
the same canonical syntax
25419
25420
(\ref{theCanonicalSyntaxOfTypes}).
25421
+ \commentary{%
25422
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25423
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25424
+ }
25420
25425
The algorithm must be performed such that the first case that matches
25421
25426
is always the case which is performed.
25422
25427
The algorithm produces results which are both positive and negative
25423
- (\commentary{
25428
+ (\commentary{%
25424
25429
that is, in some situations the subtype relation is determined to be false%
25425
25430
}),
25426
25431
which is important for performance because
@@ -25432,16 +25437,18 @@ \section*{Appendix: Algorithmic Subtyping}
25432
25437
\begin{itemize}
25433
25438
\item
25434
25439
\textbf{Reflexivity:}
25435
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25440
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25436
25441
25437
25442
\commentary{%
25438
- Note that this check is necessary as the base case for primitive types,
25443
+ This check is necessary as the base case for primitive types,
25439
25444
and type variables, but not for composite types.
25440
25445
In particular, a structural equality check is admissible,
25441
25446
but not required here.
25442
- Pragmatically, non-constant time identity checks here are
25443
- counter-productive.
25444
- So this rule should only be used when $T$ is atomic.%
25447
+ Non-constant time identity checks here are counter-productive
25448
+ because the following rules will yield the same result anyway,
25449
+ so we may just perform a full traversal of a large structure twice
25450
+ for no reason.
25451
+ Hence, this rule is only used when the given type is atomic.%
25445
25452
}
25446
25453
\item
25447
25454
\textbf{Right Top:}
@@ -25451,7 +25458,7 @@ \section*{Appendix: Algorithmic Subtyping}
25451
25458
if $T_0$ is \DYNAMIC{} or \VOID{}
25452
25459
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25453
25460
\item
25454
- \textbf{Left Bottom:}
25461
+ \textbf{Bottom:}
25455
25462
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25456
25463
\item
25457
25464
\textbf{Right Object:}
@@ -25504,7 +25511,7 @@ \section*{Appendix: Algorithmic Subtyping}
25504
25511
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25505
25512
then \SubtypeNE{T_0}{T_1}.
25506
25513
25507
- \commentary{
25514
+ \commentary{%
25508
25515
Note that this rule is admissible, and can be safely elided if desired.%
25509
25516
}
25510
25517
\item
@@ -25587,7 +25594,7 @@ \section*{Appendix: Algorithmic Subtyping}
25587
25594
for $i \in 0 .. q$.
25588
25595
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25589
25596
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25590
- have the same canonical syntax , for $i \in 0 .. k$.
25597
+ are subtypes of each other , for $i \in 0 .. k$.
25591
25598
\end{itemize}
25592
25599
\item
25593
25600
\textbf{Named Function Types:}
@@ -25628,8 +25635,7 @@ \section*{Appendix: Algorithmic Subtyping}
25628
25635
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25629
25636
\item
25630
25637
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25631
- have the same canonical syntax,
25632
- for each $i \in 0 .. k$.
25638
+ are subtypes of each other, for each $i \in 0 .. k$.
25633
25639
\end{itemize}
25634
25640
25635
25641
\commentary{%
0 commit comments