Skip to content

Commit fc09d1e

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent 856ed02 commit fc09d1e

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
@@ -22663,7 +22663,8 @@ \subsubsection{Subtype Rules}
2266322663

2266422664
\LMHash{}%
2266522665
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
2266722668
(\ref{theCanonicalSyntaxOfTypes}).
2266822669

2266922670
\commentary{%
@@ -23500,7 +23501,12 @@ \subsubsection{The Canonical Syntax of Types}
2350023501
and $L_2$ could declare a function
2350123502
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2350223503
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.%
2350423510
}
2350523511

2350623512
\rationale{%
@@ -23523,16 +23529,28 @@ \subsubsection{The Canonical Syntax of Types}
2352323529
}
2352423530

2352523531
\LMHash{}%
23526-
To determine the
23532+
The
2352723533
\IndexCustom{canonical syntax}{type!canonical syntax of}
2352823534
of the types in a given library $L_1$
2352923535
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
2353223539
\List{\metavar{prefix}}{1}{n}.
2353323540
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2353423541

2353523542
\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+
}
2353623554
\item
2353723555
Add a set of import directives to $L_i$ that imports
2353823556
each of the libraries \List{L}{1}{n} with
@@ -23545,18 +23563,20 @@ \subsubsection{The Canonical Syntax of Types}
2354523563
even itself and system libraries like \code{dart:core}.%
2354623564
}
2354723565
\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,
2356023580
by its transitive alias expansion
2356123581
(\ref{typedef}).
2356223582
\commentary{%
@@ -23568,15 +23588,32 @@ \subsubsection{The Canonical Syntax of Types}
2356823588
\end{enumerate}
2356923589

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

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+
2357523601
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.
2357623604
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.%
2358023617
}
2358123618

2358223619
\LMHash{}%
@@ -23613,15 +23650,21 @@ \subsubsection{The Canonical Syntax of Types}
2361323650
because we would need to re-build all the structures that the
2361423651
syntax offers.
2361523652
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},
2361823656
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>}}.
2362023659
This would give rise to a lot of mechanism that will simply duplicate
2362123660
the structure of the syntax.
2362223661
So we prefer to show that the syntax \emph{can} be location independent,
2362323662
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.%
2362523668
}
2362623669

2362723670

@@ -23712,6 +23755,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2371223755
Finally, it is assumed that all types are denoted by their canonical syntax
2371323756
(\ref{theCanonicalSyntaxOfTypes}).
2371423757

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

0 commit comments

Comments
 (0)