Skip to content

Commit 4e1854f

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent 7b4eca8 commit 4e1854f

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

2234322343
\LMHash{}%
2234422344
In section~\ref{subtypes} and its subsections,
22345-
all types are considered to be denoted by their canonical syntax
22345+
all designations of types are considered to be the same
22346+
if{}f they have the same canonical syntax
2234622347
(\ref{theCanonicalSyntaxOfTypes}).
2234722348

2234822349
\commentary{%
@@ -23179,7 +23180,12 @@ \subsubsection{The Canonical Syntax of Types}
2317923180
and $L_2$ could declare a function
2318023181
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2318123182
which uses the type \code{C}-in-$L_2$,
23182-
and $L$ could contain the expression \code{foo(v)}.%
23183+
and $L$ could contain the expression \code{foo(v)}.
23184+
23185+
Note that even though it would be a compile-time error to use \code{C} in $L$
23186+
(because it is ambiguous),
23187+
it is not an error to have an expression like \code{foo(v)},
23188+
and the static analysis of this expression must handle the name clash.%
2318323189
}
2318423190

2318523191
\rationale{%
@@ -23202,16 +23208,28 @@ \subsubsection{The Canonical Syntax of Types}
2320223208
}
2320323209

2320423210
\LMHash{}%
23205-
To determine the
23211+
The
2320623212
\IndexCustom{canonical syntax}{type!canonical syntax of}
2320723213
of the types in a given library $L_1$
2320823214
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23209-
one or more import links,
23210-
first choose a set of distinct, globally fresh identifiers
23215+
one or more import links
23216+
is determined as follows.
23217+
First, choose a set of distinct, globally fresh identifiers
2321123218
\List{\metavar{prefix}}{1}{n}.
2321223219
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2321323220

2321423221
\begin{enumerate}
23222+
\item
23223+
If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23224+
whose name $n$ is private,
23225+
and an occurrence of $n$ that resolves to $D$
23226+
exists in a type alias declaration $D_A$ whose name is non-private,
23227+
then perform a consistent renaming of
23228+
all occurrences of $n$ in $L_i$ that resolve to $D_T$
23229+
to a fresh, non-private identifier.
23230+
\commentary{%
23231+
So we make $D_T$ public, because it is being leaked anyway.%
23232+
}
2321523233
\item
2321623234
Add a set of import directives to $L_i$ that imports
2321723235
each of the libraries \List{L}{1}{n} with
@@ -23224,18 +23242,20 @@ \subsubsection{The Canonical Syntax of Types}
2322423242
even itself and system libraries like \code{dart:core}.%
2322523243
}
2322623244
\item
23227-
Let \id{} be a non-private identifier that resolves to
23228-
a library declaration in the library $L_j$ in the original program;
23229-
\id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23230-
Let \code{$p$.\id} be a qualified identifier where $p$ is
23231-
an import prefix in the original program,
23232-
\id{} is a non-private identifier,
23233-
and \code{$p$.\id} resolves to
23234-
a library declaration in the library $L_j$ in the original program;
23235-
\code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23236-
\item
23237-
%% TODO(eernst): We should rename private names to fresh public names.
23238-
Replace every type that denotes a type alias
23245+
Let \id{} be a non-private type identifier derived from \synt{typeName}
23246+
that resolves to a library declaration in the library $L_j$
23247+
in the original program;
23248+
\id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23249+
Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23250+
an import prefix in the original program
23251+
and \id{} is a non-private identifier,
23252+
and consider the case where \code{$p$.\id} resolves to
23253+
a library declaration in the library $L_j$ in the original program,
23254+
for some $j$;
23255+
\code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23256+
\item
23257+
Replace every type in $L_i$ that denotes a type alias
23258+
along with its actual type arguments, if any,
2323923259
by its transitive alias expansion
2324023260
(\ref{typedef}).
2324123261
\commentary{%
@@ -23247,15 +23267,32 @@ \subsubsection{The Canonical Syntax of Types}
2324723267
\end{enumerate}
2324823268

2324923269
\commentary{%
23250-
Note that this transformation does not change any occurrence of \VOID;
23251-
\VOID{} is a reserved word, not an identifier.
23270+
This transformation does not change any occurrence of \VOID;
23271+
\VOID{} is a reserved word, not a type identifier.
2325223272
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2325323273

23274+
Note that the transformation changes terms derived from \synt{type},
23275+
but it does not change expressions, or any other program element
23276+
(except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23277+
In particular, it does not change type literals
23278+
(that is, expressions denoting types).
23279+
2325423280
The transformation also does not change identifiers denoting type variables,
23281+
because they are never resolved to a library declaration,
23282+
they are always introduced by a scope which is nested inside the library scope.
2325523283
There is no need to change those identifiers, because
23256-
no occurrence of such an identifier resolves to a declaration in a
23257-
different library.%
23258-
%% TODO(eernst): Sort out the treatment of private identifiers, too.
23284+
no occurrence of such an identifier in the type of an expression
23285+
denotes a declaration in a different library.%
23286+
}
23287+
23288+
\rationale{%
23289+
The only purpose of this transformation is to obtain a
23290+
location-independent designation of all types,
23291+
in such a way that each \synt{typeName} resolves to the same declaration
23292+
before and after the transformation.
23293+
The program behavior may change due to different values returned from
23294+
\code{toString()} on reified types,
23295+
but the transformation is otherwise semantics preserving.%
2325923296
}
2326023297

2326123298
\LMHash{}%
@@ -23292,15 +23329,21 @@ \subsubsection{The Canonical Syntax of Types}
2329223329
because we would need to re-build all the structures that the
2329323330
syntax offers.
2329423331
For instance, we would need to support the construction of
23295-
a semantic type entity for \code{Map<int, String>},
23296-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23332+
a semantic type entity for \code{Map<int,\,String>},
23333+
based on the semantic type entities for
23334+
\code{int}, \code{String}, and \code{Map},
2329723335
and we would need to support deconstruction of those entities
23298-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23336+
in order to prove things like
23337+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2329923338
This would give rise to a lot of mechanism that will simply duplicate
2330023339
the structure of the syntax.
2330123340
So we prefer to show that the syntax \emph{can} be location independent,
2330223341
and that's sufficient to make syntax usable as our representation of
23303-
static semantic types.%
23342+
static semantic types.
23343+
23344+
We are basically taking the approach that a static semantic type is
23345+
an equivalence class of all syntactic elements derived from \synt{type}
23346+
that have the same canonical syntax.%
2330423347
}
2330523348

2330623349

@@ -23391,6 +23434,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2339123434
Finally, it is assumed that all types are denoted by their canonical syntax
2339223435
(\ref{theCanonicalSyntaxOfTypes}).
2339323436

23437+
\commentary{%
23438+
This implies that type aliases have already been fully expanded,
23439+
and two types are the same if and only if they have the same syntax.%
23440+
}
23441+
2339423442
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2339523443
\LMHash{}%
2339623444
We define the

0 commit comments

Comments
 (0)