Skip to content

Commit 7b59bfa

Browse files
committed
Constant instances (in particular: about canonical instances)
1 parent 0b2e748 commit 7b59bfa

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

specification/dartLangSpec.tex

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10484,6 +10484,13 @@ \subsubsection{Lists}
1048410484
the result of evaluating a constant expression.%
1048510485
}
1048610486

10487+
\LMHash{}%
10488+
The canonical instance of a constant list literal has a type argument
10489+
which is transitively alias expanded
10490+
(\ref{typedef})
10491+
and normalized
10492+
(\ref{typeNormalization}).
10493+
1048710494
\LMHash{}%
1048810495
A run-time list literal
1048910496
\code{<$T$>[\List{\ell}{1}{m}]}
@@ -11298,6 +11305,13 @@ \subsubsection{Sets}
1129811305
the result of evaluating a constant expression.%
1129911306
}
1130011307

11308+
\LMHash{}%
11309+
The canonical instance of a constant set literal has a type argument
11310+
which is transitively alias expanded
11311+
(\ref{typedef})
11312+
and normalized
11313+
(\ref{typeNormalization}).
11314+
1130111315
\LMHash{}%
1130211316
A run-time set literal \code{<$T$>\{\List{\ell}{1}{n}\}}
1130311317
is evaluated as follows:
@@ -11493,6 +11507,13 @@ \subsubsection{Maps}
1149311507
the result of evaluating a constant expression.%
1149411508
}
1149511509

11510+
\LMHash{}%
11511+
The canonical instance of a constant map literal has type arguments
11512+
which are transitively alias expanded
11513+
(\ref{typedef})
11514+
and normalized
11515+
(\ref{typeNormalization}).
11516+
1149611517
\LMHash{}%
1149711518
A run-time map literal
1149811519
\code{<$T_1, T_2$>\{\List{\ell}{1}{m}\}}
@@ -12306,6 +12327,14 @@ \subsubsection{Const}
1230612327
The constructor need only be executed once per call site, at compile time.%
1230712328
}
1230812329

12330+
\LMHash{}%
12331+
For instances of a generic class,
12332+
the canonical instance of a constant object expression has type arguments
12333+
which are transitively alias expanded
12334+
(\ref{typedef})
12335+
and normalized
12336+
(\ref{typeNormalization}).
12337+
1230912338
\LMHash{}%
1231012339
It is a \Error{compile-time error} if evaluation of a constant object
1231112340
results in an uncaught exception being thrown.
@@ -13382,6 +13411,14 @@ \subsection{Function Closurization}
1338213411
are canonicalized.%
1338313412
}
1338413413

13414+
\LMHash{}%
13415+
The canonical instance of a constant function closurization has
13416+
parameter types and a return type
13417+
which are transitively alias expanded
13418+
(\ref{typedef})
13419+
and normalized
13420+
(\ref{typeNormalization}).
13421+
1338513422

1338613423
\subsection{Generic Function Instantiation}
1338713424
\LMLabel{genericFunctionInstantiation}
@@ -24319,36 +24356,10 @@ \subsubsection{Null promotion}
2431924356
These are extended as per
2432024357
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2432124358

24322-
2432324359
\paragraph{Constant instances}
2432424360

2432524361
!!!TODO!!!
2432624362

24327-
Any two instances which are otherwise identical except for their
24328-
generic type arguments shall be considered identical if those generic
24329-
type arguments compare equal using the definition of runtime type
24330-
object equality defined above. That is, comparison (or
24331-
canonicalization) of constant instances of generic classes is
24332-
performed relative to the normal forms of their generic type
24333-
arguments. Hence, an instance of \code{$C$<$T_0$>} compares identical
24334-
to \code{C<$T_1$>} if $T_0$ and $T_1$ have the same normal form (up to
24335-
the identity of bound variables), and the objects are otherwise
24336-
identical.
24337-
24338-
Implementations of the Dart runtime semantics rely on canonicalization of
24339-
constant objects to allow the identity semantics specified above to be
24340-
implemented as fast pointer equality checks on the reference to the canonical
24341-
form. The definition above defines equivalence classes of constant objects for
24342-
which we must choose the canonical representative.
24343-
24344-
We define the choice of the canonical instance representing an
24345-
equivalence class of constant objects as follows.
24346-
24347-
All generic constant constructors and generic constant
24348-
literals are evaluated using the type arguments provided, and canonicalization
24349-
is performed with respect to the normal form of the type arguments. This
24350-
ensures a consistent semantics, since it is not observable which instance is
24351-
chosen as the canonical representative.
2435224363

2435324364
\subsubsection{Null check operator}
2435424365

0 commit comments

Comments
 (0)