@@ -22215,7 +22215,8 @@ \subsubsection{Subtype Rules}
22215
22215
22216
22216
\LMHash{}%
22217
22217
In section~\ref{subtypes} and its subsections,
22218
- all types are considered to be denoted by their canonical syntax
22218
+ all designations of types are considered to be the same
22219
+ if{}f they have the same canonical syntax
22219
22220
(\ref{theCanonicalSyntaxOfTypes}).
22220
22221
22221
22222
\commentary{%
@@ -23052,7 +23053,12 @@ \subsubsection{The Canonical Syntax of Types}
23052
23053
and $L_2$ could declare a function
23053
23054
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23054
23055
which uses the type \code{C}-in-$L_2$,
23055
- and $L$ could contain the expression \code{foo(v)}.%
23056
+ and $L$ could contain the expression \code{foo(v)}.
23057
+
23058
+ Note that even though it would be a compile-time error to use \code{C} in $L$
23059
+ (because it is ambiguous),
23060
+ it is not an error to have an expression like \code{foo(v)},
23061
+ and the static analysis of this expression must handle the name clash.%
23056
23062
}
23057
23063
23058
23064
\rationale{%
@@ -23075,16 +23081,28 @@ \subsubsection{The Canonical Syntax of Types}
23075
23081
}
23076
23082
23077
23083
\LMHash{}%
23078
- To determine the
23084
+ The
23079
23085
\IndexCustom{canonical syntax}{type!canonical syntax of}
23080
23086
of the types in a given library $L_1$
23081
23087
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23082
- one or more import links,
23083
- first choose a set of distinct, globally fresh identifiers
23088
+ one or more import links
23089
+ is determined as follows.
23090
+ First, choose a set of distinct, globally fresh identifiers
23084
23091
\List{\metavar{prefix}}{1}{n}.
23085
23092
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23086
23093
23087
23094
\begin{enumerate}
23095
+ \item
23096
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23097
+ whose name $n$ is private,
23098
+ and an occurrence of $n$ that resolves to $D$
23099
+ exists in a type alias declaration $D_A$ whose name is non-private,
23100
+ then perform a consistent renaming of
23101
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23102
+ to a fresh, non-private identifier.
23103
+ \commentary{%
23104
+ So we make $D_T$ public, because it is being leaked anyway.%
23105
+ }
23088
23106
\item
23089
23107
Add a set of import directives to $L_i$ that imports
23090
23108
each of the libraries \List{L}{1}{n} with
@@ -23097,18 +23115,20 @@ \subsubsection{The Canonical Syntax of Types}
23097
23115
even itself and system libraries like \code{dart:core}.%
23098
23116
}
23099
23117
\item
23100
- Let \id{} be a non-private identifier that resolves to
23101
- a library declaration in the library $L_j$ in the original program;
23102
- \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23103
- Let \code{$p$.\id} be a qualified identifier where $p$ is
23104
- an import prefix in the original program,
23105
- \id{} is a non-private identifier,
23106
- and \code{$p$.\id} resolves to
23107
- a library declaration in the library $L_j$ in the original program;
23108
- \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23109
- \item
23110
- %% TODO(eernst): We should rename private names to fresh public names.
23111
- Replace every type that denotes a type alias
23118
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
23119
+ that resolves to a library declaration in the library $L_j$
23120
+ in the original program;
23121
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23122
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23123
+ an import prefix in the original program
23124
+ and \id{} is a non-private identifier,
23125
+ and consider the case where \code{$p$.\id} resolves to
23126
+ a library declaration in the library $L_j$ in the original program,
23127
+ for some $j$;
23128
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23129
+ \item
23130
+ Replace every type in $L_i$ that denotes a type alias
23131
+ along with its actual type arguments, if any,
23112
23132
by its transitive alias expansion
23113
23133
(\ref{typedef}).
23114
23134
\commentary{%
@@ -23120,15 +23140,32 @@ \subsubsection{The Canonical Syntax of Types}
23120
23140
\end{enumerate}
23121
23141
23122
23142
\commentary{%
23123
- Note that this transformation does not change any occurrence of \VOID;
23124
- \VOID{} is a reserved word, not an identifier.
23143
+ This transformation does not change any occurrence of \VOID;
23144
+ \VOID{} is a reserved word, not a type identifier.
23125
23145
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23126
23146
23147
+ Note that the transformation changes terms derived from \synt{type},
23148
+ but it does not change expressions, or any other program element
23149
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23150
+ In particular, it does not change type literals
23151
+ (that is, expressions denoting types).
23152
+
23127
23153
The transformation also does not change identifiers denoting type variables,
23154
+ because they are never resolved to a library declaration,
23155
+ they are always introduced by a scope which is nested inside the library scope.
23128
23156
There is no need to change those identifiers, because
23129
- no occurrence of such an identifier resolves to a declaration in a
23130
- different library.%
23131
- %% TODO(eernst): Sort out the treatment of private identifiers, too.
23157
+ no occurrence of such an identifier in the type of an expression
23158
+ denotes a declaration in a different library.%
23159
+ }
23160
+
23161
+ \rationale{%
23162
+ The only purpose of this transformation is to obtain a
23163
+ location-independent designation of all types,
23164
+ in such a way that each \synt{typeName} resolves to the same declaration
23165
+ before and after the transformation.
23166
+ The program behavior may change due to different values returned from
23167
+ \code{toString()} on reified types,
23168
+ but the transformation is otherwise semantics preserving.%
23132
23169
}
23133
23170
23134
23171
\LMHash{}%
@@ -23165,15 +23202,21 @@ \subsubsection{The Canonical Syntax of Types}
23165
23202
because we would need to re-build all the structures that the
23166
23203
syntax offers.
23167
23204
For instance, we would need to support the construction of
23168
- a semantic type entity for \code{Map<int, String>},
23169
- based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23205
+ a semantic type entity for \code{Map<int,\,String>},
23206
+ based on the semantic type entities for
23207
+ \code{int}, \code{String}, and \code{Map},
23170
23208
and we would need to support deconstruction of those entities
23171
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23209
+ in order to prove things like
23210
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
23172
23211
This would give rise to a lot of mechanism that will simply duplicate
23173
23212
the structure of the syntax.
23174
23213
So we prefer to show that the syntax \emph{can} be location independent,
23175
23214
and that's sufficient to make syntax usable as our representation of
23176
- static semantic types.%
23215
+ static semantic types.
23216
+
23217
+ We are basically taking the approach that a static semantic type is
23218
+ an equivalence class of all syntactic elements derived from \synt{type}
23219
+ that have the same canonical syntax.%
23177
23220
}
23178
23221
23179
23222
@@ -23264,6 +23307,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23264
23307
Finally, it is assumed that all types are denoted by their canonical syntax
23265
23308
(\ref{theCanonicalSyntaxOfTypes}).
23266
23309
23310
+ \commentary{%
23311
+ This implies that type aliases have already been fully expanded,
23312
+ and two types are the same if and only if they have the same syntax.%
23313
+ }
23314
+
23267
23315
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23268
23316
\LMHash{}%
23269
23317
We define the
0 commit comments