Skip to content

Commit e101c47

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent 51a32ab commit e101c47

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

2309523095
\LMHash{}%
2309623096
In section~\ref{subtypes} and its subsections,
23097-
all types are considered to be denoted by their canonical syntax
23097+
all designations of types are considered to be the same
23098+
if{}f they have the same canonical syntax
2309823099
(\ref{theCanonicalSyntaxOfTypes}).
2309923100

2310023101
\commentary{%
@@ -23933,7 +23934,12 @@ \subsubsection{The Canonical Syntax of Types}
2393323934
and $L_2$ could declare a function
2393423935
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2393523936
which uses the type \code{C}-in-$L_2$,
23936-
and $L$ could contain the expression \code{foo(v)}.%
23937+
and $L$ could contain the expression \code{foo(v)}.
23938+
23939+
Note that even though it would be a compile-time error to use \code{C} in $L$
23940+
(because it is ambiguous),
23941+
it is not an error to have an expression like \code{foo(v)},
23942+
and the static analysis of this expression must handle the name clash.%
2393723943
}
2393823944

2393923945
\rationale{%
@@ -23956,16 +23962,28 @@ \subsubsection{The Canonical Syntax of Types}
2395623962
}
2395723963

2395823964
\LMHash{}%
23959-
To determine the
23965+
The
2396023966
\IndexCustom{canonical syntax}{type!canonical syntax of}
2396123967
of the types in a given library $L_1$
2396223968
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23963-
one or more import links,
23964-
first choose a set of distinct, globally fresh identifiers
23969+
one or more import links
23970+
is determined as follows.
23971+
First, choose a set of distinct, globally fresh identifiers
2396523972
\List{\metavar{prefix}}{1}{n}.
2396623973
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2396723974

2396823975
\begin{enumerate}
23976+
\item
23977+
If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23978+
whose name $n$ is private,
23979+
and an occurrence of $n$ that resolves to $D$
23980+
exists in a type alias declaration $D_A$ whose name is non-private,
23981+
then perform a consistent renaming of
23982+
all occurrences of $n$ in $L_i$ that resolve to $D_T$
23983+
to a fresh, non-private identifier.
23984+
\commentary{%
23985+
So we make $D_T$ public, because it is being leaked anyway.%
23986+
}
2396923987
\item
2397023988
Add a set of import directives to $L_i$ that imports
2397123989
each of the libraries \List{L}{1}{n} with
@@ -23978,18 +23996,20 @@ \subsubsection{The Canonical Syntax of Types}
2397823996
even itself and system libraries like \code{dart:core}.%
2397923997
}
2398023998
\item
23981-
Let \id{} be a non-private identifier that resolves to
23982-
a library declaration in the library $L_j$ in the original program;
23983-
\id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23984-
Let \code{$p$.\id} be a qualified identifier where $p$ is
23985-
an import prefix in the original program,
23986-
\id{} is a non-private identifier,
23987-
and \code{$p$.\id} resolves to
23988-
a library declaration in the library $L_j$ in the original program;
23989-
\code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23990-
\item
23991-
%% TODO(eernst): We should rename private names to fresh public names.
23992-
Replace every type that denotes a type alias
23999+
Let \id{} be a non-private type identifier derived from \synt{typeName}
24000+
that resolves to a library declaration in the library $L_j$
24001+
in the original program;
24002+
\id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
24003+
Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
24004+
an import prefix in the original program
24005+
and \id{} is a non-private identifier,
24006+
and consider the case where \code{$p$.\id} resolves to
24007+
a library declaration in the library $L_j$ in the original program,
24008+
for some $j$;
24009+
\code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
24010+
\item
24011+
Replace every type in $L_i$ that denotes a type alias
24012+
along with its actual type arguments, if any,
2399324013
by its transitive alias expansion
2399424014
(\ref{typedef}).
2399524015
\commentary{%
@@ -24001,15 +24021,32 @@ \subsubsection{The Canonical Syntax of Types}
2400124021
\end{enumerate}
2400224022

2400324023
\commentary{%
24004-
Note that this transformation does not change any occurrence of \VOID;
24005-
\VOID{} is a reserved word, not an identifier.
24024+
This transformation does not change any occurrence of \VOID;
24025+
\VOID{} is a reserved word, not a type identifier.
2400624026
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2400724027

24028+
Note that the transformation changes terms derived from \synt{type},
24029+
but it does not change expressions, or any other program element
24030+
(except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
24031+
In particular, it does not change type literals
24032+
(that is, expressions denoting types).
24033+
2400824034
The transformation also does not change identifiers denoting type variables,
24035+
because they are never resolved to a library declaration,
24036+
they are always introduced by a scope which is nested inside the library scope.
2400924037
There is no need to change those identifiers, because
24010-
no occurrence of such an identifier resolves to a declaration in a
24011-
different library.%
24012-
%% TODO(eernst): Sort out the treatment of private identifiers, too.
24038+
no occurrence of such an identifier in the type of an expression
24039+
denotes a declaration in a different library.%
24040+
}
24041+
24042+
\rationale{%
24043+
The only purpose of this transformation is to obtain a
24044+
location-independent designation of all types,
24045+
in such a way that each \synt{typeName} resolves to the same declaration
24046+
before and after the transformation.
24047+
The program behavior may change due to different values returned from
24048+
\code{toString()} on reified types,
24049+
but the transformation is otherwise semantics preserving.%
2401324050
}
2401424051

2401524052
\LMHash{}%
@@ -24046,15 +24083,21 @@ \subsubsection{The Canonical Syntax of Types}
2404624083
because we would need to re-build all the structures that the
2404724084
syntax offers.
2404824085
For instance, we would need to support the construction of
24049-
a semantic type entity for \code{Map<int, String>},
24050-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
24086+
a semantic type entity for \code{Map<int,\,String>},
24087+
based on the semantic type entities for
24088+
\code{int}, \code{String}, and \code{Map},
2405124089
and we would need to support deconstruction of those entities
24052-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
24090+
in order to prove things like
24091+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2405324092
This would give rise to a lot of mechanism that will simply duplicate
2405424093
the structure of the syntax.
2405524094
So we prefer to show that the syntax \emph{can} be location independent,
2405624095
and that's sufficient to make syntax usable as our representation of
24057-
static semantic types.%
24096+
static semantic types.
24097+
24098+
We are basically taking the approach that a static semantic type is
24099+
an equivalence class of all syntactic elements derived from \synt{type}
24100+
that have the same canonical syntax.%
2405824101
}
2405924102

2406024103

@@ -24145,6 +24188,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2414524188
Finally, it is assumed that all types are denoted by their canonical syntax
2414624189
(\ref{theCanonicalSyntaxOfTypes}).
2414724190

24191+
\commentary{%
24192+
This implies that type aliases have already been fully expanded,
24193+
and two types are the same if and only if they have the same syntax.%
24194+
}
24195+
2414824196
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2414924197
\LMHash{}%
2415024198
We define the

0 commit comments

Comments
 (0)