@@ -22480,7 +22480,8 @@ \subsubsection{Subtype Rules}
22480
22480
22481
22481
\LMHash{}%
22482
22482
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
22484
22485
(\ref{theCanonicalSyntaxOfTypes}).
22485
22486
22486
22487
\commentary{%
@@ -23317,7 +23318,12 @@ \subsubsection{The Canonical Syntax of Types}
23317
23318
and $L_2$ could declare a function
23318
23319
\code{\VOID\,foo(C\,\,c)\,\,\{\}}
23319
23320
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.%
23321
23327
}
23322
23328
23323
23329
\rationale{%
@@ -23340,16 +23346,28 @@ \subsubsection{The Canonical Syntax of Types}
23340
23346
}
23341
23347
23342
23348
\LMHash{}%
23343
- To determine the
23349
+ The
23344
23350
\IndexCustom{canonical syntax}{type!canonical syntax of}
23345
23351
of the types in a given library $L_1$
23346
23352
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
23349
23356
\List{\metavar{prefix}}{1}{n}.
23350
23357
Then transform each library $L_i$, $i \in 1 .. n$ as follows:
23351
23358
23352
23359
\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
+ }
23353
23371
\item
23354
23372
Add a set of import directives to $L_i$ that imports
23355
23373
each of the libraries \List{L}{1}{n} with
@@ -23362,18 +23380,20 @@ \subsubsection{The Canonical Syntax of Types}
23362
23380
even itself and system libraries like \code{dart:core}.%
23363
23381
}
23364
23382
\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,
23377
23397
by its transitive alias expansion
23378
23398
(\ref{typedef}).
23379
23399
\commentary{%
@@ -23385,15 +23405,32 @@ \subsubsection{The Canonical Syntax of Types}
23385
23405
\end{enumerate}
23386
23406
23387
23407
\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.
23390
23410
Also, \code{$\metavar{prefix}_j$.\VOID} would be a syntax error.
23391
23411
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
+
23392
23418
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.
23393
23421
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.%
23397
23434
}
23398
23435
23399
23436
\LMHash{}%
@@ -23430,15 +23467,21 @@ \subsubsection{The Canonical Syntax of Types}
23430
23467
because we would need to re-build all the structures that the
23431
23468
syntax offers.
23432
23469
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},
23435
23473
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>}}.
23437
23476
This would give rise to a lot of mechanism that will simply duplicate
23438
23477
the structure of the syntax.
23439
23478
So we prefer to show that the syntax \emph{can} be location independent,
23440
23479
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.%
23442
23485
}
23443
23486
23444
23487
@@ -23529,6 +23572,11 @@ \subsubsection{Standard Upper Bounds and Standard Lower Bounds}
23529
23572
Finally, it is assumed that all types are denoted by their canonical syntax
23530
23573
(\ref{theCanonicalSyntaxOfTypes}).
23531
23574
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
+
23532
23580
%% TODO(eernst), for review: Is this the correct associativity of SUB/SLB?
23533
23581
\LMHash{}%
23534
23582
We define the
0 commit comments