Skip to content

Commit ec4eb1f

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent aeec3d4 commit ec4eb1f

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

2221422214
\LMHash{}%
2221522215
In section~\ref{subtypes} and its subsections,
22216-
all types are considered to be denoted by their canonical syntax
22216+
all designations of types are considered to be the same
22217+
if{}f they have the same canonical syntax
2221722218
(\ref{theCanonicalSyntaxOfTypes}).
2221822219

2221922220
\commentary{%
@@ -23050,7 +23051,12 @@ \subsubsection{The Canonical Syntax of Types}
2305023051
and $L_2$ could declare a function
2305123052
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2305223053
which uses the type \code{C}-in-$L_2$,
23053-
and $L$ could contain the expression \code{foo(v)}.%
23054+
and $L$ could contain the expression \code{foo(v)}.
23055+
23056+
Note that even though it would be a compile-time error to use \code{C} in $L$
23057+
(because it is ambiguous),
23058+
it is not an error to have an expression like \code{foo(v)},
23059+
and the static analysis of this expression must handle the name clash.%
2305423060
}
2305523061

2305623062
\rationale{%
@@ -23073,16 +23079,28 @@ \subsubsection{The Canonical Syntax of Types}
2307323079
}
2307423080

2307523081
\LMHash{}%
23076-
To determine the
23082+
The
2307723083
\IndexCustom{canonical syntax}{type!canonical syntax of}
2307823084
of the types in a given library $L_1$
2307923085
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23080-
one or more import links,
23081-
first choose a set of distinct, globally fresh identifiers
23086+
one or more import links
23087+
is determined as follows.
23088+
First, choose a set of distinct, globally fresh identifiers
2308223089
\List{\metavar{prefix}}{1}{n}.
2308323090
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2308423091

2308523092
\begin{enumerate}
23093+
\item
23094+
If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23095+
whose name $n$ is private,
23096+
and an occurrence of $n$ that resolves to $D$
23097+
exists in a type alias declaration $D_A$ whose name is non-private,
23098+
then perform a consistent renaming of
23099+
all occurrences of $n$ in $L_i$ that resolve to $D_T$
23100+
to a fresh, non-private identifier.
23101+
\commentary{%
23102+
So we make $D_T$ public, because it is being leaked anyway.%
23103+
}
2308623104
\item
2308723105
Add a set of import directives to $L_i$ that imports
2308823106
each of the libraries \List{L}{1}{n} with
@@ -23095,18 +23113,20 @@ \subsubsection{The Canonical Syntax of Types}
2309523113
even itself and system libraries like \code{dart:core}.%
2309623114
}
2309723115
\item
23098-
Let \id{} be a non-private identifier that resolves to
23099-
a library declaration in the library $L_j$ in the original program;
23100-
\id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23101-
Let \code{$p$.\id} be a qualified identifier where $p$ is
23102-
an import prefix in the original program,
23103-
\id{} is a non-private identifier,
23104-
and \code{$p$.\id} resolves to
23105-
a library declaration in the library $L_j$ in the original program;
23106-
\code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23107-
\item
23108-
%% TODO(eernst): We should rename private names to fresh public names.
23109-
Replace every type that denotes a type alias
23116+
Let \id{} be a non-private type identifier derived from \synt{typeName}
23117+
that resolves to a library declaration in the library $L_j$
23118+
in the original program;
23119+
\id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23120+
Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23121+
an import prefix in the original program
23122+
and \id{} is a non-private identifier,
23123+
and consider the case where \code{$p$.\id} resolves to
23124+
a library declaration in the library $L_j$ in the original program,
23125+
for some $j$;
23126+
\code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23127+
\item
23128+
Replace every type in $L_i$ that denotes a type alias
23129+
along with its actual type arguments, if any,
2311023130
by its transitive alias expansion
2311123131
(\ref{typedef}).
2311223132
\commentary{%
@@ -23118,15 +23138,32 @@ \subsubsection{The Canonical Syntax of Types}
2311823138
\end{enumerate}
2311923139

2312023140
\commentary{%
23121-
Note that this transformation does not change any occurrence of \VOID;
23122-
\VOID{} is a reserved word, not an identifier.
23141+
This transformation does not change any occurrence of \VOID;
23142+
\VOID{} is a reserved word, not a type identifier.
2312323143
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2312423144

23145+
Note that the transformation changes terms derived from \synt{type},
23146+
but it does not change expressions, or any other program element
23147+
(except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23148+
In particular, it does not change type literals
23149+
(that is, expressions denoting types).
23150+
2312523151
The transformation also does not change identifiers denoting type variables,
23152+
because they are never resolved to a library declaration,
23153+
they are always introduced by a scope which is nested inside the library scope.
2312623154
There is no need to change those identifiers, because
23127-
no occurrence of such an identifier resolves to a declaration in a
23128-
different library.%
23129-
%% TODO(eernst): Sort out the treatment of private identifiers, too.
23155+
no occurrence of such an identifier in the type of an expression
23156+
denotes a declaration in a different library.%
23157+
}
23158+
23159+
\rationale{%
23160+
The only purpose of this transformation is to obtain a
23161+
location-independent designation of all types,
23162+
in such a way that each \synt{typeName} resolves to the same declaration
23163+
before and after the transformation.
23164+
The program behavior may change due to different values returned from
23165+
\code{toString()} on reified types,
23166+
but the transformation is otherwise semantics preserving.%
2313023167
}
2313123168

2313223169
\LMHash{}%
@@ -23163,15 +23200,21 @@ \subsubsection{The Canonical Syntax of Types}
2316323200
because we would need to re-build all the structures that the
2316423201
syntax offers.
2316523202
For instance, we would need to support the construction of
23166-
a semantic type entity for \code{Map<int, String>},
23167-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23203+
a semantic type entity for \code{Map<int,\,String>},
23204+
based on the semantic type entities for
23205+
\code{int}, \code{String}, and \code{Map},
2316823206
and we would need to support deconstruction of those entities
23169-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23207+
in order to prove things like
23208+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2317023209
This would give rise to a lot of mechanism that will simply duplicate
2317123210
the structure of the syntax.
2317223211
So we prefer to show that the syntax \emph{can} be location independent,
2317323212
and that's sufficient to make syntax usable as our representation of
23174-
static semantic types.%
23213+
static semantic types.
23214+
23215+
We are basically taking the approach that a static semantic type is
23216+
an equivalence class of all syntactic elements derived from \synt{type}
23217+
that have the same canonical syntax.%
2317523218
}
2317623219

2317723220

@@ -23262,6 +23305,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2326223305
Finally, it is assumed that all types are denoted by their canonical syntax
2326323306
(\ref{theCanonicalSyntaxOfTypes}).
2326423307

23308+
\commentary{%
23309+
This implies that type aliases have already been fully expanded,
23310+
and two types are the same if and only if they have the same syntax.%
23311+
}
23312+
2326523313
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2326623314
\LMHash{}%
2326723315
We define the

0 commit comments

Comments
 (0)