Skip to content

Commit 55fdf3f

Browse files
committed
Main
1 parent d12166d commit 55fdf3f

File tree

1 file changed

+86
-68
lines changed

1 file changed

+86
-68
lines changed

specification/dartLangSpec.tex

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8835,13 +8835,11 @@ \subsection{Constants}
88358835
respectively a constant type expression
88368836
if{}f $T$ is a potentially constant type expression
88378837
respectively a constant type expression.
8838-
\item
8839-
A type variable is a potentially constant type expression.
88408838
\item
88418839
%% TODO(eernst): This does not allow for type variables introduced by
88428840
%% the type itself. `Function<X>(X)` could be a constant type expression,
88438841
%% but that is not covered by the current rules: `X` is a type variable,
8844-
%% and they are never allowed.
8842+
%% and they are never constant type expressions.
88458843
A function type
88468844
\code{$R$ Function<\metavar{typeParameters}>(\metavar{parameterTypes})}
88478845
(where $R$ and \code{<\metavar{typeParameters}>} may be omitted)
@@ -8851,9 +8849,11 @@ \subsection{Constants}
88518849
(if present) contain only potentially constant type expressions
88528850
respectively constant type expressions.
88538851
\item
8854-
The type \VOID is a potentially constant and a constant type expression.
8852+
The type \VOID{} is a potentially constant and a constant type expression.
8853+
\item
8854+
The type \DYNAMIC{} is a potentially constant and a constant type expression.
88558855
\item
8856-
The type \DYNAMIC is a potentially constant and a constant type expression.
8856+
A type variable is a potentially constant type expression.
88578857
\end{itemize}
88588858

88598859
% Being potentially constant is entirely structural, not type based,
@@ -20926,6 +20926,76 @@ \subsection{Parts}
2092620926
\subsection{Scripts}
2092720927
\LMLabel{scripts}
2092820928

