Skip to content

Commit 079e381

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent c7b5ca1 commit 079e381

File tree

1 file changed

+74
-26
lines changed

1 file changed

+74
-26
lines changed

specification/dartLangSpec.tex

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22643,7 +22643,8 @@ \subsubsection{Subtype Rules}
2264322643

2264422644
\LMHash{}%
2264522645
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
2264722648
(\ref{theCanonicalSyntaxOfTypes}).
2264822649

2264922650
\commentary{%
@@ -23480,7 +23481,12 @@ \subsubsection{The Canonical Syntax of Types}
2348023481
and $L_2$ could declare a function
2348123482
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2348223483
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.%
2348423490
}
2348523491

2348623492
\rationale{%
@@ -23503,16 +23509,28 @@ \subsubsection{The Canonical Syntax of Types}
2350323509
}
2350423510

2350523511
\LMHash{}%
23506-
To determine the
23512+
The
2350723513
\IndexCustom{canonical syntax}{type!canonical syntax of}
2350823514
of the types in a given library $L_1$
2350923515
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
2351223519
\List{\metavar{prefix}}{1}{n}.
2351323520
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2351423521

2351523522
\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+
}
2351623534
\item
2351723535
Add a set of import directives to $L_i$ that imports
2351823536
each of the libraries \List{L}{1}{n} with
@@ -23525,18 +23543,20 @@ \subsubsection{The Canonical Syntax of Types}
2352523543
even itself and system libraries like \code{dart:core}.%
2352623544
}
2352723545
\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,
2354023560
by its transitive alias expansion
2354123561
(\ref{typedef}).
2354223562
\commentary{%
@@ -23548,15 +23568,32 @@ \subsubsection{The Canonical Syntax of Types}
2354823568
\end{enumerate}
2354923569

2355023570
\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.
2355323573
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2355423574

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+
2355523581
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.
2355623584
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.%
2356023597
}
2356123598

2356223599
\LMHash{}%
@@ -23593,15 +23630,21 @@ \subsubsection{The Canonical Syntax of Types}
2359323630
because we would need to re-build all the structures that the
2359423631
syntax offers.
2359523632
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},
2359823636
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>}}.
2360023639
This would give rise to a lot of mechanism that will simply duplicate
2360123640
the structure of the syntax.
2360223641
So we prefer to show that the syntax \emph{can} be location independent,
2360323642
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.%
2360523648
}
2360623649

2360723650

@@ -23692,6 +23735,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2369223735
Finally, it is assumed that all types are denoted by their canonical syntax
2369323736
(\ref{theCanonicalSyntaxOfTypes}).
2369423737

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+
2369523743
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2369623744
\LMHash{}%
2369723745
We define the

0 commit comments

Comments
 (0)