Skip to content

Commit acd3824

Browse files
committed
WIP
1 parent 5a0c3f5 commit acd3824

File tree

2 files changed

+65
-59
lines changed

2 files changed

+65
-59
lines changed

specification/dart.sty

Lines changed: 1 addition & 1 deletion
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

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21466,9 +21466,6 @@ \subsection{Subtypes}
2146621466
\newcommand{\SrnRightTop}{2}
2146721467
\newcommand{\SrnLeftTop}{3}
2146821468
\newcommand{\SrnBottom}{4}
21469-
%\newcommand{\SrnRightObjectOne}{} Redundant
21470-
%\newcommand{\SrnRightObjectTwo}{} Redundant
21471-
%\newcommand{\SrnRightObjectThree}{} Redundant
2147221469
\newcommand{\SrnRightObjectFour}{5}
2147321470
\newcommand{\SrnNullOne}{6}
2147421471
\newcommand{\SrnNullTwo}{7}
@@ -22079,7 +22076,8 @@ \subsection{Type Nullability}
2207922076
Nullable types are types which are
2208022077
definitively known to include the null object,
2208122078
regardless of the value of any type variables.
22082-
This is equivalent to the syntactic criterion that $T$ is any of:
22079+
If $T'$ is the transitive alias expansion (\ref{typedef}) of $T$
22080+
then this is equivalent to the syntactic criterion that $T'$ is any of:
2208322081

2208422082
\begin{itemize}[itemsep=-0.5ex]
2208522083
\item \VOID.
@@ -22101,7 +22099,8 @@ \subsection{Type Nullability}
2210122099
Non-nullable types are types which are definitively known to
2210222100
\emph{not} include the null object,
2210322101
regardless of the value of any type variables.
22104-
This is equivalent to the syntactic criterion that $T$ is any of:
22102+
If $T'$ is the transitive alias expansion (\ref{typedef}) of $T$
22103+
then this is equivalent to the syntactic criterion that $T$ is any of:
2210522104

2210622105
\begin{itemize}[itemsep=-0.5ex]
2210722106
\item \code{Never}.
@@ -22468,21 +22467,23 @@ \subsection{Type Normalization}
2246822467

2246922468
\noindent
2247022469
then $T_r$ is
22471-
\FunctionTypePositional{R_0}{ }{X}{B}{s}{R}{n}{k}
22470+
\FunctionTypePositional{T'\!_0}{ }{X}{B'\!}{s}{T'\!}{n}{k}
2247222471

2247322472
\noindent
22474-
where $R_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$.
22473+
where $T'\!_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$
22474+
and $B'\!_i$ is \NormalizedTypeOf{$B_i$} for $i \in 1 .. s$.
2247522475
\item If $T_u$ is of the form
2247622476
\FunctionTypeNamedStd{T_0}
2247722477

2247822478
\noindent
2247922479
where $r_j$ is either \REQUIRED{} or empty
2248022480
then $T_r$ is
2248122481
\noindent
22482-
\FunctionTypeNamed{R_0}{ }{X}{B}{s}{R}{n}{x}{k}{r}
22482+
\FunctionTypeNamed{T'\!_0}{ }{X}{B'\!}{s}{T'\!}{n}{x}{k}
2248322483

2248422484
\noindent
22485-
where $R_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$.
22485+
where $T'\!_i$ is \NormalizedTypeOf{$T_i$} for $i \in 0 .. n+k$
22486+
and $B'\!_i$ is \NormalizedTypeOf{$B_i$} for $i \in 0 .. s$.
2248622487
\end{itemize}
2248722488

2248822489
\commentary{%
@@ -22820,8 +22821,8 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2282022821
which is defined as follows.
2282122822
Assume that $P_1$ and $P_2$ are two formal parameter type declarations
2282222823
with declared type $T_1$ respectively $T_2$,
22823-
such that both are positional or both are named,
22824-
with the same name \DefineSymbol{n}.
22824+
such that both are positional,
22825+
or both are named and have the same name \DefineSymbol{n}.
2282522826
Then \UpperBoundType{$P_1$}{$P_2$} (respectively \LowerBoundType{$P_1$}{$P_2$})
2282622827
is the formal parameter declaration $P$,
2282722828
with the following proporties:
@@ -22840,7 +22841,8 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2284022841
}
2284122842
\item
2284222843
$P$ is named if $P_1$ and $P_2$ are named.
22843-
In this case, the name of $P$ is $n$.
22844+
In this case, the name of $P$ is $n$
22845+
(\commentary{which is also the name of $P_1$ and $P_2$}).
2284422846
$P$ is marked with the modifier \REQUIRED{}
2284522847
if both $P_1$ and $P_2$ have this modifier
2284622848
(respectively, if either $P_1$ or $P_2$ has this modifier).
@@ -23019,22 +23021,25 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2301923021

2302023022
\noindent
2302123023
\code{$T_1$\,\FUNCTION<$X_1$\,\EXTENDS\,$B_{11}$,\,\ldots,\,$X_m$\,%
23022-
\EXTENDS\,$B_{1m}$>($P_{11}$,\,\ldots,\,$P_{1k}$)}
23024+
\EXTENDS\,$B_{1m}$>($P_{11}$,\,\ldots[\ldots\,$P_{1k}$])}
2302323025

2302423026
\noindent
2302523027
\code{$T_2$\,\FUNCTION<$X_1$\,\EXTENDS\,$B_{21}$,\,\ldots,\,$X_m$\,%
23026-
\EXTENDS\,$B_{2m}$>($P_{21}$,\,\ldots,\,$P_{2l}$)}
23028+
\EXTENDS\,$B_{2m}$>($P_{21}$,\,\ldots[\ldots\,$P_{2l}$])}
2302723029

