Skip to content

Commit 374b22d

Browse files
committed
Clarified and corrected Canonical Syntax
1 parent b6b2892 commit 374b22d

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

2248122481
\LMHash{}%
2248222482
In section~\ref{subtypes} and its subsections,
22483-
all types are considered to be denoted by their canonical syntax
22483+
all designations of types are considered to be the same
22484+
if{}f they have the same canonical syntax
2248422485
(\ref{theCanonicalSyntaxOfTypes}).
2248522486

2248622487
\commentary{%
@@ -23317,7 +23318,12 @@ \subsubsection{The Canonical Syntax of Types}
2331723318
and $L_2$ could declare a function
2331823319
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
2331923320
which uses the type \code{C}-in-$L_2$,
23320-
and $L$ could contain the expression \code{foo(v)}.%
23321+
and $L$ could contain the expression \code{foo(v)}.
23322+
23323+
Note that even though it would be a compile-time error to use \code{C} in $L$
23324+
(because it is ambiguous),
23325+
it is not an error to have an expression like \code{foo(v)},
23326+
and the static analysis of this expression must handle the name clash.%
2332123327
}
2332223328

2332323329
\rationale{%
@@ -23340,16 +23346,28 @@ \subsubsection{The Canonical Syntax of Types}
2334023346
}
2334123347

2334223348
\LMHash{}%
23343-
To determine the
23349+
The
2334423350
\IndexCustom{canonical syntax}{type!canonical syntax of}
2334523351
of the types in a given library $L_1$
2334623352
and all libraries \List{L}{2}{n} reachable from $L_1$ via
23347-
one or more import links,
23348-
first choose a set of distinct, globally fresh identifiers
23353+
one or more import links
23354+
is determined as follows.
23355+
First, choose a set of distinct, globally fresh identifiers
2334923356
\List{\metavar{prefix}}{1}{n}.
2335023357
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
2335123358

