Skip to content

Commit 6ed4f88

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent 2e37a22 commit 6ed4f88

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

2212522125
\LMHash{}%
2212622126
In section~\ref{subtypes} and its subsections,
22127-
all types are considered to be denoted by their canonical syntax
22127+
all designations of types are considered to be the same
22128+
if{}f they have the same canonical syntax
2212822129
(\ref{theCanonicalSyntaxOfTypes}).
2212922130

2213022131
\commentary{%
@@ -22961,7 +22962,12 @@ \subsubsection{The Canonical Syntax of Types}
2296122962
and $L_2$ could declare a function
2296222963
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2296322964
which uses the type \code{C}-in-$L_2$,
22964-
and $L$ could contain the expression \code{foo(v)}.%
22965+
and $L$ could contain the expression \code{foo(v)}.
22966+
22967+
Note that even though it would be a compile-time error to use \code{C} in $L$
22968+
(because it is ambiguous),
22969+
it is not an error to have an expression like \code{foo(v)},
22970+
and the static analysis of this expression must handle the name clash.%
2296522971
}
2296622972

2296722973
\rationale{%
@@ -22984,16 +22990,28 @@ \subsubsection{The Canonical Syntax of Types}
2298422990
}
2298522991

2298622992
\LMHash{}%
22987-
To determine the
22993+
The
2298822994
\IndexCustom{canonical syntax}{type!canonical syntax of}
2298922995
of the types in a given library $L_1$
2299022996
and all libraries \List{L}{2}{n} reachable from $L_1$ via
22991-
one or more import links,
22992-
first choose a set of distinct, globally fresh identifiers
22997+
one or more import links
22998+
is determined as follows.
22999+
First, choose a set of distinct, globally fresh identifiers
2299323000
\List{\metavar{prefix}}{1}{n}.
2299423001
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2299523002

2299623003
\begin{enumerate}
23004+
\item
23005+
If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23006+
whose name $n$ is private,
23007+
and an occurrence of $n$ that resolves to $D$
23008+
exists in a type alias declaration $D_A$ whose name is non-private,
23009+
then perform a consistent renaming of
23010+
all occurrences of $n$ in $L_i$ that resolve to $D_T$
23011+
to a fresh, non-private identifier.
23012+
\commentary{%
23013+
So we make $D_T$ public, because it is being leaked anyway.%
23014+
}
2299723015
\item
2299823016
Add a set of import directives to $L_i$ that imports
2299923017
each of the libraries \List{L}{1}{n} with
@@ -23006,18 +23024,20 @@ \subsubsection{The Canonical Syntax of Types}
2300623024
even itself and system libraries like \code{dart:core}.%
2300723025
}
2300823026
\item
23009-
Let \id{} be a non-private identifier that resolves to
23010-
a library declaration in the library $L_j$ in the original program;
23011-
\id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23012-
Let \code{$p$.\id} be a qualified identifier where $p$ is
23013-
an import prefix in the original program,
23014-
\id{} is a non-private identifier,
23015-
and \code{$p$.\id} resolves to
23016-
a library declaration in the library $L_j$ in the original program;
23017-
\code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23018-
\item
23019-
%% TODO(eernst): We should rename private names to fresh public names.
23020-
Replace every type that denotes a type alias
23027+
Let \id{} be a non-private type identifier derived from \synt{typeName}
23028+
that resolves to a library declaration in the library $L_j$
23029+
in the original program;
23030+
\id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23031+
Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23032+
an import prefix in the original program
23033+
and \id{} is a non-private identifier,
23034+
and consider the case where \code{$p$.\id} resolves to
23035+
a library declaration in the library $L_j$ in the original program,
23036+
for some $j$;
23037+
\code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23038+
\item
23039+
Replace every type in $L_i$ that denotes a type alias
23040+
along with its actual type arguments, if any,
2302123041
by its transitive alias expansion
2302223042
(\ref{typedef}).
2302323043
\commentary{%
@@ -23029,15 +23049,32 @@ \subsubsection{The Canonical Syntax of Types}
2302923049
\end{enumerate}
2303023050

2303123051
\commentary{%
23032-
Note that this transformation does not change any occurrence of \VOID;
23033-
\VOID{} is a reserved word, not an identifier.
23052+
This transformation does not change any occurrence of \VOID;
23053+
\VOID{} is a reserved word, not a type identifier.
2303423054
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2303523055

23056+
Note that the transformation changes terms derived from \synt{type},
23057+
but it does not change expressions, or any other program element
23058+
(except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23059+
In particular, it does not change type literals
23060+
(that is, expressions denoting types).
23061+
2303623062
The transformation also does not change identifiers denoting type variables,
23063+
because they are never resolved to a library declaration,
23064+
they are always introduced by a scope which is nested inside the library scope.
2303723065
There is no need to change those identifiers, because
23038-
no occurrence of such an identifier resolves to a declaration in a
23039-
different library.%
23040-
%% TODO(eernst): Sort out the treatment of private identifiers, too.
23066+
no occurrence of such an identifier in the type of an expression
23067+
denotes a declaration in a different library.%
23068+
}
23069+
23070+
\rationale{%
23071+
The only purpose of this transformation is to obtain a
23072+
location-independent designation of all types,
23073+
in such a way that each \synt{typeName} resolves to the same declaration
23074+
before and after the transformation.
23075+
The program behavior may change due to different values returned from
23076+
\code{toString()} on reified types,
23077+
but the transformation is otherwise semantics preserving.%
2304123078
}
2304223079

2304323080
\LMHash{}%
@@ -23074,15 +23111,21 @@ \subsubsection{The Canonical Syntax of Types}
2307423111
because we would need to re-build all the structures that the
2307523112
syntax offers.
2307623113
For instance, we would need to support the construction of
23077-
a semantic type entity for \code{Map<int, String>},
23078-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23114+
a semantic type entity for \code{Map<int,\,String>},
23115+
based on the semantic type entities for
23116+
\code{int}, \code{String}, and \code{Map},
2307923117
and we would need to support deconstruction of those entities
23080-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23118+
in order to prove things like
23119+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2308123120
This would give rise to a lot of mechanism that will simply duplicate
2308223121
the structure of the syntax.
2308323122
So we prefer to show that the syntax \emph{can} be location independent,
2308423123
and that's sufficient to make syntax usable as our representation of
23085-
static semantic types.%
23124+
static semantic types.
23125+
23126+
We are basically taking the approach that a static semantic type is
23127+
an equivalence class of all syntactic elements derived from \synt{type}
23128+
that have the same canonical syntax.%
2308623129
}
2308723130

2308823131

@@ -23173,6 +23216,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2317323216
Finally, it is assumed that all types are denoted by their canonical syntax
2317423217
(\ref{theCanonicalSyntaxOfTypes}).
2317523218

23219+
\commentary{%
23220+
This implies that type aliases have already been fully expanded,
23221+
and two types are the same if and only if they have the same syntax.%
23222+
}
23223+
2317623224
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2317723225
\LMHash{}%
2317823226
We define the

0 commit comments

Comments
 (0)