Skip to content

Commit 99e261f

Browse files
committed
Constant instances (in particular: about canonical instances)
1 parent 563d587 commit 99e261f

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
@@ -10676,6 +10676,13 @@ \subsubsection{Lists}
1067610676
the result of evaluating a constant expression.%
1067710677
}
1067810678

10679+
\LMHash{}%
10680+
The canonical instance of a constant list literal has a type argument
10681+
which is transitively alias expanded
10682+
(\ref{typedef})
10683+
and normalized
10684+
(\ref{typeNormalization}).
10685+
1067910686
\LMHash{}%
1068010687
A run-time list literal
1068110688
\code{<$T$>[\List{\ell}{1}{m}]}
@@ -11490,6 +11497,13 @@ \subsubsection{Sets}
1149011497
the result of evaluating a constant expression.%
1149111498
}
1149211499

11500+
\LMHash{}%
11501+
The canonical instance of a constant set literal has a type argument
11502+
which is transitively alias expanded
11503+
(\ref{typedef})
11504+
and normalized
11505+
(\ref{typeNormalization}).
11506+
1149311507
\LMHash{}%
1149411508
A run-time set literal \code{<$T$>\{\List{\ell}{1}{n}\}}
1149511509
is evaluated as follows:
@@ -11685,6 +11699,13 @@ \subsubsection{Maps}
1168511699
the result of evaluating a constant expression.%
1168611700
}
1168711701

11702+
\LMHash{}%
11703+
The canonical instance of a constant map literal has type arguments
11704+
which are transitively alias expanded
11705+
(\ref{typedef})
11706+
and normalized
11707+
(\ref{typeNormalization}).
11708+
1168811709
\LMHash{}%
1168911710
A run-time map literal
1169011711
\code{<$T_1, T_2$>\{\List{\ell}{1}{m}\}}
@@ -12504,6 +12525,14 @@ \subsubsection{Const}
1250412525
The constructor need only be executed once per call site, at compile time.%
1250512526
}
1250612527

12528+
\LMHash{}%
12529+
For instances of a generic class,
12530+
the canonical instance of a constant object expression has type arguments
12531+
which are transitively alias expanded
12532+
(\ref{typedef})
12533+
and normalized
12534+
(\ref{typeNormalization}).
12535+
1250712536
\LMHash{}%
1250812537
It is a \Error{compile-time error} if evaluation of a constant object
1250912538
results in an uncaught exception being thrown.
@@ -13580,6 +13609,14 @@ \subsection{Function Closurization}
1358013609
are canonicalized.%
1358113610
}
1358213611

13612+
\LMHash{}%
13613+
The canonical instance of a constant function closurization has
13614+
parameter types and a return type
13615+
which are transitively alias expanded
13616+
(\ref{typedef})
13617+
and normalized
13618+
(\ref{typeNormalization}).
13619+
1358313620

1358413621
\subsection{Generic Function Instantiation}
1358513622
\LMLabel{genericFunctionInstantiation}
@@ -24696,36 +24733,10 @@ \subsubsection{Null promotion}
2469624733
These are extended as per
2469724734
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2469824735

24699-
2470024736
\paragraph{Constant instances}
2470124737

2470224738
!!!TODO!!!
2470324739

24704-
Any two instances which are otherwise identical except for their
24705-
generic type arguments shall be considered identical if those generic
24706-
type arguments compare equal using the definition of runtime type
24707-
object equality defined above. That is, comparison (or
24708-
canonicalization) of constant instances of generic classes is
24709-
performed relative to the normal forms of their generic type
24710-
arguments. Hence, an instance of \code{$C$<$T_0$>} compares identical
24711-
to \code{C<$T_1$>} if $T_0$ and $T_1$ have the same normal form (up to
24712-
the identity of bound variables), and the objects are otherwise
24713-
identical.
24714-
24715-
Implementations of the Dart runtime semantics rely on canonicalization of
24716-
constant objects to allow the identity semantics specified above to be
24717-
implemented as fast pointer equality checks on the reference to the canonical
24718-
form. The definition above defines equivalence classes of constant objects for
24719-
which we must choose the canonical representative.
24720-
24721-
We define the choice of the canonical instance representing an
24722-
equivalence class of constant objects as follows.
24723-
24724-
All generic constant constructors and generic constant
24725-
literals are evaluated using the type arguments provided, and canonicalization
24726-
is performed with respect to the normal form of the type arguments. This
24727-
ensures a consistent semantics, since it is not observable which instance is
24728-
chosen as the canonical representative.
2472924740

2473024741
\subsubsection{Null check operator}
2473124742

0 commit comments

Comments
 (0)