2302823030
\noindent
2302923031
such that each $B_{1i}$ and $B_{2i}$ are types with the same canonical syntax,
23030-
and both have the same number of required positional parameters.
23032+
and both $U_1$ or $U_2$ have
23033+
the same number of required positional parameters.
23034+
In the case where $U_1$ or $U_2$ has no optional positional parameters,
23035+
the brackets are omitted.
2303123036
Let $q$ be $\metavar{min}(k, l)$,
2303223037
let $T_3$ be \UpperBoundType{$T_1$}{$T_2$},
23033-
let $B_{3i}$ be $B_{1i}$, and
23038+
let $B_{3i}$ be $B_{1i}$, and finally
2303423039
let $P_{3i}$ be \LowerBoundType{$P_{1i}$}{$P_{2i}$}.
23035-
Then \DefEquals{\UpperBoundType{$U_1$}{$U_2$}}{%
23040+
Then \DefEqualsNewline{\UpperBoundType{$U_1$}{$U_2$}}{%
2303623041
\code{$T_3$\,\FUNCTION<$X_1$\,\EXTENDS\,$B_{31}$,\,\ldots,\,$X_m$\,%
23037-
\EXTENDS\,$B_{3m}$>($P_{31}$,\,\ldots,\,$P_{3q}$)}}.
23042+
\EXTENDS\,$B_{3m}$>($P_{31}$,\,\ldots[\ldots\,$P_{3q}$])}}.
2303823043

