Skip to content

Commit 90a6386

Browse files
committed
Rebase
1 parent 7a57a81 commit 90a6386

File tree

1 file changed

+173
-16
lines changed

1 file changed

+173
-16
lines changed

specification/dartLangSpec.tex

Lines changed: 173 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8672,6 +8672,10 @@ \subsection{Null}
86728672
The static type of \NULL{} is the \code{Null} type
86738673
(\ref{typeNull}).
86748674

8675+
\LMHash{}%
8676+
The dynamic type of the null object is \code{Null}.
8677+
8678+
86758679
\subsection{Numbers}
86768680
\LMLabel{numbers}
86778681

@@ -21366,11 +21370,171 @@ \subsubsection{Additional Subtyping Concepts}
2136621370
}
2136721371

2136821372

21373+
\subsection{Type Normalization}
21374+
\LMLabel{typeNormalization}
21375+
21376+
\LMHash{}%
21377+
Some Dart types are mutual subtypes,
21378+
but are not considered to be the same type.
21379+
21380+
\commentary{%
21381+
For instance, \DYNAMIC{} and \code{Object?} are subtypes of each other,
21382+
but they are not considered to be the same type.
21383+
This is useful because it allows us to treat two expressions very differently
21384+
even though the set of objects that they could evaluate to is exactly the same.
21385+
In particular, a member access on a receiver of type \code{Object?}
21386+
can only call \code{hashCode} and a few other members,
21387+
but a member access on a receiver of type \DYNAMIC{} can invoke
21388+
any member as a method accepting any actual list of arguments,
21389+
and as a getter or as a setter,
21390+
and it will be checked at run time that said invocation is possible.%
21391+
}
21392+
21393+
\LMHash{}%
21394+
This section defines a normalization procedure on types
21395+
which yields a canonical representation for any given type.
21396+
21397+
\commentary{%
21398+
In other words, subtyping on Dart types is a preorder,
21399+
but subtyping on normalized Dart types is a total order.%
21400+
}
21401+
21402+
\LMHash{}%
21403+
An \IndexCustom{atomic type}{type!atomic}
21404+
is a term derived from \synt{typeName}
21405+
that denotes a type.
21406+
21407+
\commentary{%
21408+
For instance, \DYNAMIC{} is an atomic type,
21409+
and so is \code{prefix.MyClass},
21410+
if it denotes a class.%
21411+
}
21412+
21413+
\newlength{\FunCr}
21414+
\setlength{\FunCr}{1.5ex}
21415+
21416+
\begin{figure}[t]
21417+
\begin{minipage}[c]{\textwidth}
21418+
\begin{displaymath}
21419+
\begin{array}{ll}
21420+
\mbox{\bf Unaliased argument} & \mbox{\bf Result}\\[\FunCr]
21421+
\hline
21422+
\mbox{If $T$ is atomic: }T & T\\[\FunCr]
21423+
%
21424+
\code{FutureOr<$T$>} &
21425+
\left\{
21426+
\begin{array}{l}
21427+
S\mbox{, if $S$ is a top type or \code{Object}}\\
21428+
\code{Future<Never>}\mbox{, if $S$ is \code{Never}}\\
21429+
\code{Future<Null>?}\mbox{, if $S$ is \code{Null}}\\
21430+
\code{FutureOr<S>}\mbox{, otherwise}
21431+
\end{array}
21432+
\right.\\[1ex]
21433+
\mbox{where $S$ is \NormalizedTypeOf{$T$}}\\[\FunCr]
21434+
%
21435+
\code{$T$?} &
21436+
\left\{
21437+
\begin{array}{l}
21438+
S\mbox{, if $S$ is a top type}\\
21439+
\code{Null}\mbox{, if $S$ is \code{Never} or \code{Null}}\\
21440+
S\mbox{, if $S$ is \code{FutureOr<$R$>} where $R$ is nullable}\\
21441+
\code{$R$?}\mbox{, if $S$ is \code{$R$?} for some $R$}\\
21442+
\code{$S$?}\mbox{, otherwise}
21443+
\end{array}
21444+
\right.\\
21445+
\mbox{where $S$ is \NormalizedTypeOf{$T$}}\\[\FunCr]
21446+
%
21447+
\code{$X$\,\,\EXTENDS\,\,$T$} &
21448+
\left\{
21449+
\begin{array}{l}
21450+
\code{Never}\mbox{,if $T$ is \code{Never}}\\
21451+
\code{Never}\mbox{,
21452+
if $T$ is a type variable $Y$,
21453+
and \NormalizedTypeOf{$Y$} is \code{Never}}\\
21454+
\code{$X$\,\,\EXTENDS\,\,$T$}\mbox{, otherwise}
21455+
\end{array}
21456+
\right.\\
21457+
\mbox{}\\[\FunCr]
21458+
%
21459+
\code{$X$\,\,\&\,\,$T$} &
21460+
\left\{
21461+
\begin{array}{l}
21462+
\code{Never}\mbox{, if $S$ is \code{Never}}\\
21463+
X\mbox{, if $S$` is $X$ or a top type}\\
21464+
X\mbox{, if \SubtypeStd{\NormalizedTypeOf{$B$}}{S}, where $B$ is the bound of $X$}\\
21465+
\code{$X$\,\,\&\,\,$S$}\mbox{, otherwise}
21466+
\end{array}
21467+
\right.\\
21468+
\mbox{where $S$ is \NormalizedTypeOf{$T$}}\\[\FunCr]
21469+
%
21470+
\code{$C$<\List{T}{1}{k}>} & \code{$C$<\List{R}{1}{k}>}\\
21471+
\mbox{where $R_i$ is \NormalizedTypeOf{$T_i$},}\\
21472+
\mbox{\quad{}for $i \in 1 .. k$}\\[\FunCr]
21473+
%
21474+
% !!!TODO: Generalize this to handle all parameter list shapes.
21475+
\code{$R$ \FUNCTION<$X$\,\,\EXTENDS,\,$B$>($S$)} &
21476+
\code{$R_1$ Function<$X$\,\,\EXTENDS\,\,$B_1$>($S_1$)}\\
21477+
\mbox{where $R_1$ is \NormalizedTypeOf{$R$},}\\
21478+
\mbox{\quad{}$B_1$ is \NormalizedTypeOf{$B$},}\\
21479+
\mbox{\quad{}and $S_1$ is \NormalizedTypeOf{$S$}}
21480+
\end{array}
21481+
\end{displaymath}
21482+
\end{minipage}
21483+
\caption{Definition of the type function \NormalizedTypeOfName:
21484+
For a given type $T_0$,
21485+
let $T$ be the transitive alias expansion of $T_0$
21486+
(\ref{typedef}),
21487+
then look up $T$ in the left column of the table in this figure
21488+
such that the associated condition is satisfied.
21489+
Then \NormalizedTypeOf{$T$} is as shown in the right hand column.}
21490+
\end{figure}
21491+
21492+
----------------------------------------------------------------------
21493+
21494+
21495+
!!!TODO!!!
21496+
Note that there is currently no place in the type system where normalization can
21497+
apply to intersection types (promoted types). The rule is included here for
21498+
completeness.
21499+
21500+
We assume that type aliases are fully expanded, and that prefixed types are
21501+
resolved to a canonical name.
21502+
21503+
The **NORM** relation defines the canonical representative of classes of
21504+
equivalent types. In the absence of legacy (*) types, it should be the case
21505+
that for any two types which are mutual subtypes, their normal forms are
21506+
syntactically identical up to identification of top types (\DYNAMIC, \VOID,
21507+
\code{Object?}).
21508+
21509+
This is based on the following equations:
21510+
\begin{itemize}
21511+
\item \code{T?? == T?}
21512+
\item \code{Null? == Null}
21513+
\item \code{Never? == Null}
21514+
\item \code{\DYNAMIC? == \DYNAMIC}
21515+
\item \code{\VOID? == \VOID}
21516+
\item \code{FutureOr<$T$> == $T$}, if \SubtypeStd{\code{Future<$T$>}}{T}
21517+
\item \code{FutureOr<$T$> == Future<$T$>}, if \SubtypeStd{T}{\code{Future<$T$>}}
21518+
\item \code{$X$\,\,\EXTENDS\,\,Never == Never}
21519+
\item \code{$X$\,\,\&\,\,$T$ == $T$}, if \SubtypeStd{T}{X}
21520+
\item \code{$X$\,\,\&\,\,$T$ == $X$}, if \SubtypeStd{X}{T}
21521+
\end{itemize}
21522+
21523+
----------------------------------------------------------------------
21524+
\LMHash{}%
21525+
This defines a procedure \NormalizedTypeOfName{}
21526+
such that \NormalizedTypeOf{$T$} is syntactically
21527+
equal to \NormalizedTypeOf{$S$} modulo replacement of primitive top types iff
21528+
\SubtypeStd{S}{T} and \SubtypeStd{T}{S}.
21529+
21530+
21531+
21532+
2136921533
\subsection{Type \code{Never}}
2137021534
\LMLabel{typeNever}
2137121535

2137221536
\LMHash{}%
21373-
The Dart core library \code{dart:core} exports a type named \code{Never}.
21537+
The system library \code{dart:core} exports a type named \code{Never}.
2137421538
No object has a dynamic type which is \code{Never} or a subtype thereof.
2137521539

2137621540
\commentary{%
@@ -21386,19 +21550,20 @@ \subsection{Type \code{Never}}
2138621550
e.g., because it calls a function that always throws.
2138721551
This allows for a more precise control flow analysis.
2138821552

21389-
Also, the object \code{\CONST\,\,<Never>[]} can be used
21553+
Also, \code{Never} can be used to express some extreme types:
21554+
For instance, the object \code{\CONST\,\,<Never>[]} can be used
2139021555
in any situation where a \code{List<$T$>} is required,
21391-
for any $T$ whatsoever,
21392-
and the value of a variable of type \code{Object?\,\,\FUNCTION(Never)}
21393-
can be any function that accepts a single, positional argument.%
21556+
for any $T$ whatsoever.
21557+
Similarly, a variable of type \code{Object?\,\,\FUNCTION(Never)}
21558+
can be used to hold any function that accepts a single, positional argument.%
2139421559
}
2139521560

2139621561

2139721562
\subsection{Type \code{Null}}
2139821563
\LMLabel{typeNull}
2139921564

2140021565
\LMHash{}%
21401-
The Dart core library \code{dart:core} exports a type named \code{Null}.
21566+
The system library \code{dart:core} exports a type named \code{Null}.
2140221567
There is exactly one object whose dynamic type is \code{Null},
2140321568
and that is the null object
2140421569
(\ref{null}).
@@ -21408,7 +21573,8 @@ \subsection{Type \code{Null}}
2140821573
Apart from top types
2140921574
(\ref{superBoundedTypes}),
2141021575
\code{Null} is a subtype of all types of the form \code{$T$?},
21411-
and of all types $S$ such that \futureOrBase{S} is one of the above.
21576+
and of all types $S$ such that \futureOrBase{S} is
21577+
a top type or a type of the form \code{$T$?}.
2141221578
The only non-trivial subtypes of \code{Null} are
2141321579
\code{Never} and subtypes of \code{Never}
2141421580
(\ref{subtypeRules}).%
@@ -22505,17 +22671,8 @@ \section{Null safety} %% !!!TODO!!!
2250522671
%% !!!Search all `TODO`.*null
2250622672

2250722673
\subsection{Static semantics}
22508-
2250922674
\subsubsection{Type normalization}
2251022675

22511-
We define a normalization procedure on types which defines a canonical
22512-
representation for otherwise equivalent
22513-
types here
22514-
(\ref{sec:typeNormalization}).
22515-
This defines a procedure \NormalizedTypeOfName{} such that \NormalizedTypeOf{$T$} is syntactically
22516-
equal to \NormalizedTypeOf{$S$} modulo replacement of primitive top types iff \code{$S$ <: $T$}
22517-
and \code{$T$ <: $S$}.
22518-
2251922676
\subsubsection{Future flattening}
2252022677

2252122678
The \FlattenName{} function is modified as follows:

0 commit comments

Comments
 (0)