@@ -24432,15 +24432,6 @@ \subsection{Type Promotion}
24432
24432
then $T$ is also a type of interest.%
24433
24433
}
24434
24434
24435
- \LMHash{}%
24436
- The initial stack of types of interest for $v$ has exactly one element,
24437
- namely the declared type.
24438
- This is the stack of types of interest
24439
- for the declaring occurrence of the name of $v$
24440
- (\commentary{%
24441
- that is, the very first time the variable is mentioned, \ref{variables}%
24442
- }).
24443
-
24444
24435
\commentary{%
24445
24436
The flow analysis will be specified in
24446
24437
a future version of this specification.
@@ -24450,9 +24441,21 @@ \subsection{Type Promotion}
24450
24441
based on the same properties of locations
24451
24442
that are immediate predecessors of $\ell$
24452
24443
in the control flow graph,
24453
- ending in the declaration of $v$.%
24444
+ ending in the declaration of $v$.
24445
+ At this point we just specify the initial step,
24446
+ and the situations where promotion may occur.%
24454
24447
}
24455
24448
24449
+ \LMHash{}%
24450
+ The initial stack of types of interest for $v$ has exactly one element,
24451
+ namely the declared type
24452
+ (\ref{localVariableDeclaration}).
24453
+ This is the stack of types of interest
24454
+ for the declaring occurrence of the name of $v$
24455
+ (\commentary{%
24456
+ i.e., the very first time the variable is mentioned, \ref{variables}%
24457
+ }).
24458
+
24456
24459
\LMHash{}%
24457
24460
If a local variable $v$ has an initializing expression
24458
24461
and does not have the modifier \FINAL,
@@ -24492,20 +24495,91 @@ \subsection{Type Promotion}
24492
24495
Consider the situation
24493
24496
where the declaration of a local variable $v$ is of the form
24494
24497
\code{\LATE?\,\,\VAR\,\,$v$ = $e$;}
24495
- where the static type of $e$ is of the form \code{$X$\,\&\,$T$}
24498
+ where the static type of $e$ is of the form \code{$X$\,\&\,\, $T$}
24496
24499
where $X$ is a type variable.
24497
24500
In this situation, the declared type of $v$ is \code{X}
24498
24501
(\ref{localVariableDeclaration}),
24499
- but the type \code{$X$\,\&\,$T$} is added to the stack of types of interest,
24500
- and the type of $v$ is immediately promoted to \code{$X$\,\&\,$T$}.
24502
+ but the type \code{$X$\,\&\,\, $T$} is added to the stack of types of interest,
24503
+ and the type of $v$ is immediately promoted to \code{$X$\,\&\,\, $T$}.
24501
24504
24502
24505
\commentary{%
24503
- Note that \code{$X$\,\&\,$T$} is not otherwise automatically a
24506
+ Note that \code{$X$\,\&\,\, $T$} is not otherwise automatically a
24504
24507
type of interest just because $X$ is a type of interest.
24505
24508
In particular, if $w$ is declared as
24506
24509
\code{\LATE?\,\,$X$\,\,$w$ = $e$;}
24507
- where the static type of $e$ is \code{$X$\,\&\,$T$},
24508
- the type of $w$ is \emph{not} immediately promoted to \code{$X$\,\&\,$T$}.%
24510
+ where the static type of $e$ is \code{$X$\,\&\,\,$T$},
24511
+ the type of $w$ is \emph{not} promoted to \code{$X$\,\&\,\,$T$}.%
24512
+ }
24513
+
24514
+ \LMHash{}%
24515
+ We now mention the locations where promotion may occur
24516
+ independently of the control flow.
24517
+
24518
+ \commentary{%
24519
+ We might say that these promotions are ``atomic'',
24520
+ and all other promotions are derived from these,
24521
+ and from the control flow.%
24522
+ }
24523
+
24524
+ \LMHash{}%
24525
+ Let $\ell$ be a location,
24526
+ and let $v$ be a local variable which is in scope at $\ell$.
24527
+ Assume that $\ell$ occurs after the declaration of $v$.
24528
+ The expressions that give rise to promotion or demotion
24529
+ of the type of $v$ at $\ell$
24530
+ are the following:
24531
+
24532
+ \begin{itemize}
24533
+ \item A type test of the form \code{$v$\,\,\IS\,\,$T$}.
24534
+ \item A type check of the form \code{$v$\,\,\AS\,\,$T$}.
24535
+ \item An assignment of the form \code{$v$\,\,=\,\,$e$}
24536
+ where the static type of $e$ is a type of interest for $v$ at $\ell$,
24537
+ and similarly for compound assignments
24538
+ (\ref{compoundAssignment})
24539
+ including \lit{??=}.
24540
+ \item An equality test of the form \code{$v$\,\,==\,\,$e$} or
24541
+ \code{$e$\,\,==\,\,$v$}, where $e$ is \NULL,
24542
+ optionally wrapped in one or more parentheses,
24543
+ and similarly for \lit{!=}.
24544
+ \end{itemize}
24545
+
24546
+ \LMHash{}%
24547
+ In particular,
24548
+ a check of the form \code{$v$\,\,==\,\,\NULL},
24549
+ \code{\NULL\,\,==\,\,$v$},
24550
+ or \code{$v$\,\,\IS\,\,Null}
24551
+ where $v$ has type $T$ at $\ell$
24552
+ promotes the type of $v$
24553
+ to \code{Null} in the \TRUE{} continuation,
24554
+ and to \NonNullType{$T$} in the \FALSE{} continuation.
24555
+
24556
+ \LMHash{}%
24557
+ %% TODO(eernst), for review: The null safety spec says that `T?` is
24558
+ %% promoted to `T`, but implementations _do_ promote `X extends int?` to
24559
+ %% `X & int`. So I specify that.
24560
+ A check of the form \code{$v$\,\,!=\,\,\NULL},
24561
+ \code{\NULL\,\,!=\,\,$v$},
24562
+ or \code{$v$\,\,\IS\,\,$T$}
24563
+ where $v$ has type $T$ at $\ell$
24564
+ promotes the type of $v$
24565
+ to \NonNullType{$T$} in the \TRUE{} continuation,
24566
+ and to \code{Null} in the \FALSE{} continuation.
24567
+
24568
+ \commentary{%
24569
+ The resulting type of $v$ may be the obvious one, e.g.,
24570
+ \code{$v$\,\,=\,\,1} may promote $v$ to \code{int},
24571
+ but it may also give rise to a demotion
24572
+ (changing the type of $v$ to a supertype of the type of $v$ at $\ell$),
24573
+ and it may have no effect on the type of $v$
24574
+ (e.g., when the static type of $e$ is not a type of interest).
24575
+ These details will be specified in a future version of this specification.
24576
+
24577
+ Every non-trivial type of control flow determines the control flow graph,
24578
+ and the control flow graph determines which of the above
24579
+ may or must have occurred at $\ell$,
24580
+ and hence gives rise to the stack of types of interest of $v$ at $\ell$,
24581
+ which in turn determines the type of $v$ at $\ell$.
24582
+ This part of the flow analysis will also be specified in the future.%
24509
24583
}
24510
24584
24511
24585
@@ -24666,32 +24740,11 @@ \section{Null safety} %% !!!TODO!!!
24666
24740
%% !!!At the end: Search Null, change to Never where appropriate
24667
24741
%% !!!Search all `TODO`.*null
24668
24742
24669
- \subsubsection{Null promotion}
24670
- \LMLabel{}
24671
-
24672
- !!!
24673
-
24674
- The machinery of type promotion is extended to promote the type of
24675
- variables based on nullability checks subject to the same set of
24676
- restrictions as normal promotion. The relevant checks and the types
24677
- they are considered to promote to are as follows.
24678
-
24679
- A check of the form \code{$e$ == null} or of the form
24680
- \code{$e$\,\,\IS\,\,Null} where $e$ has static type $T$ promotes the
24681
- type of $e$ to \code{Null} in the \code{true} continuation, and to
24682
- \NonNullType{$T$} in the \code{false} continuation.
24683
-
24684
- A check of the form \code{$e$ != null} or of the form
24685
- \code{$e$\,\,\IS\,\,$T$} where $e$ has static type
24686
- \code{$T$?}\ promotes the type of $e$ to $T$ in the \code{true}
24687
- continuation, and to \code{Null} in the \code{false} continuation.
24688
-
24689
- The static type of an expression \code{$e$!} is \NonNullType{$T$}
24690
- where $T$ is the static type of $e$.
24691
-
24692
24743
\subsubsection{Null aware operator}
24693
24744
\LMLabel{nullShorteningTransformation}
24694
24745
24746
+ !!!
24747
+
24695
24748
The semantics of the null aware operator \code{?.} are defined via a source to source
24696
24749
translation of expressions into Dart code extended with a let binding construct.
24697
24750
The translation is defined using meta-level functions over syntax. We use the
0 commit comments