Skip to content

Commit 5931e47

Browse files
committed
Constant instances (in particular: about canonical instances)
1 parent e972003 commit 5931e47

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
@@ -10428,6 +10428,13 @@ \subsubsection{Lists}
1042810428
the result of evaluating a constant expression.%
1042910429
}
1043010430

10431+
\LMHash{}%
10432+
The canonical instance of a constant list literal has a type argument
10433+
which is transitively alias expanded
10434+
(\ref{typedef})
10435+
and normalized
10436+
(\ref{typeNormalization}).
10437+
1043110438
\LMHash{}%
1043210439
A run-time list literal
1043310440
\code{<$T$>[\List{\ell}{1}{m}]}
@@ -11242,6 +11249,13 @@ \subsubsection{Sets}
1124211249
the result of evaluating a constant expression.%
1124311250
}
1124411251

11252+
\LMHash{}%
11253+
The canonical instance of a constant set literal has a type argument
11254+
which is transitively alias expanded
11255+
(\ref{typedef})
11256+
and normalized
11257+
(\ref{typeNormalization}).
11258+
1124511259
\LMHash{}%
1124611260
A run-time set literal \code{<$T$>\{\List{\ell}{1}{n}\}}
1124711261
is evaluated as follows:
@@ -11437,6 +11451,13 @@ \subsubsection{Maps}
1143711451
the result of evaluating a constant expression.%
1143811452
}
1143911453

11454+
\LMHash{}%
11455+
The canonical instance of a constant map literal has type arguments
11456+
which are transitively alias expanded
11457+
(\ref{typedef})
11458+
and normalized
11459+
(\ref{typeNormalization}).
11460+
1144011461
\LMHash{}%
1144111462
A run-time map literal
1144211463
\code{<$T_1, T_2$>\{\List{\ell}{1}{m}\}}
@@ -12221,6 +12242,14 @@ \subsubsection{Const}
1222112242
The constructor need only be executed once per call site, at compile time.%
1222212243
}
1222312244

12245+
\LMHash{}%
12246+
For instances of a generic class,
12247+
the canonical instance of a constant object expression has type arguments
12248+
which are transitively alias expanded
12249+
(\ref{typedef})
12250+
and normalized
12251+
(\ref{typeNormalization}).
12252+
1222412253
\LMHash{}%
1222512254
It is a \Error{compile-time error} if evaluation of a constant object
1222612255
results in an uncaught exception being thrown.
@@ -13294,6 +13323,14 @@ \subsection{Function Closurization}
1329413323
are canonicalized.%
1329513324
}
1329613325

13326+
\LMHash{}%
13327+
The canonical instance of a constant function closurization has
13328+
parameter types and a return type
13329+
which are transitively alias expanded
13330+
(\ref{typedef})
13331+
and normalized
13332+
(\ref{typeNormalization}).
13333+
1329713334

1329813335
\subsection{Generic Function Instantiation}
1329913336
\LMLabel{genericFunctionInstantiation}
@@ -24190,36 +24227,10 @@ \subsubsection{Null promotion}
2419024227
These are extended as per
2419124228
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2419224229

24193-
2419424230
\paragraph{Constant instances}
2419524231

2419624232
!!!TODO!!!
2419724233

24198-
Any two instances which are otherwise identical except for their
24199-
generic type arguments shall be considered identical if those generic
24200-
type arguments compare equal using the definition of runtime type
24201-
object equality defined above. That is, comparison (or
24202-
canonicalization) of constant instances of generic classes is
24203-
performed relative to the normal forms of their generic type
24204-
arguments. Hence, an instance of \code{$C$<$T_0$>} compares identical
24205-
to \code{C<$T_1$>} if $T_0$ and $T_1$ have the same normal form (up to
24206-
the identity of bound variables), and the objects are otherwise
24207-
identical.
24208-
24209-
Implementations of the Dart runtime semantics rely on canonicalization of
24210-
constant objects to allow the identity semantics specified above to be
24211-
implemented as fast pointer equality checks on the reference to the canonical
24212-
form. The definition above defines equivalence classes of constant objects for
24213-
which we must choose the canonical representative.
24214-
24215-
We define the choice of the canonical instance representing an
24216-
equivalence class of constant objects as follows.
24217-
24218-
All generic constant constructors and generic constant
24219-
literals are evaluated using the type arguments provided, and canonicalization
24220-
is performed with respect to the normal form of the type arguments. This
24221-
ensures a consistent semantics, since it is not observable which instance is
24222-
chosen as the canonical representative.
2422324234

2422424235
\subsubsection{Null check operator}
2422524236

0 commit comments

Comments
 (0)