Skip to content

Commit 27ed4a3

Browse files
committed
WIP
1 parent 3dfeb02 commit 27ed4a3

File tree

2 files changed

+65
-59
lines changed

2 files changed

+65
-59
lines changed

specification/dart.sty

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@
456456
\FunctionTypeAllRequired{#1}{ }{X}{B}{s}{T}{n}}
457457

458458
\newcommand{\FunctionTypeNamedStdArgCr}[1]{%
459-
\FunctionTypeNamedArgCr{#1}{ }{X}{B}{s}{T}{n}{x}{k}{r}}
459+
\FunctionTypeNamedArgCr{#1}{ }{X}{B}{s}{T}{n}{x}{k}}
460460

461461
% Same as \FunctionTypeAllRequiredStd except that it includes a newline, hence
462462
% suitable for function types that are too long to fit in one line.

specification/dartLangSpec.tex

+64-58
Original file line numberDiff line numberDiff line change
@@ -21421,9 +21421,6 @@ \subsection{Subtypes}
2142121421
\newcommand{\SrnRightTop}{2}
2142221422
\newcommand{\SrnLeftTop}{3}
2142321423
\newcommand{\SrnBottom}{4}
21424-
%\newcommand{\SrnRightObjectOne}{} Redundant
21425-
%\newcommand{\SrnRightObjectTwo}{} Redundant
21426-
%\newcommand{\SrnRightObjectThree}{} Redundant
2142721424
\newcommand{\SrnRightObjectFour}{5}
2142821425
\newcommand{\SrnNullOne}{6}
2142921426
\newcommand{\SrnNullTwo}{7}
@@ -22034,7 +22031,8 @@ \subsection{Type Nullability}
2203422031
Nullable types are types which are
2203522032
definitively known to include the null object,
2203622033
regardless of the value of any type variables.
22037-
This is equivalent to the syntactic criterion that $T$ is any of:
22034+
If $T'$ is the transitive alias expansion (\ref{typedef}) of $T$
22035+
then this is equivalent to the syntactic criterion that $T'$ is any of:
2203822036

2203922037
\begin{itemize}[itemsep=-0.5ex]
2204022038
\item \VOID.
@@ -22056,7 +22054,8 @@ \subsection{Type Nullability}
2205622054
Non-nullable types are types which are definitively known to
2205722055
\emph{not} include the null object,
2205822056
regardless of the value of any type variables.
22059-
This is equivalent to the syntactic criterion that $T$ is any of:
22057+
If $T'$ is the transitive alias expansion (\ref{typedef}) of $T$
22058+
then this is equivalent to the syntactic criterion that $T$ is any of:
2206022059

2206122060
\begin{itemize}[itemsep=-0.5ex]
2206222061
\item \code{Never}.
@@ -22423,21 +22422,23 @@ \subsection{Type Normalization}
2242322422

2242422423
\noindent
2242522424
then $T_r$ is
22426-
\FunctionTypePositional{R_0}{ }{X}{B}{s}{R}{n}{k}
22425+
\FunctionTypePositional{T'\!_0}{ }{X}{B'\!}{s}{T'\!}{n}{k}
2242722426

2242822427
\noindent
22429-
where $R_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$.
22428+
where $T'\!_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$
22429+
and $B'\!_i$ is \NormalizedTypeOf{$B_i$} for $i \in 1 .. s$.
2243022430
\item If $T_u$ is of the form
2243122431
\FunctionTypeNamedStd{T_0}
2243222432

2243322433
\noindent
2243422434
where $r_j$ is either \REQUIRED{} or empty
2243522435
then $T_r$ is
2243622436
\noindent
22437-
\FunctionTypeNamed{R_0}{ }{X}{B}{s}{R}{n}{x}{k}{r}
22437+
\FunctionTypeNamed{T'\!_0}{ }{X}{B'\!}{s}{T'\!}{n}{x}{k}
2243822438

2243922439
\noindent
22440-
where $R_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$.
22440+
where $T'\!_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$
22441+
and $B'\!_i$ is \NormalizedTypeOf{$B_i$} for $i \in 0 .. s$.
2244122442
\end{itemize}
2244222443

2244322444
\commentary{%
@@ -22775,8 +22776,8 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2277522776
which is defined as follows.
2277622777
Assume that $P_1$ and $P_2$ are two formal parameter type declarations
2277722778
with declared type $T_1$ respectively $T_2$,
22778-
such that both are positional or both are named,
22779-
with the same name \DefineSymbol{n}.
22779+
such that both are positional,
22780+
or both are named and have the same name \DefineSymbol{n}.
2278022781
Then \UpperBoundType{$P_1$}{$P_2$} (respectively \LowerBoundType{$P_1$}{$P_2$})
2278122782
is the formal parameter declaration $P$,
2278222783
with the following proporties:
@@ -22795,7 +22796,8 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2279522796
}
2279622797
\item
2279722798
$P$ is named if $P_1$ and $P_2$ are named.
22798-
In this case, the name of $P$ is $n$.
22799+
In this case, the name of $P$ is $n$
22800+
(\commentary{which is also the name of $P_1$ and $P_2$}).
2279922801
$P$ is marked with the modifier \REQUIRED{}
2280022802
if both $P_1$ and $P_2$ have this modifier
2280122803
(respectively, if either $P_1$ or $P_2$ has this modifier).
@@ -22974,22 +22976,25 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2297422976

2297522977
\noindent
2297622978
\code{$T_1$\,\FUNCTION<$X_1$\,\EXTENDS\,$B_{11}$,\,\ldots,\,$X_m$\,%
22977-
\EXTENDS\,$B_{1m}$>($P_{11}$,\,\ldots,\,$P_{1k}$)}
22979+
\EXTENDS\,$B_{1m}$>($P_{11}$,\,\ldots[\ldots\,$P_{1k}$])}
2297822980

2297922981
\noindent
2298022982
\code{$T_2$\,\FUNCTION<$X_1$\,\EXTENDS\,$B_{21}$,\,\ldots,\,$X_m$\,%
22981-
\EXTENDS\,$B_{2m}$>($P_{21}$,\,\ldots,\,$P_{2l}$)}
22983+
\EXTENDS\,$B_{2m}$>($P_{21}$,\,\ldots[\ldots\,$P_{2l}$])}
2298222984

2298322985
\noindent
2298422986
such that each $B_{1i}$ and $B_{2i}$ are types with the same canonical syntax,
22985-
and both have the same number of required positional parameters.
22987+
and both $U_1$ or $U_2$ have
22988+
the same number of required positional parameters.
22989+
In the case where $U_1$ or $U_2$ has no optional positional parameters,
22990+
the brackets are omitted.
2298622991
Let $q$ be $\metavar{min}(k, l)$,
2298722992
let $T_3$ be \UpperBoundType{$T_1$}{$T_2$},
22988-
let $B_{3i}$ be $B_{1i}$, and
22993+
let $B_{3i}$ be $B_{1i}$, and finally
2298922994
let $P_{3i}$ be \LowerBoundType{$P_{1i}$}{$P_{2i}$}.
22990-
Then \DefEquals{\UpperBoundType{$U_1$}{$U_2$}}{%
22995+
Then \DefEqualsNewline{\UpperBoundType{$U_1$}{$U_2$}}{%
2299122996
\code{$T_3$\,\FUNCTION<$X_1$\,\EXTENDS\,$B_{31}$,\,\ldots,\,$X_m$\,%
22992-
\EXTENDS\,$B_{3m}$>($P_{31}$,\,\ldots,\,$P_{3q}$)}}.
22997+
\EXTENDS\,$B_{3m}$>($P_{31}$,\,\ldots[\ldots\,$P_{3q}$])}}.
2299322998

2299422999
\commentary{%
2299523000
This case includes non-generic function types by allowing $m$ to be zero.%
@@ -23047,8 +23052,11 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2304723052
%%
2304823053
%% TODO(eernst), for review: Why do we not have a rule for
2304923054
%% \UpperBoundType{T1 Function(P1..Pm, [...])}{T2 Function(P1..Pk, {...}}}
23050-
%% = T3 Function(R1..Rk), where the left operand has at least k parameters,
23051-
%% plus the converse?
23055+
%% = T3 Function(R1..Rk), where the left operand has at least k parameters
23056+
%% and every named parameter of the right operand is optional (plus the
23057+
%% same rule with operands swapped)?
23058+
%% Motivation: Some expressions of type `Function` would then have a more
23059+
%% precise type, and programs would be safer (a tiny bit, at least).
2305223060
%%
2305323061
\item
2305423062
\DefEquals{\UpperBoundType{$S_1$ \FUNCTION<\ldots>(\ldots)}{%
@@ -23411,7 +23419,7 @@ \subsubsection{The Standard Upper Bound of Distinct Interface Types}
2341123419
$\{\;T\;|\;T\,\in\,M\;\wedge\;\NominalTypeDepth{$T$}\,=\,n\,\}$
2341223420
for any natural number $n$.
2341323421
Let $q$ be the largest number such that $M_q$ has cardinality one.
23414-
Such a number must exist because $M_0$ is $\{\code{Object?}\}$.
23422+
Such a number must exist because $M_0$ is $\{\code{Object}\}$.
2341523423
The least upper bound of $I$ and $J$ is then the sole element of $M_q$.
2341623424

2341723425

@@ -23644,7 +23652,7 @@ \subsection{Least and Greatest Closure of Types}
2364423652
the least closure of $S$ with respect to $L$ is
2364523653

2364623654
\noindent
23647-
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}{r}
23655+
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}
2364823656

2364923657
\noindent
2365023658
where
@@ -23659,7 +23667,7 @@ \subsection{Least and Greatest Closure of Types}
2365923667
the greatest closure of $S$ with respect to $L$ is
2366023668

2366123669
\noindent
23662-
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}{r}
23670+
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}
2366323671

2366423672
\noindent
2366523673
where $U_0$ is the greatest closure of $T_0$ with respect to $L$,
@@ -23715,15 +23723,17 @@ \subsection{Types Bounded by Types}
2371523723
\LMLabel{typesBoundedByTypes}
2371623724

2371723725
\LMHash{}%
23718-
For a given type $T_0$, we introduce the notion of a
23719-
\IndexCustom{$T_0$ bounded type}{type!T0 bounded}:
23720-
$T_0$ itself is $T_0$ bounded;
23721-
if $B$ is $T_0$ bounded and
23726+
For a given type $T$, we introduce the notion of a
23727+
% `T bounded` at the end should have been `$T$ bounded`, but makeindex
23728+
% seems to be unable to allow math mode in that position.
23729+
\IndexCustom{$T$ bounded type}{type!T bounded}:
23730+
$T$ itself is $T$ bounded;
23731+
if $B$ is $T$ bounded and
2372223732
$X$ is a type variable with bound $B$
23723-
then $X$ is $T_0$ bounded;
23724-
finally, if $B$ is $T_0$ bounded and
23733+
then $X$ is $T$ bounded;
23734+
finally, if $B$ is $T$ bounded and
2372523735
$X$ is a type variable
23726-
then $X \& B$ is $T_0$ bounded.
23736+
then $X \& B$ is $T$ bounded.
2372723737

2372823738
\LMHash{}%
2372923739
In particular, a
@@ -23737,11 +23747,11 @@ \subsection{Types Bounded by Types}
2373723747
\LMHash{}%
2373823748
A
2373923749
\IndexCustom{function-type bounded type}{type!function-type bounded}
23740-
is a type $T$ which is $T_0$ bounded where $T_0$ is a function type
23750+
is a type $S$ which is $T$ bounded where $T$ is a function type
2374123751
(\ref{functionTypes}).
23742-
A function-type bounded type $T$ has an
23752+
A function-type bounded type $S$ has an
2374323753
\Index{associated function type}
23744-
which is the unique function type $T_0$ such that $T$ is $T_0$ bounded.
23754+
which is the unique function type $T$ such that $S$ is $T$ bounded.
2374523755

2374623756

2374723757
\subsection{Class Building Types}
@@ -23802,7 +23812,7 @@ \subsection{Interface Types}
2380223812
are interface types,
2380323813
and so are
2380423814
\code{Future<$T$>}, \code{Stream<$T$>}, \code{Iterable<$T$>},
23805-
\code{List<$T$>}, \code{Map<$S$,\,\,$T$}, and \code{Set<$T$>},
23815+
\code{List<$T$>}, \code{Map<$S$,\,\,$T$>}, and \code{Set<$T$>},
2380623816
for any $S$ and $T$.%
2380723817
}
2380823818

@@ -23928,8 +23938,13 @@ \subsection{Type Null}
2392823938
\code{Null} is a subtype of all types of the form \code{$T$?},
2392923939
and of all types $S$ such that \futureOrBase{S} is
2393023940
a top type or a type of the form \code{$T$?}.
23931-
The only non-trivial subtypes of \code{Null} are
23932-
\code{Never} and subtypes of \code{Never}
23941+
The only subtypes of \code{Null} are
23942+
other types that contain the null object and no other objects,
23943+
e.g., \code{Null?},
23944+
the empty type,
23945+
i.e., \code{Never} and subtypes of \code{Never},
23946+
and types that could be either,
23947+
e.g., a type variable with bound \code{Null}
2393323948
(\ref{subtypeRules}).%
2393423949
}
2393523950

