@@ -22663,7 +22663,8 @@ \subsubsection{Subtype Rules}
22663
22663
22664
22664
\LMHash{}%
22665
22665
In section~\ref{subtypes} and its subsections,
22666
- all types are considered to be denoted by their canonical syntax
22666
+ all designations of types are considered to be the same
22667
+ if{}f they have the same canonical syntax
22667
22668
(\ref{theCanonicalSyntaxOfTypes}).
22668
22669
22669
22670
\commentary{%
@@ -23500,7 +23501,12 @@ \subsubsection{The Canonical Syntax of Types}
23500
23501
and $L_2$ could declare a function
23501
23502
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23502
23503
which uses the type \code{C}-in-$L_2$,
23503
- and $L$ could contain the expression \code{foo(v)}.%
23504
+ and $L$ could contain the expression \code{foo(v)}.
23505
+
23506
+ Note that even though it would be a compile-time error to use \code{C} in $L$
23507
+ (because it is ambiguous),
23508
+ it is not an error to have an expression like \code{foo(v)},
23509
+ and the static analysis of this expression must handle the name clash.%
23504
23510
}
23505
23511
23506
23512
\rationale{%
@@ -23523,16 +23529,28 @@ \subsubsection{The Canonical Syntax of Types}
23523
23529
}
23524
23530
23525
23531
\LMHash{}%
23526
- To determine the
23532
+ The
23527
23533
\IndexCustom{canonical syntax}{type!canonical syntax of}
23528
23534
of the types in a given library $L_1$
23529
23535
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23530
- one or more import links,
23531
- first choose a set of distinct, globally fresh identifiers
23536
+ one or more import links
23537
+ is determined as follows.
23538
+ First, choose a set of distinct, globally fresh identifiers
23532
23539
\List{\metavar{prefix}}{1}{n}.
23533
23540
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23534
23541
23535
23542
\begin{enumerate}
23543
+ \item
23544
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23545
+ whose name $n$ is private,
23546
+ and an occurrence of $n$ that resolves to $D$
23547
+ exists in a type alias declaration $D_A$ whose name is non-private,
23548
+ then perform a consistent renaming of
23549
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23550
+ to a fresh, non-private identifier.
23551
+ \commentary{%
23552
+ So we make $D_T$ public, because it is being leaked anyway.%
23553
+ }
23536
23554
\item
23537
23555
Add a set of import directives to $L_i$ that imports
23538
23556
each of the libraries \List{L}{1}{n} with
@@ -23545,18 +23563,20 @@ \subsubsection{The Canonical Syntax of Types}
23545
23563
even itself and system libraries like \code{dart:core}.%
23546
23564
}
23547
23565
\item
23548
- Let \id{} be a non-private identifier that resolves to
23549
- a library declaration in the library $L_j$ in the original program;
23550
- \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23551
- Let \code{$p$.\id} be a qualified identifier where $p$ is
23552
- an import prefix in the original program,
23553
- \id{} is a non-private identifier,
23554
- and \code{$p$.\id} resolves to
23555
- a library declaration in the library $L_j$ in the original program;
23556
- \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23557
- \item
23558
- %% TODO(eernst): We should rename private names to fresh public names.
23559
- Replace every type that denotes a type alias
23566
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
23567
+ that resolves to a library declaration in the library $L_j$
23568
+ in the original program;
23569
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23570
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23571
+ an import prefix in the original program
23572
+ and \id{} is a non-private identifier,
23573
+ and consider the case where \code{$p$.\id} resolves to
23574
+ a library declaration in the library $L_j$ in the original program,
23575
+ for some $j$;
23576
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23577
+ \item
23578
+ Replace every type in $L_i$ that denotes a type alias
23579
+ along with its actual type arguments, if any,
23560
23580
by its transitive alias expansion
23561
23581
(\ref{typedef}).
23562
23582
\commentary{%
@@ -23568,15 +23588,32 @@ \subsubsection{The Canonical Syntax of Types}
23568
23588
\end{enumerate}
23569
23589
23570
23590
\commentary{%
23571
- Note that this transformation does not change any occurrence of \VOID;
23572
- \VOID{} is a reserved word, not an identifier.
23591
+ This transformation does not change any occurrence of \VOID;
23592
+ \VOID{} is a reserved word, not a type identifier.
23573
23593
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23574
23594
23595
+ Note that the transformation changes terms derived from \synt{type},
23596
+ but it does not change expressions, or any other program element
23597
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23598
+ In particular, it does not change type literals
23599
+ (that is, expressions denoting types).
23600
+
23575
23601
The transformation also does not change identifiers denoting type variables,
23602
+ because they are never resolved to a library declaration,
23603
+ they are always introduced by a scope which is nested inside the library scope.
23576
23604
There is no need to change those identifiers, because
23577
- no occurrence of such an identifier resolves to a declaration in a
23578
- different library.%
23579
- %% TODO(eernst): Sort out the treatment of private identifiers, too.
23605
+ no occurrence of such an identifier in the type of an expression
23606
+ denotes a declaration in a different library.%
23607
+ }
23608
+
23609
+ \rationale{%
23610
+ The only purpose of this transformation is to obtain a
23611
+ location-independent designation of all types,
23612
+ in such a way that each \synt{typeName} resolves to the same declaration
23613
+ before and after the transformation.
23614
+ The program behavior may change due to different values returned from
23615
+ \code{toString()} on reified types,
23616
+ but the transformation is otherwise semantics preserving.%
23580
23617
}
23581
23618
23582
23619
\LMHash{}%
@@ -23613,15 +23650,21 @@ \subsubsection{The Canonical Syntax of Types}
23613
23650
because we would need to re-build all the structures that the
23614
23651
syntax offers.
23615
23652
For instance, we would need to support the construction of
23616
- a semantic type entity for \code{Map<int, String>},
23617
- based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23653
+ a semantic type entity for \code{Map<int,\,String>},
23654
+ based on the semantic type entities for
23655
+ \code{int}, \code{String}, and \code{Map},
23618
23656
and we would need to support deconstruction of those entities
23619
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23657
+ in order to prove things like
23658
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
23620
23659
This would give rise to a lot of mechanism that will simply duplicate
23621
23660
the structure of the syntax.
23622
23661
So we prefer to show that the syntax \emph{can} be location independent,
23623
23662
and that's sufficient to make syntax usable as our representation of
23624
- static semantic types.%
23663
+ static semantic types.
23664
+
23665
+ We are basically taking the approach that a static semantic type is
23666
+ an equivalence class of all syntactic elements derived from \synt{type}
23667
+ that have the same canonical syntax.%
23625
23668
}
23626
23669
23627
23670
@@ -23712,6 +23755,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23712
23755
Finally, it is assumed that all types are denoted by their canonical syntax
23713
23756
(\ref{theCanonicalSyntaxOfTypes}).
23714
23757
23758
+ \commentary{%
23759
+ This implies that type aliases have already been fully expanded,
23760
+ and two types are the same if and only if they have the same syntax.%
23761
+ }
23762
+
23715
23763
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23716
23764
\LMHash{}%
23717
23765
We define the
0 commit comments