Skip to content

Commit 0ff8703

Browse files
committed
Constant instances (in particular: about canonical instances)
1 parent 98d7d32 commit 0ff8703

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
@@ -10498,6 +10498,13 @@ \subsubsection{Lists}
1049810498
the result of evaluating a constant expression.%
1049910499
}
1050010500

10501+
\LMHash{}%
10502+
The canonical instance of a constant list literal has a type argument
10503+
which is transitively alias expanded
10504+
(\ref{typedef})
10505+
and normalized
10506+
(\ref{typeNormalization}).
10507+
1050110508
\LMHash{}%
1050210509
A run-time list literal
1050310510
\code{<$T$>[\List{\ell}{1}{m}]}
@@ -11312,6 +11319,13 @@ \subsubsection{Sets}
1131211319
the result of evaluating a constant expression.%
1131311320
}
1131411321

11322+
\LMHash{}%
11323+
The canonical instance of a constant set literal has a type argument
11324+
which is transitively alias expanded
11325+
(\ref{typedef})
11326+
and normalized
11327+
(\ref{typeNormalization}).
11328+
1131511329
\LMHash{}%
1131611330
A run-time set literal \code{<$T$>\{\List{\ell}{1}{n}\}}
1131711331
is evaluated as follows:
@@ -11507,6 +11521,13 @@ \subsubsection{Maps}
1150711521
the result of evaluating a constant expression.%
1150811522
}
1150911523

11524+
\LMHash{}%
11525+
The canonical instance of a constant map literal has type arguments
11526+
which are transitively alias expanded
11527+
(\ref{typedef})
11528+
and normalized
11529+
(\ref{typeNormalization}).
11530+
1151011531
\LMHash{}%
1151111532
A run-time map literal
1151211533
\code{<$T_1, T_2$>\{\List{\ell}{1}{m}\}}
@@ -12320,6 +12341,14 @@ \subsubsection{Const}
1232012341
The constructor need only be executed once per call site, at compile time.%
1232112342
}
1232212343

12344+
\LMHash{}%
12345+
For instances of a generic class,
12346+
the canonical instance of a constant object expression has type arguments
12347+
which are transitively alias expanded
12348+
(\ref{typedef})
12349+
and normalized
12350+
(\ref{typeNormalization}).
12351+
1232312352
\LMHash{}%
1232412353
It is a \Error{compile-time error} if evaluation of a constant object
1232512354
results in an uncaught exception being thrown.
@@ -13396,6 +13425,14 @@ \subsection{Function Closurization}
1339613425
are canonicalized.%
1339713426
}
1339813427

13428+
\LMHash{}%
13429+
The canonical instance of a constant function closurization has
13430+
parameter types and a return type
13431+
which are transitively alias expanded
13432+
(\ref{typedef})
13433+
and normalized
13434+
(\ref{typeNormalization}).
13435+
1339913436

1340013437
\subsection{Generic Function Instantiation}
1340113438
\LMLabel{genericFunctionInstantiation}
@@ -24458,36 +24495,10 @@ \subsubsection{Null promotion}
2445824495
These are extended as per
2445924496
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2446024497

24461-
2446224498
\paragraph{Constant instances}
2446324499

2446424500
!!!TODO!!!
2446524501

24466-
Any two instances which are otherwise identical except for their
24467-
generic type arguments shall be considered identical if those generic
24468-
type arguments compare equal using the definition of runtime type
24469-
object equality defined above. That is, comparison (or
24470-
canonicalization) of constant instances of generic classes is
24471-
performed relative to the normal forms of their generic type
24472-
arguments. Hence, an instance of \code{$C$<$T_0$>} compares identical
24473-
to \code{C<$T_1$>} if $T_0$ and $T_1$ have the same normal form (up to
24474-
the identity of bound variables), and the objects are otherwise
24475-
identical.
24476-
24477-
Implementations of the Dart runtime semantics rely on canonicalization of
24478-
constant objects to allow the identity semantics specified above to be
24479-
implemented as fast pointer equality checks on the reference to the canonical
24480-
form. The definition above defines equivalence classes of constant objects for
24481-
which we must choose the canonical representative.
24482-
24483-
We define the choice of the canonical instance representing an
24484-
equivalence class of constant objects as follows.
24485-
24486-
All generic constant constructors and generic constant
24487-
literals are evaluated using the type arguments provided, and canonicalization
24488-
is performed with respect to the normal form of the type arguments. This
24489-
ensures a consistent semantics, since it is not observable which instance is
24490-
chosen as the canonical representative.
2449124502

2449224503
\subsubsection{Null check operator}
2449324504

0 commit comments

Comments
 (0)