@@ -23095,7 +23095,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23095
23095
\DefEquals{\UpperBoundType{$T_1$}{$T_2$}}{T_2},
23096
23096
if \SubtypeNE{T_1}{T_2}.
23097
23097
23098
- \commentary{
23098
+ \commentary{%
23099
23099
In this and in the following cases, both types must be interface types.%
23100
23100
}
23101
23101
\item
@@ -23352,7 +23352,7 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
23352
23352
\DefEquals{\LowerBoundType{$T_1$}{$T_2$}}{\code{Never}}, otherwise.
23353
23353
\end{itemize}
23354
23354
23355
- \rationale{
23355
+ \rationale{%
23356
23356
The rules defining \UpperBoundTypeName{} and \LowerBoundTypeName{}
23357
23357
are somewhat redundant in that they explicitly specify
23358
23358
a lot of pairs of symmetric cases.
@@ -25144,6 +25144,7 @@ \subsection{Type Promotion}
25144
25144
}
25145
25145
25146
25146
\LMHash{}%
25147
+ \BlindDefineSymbol{\ell, v}%
25147
25148
Let $\ell$ be a location,
25148
25149
and let $v$ be a local variable which is in scope at $\ell$.
25149
25150
Assume that $\ell$ occurs after the declaration of $v$.
@@ -25167,34 +25168,33 @@ \subsection{Type Promotion}
25167
25168
25168
25169
\LMHash{}%
25169
25170
In particular,
25170
- a check of the form \code{$v$\,\,==\,\,\NULL},
25171
- \code{\NULL\,\,==\,\,$v$},
25172
- or \code{$v$\,\,\IS\,\,Null}
25171
+ an expression of the form \code{$v$\,\,==\,\,\NULL} or
25172
+ \code{\NULL\,\,==\,\,$v$}
25173
25173
where $v$ has type $T$ at $\ell$
25174
25174
promotes the type of $v$
25175
- to \code{Null} in the \TRUE{} continuation,
25176
- and to \NonNullType{$T$} in the \FALSE{} continuation.
25177
-
25178
- %% TODO(eernst), for review: The null safety spec says that `T?` is
25179
- %% promoted to `T`, but implementations _do_ promote `X extends int?` to
25180
- %% `X & int`. So we may be able to specify something which will yield
25181
- %% slightly more precise types, and which is more precisely the implemented
25182
- %% behavior.
25183
- \LMHash{}%
25184
- A check of the form \code{$v$\,\,!=\,\,\NULL},
25185
- \code{\NULL\,\,!=\,\,$v$},
25186
- or \code{$v$\,\,\IS\,\,$T$}
25187
- where $v$ has static type $T?$ at $\ell$
25175
+ to \NonNullType{$T$} in the \FALSE{} continuation;
25176
+ and an expression of the form \code{$v$\,\,!=\,\,\NULL} or
25177
+ \code{\NULL\,\,!=\,\,$v$}
25178
+ where $v$ has static type $T$ at $\ell$
25179
+ promotes the type of $v$
25180
+ to \NonNullType{$T$} in the \TRUE{} continuation.
25181
+
25182
+ \LMHash{}%
25183
+ Similarly, a type test of the form \code{$v$\,\,\IS\,\,$T$}
25188
25184
promotes the type of $v$
25189
25185
to $T$ in the \TRUE{} continuation,
25190
- and to \code{Null} in the \FALSE{} continuation.
25186
+ and a type check of the form \code{$v$\,\,\AS\,\,$T$}
25187
+ promotes the type of $v$
25188
+ to $T$ in the continuation where the expression evaluated to an object
25189
+ (\commentary{that is, it did not throw}).
25191
25190
25192
25191
\commentary{%
25193
25192
The resulting type of $v$ may be the obvious one, e.g.,
25194
25193
\code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
25195
25194
but it may also give rise to a demotion
25196
- (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
25197
- and it may have no effect on the type of $v$
25195
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$
25196
+ and potentially promoting it to some other type of interest).
25197
+ It may also have no effect on the type of $v$
25198
25198
(e.g., when the static type of $e$ is not a type of interest).
25199
25199
These details will be specified in a future version of this specification.
25200
25200
@@ -25367,15 +25367,20 @@ \section*{Appendix: Algorithmic Subtyping}
25367
25367
the one which is specified in Fig.~\ref{fig:subtypeRules}.
25368
25368
It shows that Dart subtyping relationships can be decided
25369
25369
with good performance.
25370
+ This section is not normative.
25370
25371
25371
25372
\LMHash{}%
25372
25373
In this algorithm, types are considered to be the same when they have
25373
25374
the same canonical syntax
25374
25375
(\ref{theCanonicalSyntaxOfTypes}).
25376
+ \commentary{%
25377
+ For example, \SubtypeStd{\code{C}}{\code{C}} does not hold if
25378
+ the two occurrences of \code{C} refer to declarations in different libraries.%
25379
+ }
25375
25380
The algorithm must be performed such that the first case that matches
25376
25381
is always the case which is performed.
25377
25382
The algorithm produces results which are both positive and negative
25378
- (\commentary{
25383
+ (\commentary{%
25379
25384
that is, in some situations the subtype relation is determined to be false%
25380
25385
}),
25381
25386
which is important for performance because
@@ -25387,16 +25392,18 @@ \section*{Appendix: Algorithmic Subtyping}
25387
25392
\begin{itemize}
25388
25393
\item
25389
25394
\textbf{Reflexivity:}
25390
- if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25395
+ if $T_0$ and $T_1$ are the same atomic type then \SubtypeNE{T_0}{T_1}.
25391
25396
25392
25397
\commentary{%
25393
- Note that this check is necessary as the base case for primitive types,
25398
+ This check is necessary as the base case for primitive types,
25394
25399
and type variables, but not for composite types.
25395
25400
In particular, a structural equality check is admissible,
25396
25401
but not required here.
25397
- Pragmatically, non-constant time identity checks here are
25398
- counter-productive.
25399
- So this rule should only be used when $T$ is atomic.%
25402
+ Non-constant time identity checks here are counter-productive
25403
+ because the following rules will yield the same result anyway,
25404
+ so we may just perform a full traversal of a large structure twice
25405
+ for no reason.
25406
+ Hence, this rule is only used when the given type is atomic.%
25400
25407
}
25401
25408
\item
25402
25409
\textbf{Right Top:}
@@ -25406,7 +25413,7 @@ \section*{Appendix: Algorithmic Subtyping}
25406
25413
if $T_0$ is \DYNAMIC{} or \VOID{}
25407
25414
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25408
25415
\item
25409
- \textbf{Left Bottom:}
25416
+ \textbf{Bottom:}
25410
25417
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
25411
25418
\item
25412
25419
\textbf{Right Object:}
@@ -25459,7 +25466,7 @@ \section*{Appendix: Algorithmic Subtyping}
25459
25466
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25460
25467
then \SubtypeNE{T_0}{T_1}.
25461
25468
25462
- \commentary{
25469
+ \commentary{%
25463
25470
Note that this rule is admissible, and can be safely elided if desired.%
25464
25471
}
25465
25472
\item
@@ -25542,7 +25549,7 @@ \section*{Appendix: Algorithmic Subtyping}
25542
25549
for $i \in 0 .. q$.
25543
25550
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25544
25551
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25545
- have the same canonical syntax , for $i \in 0 .. k$.
25552
+ are subtypes of each other , for $i \in 0 .. k$.
25546
25553
\end{itemize}
25547
25554
\item
25548
25555
\textbf{Named Function Types:}
@@ -25583,8 +25590,7 @@ \section*{Appendix: Algorithmic Subtyping}
25583
25590
\SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25584
25591
\item
25585
25592
$B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25586
- have the same canonical syntax,
25587
- for each $i \in 0 .. k$.
25593
+ are subtypes of each other, for each $i \in 0 .. k$.
25588
25594
\end{itemize}
25589
25595
25590
25596
\commentary{%
0 commit comments