@@ -22276,7 +22276,8 @@ \subsubsection{Subtype Rules}
22276
22276
22277
22277
\LMHash{}%
22278
22278
In section~\ref{subtypes} and its subsections,
22279
- all types are considered to be denoted by their canonical syntax
22279
+ all designations of types are considered to be the same
22280
+ if{}f they have the same canonical syntax
22280
22281
(\ref{theCanonicalSyntaxOfTypes}).
22281
22282
22282
22283
\commentary{%
@@ -23113,7 +23114,12 @@ \subsubsection{The Canonical Syntax of Types}
23113
23114
and $L_2$ could declare a function
23114
23115
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23115
23116
which uses the type \code{C}-in-$L_2$,
23116
- and $L$ could contain the expression \code{foo(v)}.%
23117
+ and $L$ could contain the expression \code{foo(v)}.
23118
+
23119
+ Note that even though it would be a compile-time error to use \code{C} in $L$
23120
+ (because it is ambiguous),
23121
+ it is not an error to have an expression like \code{foo(v)},
23122
+ and the static analysis of this expression must handle the name clash.%
23117
23123
}
23118
23124
23119
23125
\rationale{%
@@ -23136,16 +23142,28 @@ \subsubsection{The Canonical Syntax of Types}
23136
23142
}
23137
23143
23138
23144
\LMHash{}%
23139
- To determine the
23145
+ The
23140
23146
\IndexCustom{canonical syntax}{type!canonical syntax of}
23141
23147
of the types in a given library $L_1$
23142
23148
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23143
- one or more import links,
23144
- first choose a set of distinct, globally fresh identifiers
23149
+ one or more import links
23150
+ is determined as follows.
23151
+ First, choose a set of distinct, globally fresh identifiers
23145
23152
\List{\metavar{prefix}}{1}{n}.
23146
23153
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23147
23154
23148
23155
\begin{enumerate}
23156
+ \item
23157
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23158
+ whose name $n$ is private,
23159
+ and an occurrence of $n$ that resolves to $D$
23160
+ exists in a type alias declaration $D_A$ whose name is non-private,
23161
+ then perform a consistent renaming of
23162
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23163
+ to a fresh, non-private identifier.
23164
+ \commentary{%
23165
+ So we make $D_T$ public, because it is being leaked anyway.%
23166
+ }
23149
23167
\item
23150
23168
Add a set of import directives to $L_i$ that imports
23151
23169
each of the libraries \List{L}{1}{n} with
@@ -23158,18 +23176,20 @@ \subsubsection{The Canonical Syntax of Types}
23158
23176
even itself and system libraries like \code{dart:core}.%
23159
23177
}
23160
23178
\item
23161
- Let \id{} be a non-private identifier that resolves to
23162
- a library declaration in the library $L_j$ in the original program;
23163
- \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23164
- Let \code{$p$.\id} be a qualified identifier where $p$ is
23165
- an import prefix in the original program,
23166
- \id{} is a non-private identifier,
23167
- and \code{$p$.\id} resolves to
23168
- a library declaration in the library $L_j$ in the original program;
23169
- \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23170
- \item
23171
- %% TODO(eernst): We should rename private names to fresh public names.
23172
- Replace every type that denotes a type alias
23179
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
23180
+ that resolves to a library declaration in the library $L_j$
23181
+ in the original program;
23182
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23183
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23184
+ an import prefix in the original program
23185
+ and \id{} is a non-private identifier,
23186
+ and consider the case where \code{$p$.\id} resolves to
23187
+ a library declaration in the library $L_j$ in the original program,
23188
+ for some $j$;
23189
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23190
+ \item
23191
+ Replace every type in $L_i$ that denotes a type alias
23192
+ along with its actual type arguments, if any,
23173
23193
by its transitive alias expansion
23174
23194
(\ref{typedef}).
23175
23195
\commentary{%
@@ -23181,15 +23201,32 @@ \subsubsection{The Canonical Syntax of Types}
23181
23201
\end{enumerate}
23182
23202
23183
23203
\commentary{%
23184
- Note that this transformation does not change any occurrence of \VOID;
23185
- \VOID{} is a reserved word, not an identifier.
23204
+ This transformation does not change any occurrence of \VOID;
23205
+ \VOID{} is a reserved word, not a type identifier.
23186
23206
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23187
23207
23208
+ Note that the transformation changes terms derived from \synt{type},
23209
+ but it does not change expressions, or any other program element
23210
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23211
+ In particular, it does not change type literals
23212
+ (that is, expressions denoting types).
23213
+
23188
23214
The transformation also does not change identifiers denoting type variables,
23215
+ because they are never resolved to a library declaration,
23216
+ they are always introduced by a scope which is nested inside the library scope.
23189
23217
There is no need to change those identifiers, because
23190
- no occurrence of such an identifier resolves to a declaration in a
23191
- different library.%
23192
- %% TODO(eernst): Sort out the treatment of private identifiers, too.
23218
+ no occurrence of such an identifier in the type of an expression
23219
+ denotes a declaration in a different library.%
23220
+ }
23221
+
23222
+ \rationale{%
23223
+ The only purpose of this transformation is to obtain a
23224
+ location-independent designation of all types,
23225
+ in such a way that each \synt{typeName} resolves to the same declaration
23226
+ before and after the transformation.
23227
+ The program behavior may change due to different values returned from
23228
+ \code{toString()} on reified types,
23229
+ but the transformation is otherwise semantics preserving.%
23193
23230
}
23194
23231
23195
23232
\LMHash{}%
@@ -23226,15 +23263,21 @@ \subsubsection{The Canonical Syntax of Types}
23226
23263
because we would need to re-build all the structures that the
23227
23264
syntax offers.
23228
23265
For instance, we would need to support the construction of
23229
- a semantic type entity for \code{Map<int, String>},
23230
- based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23266
+ a semantic type entity for \code{Map<int,\,String>},
23267
+ based on the semantic type entities for
23268
+ \code{int}, \code{String}, and \code{Map},
23231
23269
and we would need to support deconstruction of those entities
23232
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23270
+ in order to prove things like
23271
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
23233
23272
This would give rise to a lot of mechanism that will simply duplicate
23234
23273
the structure of the syntax.
23235
23274
So we prefer to show that the syntax \emph{can} be location independent,
23236
23275
and that's sufficient to make syntax usable as our representation of
23237
- static semantic types.%
23276
+ static semantic types.
23277
+
23278
+ We are basically taking the approach that a static semantic type is
23279
+ an equivalence class of all syntactic elements derived from \synt{type}
23280
+ that have the same canonical syntax.%
23238
23281
}
23239
23282
23240
23283
@@ -23325,6 +23368,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23325
23368
Finally, it is assumed that all types are denoted by their canonical syntax
23326
23369
(\ref{theCanonicalSyntaxOfTypes}).
23327
23370
23371
+ \commentary{%
23372
+ This implies that type aliases have already been fully expanded,
23373
+ and two types are the same if and only if they have the same syntax.%
23374
+ }
23375
+
23328
23376
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23329
23377
\LMHash{}%
23330
23378
We define the
0 commit comments