2303923044
\commentary{%
2304023045
This case includes non-generic function types by allowing $m$ to be zero.%
@@ -23092,8 +23097,11 @@ \subsection{Standard Upper Bounds and Standard Lower Bounds}
2309223097
%%
2309323098
%% TODO(eernst), for review: Why do we not have a rule for
2309423099
%% \UpperBoundType{T1 Function(P1..Pm, [...])}{T2 Function(P1..Pk, {...}}}
23095-
%% = T3 Function(R1..Rk), where the left operand has at least k parameters,
23096-
%% plus the converse?
23100+
%% = T3 Function(R1..Rk), where the left operand has at least k parameters
23101+
%% and every named parameter of the right operand is optional (plus the
23102+
%% same rule with operands swapped)?
23103+
%% Motivation: Some expressions of type `Function` would then have a more
23104+
%% precise type, and programs would be safer (a tiny bit, at least).
2309723105
%%
2309823106
\item
2309923107
\DefEquals{\UpperBoundType{$S_1$ \FUNCTION<\ldots>(\ldots)}{%
@@ -23456,7 +23464,7 @@ \subsubsection{The Standard Upper Bound of Distinct Interface Types}
2345623464
$\{\;T\;|\;T\,\in\,M\;\wedge\;\NominalTypeDepth{$T$}\,=\,n\,\}$
2345723465
for any natural number $n$.
2345823466
Let $q$ be the largest number such that $M_q$ has cardinality one.
23459-
Such a number must exist because $M_0$ is $\{\code{Object?}\}$.
23467+
Such a number must exist because $M_0$ is $\{\code{Object}\}$.
2346023468
The least upper bound of $I$ and $J$ is then the sole element of $M_q$.
2346123469

2346223470

@@ -23689,7 +23697,7 @@ \subsection{Least and Greatest Closure of Types}
2368923697
the least closure of $S$ with respect to $L$ is
2369023698

2369123699
\noindent
23692-
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}{r}
23700+
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}
2369323701

2369423702
\noindent
2369523703
where
@@ -23704,7 +23712,7 @@ \subsection{Least and Greatest Closure of Types}
2370423712
the greatest closure of $S$ with respect to $L$ is
2370523713

2370623714
\noindent
23707-
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}{r}
23715+
\FunctionTypeNamed{U_0}{ }{X}{B}{s}{U}{n}{x}{k}
2370823716

2370923717
\noindent
2371023718
where $U_0$ is the greatest closure of $T_0$ with respect to $L$,
@@ -23760,15 +23768,17 @@ \subsection{Types Bounded by Types}
2376023768
\LMLabel{typesBoundedByTypes}
2376123769

2376223770
\LMHash{}%
23763-
For a given type $T_0$, we introduce the notion of a
23764-
\IndexCustom{$T_0$ bounded type}{type!T0 bounded}:
23765-
$T_0$ itself is $T_0$ bounded;
23766-
if $B$ is $T_0$ bounded and
23771+
For a given type $T$, we introduce the notion of a
23772+
% `T bounded` at the end should have been `$T$ bounded`, but makeindex
23773+
% seems to be unable to allow math mode in that position.
23774+
\IndexCustom{$T$ bounded type}{type!T bounded}:
23775+
$T$ itself is $T$ bounded;
23776+
if $B$ is $T$ bounded and
2376723777
$X$ is a type variable with bound $B$
23768-
then $X$ is $T_0$ bounded;
23769-
finally, if $B$ is $T_0$ bounded and
23778+
then $X$ is $T$ bounded;
23779+
finally, if $B$ is $T$ bounded and
2377023780
$X$ is a type variable
23771-
then $X \& B$ is $T_0$ bounded.
23781+
then $X \& B$ is $T$ bounded.
2377223782

2377323783
\LMHash{}%
2377423784
In particular, a
@@ -23782,11 +23792,11 @@ \subsection{Types Bounded by Types}
2378223792
\LMHash{}%
2378323793
A
2378423794
\IndexCustom{function-type bounded type}{type!function-type bounded}
23785-
is a type $T$ which is $T_0$ bounded where $T_0$ is a function type
23795+
is a type $S$ which is $T$ bounded where $T$ is a function type
2378623796
(\ref{functionTypes}).
23787-
A function-type bounded type $T$ has an
23797+
A function-type bounded type $S$ has an
2378823798
\Index{associated function type}
23789-
which is the unique function type $T_0$ such that $T$ is $T_0$ bounded.
23799+
which is the unique function type $T$ such that $S$ is $T$ bounded.
2379023800

2379123801

2379223802
\subsection{Class Building Types}
@@ -23847,7 +23857,7 @@ \subsection{Interface Types}
2384723857
are interface types,
2384823858
and so are
2384923859
\code{Future<$T$>}, \code{Stream<$T$>}, \code{Iterable<$T$>},
23850-
\code{List<$T$>}, \code{Map<$S$,\,\,$T$}, and \code{Set<$T$>},
23860+
\code{List<$T$>}, \code{Map<$S$,\,\,$T$>}, and \code{Set<$T$>},
2385123861
for any $S$ and $T$.%
2385223862
}
2385323863