2335223359
\begin{enumerate}
23360+
\item
23361+
If $D_T$ is a declaration of a class, mixin, or type alias in $L_i$
23362+
whose name $n$ is private,
23363+
and an occurrence of $n$ that resolves to $D$
23364+
exists in a type alias declaration $D_A$ whose name is non-private,
23365+
then perform a consistent renaming of
23366+
all occurrences of $n$ in $L_i$ that resolve to $D_T$
23367+
to a fresh, non-private identifier.
23368+
\commentary{%
23369+
So we make $D_T$ public, because it is being leaked anyway.%
23370+
}
2335323371
\item
2335423372
Add a set of import directives to $L_i$ that imports
2335523373
each of the libraries \List{L}{1}{n} with
@@ -23362,18 +23380,20 @@ \subsubsection{The Canonical Syntax of Types}
2336223380
even itself and system libraries like \code{dart:core}.%
2336323381
}
2336423382
\item
23365-
Let \id{} be a non-private identifier that resolves to
23366-
a library declaration in the library $L_j$ in the original program;
23367-
\id{} is transformed to \code{$\metavar{prefix}_j$.\id}.
23368-
Let \code{$p$.\id} be a qualified identifier where $p$ is
23369-
an import prefix in the original program,
23370-
\id{} is a non-private identifier,
23371-
and \code{$p$.\id} resolves to
23372-
a library declaration in the library $L_j$ in the original program;
23373-
\code{$p$.\id} is transformed to \code{$\metavar{prefix}_j$.\id}.
23374-
\item
23375-
%% TODO(eernst): We should rename private names to fresh public names.
23376-
Replace every type that denotes a type alias
23383+
Let \id{} be a non-private type identifier derived from \synt{typeName}
23384+
that resolves to a library declaration in the library $L_j$
23385+
in the original program;
23386+
\id{} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23387+
Let \code{$p$.\id} be derived from \synt{typeName} such that $p$ is
23388+
an import prefix in the original program
23389+
and \id{} is a non-private identifier,
23390+
and consider the case where \code{$p$.\id} resolves to
23391+
a library declaration in the library $L_j$ in the original program,
23392+
for some $j$;
23393+
\code{$p$.\id} is then transformed to \code{$\metavar{prefix}_j$.\id}.
23394+
\item
23395+
Replace every type in $L_i$ that denotes a type alias
23396+
along with its actual type arguments, if any,
2337723397
by its transitive alias expansion
2337823398
(\ref{typedef}).
2337923399
\commentary{%
@@ -23385,15 +23405,32 @@ \subsubsection{The Canonical Syntax of Types}
2338523405
\end{enumerate}
2338623406

2338723407
\commentary{%
23388-
Note that this transformation does not change any occurrence of \VOID;
23389-
\VOID{} is a reserved word, not an identifier.
23408+
This transformation does not change any occurrence of \VOID;
23409+
\VOID{} is a reserved word, not a type identifier.
2339023410
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
2339123411

23412+
Note that the transformation changes terms derived from \synt{type},
23413+
but it does not change expressions, or any other program element
23414+
(except that a \synt{type} can occur in an expression, e.g., \code{<int>[]}).
23415+
In particular, it does not change type literals
23416+
(that is, expressions denoting types).
23417+
2339223418
The transformation also does not change identifiers denoting type variables,
23419+
because they are never resolved to a library declaration,
23420+
they are always introduced by a scope which is nested inside the library scope.
2339323421
There is no need to change those identifiers, because
23394-
no occurrence of such an identifier resolves to a declaration in a
23395-
different library.%
23396-
%% TODO(eernst): Sort out the treatment of private identifiers, too.
23422+
no occurrence of such an identifier in the type of an expression
23423+
denotes a declaration in a different library.%
23424+
}
23425+
23426+
\rationale{%
23427+
The only purpose of this transformation is to obtain a
23428+
location-independent designation of all types,
23429+
in such a way that each \synt{typeName} resolves to the same declaration
23430+
before and after the transformation.
23431+
The program behavior may change due to different values returned from
23432+
\code{toString()} on reified types,
23433+
but the transformation is otherwise semantics preserving.%
2339723434
}
2339823435

2339923436
\LMHash{}%
@@ -23430,15 +23467,21 @@ \subsubsection{The Canonical Syntax of Types}
2343023467
because we would need to re-build all the structures that the
2343123468
syntax offers.
2343223469
For instance, we would need to support the construction of
23433-
a semantic type entity for \code{Map<int, String>},
23434-
based on the semantic type entity for \code{int}, \code{String}, and \code{Map},
23470+
a semantic type entity for \code{Map<int,\,String>},
23471+
based on the semantic type entities for
23472+
\code{int}, \code{String}, and \code{Map},
2343523473
and we would need to support deconstruction of those entities
23436-
in order to prove things like \SubtypeNE{Never}{\code{Map<int, String>}}.
23474+
in order to prove things like
23475+
\SubtypeNE{\code{Map<Never,\,Never>}}{\code{Map<int,\,String>}}.
2343723476
This would give rise to a lot of mechanism that will simply duplicate
2343823477
the structure of the syntax.
2343923478
So we prefer to show that the syntax \emph{can} be location independent,
2344023479
and that's sufficient to make syntax usable as our representation of
23441-
static semantic types.%
23480+
static semantic types.
23481+
23482+
We are basically taking the approach that a static semantic type is
23483+
an equivalence class of all syntactic elements derived from \synt{type}
23484+
that have the same canonical syntax.%
2344223485
}
2344323486

2344423487

@@ -23529,6 +23572,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
2352923572
Finally, it is assumed that all types are denoted by their canonical syntax
2353023573
(\ref{theCanonicalSyntaxOfTypes}).
2353123574

23575+
\commentary{%
23576+
This implies that type aliases have already been fully expanded,
23577+
and two types are the same if and only if they have the same syntax.%
23578+
}
23579+
2353223580
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
2353323581
\LMHash{}%
2353423582
We define the

0 commit comments

Comments
 (0)