Skip to content

Commit 84e31d5

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent 89b2731 commit 84e31d5

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

2221622216
\LMHash{}%
2221722217
In section~\ref{subtypes} and its subsections,
22218-
all types are considered to be denoted by their canonical syntax
22218+
all designations of types are considered to be the same
22219+
if{}f they have the same canonical syntax
2221922220
(\ref{theCanonicalSyntaxOfTypes}).
2222022221

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

2305823064
\rationale{%
@@ -23075,16 +23081,28 @@ \subsubsection{The Canonical Syntax of Types}
2307523081
}
2307623082

2307723083
\LMHash{}%
23078-
To determine the
23084+
The
2307923085
\IndexCustom{canonical syntax}{type!canonical syntax of}
2308023086
of the types in a given library $L_1$
2308123087
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23082-
one or more import links,
23083-
first choose a set of distinct, globally fresh identifiers
23088+
one or more import links
23089+
is determined as follows.
23090+
First, choose a set of distinct, globally fresh identifiers
2308423091
\List{\metavar{prefix}}{1}{n}.
2308523092
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2308623093

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

2312223142
\commentary{%
23123-
Note that this transformation does not change any occurrence of \VOID;
23124-
\VOID{} is a reserved word, not an identifier.
23143+
This transformation does not change any occurrence of \VOID;
23144+
\VOID{} is a reserved word, not a type identifier.
2312523145
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2312623146

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

2313423171
\LMHash{}%
@@ -23165,15 +23202,21 @@ \subsubsection{The Canonical Syntax of Types}
2316523202
because we would need to re-build all the structures that the
2316623203
syntax offers.
2316723204
For instance, we would need to support the construction of
23168-
a semantic type entity for \code{Map<int, String>},
23169-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23205+
a semantic type entity for \code{Map<int,\,String>},
23206+
based on the semantic type entities for
23207+
\code{int}, \code{String}, and \code{Map},
2317023208
and we would need to support deconstruction of those entities
23171-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23209+
in order to prove things like
23210+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2317223211
This would give rise to a lot of mechanism that will simply duplicate
2317323212
the structure of the syntax.
2317423213
So we prefer to show that the syntax \emph{can} be location independent,
2317523214
and that's sufficient to make syntax usable as our representation of
23176-
static semantic types.%
23215+
static semantic types.
23216+
23217+
We are basically taking the approach that a static semantic type is
23218+
an equivalence class of all syntactic elements derived from \synt{type}
23219+
that have the same canonical syntax.%
2317723220
}
2317823221

2317923222

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

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

0 commit comments

Comments
 (0)