@@ -23973,8 +23983,13 @@ \subsection{Type Null}
2397323983
\code{Null} is a subtype of all types of the form \code{$T$?},
2397423984
and of all types $S$ such that \futureOrBase{S} is
2397523985
a top type or a type of the form \code{$T$?}.
23976-
The only non-trivial subtypes of \code{Null} are
23977-
\code{Never} and subtypes of \code{Never}
23986+
The only subtypes of \code{Null} are
23987+
other types that contain the null object and no other objects,
23988+
e.g., \code{Null?},
23989+
the empty type,
23990+
i.e., \code{Never} and subtypes of \code{Never},
23991+
and types that could be either,
23992+
e.g., a type variable with bound \code{Null}
2397823993
(\ref{subtypeRules}).%
2397923994
}
2398023995

@@ -24500,22 +24515,10 @@ \subsection{Type Void}
2450024515
\commentary{%
2450124516
The type \VOID{} is a top type
2450224517
(\ref{superBoundedTypes}),
24503-
so \VOID{} and \code{Object} are subtypes of each other
24518+
so \VOID{} and \code{Object?} are subtypes of each other
2450424519
(\ref{subtypes}),
2450524520
which also implies that any object can be
24506-
the value of an expression of type \VOID.
24507-
%
24508-
Consequently, any instance of type \code{Type} which reifies the type \VOID{}
24509-
must compare equal (according to the \lit{==} operator \ref{equality})
24510-
to any instance of \code{Type} which reifies the type \code{Object}
24511-
(\ref{dynamicTypeSystem}).
24512-
It is not guaranteed that \code{identical(\VOID, Object)} evaluates to
24513-
the \TRUE{} object.
24514-
In fact, it is not recommended that implementations strive to achieve this,
24515-
because it may be more important to ensure that diagnostic messages
24516-
(including stack traces and dynamic error messages)
24517-
preserve enough information to use the word `void' when referring to types
24518-
which are specified as such in source code.%
24521+
the value of an expression of type \VOID.%
2451924522
}
2452024523

2452124524
\LMHash{}%
@@ -24653,7 +24656,7 @@ \subsection{Type Void}
2465324656
}
2465424657

2465524658
\begin{dartCode}
24656-
\FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
24659+
\FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
2465724660
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
2465824661
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
2465924662
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -24962,9 +24965,11 @@ \subsection{Definite Assignment}
2496224965
(\commentary{%
2496324966
e.g., as an expression, or as the left hand side of an assignment%
2496424967
}),
24965-
the variable has a status as being
24966-
\IndexCustom{definitely assigned}{local variable!definitely assigned} or
24967-
\IndexCustom{definitely unassigned}{local variable!definitely unassigned}.
24968+
the variable can be
24969+
\IndexCustom{definitely assigned}{local variable!definitely assigned},
24970+
and it can be
24971+
\IndexCustom{definitely unassigned}{local variable!definitely unassigned},
24972+
and it can be neither.
2496824973

2496924974
\commentary{%
2497024975
The precise flow analysis which determines this status at each location
@@ -25217,15 +25222,16 @@ \subsection{Type Promotion}
2521725222

2521825223
%% TODO(eernst), for review: The null safety spec says that `T?` is
2521925224
%% promoted to `T`, but implementations _do_ promote `X extends int?` to
25220-
%% `X & int`. So I've specified the latter. This is also more consistent
25221-
%% with the approach used with `==`.
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.
2522225228
\LMHash{}%
2522325229
A check of the form \code{$v$\,\,!=\,\,\NULL},
2522425230
\code{\NULL\,\,!=\,\,$v$},
2522525231
or \code{$v$\,\,\IS\,\,$T$}
25226-
where $v$ has type $T$ at $\ell$
25232+
where $v$ has static type $T?$ at $\ell$
2522725233
promotes the type of $v$
25228-
to \NonNullType{$T$} in the \TRUE{} continuation,
25234+
to $T$ in the \TRUE{} continuation,
2522925235
and to \code{Null} in the \FALSE{} continuation.
2523025236

2523125237
\commentary{%

0 commit comments

Comments
 (0)