@@ -22967,12 +22967,13 @@ \subsubsection{The Canonical Syntax of Types}
22967
22967
\rationale{%
22968
22968
This shows that concrete syntax behaves in such a manner that it is
22969
22969
unsafe to consider two types as the same type,
22970
- based on the fact that they are denoted by the same syntax.
22970
+ based on the fact that they are denoted by the same syntax,
22971
+ even during the static analysis of a single expression.
22971
22972
22972
22973
Similarly, it is incorrect to consider two terms derived from \synt{type}
22973
- as different types based on the fact that they are syntactically different,
22974
- as they could in fact be the same type,
22975
- e.g., imported with different import prefixes.%
22974
+ as different types based on the fact that they are syntactically different.
22975
+ They could in fact be the same type,
22976
+ e.g., imported with different import prefixes.
22976
22977
22977
22978
Consequently, we introduce the notion of the canonical syntax for a type,
22978
22979
which has the property that each type has a unique syntactic form.
@@ -22988,49 +22989,63 @@ \subsubsection{The Canonical Syntax of Types}
22988
22989
of the types in a given library $L_1$
22989
22990
and all libraries \List{L}{2}{n} reachable from $L_1$ via
22990
22991
one or more import links,
22991
- first choose a set of distinct fresh identifiers
22992
+ first choose a set of distinct, globally fresh identifiers
22992
22993
\List{\metavar{prefix}}{1}{n}.
22993
- Then transform each library $L_i$, $i \in 1 .. n$,
22994
- such that $L_i$ imports itself with the prefix $\metavar{prefix}_i$,
22995
- and $L_i$ imports \code{dart:core} explicitly
22996
- with the suitable prefix $\metavar{prefix}_j$ for some $j$,
22997
- and change all existing imports to use the prefix
22998
- corresponding to the library which is being imported.
22994
+ Then transform each library $L_i$, $i \in 1 .. n$ as follows:
22999
22995
23000
- \LMHash{}%
23001
- Next, transform every identifier expression and every \synt{typeName}
23002
- that refers to an imported declaration or a library declaration
23003
- such that it uses the prefix $\metavar{prefix}_j$ with the relevant $j$,
23004
- and such that every name resolves to the same declaration
23005
- as it did in the original program.
22996
+ \begin{enumerate}
22997
+ \item
22998
+ Add a set of import directives to $L_i$ that imports
22999
+ each of the libraries \List{L}{1}{n} with
23000
+ the corresponding prefix $\metavar{prefix}_j$, $j \in 1 .. n$.
23001
+
23002
+ \commentary{%
23003
+ This means that every library in the set
23004
+ $\{\,\List{L}{1}{n}\,\}$
23005
+ imports every other library in that set,
23006
+ even itself and system libraries like \code{dart:core}.%
23007
+ }
23008
+ \item
23009
+ Let \id{} be a non-private identifier that resolves to
23010
+ a library declaration in the library $L_j$ in the original program;
23011
+ \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23012
+ Let \code{$p$.\id} be a qualified identifier where $p$ is
23013
+ an import prefix in the original program,
23014
+ \id{} is a non-private identifier,
23015
+ and \code{$p$.\id} resolves to
23016
+ a library declaration in the library $L_j$ in the original program;
23017
+ \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23018
+ \item
23019
+ %% TODO(eernst): We should rename private names to fresh public names.
23020
+ Replace every type that denotes a type alias
23021
+ by its transitive alias expansion
23022
+ (\ref{typedef}).
23023
+ \commentary{%
23024
+ Note that the bodies of type alias declarations
23025
+ already use the new prefixes,
23026
+ so the results of the alias expansion will also use
23027
+ the new prefixes consistently.%
23028
+ }
23029
+ \end{enumerate}
23006
23030
23007
23031
\commentary{%
23008
23032
Note that this transformation does not change any occurrence of \VOID;
23009
- \VOID{} is a reserved word
23010
- and \code{$\metavar{prefix}_j$.\VOID} is a syntax error.%
23011
- }
23033
+ \VOID{} is a reserved word, not an identifier.
23034
+ Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23012
23035
23013
- %% TODO(eernst), for review: Rename private names to fresh public names?
23014
- %% Otherwise the type alias could turn into a term containing private names
23015
- %% from different libraries.
23016
- \LMHash{}%
23017
- Finally, replace every type that denotes a type alias
23018
- by its transitive alias expansion
23019
- (\ref{typedef}).
23020
- \commentary{%
23021
- Note that the bodies of type alias declarations already use the new prefixes,
23022
- so the results of the alias expansion will also use
23023
- the new prefixes consistently.%
23036
+ The transformation also does not change identifiers denoting type variables,
23037
+ There is no need to change those identifiers, because
23038
+ no occurrence of such an identifier resolves to a declaration in a
23039
+ different library.%
23040
+ %% TODO(eernst): Sort out the treatment of private identifiers, too.
23024
23041
}
23025
23042
23026
23043
\LMHash{}%
23027
- Every \synt{type} and type literal in the resulting program
23028
- is now expressed in a globally unique syntactic form.
23029
-
23030
- \rationale{%
23031
- This means that two terms denoting a type will have the same syntactic form
23032
- if and only if they denote the same type.
23033
- }
23044
+ Every \synt{type} and type literal in the resulting set of libraries
23045
+ is now expressed in a globally unique syntactic form,
23046
+ which is the form that we call the
23047
+ \IndexCustom{canonical syntax of}{type!canonical syntax of}
23048
+ said types.
23034
23049
23035
23050
\LMHash{}%
23036
23051
When we say that two types $T_1$ and $T_2$ have the
@@ -23040,6 +23055,36 @@ \subsubsection{The Canonical Syntax of Types}
23040
23055
have been transformed as described above,
23041
23056
and the resulting canonical syntaxes are identical.
23042
23057
23058
+ \rationale{%
23059
+ The transformation described here would not be useful in practice
23060
+ (or even possible---we can't edit \code{dart:core}).
23061
+ It only serves to show that we can express types using a syntactic form
23062
+ which is independent of the location.
23063
+ This is in turn needed in order to ensure that operations are well-defined
23064
+ even when they bring syntactic elements from different locations together,
23065
+ such as computations of subtype relationships,
23066
+ and construction of standard upper or lower bounds.
23067
+
23068
+ We could just as well have replaced the concrete syntax by a semantic
23069
+ notion of types,
23070
+ where each entity that denotes a type would be, in some sense,
23071
+ a reference to a specific declaration
23072
+ (this is likely to be the approach used by tool implementations).
23073
+ However, that approach would be somewhat inconvenient in a specification,
23074
+ because we would need to re-build all the structures that the
23075
+ syntax offers.
23076
+ For instance, we would need to support the construction of
23077
+ a semantic type entity for \code{Map<int, String>},
23078
+ based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23079
+ and we would need to support deconstruction of those entities
23080
+ in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23081
+ This would give rise to a lot of mechanism that will simply duplicate
23082
+ the structure of the syntax.
23083
+ So we prefer to show that the syntax \emph{can} be location independent,
23084
+ and that's sufficient to make syntax usable as our representation of
23085
+ static semantic types.%
23086
+ }
23087
+
23043
23088
23044
23089
\subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23045
23090
\LMLabel{standardUpperBoundsAndStandardLowerBounds}
@@ -25762,7 +25807,7 @@ \section*{Appendix: Algorithmic Subtyping}
25762
25807
\item
25763
25808
\textbf{Reflexivity:}
25764
25809
if $T_0$ and $T_1$ are the same type then \SubtypeNE{T_0}{T_1}
25765
-
25810
+
25766
25811
\commentary{%
25767
25812
Note that this check is necessary as the base case for primitive types,
25768
25813
and type variables, but not for composite types.
@@ -25778,7 +25823,7 @@ \section*{Appendix: Algorithmic Subtyping}
25778
25823
\item
25779
25824
\textbf{Left Top:}
25780
25825
if $T_0$ is \DYNAMIC{} or \VOID{}
25781
- then \SubtypeNE{T_0}{T_1} if \SubtypeNE{\code{Object?}}{T_1}.
25826
+ then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
25782
25827
\item
25783
25828
\textbf{Left Bottom:}
25784
25829
if $T_0$ is \code{Never} then \SubtypeNE{T_0}{T_1}.
@@ -25814,8 +25859,7 @@ \section*{Appendix: Algorithmic Subtyping}
25814
25859
if $T_1$ is \code{FutureOr<$S$>} for some $S$,
25815
25860
then the query is true if{}f \SubtypeNE{\code{Null}}{S}.
25816
25861
\item
25817
- if $T_1$ is \code{Null} or \code{$S$?} for some $S$,
25818
- then the query is true.
25862
+ if $T_1$ is \code{$S$?} for some $S$ then the query is true.
25819
25863
\item
25820
25864
Otherwise, the query is false.
25821
25865
\end{itemize}
@@ -25833,7 +25877,7 @@ \section*{Appendix: Algorithmic Subtyping}
25833
25877
if $T_0$ is a type variable $X_0$
25834
25878
or a promoted type variables \code{$X_0$\,\&\,$S_0$} and $T_1$ is $X_0$
25835
25879
then \SubtypeNE{T_0}{T_1}.
25836
-
25880
+
25837
25881
\commentary{
25838
25882
Note that this rule is admissible, and can be safely elided if desired.%
25839
25883
}
@@ -25858,7 +25902,7 @@ \section*{Appendix: Algorithmic Subtyping}
25858
25902
\begin{itemize}
25859
25903
\item either \SubtypeNE{T_0}{\code{Future<$S_1$>}}.
25860
25904
\item or \SubtypeNE{T_0}{S_1}.
25861
- \item or $T_0$ is $X_0$ and $X_0$ has bound $S_0 $ and \SubtypeNE{S_0 }{T_1}.
25905
+ \item or $T_0$ is $X_0$ and $X_0$ has bound $B_0 $ and \SubtypeNE{B_0 }{T_1}.
25862
25906
\item or $T_0$ is \code{$X_0$\,\&\,$S_0$} and \SubtypeNE{S_0}{T_1}.
25863
25907
\end{itemize}
25864
25908
\item
@@ -25868,7 +25912,7 @@ \section*{Appendix: Algorithmic Subtyping}
25868
25912
\begin{itemize}
25869
25913
\item either \SubtypeNE{T_0}{S_1}.
25870
25914
\item or \SubtypeNE{T_0}{\code{Null}}.
25871
- \item or $T_0$ is $X_0$ and $X_0$ has bound $S_0 $ and \SubtypeNE{S_0 }{T_1}.
25915
+ \item or $T_0$ is $X_0$ and $X_0$ has bound $B_0 $ and \SubtypeNE{B_0 }{T_1}.
25872
25916
\item or $T_0$ is \code{$X_0$\,\&\,$S_0$} and \SubtypeNE{S_0}{T_1}.
25873
25917
\end{itemize}
25874
25918
\item
@@ -25906,7 +25950,10 @@ \section*{Appendix: Algorithmic Subtyping}
25906
25950
$S_0$\,$y_0$, \ldots, $S_p$\,$y_p$, %
25907
25951
[$S_{p+1}$\,$y_{p+1}$, \ldots, $S_q$\,$y_q$])}
25908
25952
25909
- where each of the following hold:
25953
+ such that each of the following criteria is satisfied,
25954
+ where the $Z_i$ are fresh type variables with bounds
25955
+ $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$:
25956
+
25910
25957
\begin{itemize}
25911
25958
\item $p \geq n$.
25912
25959
\item $m \geq q$.
@@ -25915,8 +25962,6 @@ \section*{Appendix: Algorithmic Subtyping}
25915
25962
\item \SubtypeNE{U_0[Z_0/X_0, \ldots, Z_k/X_k]}{U_1[Z_0/Y_0, \ldots, Z_k/Y_k]}.
25916
25963
\item $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$ and $B_{1i}[Z_0/Y_0, \ldots, Z_k/Y_k]$
25917
25964
have the same canonical syntax, for $i \in 0 .. k$.
25918
- \item where the $Z_i$ are fresh type variables with bounds
25919
- $B_{0i}[Z_0/X_0, \ldots, Z_k/X_k]$.
25920
25965
\end{itemize}
25921
25966
\item
25922
25967
\textbf{Named Function Types:}
@@ -25926,7 +25971,7 @@ \section*{Appendix: Algorithmic Subtyping}
25926
25971
$U_0$ \FUNCTION<$X_0$\,\EXTENDS\,$B_{00}$, \ldots, %
25927
25972
$X_k$\,\EXTENDS\,$B_{0k}$>(%
25928
25973
$V_0$\,$x_0$, \ldots, $V_n$\,$x_n$, %
25929
- \{ $r_{0,n+1}$\,$V_{n+1}$\,$x_{n+1}$, \ldots, $r_{0m}$\,$V_m$\,$x_m$\})}
25974
+ \{$r_{0,n+1}$\,$V_{n+1}$\,$x_{n+1}$, \ldots, $r_{0m}$\,$V_m$\,$x_m$\})}
25930
25975
25931
25976
where $r_{0j}$ is empty or \REQUIRED{} for $j \in n+1 .. m$
25932
25977
and $T_1$ is
@@ -25935,7 +25980,7 @@ \section*{Appendix: Algorithmic Subtyping}
25935
25980
$U_1$ \FUNCTION<$Y_0$\,\EXTENDS\,$B_{10}$, \ldots, %
25936
25981
$Y_k$\,\EXTENDS\,$B_{1k}$>(%
25937
25982
$S_0$\,$y_0$, \ldots, $S_n$\,$y_n$, %
25938
- \{ $r_{1,n+1}$\,$S_{n+1}$\,$y_{n+1}$, \ldots, $r_{1q}$\,$S_q$\,$y_q$\})}
25983
+ \{$r_{1,n+1}$\,$S_{n+1}$\,$y_{n+1}$, \ldots, $r_{1q}$\,$S_q$\,$y_q$\})}
25939
25984
25940
25985
where $r_{1j}$ is empty or \REQUIRED{} for $j \in n+1 .. q$
25941
25986
and the following criteria are all satisfied,
0 commit comments