@@ -22643,7 +22643,8 @@ \subsubsection{Subtype Rules}
22643
22643
22644
22644
\LMHash{}%
22645
22645
In section~\ref{subtypes} and its subsections,
22646
- all types are considered to be denoted by their canonical syntax
22646
+ all designations of types are considered to be the same
22647
+ if{}f they have the same canonical syntax
22647
22648
(\ref{theCanonicalSyntaxOfTypes}).
22648
22649
22649
22650
\commentary{%
@@ -23480,7 +23481,12 @@ \subsubsection{The Canonical Syntax of Types}
23480
23481
and $L_2$ could declare a function
23481
23482
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23482
23483
which uses the type \code{C}-in-$L_2$,
23483
- and $L$ could contain the expression \code{foo(v)}.%
23484
+ and $L$ could contain the expression \code{foo(v)}.
23485
+
23486
+ Note that even though it would be a compile-time error to use \code{C} in $L$
23487
+ (because it is ambiguous),
23488
+ it is not an error to have an expression like \code{foo(v)},
23489
+ and the static analysis of this expression must handle the name clash.%
23484
23490
}
23485
23491
23486
23492
\rationale{%
@@ -23503,16 +23509,28 @@ \subsubsection{The Canonical Syntax of Types}
23503
23509
}
23504
23510
23505
23511
\LMHash{}%
23506
- To determine the
23512
+ The
23507
23513
\IndexCustom{canonical syntax}{type!canonical syntax of}
23508
23514
of the types in a given library $L_1$
23509
23515
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23510
- one or more import links,
23511
- first choose a set of distinct, globally fresh identifiers
23516
+ one or more import links
23517
+ is determined as follows.
23518
+ First, choose a set of distinct, globally fresh identifiers
23512
23519
\List{\metavar{prefix}}{1}{n}.
23513
23520
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23514
23521
23515
23522
\begin{enumerate}
23523
+ \item
23524
+ If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23525
+ whose name $n$ is private,
23526
+ and an occurrence of $n$ that resolves to $D$
23527
+ exists in a type alias declaration $D_A$ whose name is non-private,
23528
+ then perform a consistent renaming of
23529
+ all occurrences of $n$ in $L_i$ that resolve to $D_T$
23530
+ to a fresh, non-private identifier.
23531
+ \commentary{%
23532
+ So we make $D_T$ public, because it is being leaked anyway.%
23533
+ }
23516
23534
\item
23517
23535
Add a set of import directives to $L_i$ that imports
23518
23536
each of the libraries \List{L}{1}{n} with
@@ -23525,18 +23543,20 @@ \subsubsection{The Canonical Syntax of Types}
23525
23543
even itself and system libraries like \code{dart:core}.%
23526
23544
}
23527
23545
\item
23528
- Let \id{} be a non-private identifier that resolves to
23529
- a library declaration in the library $L_j$ in the original program;
23530
- \id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23531
- Let \code{$p$.\id} be a qualified identifier where $p$ is
23532
- an import prefix in the original program,
23533
- \id{} is a non-private identifier,
23534
- and \code{$p$.\id} resolves to
23535
- a library declaration in the library $L_j$ in the original program;
23536
- \code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23537
- \item
23538
- %% TODO(eernst): We should rename private names to fresh public names.
23539
- Replace every type that denotes a type alias
23546
+ Let \id{} be a non-private type identifier derived from \synt{typeName}
23547
+ that resolves to a library declaration in the library $L_j$
23548
+ in the original program;
23549
+ \id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23550
+ Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23551
+ an import prefix in the original program
23552
+ and \id{} is a non-private identifier,
23553
+ and consider the case where \code{$p$.\id} resolves to
23554
+ a library declaration in the library $L_j$ in the original program,
23555
+ for some $j$;
23556
+ \code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23557
+ \item
23558
+ Replace every type in $L_i$ that denotes a type alias
23559
+ along with its actual type arguments, if any,
23540
23560
by its transitive alias expansion
23541
23561
(\ref{typedef}).
23542
23562
\commentary{%
@@ -23548,15 +23568,32 @@ \subsubsection{The Canonical Syntax of Types}
23548
23568
\end{enumerate}
23549
23569
23550
23570
\commentary{%
23551
- Note that this transformation does not change any occurrence of \VOID;
23552
- \VOID{} is a reserved word, not an identifier.
23571
+ This transformation does not change any occurrence of \VOID;
23572
+ \VOID{} is a reserved word, not a type identifier.
23553
23573
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23554
23574
23575
+ Note that the transformation changes terms derived from \synt{type},
23576
+ but it does not change expressions, or any other program element
23577
+ (except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23578
+ In particular, it does not change type literals
23579
+ (that is, expressions denoting types).
23580
+
23555
23581
The transformation also does not change identifiers denoting type variables,
23582
+ because they are never resolved to a library declaration,
23583
+ they are always introduced by a scope which is nested inside the library scope.
23556
23584
There is no need to change those identifiers, because
23557
- no occurrence of such an identifier resolves to a declaration in a
23558
- different library.%
23559
- %% TODO(eernst): Sort out the treatment of private identifiers, too.
23585
+ no occurrence of such an identifier in the type of an expression
23586
+ denotes a declaration in a different library.%
23587
+ }
23588
+
23589
+ \rationale{%
23590
+ The only purpose of this transformation is to obtain a
23591
+ location-independent designation of all types,
23592
+ in such a way that each \synt{typeName} resolves to the same declaration
23593
+ before and after the transformation.
23594
+ The program behavior may change due to different values returned from
23595
+ \code{toString()} on reified types,
23596
+ but the transformation is otherwise semantics preserving.%
23560
23597
}
23561
23598
23562
23599
\LMHash{}%
@@ -23593,15 +23630,21 @@ \subsubsection{The Canonical Syntax of Types}
23593
23630
because we would need to re-build all the structures that the
23594
23631
syntax offers.
23595
23632
For instance, we would need to support the construction of
23596
- a semantic type entity for \code{Map<int, String>},
23597
- based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23633
+ a semantic type entity for \code{Map<int,\,String>},
23634
+ based on the semantic type entities for
23635
+ \code{int}, \code{String}, and \code{Map},
23598
23636
and we would need to support deconstruction of those entities
23599
- in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23637
+ in order to prove things like
23638
+ \SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
23600
23639
This would give rise to a lot of mechanism that will simply duplicate
23601
23640
the structure of the syntax.
23602
23641
So we prefer to show that the syntax \emph{can} be location independent,
23603
23642
and that's sufficient to make syntax usable as our representation of
23604
- static semantic types.%
23643
+ static semantic types.
23644
+
23645
+ We are basically taking the approach that a static semantic type is
23646
+ an equivalence class of all syntactic elements derived from \synt{type}
23647
+ that have the same canonical syntax.%
23605
23648
}
23606
23649
23607
23650
@@ -23692,6 +23735,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23692
23735
Finally, it is assumed that all types are denoted by their canonical syntax
23693
23736
(\ref{theCanonicalSyntaxOfTypes}).
23694
23737
23738
+ \commentary{%
23739
+ This implies that type aliases have already been fully expanded,
23740
+ and two types are the same if and only if they have the same syntax.%
23741
+ }
23742
+
23695
23743
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23696
23744
\LMHash{}%
23697
23745
We define the
0 commit comments