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