20929+
\LMHash{}%
20930+
Let $L$ be a library that exports a declaration $D$ named \code{main}.
20931+
It is a \Error{compile-time error} unless $D$ is
20932+
a non-getter function declaration.
20933+
It is a \Error{compile-time error} if $D$ declares
20934+
more than two required positional parameters,
20935+
or if there are any required named parameters.
20936+
It is a \Error{compile-time error} if $D$ declares
20937+
at least one positional parameter,
20938+
and the first positional parameter has a type which is
20939+
not a supertype of \code{List<String>}.
20940+
20941+
\LMHash{}%
20942+
Implementations are free to impose any additional restrictions on
20943+
the signature of \code{main}.
20944+
20945+
\LMHash{}%
20946+
A \Index{script} is a library that exports a declaration named \code{main}.
20947+
A script $L$ is executed as follows:
20948+
20949+
\LMHash{}%
20950+
First, $L$ is compiled as a library as specified above.
20951+
Then, the top-level function defined by \code{main}
20952+
in the exported namespace of $L$ is invoked as follows:
20953+
20954+
\LMHash{}%
20955+
If \code{main} can be called with two positional arguments,
20956+
it is invoked with the following two actual arguments:
20957+
20958+
\begin{itemize}
20959+
\item
20960+
An object whose run-time type implements \code{List<String>}.
20961+
\item
20962+
An object specified when the current isolate $i$ was created,
20963+
(\commentary{%
20964+
for example through the invocation of \code{Isolate.spawnUri}
20965+
that spawned $i$%
20966+
}),
20967+
or the null object if no such object was supplied.
20968+
A dynamic error occurs if
20969+
the run-time type of this object is not a subtype of
20970+
the declared type of the corresponding parameter of \code{main}.
20971+
\end{itemize}
20972+
20973+
\LMHash{}%
20974+
If \code{main} cannot be called with two positional arguments,
20975+
but it can be called with one positional argument,
20976+
it is invoked with an object whose run-time type implements \code{List<String>}
20977+
as the only argument.
20978+
20979+
\LMHash{}%
20980+
If \code{main} cannot be called with one or two positional arguments,
20981+
it is invoked with no arguments.
20982+
20983+
\LMHash{}%
20984+
In each of the above three cases,
20985+
an implementation is free to provide additional arguments
20986+
allowed by the signature of \code{main}
20987+
(\commentary{%
20988+
the above rules ensure that the corresponding parameters are optional%
20989+
}).
20990+
But the implementation must ensure that a dynamic error occurs
20991+
if an actual argument does not have a run-time type which is
20992+
a subtype of the declared type of the parameter.
20993+
20994+
\LMHash{}%
20995+
A Dart program will typically be executed by executing a script.
20996+
The procedure whereby this script is chosen is implementation specific.
20997+
20998+
----------------------------------------------------------------------
2092920999
\LMHash{}%
2093021000
A \Index{script} is a library whose exported namespace (\ref{exports}) includes
2093121001
a top-level function declaration named \code{main}
@@ -24540,72 +24610,20 @@ \subsubsection{Null promotion}
2454024610
These are extended as per
2454124611
[separate proposal](https://github.com/dart-lang/language/blob/master/resources/type-system/flow-analysis.md).
2454224612

24543-
\subsubsection{The main function}
24613+
\subsubsection{Runtime type equality operator}
2454424614

2454524615
!!!TODO!!!
2454624616

24547-
The section 'Scripts' in the language specification is replaced by the
24548-
following:
24549-
24550-
Let $L$ be a library that exports a declaration $D$ named \code{main}.
24551-
It is a \Error{compile-time error} unless $D$ is a non-getter function
24552-
declaration. It is a \Error{compile-time error} if $D$ declares more
24553-
than two required positional parameters, or if there are any required
24554-
named parameters. It is a \Error{compile-time error} if $D$ declares
24555-
at least one positional parameter, and the first positional parameter
24556-
has a type which is not a supertype of \code{List<String>}.
24557-
24558-
Implementations are free to impose any additional restrictions on the
24559-
signature of \code{main}.
24560-
24561-
A _script_ is a library that exports a declaration named \code{main}.
24562-
A script $L$ is executed as follows:
24563-
24564-
First, $L$ is compiled as a library as specified above.
24565-
Then, the top-level function defined by \code{main}
24566-
in the exported namespace of $L$ is invoked as follows:
24567-
24568-
If \code{main} can be called with two positional arguments,
24569-
it is invoked with the following two actual arguments:
24570-
24571-
\begin{itemize}
24572-
\item An object whose run-time type implements \code{List<String>}.
24573-
\item An object specified when the current isolate $i$ was created,
24574-
for example through the invocation of \code{Isolate.spawnUri} that spawned $i$,
24575-
or the null object if no such object was supplied.
24576-
A dynamic error occurs if the run-time type of this object is not a
24577-
subtype of the declared type of the corresponding parameter of \code{main}.
24578-
\end{itemize}
24579-
24580-
If \code{main} cannot be called with two positional arguments, but it can be
24581-
called with one positional argument, it is invoked with an object whose
24582-
run-time type implements \code{List<String>} as the only argument.
24583-
24584-
If \code{main} cannot be called with one or two positional arguments, it is
24585-
invoked with no arguments.
24586-
24587-
In each of the above three cases, an implementation is free to provide
24588-
additional arguments allowed by the signature of \code{main}
24589-
(\commentary{the above rules ensure that the corresponding parameters are optional}).
24590-
But the implementation must ensure that a dynamic error occurs if an
24591-
actual argument does not have a run-time type which is a subtype of
24592-
the declared type of the parameter.
24593-
24594-
A Dart program will typically be executed by executing a script. The
24595-
procedure whereby this script is chosen is implementation specific.
24596-
24597-
\subsection{Runtime semantics}
24598-
24599-
\subsubsection{Runtime type equality operator}
24600-
24601-
Two objects $T_1$ and $T_2$ which are instances of \code{Type} (that is, runtime type
24602-
objects) are considered equal if and only if the runtime type objects $T_1$ and
24603-
$T_2$ corresponds to the types $S_1$ and $S_2$ respectively, and the normal forms
24604-
\NormalizedTypeOf{$S_1$} and \NormalizedTypeOf{$S_2$} are syntactically equal up to equivalence of
24605-
bound variables. Note that we do not equate primitive top types. \code{List<\VOID>}
24606-
and \code{List<\DYNAMIC>} are still considered distinct runtime type objects. Note
24607-
that we also do not equate function
24608-
types which differ in the placement of \REQUIRED{} on parameter types.
24617+
Two objects $T_1$ and $T_2$ which are instances of \code{Type} (that
24618+
is, runtime type objects) are considered equal if and only if the
24619+
runtime type objects $T_1$ and $T_2$ corresponds to the types $S_1$
24620+
and $S_2$ respectively, and the normal forms \NormalizedTypeOf{$S_1$}
24621+
and \NormalizedTypeOf{$S_2$} are syntactically equal up to equivalence
24622+
of bound variables. Note that we do not equate primitive top types.
24623+
\code{List<\VOID>} and \code{List<\DYNAMIC>} are still considered
24624+
distinct runtime type objects. Note that we also do not equate
24625+
function types which differ in the placement of \REQUIRED{} on
24626+
parameter types.
2460924627

2461024628
\subsubsection{Constant evaluation and canonicalization}
2461124629

0 commit comments

Comments
 (0)