@@ -22342,7 +22342,8 @@ \subsubsection{Subtype Rules}
22342
22342
22343
22343
\LMHash{}%
22344
22344
In section~\ref{subtypes} and its subsections,
22345
- all types are considered to be denoted by their canonical syntax
22345
+ all designations of types are considered to be the same
22346
+ if{}f they have the same canonical syntax
22346
22347
(\ref{theCanonicalSyntaxOfTypes}).
22347
22348
22348
22349
\commentary{%
@@ -23179,7 +23180,12 @@ \subsubsection{The Canonical Syntax of Types}
23179
23180
and $L_2$ could declare a function
23180
23181
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23181
23182
which uses the type \code{C}-in-$L_2$,
23182
- and $L$ could contain the expression \code{foo(v)}.%
23183
+ and $L$ could contain the expression \code{foo(v)}.
23184
+
23185
+ Note that even though it would be a compile-time error to use \code{C} in $L$
23186
+ (because it is ambiguous),
23187
+ it is not an error to have an expression like \code{foo(v)},
23188
+ and the static analysis of this expression must handle the name clash.%
23183
23189
}
23184
23190
23185
23191
\rationale{%
@@ -23202,16 +23208,28 @@ \subsubsection{The Canonical Syntax of Types}
23202
23208
}
23203
23209
23204
23210
\LMHash{}%
23205
- To determine the
23211
+ The
23206
23212
\IndexCustom{canonical syntax}{type!canonical syntax of}
23207
23213
of the types in a given library $L_1$
23208
23214
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23209
- one or more import links,
23210
- first choose a set of distinct, globally fresh identifiers
23215
+ one or more import links
23216
+ is determined as follows.
23217
+ First, choose a set of distinct, globally fresh identifiers
23211
23218
\List{\metavar{prefix}}{1}{n}.
23212
23219
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23213
23220
23214
23221
\begin{enumerate}
23222
+ \item
23223
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23224
+ whose name $n$ is private,
23225
+ and an occurrence of $n$ that resolves to $D$
23226
+ exists in a type alias declaration $D_A$ whose name is non-private,
23227
+ then perform a consistent renaming of
23228
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23229
+ to a fresh, non-private identifier.
23230
+ \commentary{%
23231
+ So we make $D_T$ public, because it is being leaked anyway.%
23232
+ }
23215
23233
\item
23216
23234
Add a set of import directives to $L_i$ that imports
23217
23235
each of the libraries \List{L}{1}{n} with
@@ -23224,18 +23242,20 @@ \subsubsection{The Canonical Syntax of Types}
23224
23242
even itself and system libraries like \code{dart:core}.%
23225
23243
}
23226
23244
\item
23227
- Let \id{} be a non-private identifier that resolves to
23228
- a library declaration in the library $L_j$ in the original program;
23229
- \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23230
- Let \code{$p$.\id} be a qualified identifier where $p$ is
23231
- an import prefix in the original program,
23232
- \id{} is a non-private identifier,
23233
- and \code{$p$.\id} resolves to
23234
- a library declaration in the library $L_j$ in the original program;
23235
- \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23236
- \item
23237
- %% TODO(eernst): We should rename private names to fresh public names.
23238
- Replace every type that denotes a type alias
23245
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
23246
+ that resolves to a library declaration in the library $L_j$
23247
+ in the original program;
23248
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23249
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23250
+ an import prefix in the original program
23251
+ and \id{} is a non-private identifier,
23252
+ and consider the case where \code{$p$.\id} resolves to
23253
+ a library declaration in the library $L_j$ in the original program,
23254
+ for some $j$;
23255
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23256
+ \item
23257
+ Replace every type in $L_i$ that denotes a type alias
23258
+ along with its actual type arguments, if any,
23239
23259
by its transitive alias expansion
23240
23260
(\ref{typedef}).
23241
23261
\commentary{%
@@ -23247,15 +23267,32 @@ \subsubsection{The Canonical Syntax of Types}
23247
23267
\end{enumerate}
23248
23268
23249
23269
\commentary{%
23250
- Note that this transformation does not change any occurrence of \VOID;
23251
- \VOID{} is a reserved word, not an identifier.
23270
+ This transformation does not change any occurrence of \VOID;
23271
+ \VOID{} is a reserved word, not a type identifier.
23252
23272
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23253
23273
23274
+ Note that the transformation changes terms derived from \synt{type},
23275
+ but it does not change expressions, or any other program element
23276
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23277
+ In particular, it does not change type literals
23278
+ (that is, expressions denoting types).
23279
+
23254
23280
The transformation also does not change identifiers denoting type variables,
23281
+ because they are never resolved to a library declaration,
23282
+ they are always introduced by a scope which is nested inside the library scope.
23255
23283
There is no need to change those identifiers, because
23256
- no occurrence of such an identifier resolves to a declaration in a
23257
- different library.%
23258
- %% TODO(eernst): Sort out the treatment of private identifiers, too.
23284
+ no occurrence of such an identifier in the type of an expression
23285
+ denotes a declaration in a different library.%
23286
+ }
23287
+
23288
+ \rationale{%
23289
+ The only purpose of this transformation is to obtain a
23290
+ location-independent designation of all types,
23291
+ in such a way that each \synt{typeName} resolves to the same declaration
23292
+ before and after the transformation.
23293
+ The program behavior may change due to different values returned from
23294
+ \code{toString()} on reified types,
23295
+ but the transformation is otherwise semantics preserving.%
23259
23296
}
23260
23297
23261
23298
\LMHash{}%
@@ -23292,15 +23329,21 @@ \subsubsection{The Canonical Syntax of Types}
23292
23329
because we would need to re-build all the structures that the
23293
23330
syntax offers.
23294
23331
For instance, we would need to support the construction of
23295
- a semantic type entity for \code{Map<int, String>},
23296
- based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23332
+ a semantic type entity for \code{Map<int,\,String>},
23333
+ based on the semantic type entities for
23334
+ \code{int}, \code{String}, and \code{Map},
23297
23335
and we would need to support deconstruction of those entities
23298
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23336
+ in order to prove things like
23337
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
23299
23338
This would give rise to a lot of mechanism that will simply duplicate
23300
23339
the structure of the syntax.
23301
23340
So we prefer to show that the syntax \emph{can} be location independent,
23302
23341
and that's sufficient to make syntax usable as our representation of
23303
- static semantic types.%
23342
+ static semantic types.
23343
+
23344
+ We are basically taking the approach that a static semantic type is
23345
+ an equivalence class of all syntactic elements derived from \synt{type}
23346
+ that have the same canonical syntax.%
23304
23347
}
23305
23348
23306
23349
@@ -23391,6 +23434,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23391
23434
Finally, it is assumed that all types are denoted by their canonical syntax
23392
23435
(\ref{theCanonicalSyntaxOfTypes}).
23393
23436
23437
+ \commentary{%
23438
+ This implies that type aliases have already been fully expanded,
23439
+ and two types are the same if and only if they have the same syntax.%
23440
+ }
23441
+
23394
23442
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23395
23443
\LMHash{}%
23396
23444
We define the
0 commit comments