@@ -22124,7 +22124,8 @@ \subsubsection{Subtype Rules}
22124
22124
22125
22125
\LMHash{}%
22126
22126
In section~\ref{subtypes} and its subsections,
22127
- all types are considered to be denoted by their canonical syntax
22127
+ all designations of types are considered to be the same
22128
+ if{}f they have the same canonical syntax
22128
22129
(\ref{theCanonicalSyntaxOfTypes}).
22129
22130
22130
22131
\commentary{%
@@ -22961,7 +22962,12 @@ \subsubsection{The Canonical Syntax of Types}
22961
22962
and $L_2$ could declare a function
22962
22963
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
22963
22964
which uses the type \code{C}-in-$L_2$,
22964
- and $L$ could contain the expression \code{foo(v)}.%
22965
+ and $L$ could contain the expression \code{foo(v)}.
22966
+
22967
+ Note that even though it would be a compile-time error to use \code{C} in $L$
22968
+ (because it is ambiguous),
22969
+ it is not an error to have an expression like \code{foo(v)},
22970
+ and the static analysis of this expression must handle the name clash.%
22965
22971
}
22966
22972
22967
22973
\rationale{%
@@ -22984,16 +22990,28 @@ \subsubsection{The Canonical Syntax of Types}
22984
22990
}
22985
22991
22986
22992
\LMHash{}%
22987
- To determine the
22993
+ The
22988
22994
\IndexCustom{canonical syntax}{type!canonical syntax of}
22989
22995
of the types in a given library $L_1$
22990
22996
and all libraries \List{L}{2}{n} reachable from $L_1$ via
22991
- one or more import links,
22992
- first choose a set of distinct, globally fresh identifiers
22997
+ one or more import links
22998
+ is determined as follows.
22999
+ First, choose a set of distinct, globally fresh identifiers
22993
23000
\List{\metavar{prefix}}{1}{n}.
22994
23001
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
22995
23002
22996
23003
\begin{enumerate}
23004
+ \item
23005
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23006
+ whose name $n$ is private,
23007
+ and an occurrence of $n$ that resolves to $D$
23008
+ exists in a type alias declaration $D_A$ whose name is non-private,
23009
+ then perform a consistent renaming of
23010
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23011
+ to a fresh, non-private identifier.
23012
+ \commentary{%
23013
+ So we make $D_T$ public, because it is being leaked anyway.%
23014
+ }
22997
23015
\item
22998
23016
Add a set of import directives to $L_i$ that imports
22999
23017
each of the libraries \List{L}{1}{n} with
@@ -23006,18 +23024,20 @@ \subsubsection{The Canonical Syntax of Types}
23006
23024
even itself and system libraries like \code{dart:core}.%
23007
23025
}
23008
23026
\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
23027
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
23028
+ that resolves to a library declaration in the library $L_j$
23029
+ in the original program;
23030
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23031
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23032
+ an import prefix in the original program
23033
+ and \id{} is a non-private identifier,
23034
+ and consider the case where \code{$p$.\id} resolves to
23035
+ a library declaration in the library $L_j$ in the original program,
23036
+ for some $j$;
23037
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23038
+ \item
23039
+ Replace every type in $L_i$ that denotes a type alias
23040
+ along with its actual type arguments, if any,
23021
23041
by its transitive alias expansion
23022
23042
(\ref{typedef}).
23023
23043
\commentary{%
@@ -23029,15 +23049,32 @@ \subsubsection{The Canonical Syntax of Types}
23029
23049
\end{enumerate}
23030
23050
23031
23051
\commentary{%
23032
- Note that this transformation does not change any occurrence of \VOID;
23033
- \VOID{} is a reserved word, not an identifier.
23052
+ This transformation does not change any occurrence of \VOID;
23053
+ \VOID{} is a reserved word, not a type identifier.
23034
23054
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23035
23055
23056
+ Note that the transformation changes terms derived from \synt{type},
23057
+ but it does not change expressions, or any other program element
23058
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23059
+ In particular, it does not change type literals
23060
+ (that is, expressions denoting types).
23061
+
23036
23062
The transformation also does not change identifiers denoting type variables,
23063
+ because they are never resolved to a library declaration,
23064
+ they are always introduced by a scope which is nested inside the library scope.
23037
23065
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.
23066
+ no occurrence of such an identifier in the type of an expression
23067
+ denotes a declaration in a different library.%
23068
+ }
23069
+
23070
+ \rationale{%
23071
+ The only purpose of this transformation is to obtain a
23072
+ location-independent designation of all types,
23073
+ in such a way that each \synt{typeName} resolves to the same declaration
23074
+ before and after the transformation.
23075
+ The program behavior may change due to different values returned from
23076
+ \code{toString()} on reified types,
23077
+ but the transformation is otherwise semantics preserving.%
23041
23078
}
23042
23079
23043
23080
\LMHash{}%
@@ -23074,15 +23111,21 @@ \subsubsection{The Canonical Syntax of Types}
23074
23111
because we would need to re-build all the structures that the
23075
23112
syntax offers.
23076
23113
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},
23114
+ a semantic type entity for \code{Map<int,\,String>},
23115
+ based on the semantic type entities for
23116
+ \code{int}, \code{String}, and \code{Map},
23079
23117
and we would need to support deconstruction of those entities
23080
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23118
+ in order to prove things like
23119
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
23081
23120
This would give rise to a lot of mechanism that will simply duplicate
23082
23121
the structure of the syntax.
23083
23122
So we prefer to show that the syntax \emph{can} be location independent,
23084
23123
and that's sufficient to make syntax usable as our representation of
23085
- static semantic types.%
23124
+ static semantic types.
23125
+
23126
+ We are basically taking the approach that a static semantic type is
23127
+ an equivalence class of all syntactic elements derived from \synt{type}
23128
+ that have the same canonical syntax.%
23086
23129
}
23087
23130
23088
23131
@@ -23173,6 +23216,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23173
23216
Finally, it is assumed that all types are denoted by their canonical syntax
23174
23217
(\ref{theCanonicalSyntaxOfTypes}).
23175
23218
23219
+ \commentary{%
23220
+ This implies that type aliases have already been fully expanded,
23221
+ and two types are the same if and only if they have the same syntax.%
23222
+ }
23223
+
23176
23224
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23177
23225
\LMHash{}%
23178
23226
We define the
0 commit comments