Skip to content

Commit ccf3eb2

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent aae3ed5 commit ccf3eb2

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

2227722277
\LMHash{}%
2227822278
In section~\ref{subtypes} and its subsections,
22279-
all types are considered to be denoted by their canonical syntax
22279+
all designations of types are considered to be the same
22280+
if{}f they have the same canonical syntax
2228022281
(\ref{theCanonicalSyntaxOfTypes}).
2228122282

2228222283
\commentary{%
@@ -23113,7 +23114,12 @@ \subsubsection{The Canonical Syntax of Types}
2311323114
and $L_2$ could declare a function
2311423115
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2311523116
which uses the type \code{C}-in-$L_2$,
23116-
and $L$ could contain the expression \code{foo(v)}.%
23117+
and $L$ could contain the expression \code{foo(v)}.
23118+
23119+
Note that even though it would be a compile-time error to use \code{C} in $L$
23120+
(because it is ambiguous),
23121+
it is not an error to have an expression like \code{foo(v)},
23122+
and the static analysis of this expression must handle the name clash.%
2311723123
}
2311823124

2311923125
\rationale{%
@@ -23136,16 +23142,28 @@ \subsubsection{The Canonical Syntax of Types}
2313623142
}
2313723143

2313823144
\LMHash{}%
23139-
To determine the
23145+
The
2314023146
\IndexCustom{canonical syntax}{type!canonical syntax of}
2314123147
of the types in a given library $L_1$
2314223148
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23143-
one or more import links,
23144-
first choose a set of distinct, globally fresh identifiers
23149+
one or more import links
23150+
is determined as follows.
23151+
First, choose a set of distinct, globally fresh identifiers
2314523152
\List{\metavar{prefix}}{1}{n}.
2314623153
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2314723154

2314823155
\begin{enumerate}
23156+
\item
23157+
If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23158+
whose name $n$ is private,
23159+
and an occurrence of $n$ that resolves to $D$
23160+
exists in a type alias declaration $D_A$ whose name is non-private,
23161+
then perform a consistent renaming of
23162+
all occurrences of $n$ in $L_i$ that resolve to $D_T$
23163+
to a fresh, non-private identifier.
23164+
\commentary{%
23165+
So we make $D_T$ public, because it is being leaked anyway.%
23166+
}
2314923167
\item
2315023168
Add a set of import directives to $L_i$ that imports
2315123169
each of the libraries \List{L}{1}{n} with
@@ -23158,18 +23176,20 @@ \subsubsection{The Canonical Syntax of Types}
2315823176
even itself and system libraries like \code{dart:core}.%
2315923177
}
2316023178
\item
23161-
Let \id{} be a non-private identifier that resolves to
23162-
a library declaration in the library $L_j$ in the original program;
23163-
\id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23164-
Let \code{$p$.\id} be a qualified identifier where $p$ is
23165-
an import prefix in the original program,
23166-
\id{} is a non-private identifier,
23167-
and \code{$p$.\id} resolves to
23168-
a library declaration in the library $L_j$ in the original program;
23169-
\code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23170-
\item
23171-
%% TODO(eernst): We should rename private names to fresh public names.
23172-
Replace every type that denotes a type alias
23179+
Let \id{} be a non-private type identifier derived from \synt{typeName}
23180+
that resolves to a library declaration in the library $L_j$
23181+
in the original program;
23182+
\id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23183+
Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23184+
an import prefix in the original program
23185+
and \id{} is a non-private identifier,
23186+
and consider the case where \code{$p$.\id} resolves to
23187+
a library declaration in the library $L_j$ in the original program,
23188+
for some $j$;
23189+
\code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23190+
\item
23191+
Replace every type in $L_i$ that denotes a type alias
23192+
along with its actual type arguments, if any,
2317323193
by its transitive alias expansion
2317423194
(\ref{typedef}).
2317523195
\commentary{%
@@ -23181,15 +23201,32 @@ \subsubsection{The Canonical Syntax of Types}
2318123201
\end{enumerate}
2318223202

2318323203
\commentary{%
23184-
Note that this transformation does not change any occurrence of \VOID;
23185-
\VOID{} is a reserved word, not an identifier.
23204+
This transformation does not change any occurrence of \VOID;
23205+
\VOID{} is a reserved word, not a type identifier.
2318623206
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2318723207

23208+
Note that the transformation changes terms derived from \synt{type},
23209+
but it does not change expressions, or any other program element
23210+
(except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23211+
In particular, it does not change type literals
23212+
(that is, expressions denoting types).
23213+
2318823214
The transformation also does not change identifiers denoting type variables,
23215+
because they are never resolved to a library declaration,
23216+
they are always introduced by a scope which is nested inside the library scope.
2318923217
There is no need to change those identifiers, because
23190-
no occurrence of such an identifier resolves to a declaration in a
23191-
different library.%
23192-
%% TODO(eernst): Sort out the treatment of private identifiers, too.
23218+
no occurrence of such an identifier in the type of an expression
23219+
denotes a declaration in a different library.%
23220+
}
23221+
23222+
\rationale{%
23223+
The only purpose of this transformation is to obtain a
23224+
location-independent designation of all types,
23225+
in such a way that each \synt{typeName} resolves to the same declaration
23226+
before and after the transformation.
23227+
The program behavior may change due to different values returned from
23228+
\code{toString()} on reified types,
23229+
but the transformation is otherwise semantics preserving.%
2319323230
}
2319423231

2319523232
\LMHash{}%
@@ -23226,15 +23263,21 @@ \subsubsection{The Canonical Syntax of Types}
2322623263
because we would need to re-build all the structures that the
2322723264
syntax offers.
2322823265
For instance, we would need to support the construction of
23229-
a semantic type entity for \code{Map<int, String>},
23230-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23266+
a semantic type entity for \code{Map<int,\,String>},
23267+
based on the semantic type entities for
23268+
\code{int}, \code{String}, and \code{Map},
2323123269
and we would need to support deconstruction of those entities
23232-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23270+
in order to prove things like
23271+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2323323272
This would give rise to a lot of mechanism that will simply duplicate
2323423273
the structure of the syntax.
2323523274
So we prefer to show that the syntax \emph{can} be location independent,
2323623275
and that's sufficient to make syntax usable as our representation of
23237-
static semantic types.%
23276+
static semantic types.
23277+
23278+
We are basically taking the approach that a static semantic type is
23279+
an equivalence class of all syntactic elements derived from \synt{type}
23280+
that have the same canonical syntax.%
2323823281
}
2323923282

2324023283

@@ -23325,6 +23368,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2332523368
Finally, it is assumed that all types are denoted by their canonical syntax
2332623369
(\ref{theCanonicalSyntaxOfTypes}).
2332723370

23371+
\commentary{%
23372+
This implies that type aliases have already been fully expanded,
23373+
and two types are the same if and only if they have the same syntax.%
23374+
}
23375+
2332823376
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2332923377
\LMHash{}%
2333023378
We define the

0 commit comments

Comments
 (0)