@@ -24455,22 +24470,10 @@ \subsection{Type Void}
2445524470
\commentary{%
2445624471
The type \VOID{} is a top type
2445724472
(\ref{superBoundedTypes}),
24458-
so \VOID{} and \code{Object} are subtypes of each other
24473+
so \VOID{} and \code{Object?} are subtypes of each other
2445924474
(\ref{subtypes}),
2446024475
which also implies that any object can be
24461-
the value of an expression of type \VOID.
24462-
%
24463-
Consequently, any instance of type \code{Type} which reifies the type \VOID{}
24464-
must compare equal (according to the \lit{==} operator \ref{equality})
24465-
to any instance of \code{Type} which reifies the type \code{Object}
24466-
(\ref{dynamicTypeSystem}).
24467-
It is not guaranteed that \code{identical(\VOID, Object)} evaluates to
24468-
the \TRUE{} object.
24469-
In fact, it is not recommended that implementations strive to achieve this,
24470-
because it may be more important to ensure that diagnostic messages
24471-
(including stack traces and dynamic error messages)
24472-
preserve enough information to use the word `void' when referring to types
24473-
which are specified as such in source code.%
24476+
the value of an expression of type \VOID.%
2447424477
}
2447524478

2447624479
\LMHash{}%
@@ -24608,7 +24611,7 @@ \subsection{Type Void}
2460824611
}
2460924612

2461024613
\begin{dartCode}
24611-
\FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
24614+
\FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
2461224615
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
2461324616
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
2461424617
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -24917,9 +24920,11 @@ \subsection{Definite Assignment}
2491724920
(\commentary{%
2491824921
e.g., as an expression, or as the left hand side of an assignment%
2491924922
}),
24920-
the variable has a status as being
24921-
\IndexCustom{definitely assigned}{local variable!definitely assigned} or
24922-
\IndexCustom{definitely unassigned}{local variable!definitely unassigned}.
24923+
the variable can be
24924+
\IndexCustom{definitely assigned}{local variable!definitely assigned},
24925+
and it can be
24926+
\IndexCustom{definitely unassigned}{local variable!definitely unassigned},
24927+
and it can be neither.
2492324928

2492424929
\commentary{%
2492524930
The precise flow analysis which determines this status at each location
@@ -25172,15 +25177,16 @@ \subsection{Type Promotion}
2517225177

2517325178
%% TODO(eernst), for review: The null safety spec says that `T?` is
2517425179
%% promoted to `T`, but implementations _do_ promote `X extends int?` to
25175-
%% `X & int`. So I've specified the latter. This is also more consistent
25176-
%% with the approach used with `==`.
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.
2517725183
\LMHash{}%
2517825184
A check of the form \code{$v$\,\,!=\,\,\NULL},
2517925185
\code{\NULL\,\,!=\,\,$v$},
2518025186
or \code{$v$\,\,\IS\,\,$T$}
25181-
where $v$ has type $T$ at $\ell$
25187+
where $v$ has static type $T?$ at $\ell$
2518225188
promotes the type of $v$
25183-
to \NonNullType{$T$} in the \TRUE{} continuation,
25189+
to $T$ in the \TRUE{} continuation,
2518425190
and to \code{Null} in the \FALSE{} continuation.
2518525191

2518625192
\commentary{%

0 commit comments

Comments
 (0)