@@ -23094,7 +23094,8 @@ \subsubsection{Subtype Rules}
23094
23094
23095
23095
\LMHash{}%
23096
23096
In section~\ref{subtypes} and its subsections,
23097
- all types are considered to be denoted by their canonical syntax
23097
+ all designations of types are considered to be the same
23098
+ if{}f they have the same canonical syntax
23098
23099
(\ref{theCanonicalSyntaxOfTypes}).
23099
23100
23100
23101
\commentary{%
@@ -23933,7 +23934,12 @@ \subsubsection{The Canonical Syntax of Types}
23933
23934
and $L_2$ could declare a function
23934
23935
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23935
23936
which uses the type \code{C}-in-$L_2$,
23936
- and $L$ could contain the expression \code{foo(v)}.%
23937
+ and $L$ could contain the expression \code{foo(v)}.
23938
+
23939
+ Note that even though it would be a compile-time error to use \code{C} in $L$
23940
+ (because it is ambiguous),
23941
+ it is not an error to have an expression like \code{foo(v)},
23942
+ and the static analysis of this expression must handle the name clash.%
23937
23943
}
23938
23944
23939
23945
\rationale{%
@@ -23956,16 +23962,28 @@ \subsubsection{The Canonical Syntax of Types}
23956
23962
}
23957
23963
23958
23964
\LMHash{}%
23959
- To determine the
23965
+ The
23960
23966
\IndexCustom{canonical syntax}{type!canonical syntax of}
23961
23967
of the types in a given library $L_1$
23962
23968
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23963
- one or more import links,
23964
- first choose a set of distinct, globally fresh identifiers
23969
+ one or more import links
23970
+ is determined as follows.
23971
+ First, choose a set of distinct, globally fresh identifiers
23965
23972
\List{\metavar{prefix}}{1}{n}.
23966
23973
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23967
23974
23968
23975
\begin{enumerate}
23976
+ \item
23977
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23978
+ whose name $n$ is private,
23979
+ and an occurrence of $n$ that resolves to $D$
23980
+ exists in a type alias declaration $D_A$ whose name is non-private,
23981
+ then perform a consistent renaming of
23982
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23983
+ to a fresh, non-private identifier.
23984
+ \commentary{%
23985
+ So we make $D_T$ public, because it is being leaked anyway.%
23986
+ }
23969
23987
\item
23970
23988
Add a set of import directives to $L_i$ that imports
23971
23989
each of the libraries \List{L}{1}{n} with
@@ -23978,18 +23996,20 @@ \subsubsection{The Canonical Syntax of Types}
23978
23996
even itself and system libraries like \code{dart:core}.%
23979
23997
}
23980
23998
\item
23981
- Let \id{} be a non-private identifier that resolves to
23982
- a library declaration in the library $L_j$ in the original program;
23983
- \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23984
- Let \code{$p$.\id} be a qualified identifier where $p$ is
23985
- an import prefix in the original program,
23986
- \id{} is a non-private identifier,
23987
- and \code{$p$.\id} resolves to
23988
- a library declaration in the library $L_j$ in the original program;
23989
- \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23990
- \item
23991
- %% TODO(eernst): We should rename private names to fresh public names.
23992
- Replace every type that denotes a type alias
23999
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
24000
+ that resolves to a library declaration in the library $L_j$
24001
+ in the original program;
24002
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
24003
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
24004
+ an import prefix in the original program
24005
+ and \id{} is a non-private identifier,
24006
+ and consider the case where \code{$p$.\id} resolves to
24007
+ a library declaration in the library $L_j$ in the original program,
24008
+ for some $j$;
24009
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
24010
+ \item
24011
+ Replace every type in $L_i$ that denotes a type alias
24012
+ along with its actual type arguments, if any,
23993
24013
by its transitive alias expansion
23994
24014
(\ref{typedef}).
23995
24015
\commentary{%
@@ -24001,15 +24021,32 @@ \subsubsection{The Canonical Syntax of Types}
24001
24021
\end{enumerate}
24002
24022
24003
24023
\commentary{%
24004
- Note that this transformation does not change any occurrence of \VOID;
24005
- \VOID{} is a reserved word, not an identifier.
24024
+ This transformation does not change any occurrence of \VOID;
24025
+ \VOID{} is a reserved word, not a type identifier.
24006
24026
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
24007
24027
24028
+ Note that the transformation changes terms derived from \synt{type},
24029
+ but it does not change expressions, or any other program element
24030
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
24031
+ In particular, it does not change type literals
24032
+ (that is, expressions denoting types).
24033
+
24008
24034
The transformation also does not change identifiers denoting type variables,
24035
+ because they are never resolved to a library declaration,
24036
+ they are always introduced by a scope which is nested inside the library scope.
24009
24037
There is no need to change those identifiers, because
24010
- no occurrence of such an identifier resolves to a declaration in a
24011
- different library.%
24012
- %% TODO(eernst): Sort out the treatment of private identifiers, too.
24038
+ no occurrence of such an identifier in the type of an expression
24039
+ denotes a declaration in a different library.%
24040
+ }
24041
+
24042
+ \rationale{%
24043
+ The only purpose of this transformation is to obtain a
24044
+ location-independent designation of all types,
24045
+ in such a way that each \synt{typeName} resolves to the same declaration
24046
+ before and after the transformation.
24047
+ The program behavior may change due to different values returned from
24048
+ \code{toString()} on reified types,
24049
+ but the transformation is otherwise semantics preserving.%
24013
24050
}
24014
24051
24015
24052
\LMHash{}%
@@ -24046,15 +24083,21 @@ \subsubsection{The Canonical Syntax of Types}
24046
24083
because we would need to re-build all the structures that the
24047
24084
syntax offers.
24048
24085
For instance, we would need to support the construction of
24049
- a semantic type entity for \code{Map<int, String>},
24050
- based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
24086
+ a semantic type entity for \code{Map<int,\,String>},
24087
+ based on the semantic type entities for
24088
+ \code{int}, \code{String}, and \code{Map},
24051
24089
and we would need to support deconstruction of those entities
24052
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
24090
+ in order to prove things like
24091
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
24053
24092
This would give rise to a lot of mechanism that will simply duplicate
24054
24093
the structure of the syntax.
24055
24094
So we prefer to show that the syntax \emph{can} be location independent,
24056
24095
and that's sufficient to make syntax usable as our representation of
24057
- static semantic types.%
24096
+ static semantic types.
24097
+
24098
+ We are basically taking the approach that a static semantic type is
24099
+ an equivalence class of all syntactic elements derived from \synt{type}
24100
+ that have the same canonical syntax.%
24058
24101
}
24059
24102
24060
24103
@@ -24145,6 +24188,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
24145
24188
Finally, it is assumed that all types are denoted by their canonical syntax
24146
24189
(\ref{theCanonicalSyntaxOfTypes}).
24147
24190
24191
+ \commentary{%
24192
+ This implies that type aliases have already been fully expanded,
24193
+ and two types are the same if and only if they have the same syntax.%
24194
+ }
24195
+
24148
24196
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
24149
24197
\LMHash{}%
24150
24198
We define the
0 commit comments