Skip to content

Commit 9848289

Browse files
eernstglrhn
authored andcommitted
Specify null safety: Sections 'Variables' and 'Local Variable Declarations' (#2052)
Integrate the null-safety aware sections about variables and local variable declarations in the the language specification. Also updates the terminology to talk about 'static X' meaning a member declaration that includes the keyword `static` (or a member whose declaration includes `static`). This means that we avoid having the extremely confusing phrase 'static variable' (meaning a top-level variable or a variable whose declaration includes `static`). The new meaning of 'static variable' is simply a variable whose declaration includes `static`. Eliminated the single occurrence of 'static function' (now using 'static member', which is well defined). Similarly, updates the terminology to avoid the words 'mutable' and 'immutable' (about variables). The reason for this is that the concept of being immutable is confusing now that we have `late final v;`: That declaration induces a setter, but it is semantically immutable (because it may be initialized, but it will never update the initial value to a different value).
1 parent 7befd1d commit 9848289

File tree

2 files changed

+896
-313
lines changed

2 files changed

+896
-313
lines changed

specification/dart.sty

+214-44
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
\def\WITH{\keyword{with}}
6969
\def\YIELD{\keyword{yield}}
7070

71+
% Used for inline code snippets.
72+
\newcommand{\code}[1]{\texttt{#1}}
73+
7174
% Used to specify syntactic sugar.
7275
\def\LET{\keyword{let}}
7376
\newcommand{\Let}[3]{\code{\LET\,\,{#1}\,=\,{#2}\ \IN\ {#3}}}
@@ -78,8 +81,8 @@
7881
\newcommand{\LetMany}[5]{%
7982
\code{\LET\,\,{#1}\,=\,{#2},\ $\cdots$,\ {#3}\,=\,{#4}\ \IN\ {#5}}}
8083

81-
% Used for inline code snippets.
82-
\def\code#1{\texttt{#1}}
84+
% Used for inline meta-code snippets
85+
\newcommand{\metaCode}[1]{{\color{metaColor}\texttt{#1}}}
8386

8487
% `call` has no special lexical status, so we just use \code{}.
8588
\def\CALL{\code{call}}
@@ -112,6 +115,7 @@
112115
\definecolor{normativeColor}{rgb}{0,0,0}
113116
\definecolor{commentaryColor}{rgb}{0.5,0.5,0.5}
114117
\definecolor{rationaleColor}{rgb}{0.5,0.5,0.5}
118+
\definecolor{metaColor}{rgb}{0,0,1}
115119

116120
% Environments for different kinds of text.
117121
\newenvironment{Q}[1]{{\bf{}Upcoming: {#1}}}{}
@@ -132,22 +136,35 @@
132136
\newcommand{\Case}[1]{\textbf{Case }$\langle\hspace{0.1em}${#1}$\hspace{0.1em}\rangle$\textbf{.}}
133137
\newcommand{\EndCase}{\mbox{}\hfill$\scriptscriptstyle\Box$\xspace}
134138

135-
\newenvironment{dartCode}[1][!ht] {%
139+
% Used for source code examples.
140+
\newenvironment{dartCode}[1][!ht]{%
136141
\def\@programcr{\@addfield\strut}%
137142
\let\\=\@programcr%
138143
\relax\@vobeyspaces\obeylines%
139144
\ttfamily\color{commentaryColor}%
140145
\vspace{1em}%
141146
}{\normalcolor\vspace{1em}}
142147

143-
\newenvironment{normativeDartCode}[1][!ht] {%
148+
% Used for normative code snippets (mainly desugaring).
149+
\newenvironment{normativeDartCode}[1][!ht]{%
144150
\def\@programcr{\@addfield\strut}%
145151
\let\\=\@programcr%
146152
\relax\@vobeyspaces\obeylines%
147153
\ttfamily\color{normativeColor}%
148154
\vspace{1em}%
149155
}{\normalcolor\vspace{1em}}
150156

157+
% Used for meta-level code, such as the code transformations used
158+
% to specify the semantics of "null shorting" in expressions like
159+
% `a?.b.c`.
160+
\newenvironment{metaLevelCode}[1][!ht]{%
161+
\def\@programcr{\@addfield\strut}%
162+
\let\\=\@programcr%
163+
\relax\@vobeyspaces\obeylines%
164+
\ttfamily\color{metaColor}%
165+
\vspace{1em}%
166+
}{\normalcolor\vspace{1em}}
167+
151168
% Used for comments in a code context.
152169
\def\comment#1{\textsf{#1}}
153170

@@ -157,7 +174,7 @@
157174

158175
% Used for defining occurrence of phrase, with customized index entry.
159176
\newcommand{\IndexCustom}[2]{%
160-
\leavevmode\marginpar{\ensuremath{\diamond}}\emph{#1}\index{#2}}
177+
\leavevmode\marginpar{\ensuremath{_{^\vartriangle}}}\emph{#1}\index{#2}}
161178

162179
% Used for the defining occurrence of a local symbol.
163180
\newcommand{\DefineSymbol}[1]{%
@@ -178,7 +195,11 @@
178195

179196
% Same appearance, but not adding an entry to the index.
180197
\newcommand{\NoIndex}[1]{%
181-
\leavevmode\marginpar{\quad\ensuremath{\diamond}}\emph{#1}}
198+
\leavevmode\marginpar{\ensuremath{_{^\vartriangle}}}\emph{#1}}
199+
200+
% Mark a compile-time error in the margin.
201+
\newcommand{\Error}[1]{%
202+
\leavevmode\marginpar{\ensuremath{_{^\ominus}}}{#1}}
182203

183204
% Used to specify comma separated lists of similar symbols.
184205
\newcommand{\List}[3]{\ensuremath{{#1}_{#2},\,\ldots,\ {#1}_{#3}}}
@@ -190,6 +211,39 @@
190211
\newcommand{\PairList}[4]{\ensuremath{%
191212
{#1}_{#3}\ {#2}_{#3},\,\ldots,\ {#1}_{#4}\ {#2}_{#4}}}
192213

214+
% A sequence of labeled arguments with the same label and expression,
215+
% only differing by subscript.
216+
% Parameters: Argument label, argument expression, start index,
217+
% end index.
218+
%
219+
% For example, \NamedArgumentList{n}{e}{1}{k} yields approximately
220+
% "n1: e1, n2: e2, ... nk: ek".
221+
\newcommand{\NamedArgumentList}[4]{\PairList{#1}{\!\!:\,\,{#2}}{#3}{#4}}
222+
223+
% A sequence of unlabeled and labeled arguments with the same expression and
224+
% (for all labeled arguments) the same label, only differing by subscript.
225+
% Parameters: Argument name, number of positional arguments, labeled parameter
226+
% label, number of labeled arguments.
227+
%
228+
% For example, \ArgumentList{a}{n}{x}{k} yields approximately
229+
% "a1, .. an, xn+1: an+1, .. xn+k: an+k".
230+
\newcommand{\ArgumentList}[4]{%
231+
\List{#1}{1}{#2},\ \NamedArgumentList{#3}{#1}{{#2}+1}{{#2}+{#4}}}
232+
233+
% Used to specify a standard argument list, that is, an argument list
234+
% which uses the symbols that we prefer to use for that purpose
235+
% whenever possible.
236+
%
237+
% Approximately "a1 .. an, xn+1: an+1 .. xn+k: an+k".
238+
\newcommand{\ArgumentListStd}{\ArgumentList{a}{n}{x}{k}}
239+
240+
% Used to specify a standard type argument list, that is, a type
241+
% argument list which uses the symbols we prefer to use for that
242+
% purpose whenever possible.
243+
%
244+
% Approximately "A1 .. Ar".
245+
\newcommand{\TypeArgumentListStd}{\List{A}{1}{r}}
246+
193247
% Used to specify a list of tuples of the form $(K_j, V_j)$ which are
194248
% used with collection literals.
195249
\newcommand{\KeyValueTypeList}[4]{\ensuremath{%
@@ -224,7 +278,11 @@
224278
\newcommand{\TypeParametersNoBounds}[2]{\ensuremath{%
225279
{#1}_1\,\EXTENDS\,\ldots,\ \ldots,\ {#1}_{#2}\,\EXTENDS\,\ldots}}
226280

227-
% For consistency, we may as well use this whenever possible.
281+
% Used to specify a standard type parameter list, that is, a type
282+
% parameter declaration list which uses the symbols we prefer to use
283+
% for that purpose whenever possible.
284+
%
285+
% Approximately "X1 extends B1, .. Xs extends Bs".
228286
\newcommand{\TypeParametersStd}{\TypeParameters{X}{B}{s}}
229287

230288
% Used to specify comma separated lists of pairs of symbols
@@ -256,78 +314,140 @@
256314

257315
% Used to specify function type parameter lists with positional optionals.
258316
% Arguments: Parameter type, number of required parameters,
259-
% number of optional parameters.
260-
\newcommand{\FunctionTypePositionalArguments}[3]{%
317+
% number of optional parameters.
318+
%
319+
% For example, \FunctionTypePositionalParameters{T}{n}{k} yields
320+
% approximately "T1, .. Tn, [Tn+1, .. Tn+k]".
321+
\newcommand{\FunctionTypePositionalParameters}[3]{%
261322
\List{#1}{1}{#2},\ [\List{#1}{{#2}+1}{{#2}+{#3}}]}
262323

263-
\newcommand{\FunctionTypePositionalArgumentsStd}{%
264-
\FunctionTypePositionalArguments{T}{n}{k}}
324+
% Used to specify a standard positional function type, that is, a function
325+
% type with positional optional parameters which uses the symbols we prefer
326+
% to use for that purpose whenever possible.
327+
%
328+
% Approximately "T1, .. Tn, [Tn+1, .. Tn+k]".
329+
\newcommand{\FunctionTypePositionalParametersStd}{%
330+
\FunctionTypePositionalParameters{T}{n}{k}}
331+
332+
% Used to specify function type parameter lists with named optionals.
333+
% Arguments: Parameter type, number of required parameters,
334+
% name of optional parameters, number of optional parameters.
335+
%
336+
% For example \FunctionTypeNamedParameters{T}{n}{x}{k}{r} yields approximately
337+
% "T1, .. Tn, {rn+1 Tn+1 xn+1, .. rn+k Tn+k xn+k}".
338+
\newcommand{\FunctionTypeNamedParameters}[5]{%
339+
\List{#1}{1}{#2},\ \{\TripleList{#5}{#1}{#3}{{#2}+1}{{#2}+{#4}}\}}
340+
341+
% Variant of \FunctionTypeNamedParameters that uses the standard symbols,
342+
% that is, a list of function type parameter declarations with named
343+
% parameters which uses the symbols that we prefer to use for that purpose
344+
% whenever possible.
345+
%
346+
% Approximately "T1, .. Tn, {rn+1 Tn+1 xn+1, .. rn+k Tn+k xn+k}".
347+
\newcommand{\FunctionTypeNamedParametersStd}{%
348+
\FunctionTypeNamedParameters{T}{n}{x}{k}{r}}
265349

266350
% Used to specify function types with positional optionals:
267351
% Arguments: Return type, spacer, type parameter name, bound name,
268352
% number of type parameters, parameter type, number of required parameters,
269353
% number of optional parameters.
354+
%
355+
% For example, \FunctionTypePositional{R}{ }{X}{B}{s}{T}{n}{k} yields
356+
% approximately
357+
% "R Function<X1 extends B1, .. Xs extends Bs>(T1, .. Tn, [Tn+1, .. Tn+k])".
270358
\newcommand{\FunctionTypePositional}[8]{%
271359
\FunctionType{#1}{#2}{#3}{#4}{#5}{%
272-
\FunctionTypePositionalArguments{#6}{#7}{#8}}}
360+
\FunctionTypePositionalParameters{#6}{#7}{#8}}}
273361

274362
% Same as \FunctionTypePositional except suitable for inline usage,
275363
% hence omitting the spacer argument.
276364
\newcommand{\RawFunctionTypePositional}[7]{%
277365
\RawFunctionType{#1}{#2}{#3}{#4}{%
278-
\FunctionTypePositionalArguments{#5}{#6}{#7}}}
366+
\FunctionTypePositionalParameters{#5}{#6}{#7}}}
367+
368+
% A variant of \FunctionTypePositional that uses the standard symbols,
369+
% that is, a function type with positional optional parameters which
370+
% uses the symbols that we prefer to use for that purpose whenever
371+
% possible.
372+
%
373+
% For example, \FunctionTypePositionalStd{R} yields approximately
374+
% "R Function<X1 extends B1, .. Xs extends Bs>(T1, T2, .. Tn, [Tn+1 .. Tn+k])".
375+
\newcommand{\FunctionTypePositionalStd}[1]{%
376+
\FunctionTypePositional{#1}{ }{X}{B}{s}{T}{n}{k}}
279377

280-
% Used to specify function type parameter lists with named optionals.
281-
% Arguments: Parameter type, number of required parameters,
282-
% name of optional parameters, number of optional parameters.
283-
\newcommand{\FunctionTypeNamedArguments}[4]{%
284-
\List{#1}{1}{#2},\ \{\PairList{#1}{#3}{{#2}+1}{{#2}+{#4}}\}}
378+
% Same as \FunctionTypePositionalStd except suitable for inline usage,
379+
% hence omitting the spacer argument.
380+
\newcommand{\RawFunctionTypePositionalStd}[1]{%
381+
\RawFunctionTypePositional{#1}{X}{B}{s}{T}{n}{k}}
285382

286-
\newcommand{\FunctionTypeNamedArgumentsStd}{%
287-
\FunctionTypeNamedArguments{T}{n}{x}{k}}
383+
% Same as \FunctionTypePositionalStd except that it includes a newline, hence
384+
% suitable for function types that are too long to fit in one line.
385+
\newcommand{\FunctionTypePositionalStdCr}[1]{%
386+
\FunctionTypePositional{#1}{\\}{X}{B}{s}{T}{n}{k}}
288387

289388
% Used to specify function types with named parameters:
290389
% Arguments: Return type, spacer, type parameter name, bound name,
291390
% number of type parameters, parameter type, number of required parameters,
292391
% name of optional parameters, number of optional parameters.
392+
% The name of the `required` symbol is always `r` (because we can't have
393+
% 10 arguments in a LaTeX command, and `r` is always OK in practice).
394+
%
395+
% For example, \FunctionTypeNamed{R}{ }{X}{B}{s}{T}{n}{x}{k} yields
396+
% approximately "R Function<X1 extends B1, .. Xs extends Bs>(
397+
% T1, T2, .. Tn, {rn+1 Tn+1 xn+1, .. rn+k Tn+k xn+k])".
293398
\newcommand{\FunctionTypeNamed}[9]{%
294-
\FunctionType{#1}{#2}{#3}{#4}{#5}{%
295-
\FunctionTypeNamedArguments{#6}{#7}{#8}{#9}}}
399+
\FunctionType{#1}{#2}{#3}{#4}{#5}{\\
400+
\mbox{}\qquad\FunctionTypeNamedParameters{#6}{#7}{#8}{#9}{r}}}
296401

297-
% Same as \FunctionType except suitable for inline usage, hence omitting
402+
% Same as \FunctionTypeNamed except suitable for inline usage, hence omitting
298403
% the spacer argument.
299404
\newcommand{\RawFunctionTypeNamed}[8]{%
300405
\RawFunctionType{#1}{#2}{#3}{#4}{%
301-
\FunctionTypeNamedArguments{#5}{#6}{#7}{#8}}}
406+
\FunctionTypeNamedParameters{#5}{#6}{#7}{#8}{r}}}
407+
408+
% A variant of \FunctionTypeNamed that uses the standard symbols,
409+
% that is, a function type with positional optional parameters which
410+
% uses the symbols that we prefer to use for that purpose whenever
411+
% possible.
412+
%
413+
% For example, \FunctionTypeNamedStd{R} yields approximately
414+
% "R Function<X1 extends B1, .. Xs extends Bs>(
415+
% T1, T2, .. Tn, {rn+1 Tn+1 xn+1, .. rn+k Tn+k xn+k})".
416+
\newcommand{\FunctionTypeNamedStd}[1]{%
417+
\FunctionTypeNamed{#1}{ }{X}{B}{s}{T}{n}{x}{k}}
418+
419+
% Same as \FunctionTypeNamedStd except suitable for inline usage, hence
420+
% omitting the spacer argument.
421+
\newcommand{\RawFunctionTypeNamedStd}[1]{%
422+
\RawFunctionTypeNamed{#1}{X}{B}{s}{T}{n}{x}{k}{r}}
423+
424+
% Same as \FunctionTypeNamedStd except that it includes a newline, hence
425+
% suitable for function types that are too long to fit in one line.
426+
\newcommand{\FunctionTypeNamedStdCr}[1]{%
427+
\FunctionTypeNamed{#1}{\\}{X}{B}{s}{T}{n}{x}{k}}
302428

303429
% Used to specify function types with no optional parameters:
304430
% Arguments: Return type, spacer, type parameter name, bound name,
305431
% number of type parameters, parameter type,
306432
% number of parameters (all required).
433+
%
434+
% For example, \FunctionTypeAllRequired{R}{ }{X}{B}{s}{T}{n} yields
435+
% approximately "R Function<X1 extends B1, .. Xs extends Bs>(T1, T2, .. Tn)".
307436
\newcommand{\FunctionTypeAllRequired}[7]{%
308437
\FunctionType{#1}{#2}{#3}{#4}{#5}{\List{#6}{1}{#7}}}
309438

310-
\newcommand{\FunctionTypePositionalStd}[1]{%
311-
\FunctionTypePositional{#1}{ }{X}{B}{s}{T}{n}{k}}
312-
313-
\newcommand{\RawFunctionTypePositionalStd}[1]{%
314-
\RawFunctionTypePositional{#1}{X}{B}{s}{T}{n}{k}}
315-
316-
\newcommand{\FunctionTypeNamedStd}[1]{%
317-
\FunctionTypeNamed{#1}{ }{X}{B}{s}{T}{n}{x}{k}}
318-
319-
\newcommand{\RawFunctionTypeNamedStd}[1]{%
320-
\RawFunctionTypeNamed{#1}{X}{B}{s}{T}{n}{x}{k}}
321-
439+
% A variant of \FunctionTypeAllRequired that uses the standard symbols,
440+
% that is, a function type with positional optional parameters which
441+
% uses the symbols that we prefer to use for that purpose whenever
442+
% possible.
443+
%
444+
% For example, \FunctionTypeAllRequiredStd{R} yields approximately
445+
% "R Function<X1 extends B1, .. Xs extends Bs>(T1, T2, .. Tn)".
322446
\newcommand{\FunctionTypeAllRequiredStd}[1]{%
323447
\FunctionTypeAllRequired{#1}{ }{X}{B}{s}{T}{n}}
324448

325-
\newcommand{\FunctionTypePositionalStdCr}[1]{%
326-
\FunctionTypePositional{#1}{\\}{X}{B}{s}{T}{n}{k}}
327-
328-
\newcommand{\FunctionTypeNamedStdCr}[1]{%
329-
\FunctionTypeNamed{#1}{\\}{X}{B}{s}{T}{n}{x}{k}}
330-
449+
% Same as \FunctionTypeAllRequiredStd except that it includes a newline, hence
450+
% suitable for function types that are too long to fit in one line.
331451
\newcommand{\FunctionTypeAllRequiredStdCr}[1]{%
332452
\FunctionTypeAllRequired{#1}{\\}{X}{B}{s}{T}{n}}
333453

@@ -342,13 +462,13 @@
342462

343463
% Judgment expressing that a subtype relation exists.
344464
\newcommand{\Subtype}[3]{\ensuremath{{#1}\vdash{#2}\,<:\,{#3}}}
345-
\newcommand{\SubtypeStd}[2]{\Subtype{\Gamma}{#1}{#2}}
465+
\newcommand{\SubtypeStd}[2]{\Subtype{\Delta}{#1}{#2}}
346466
% Subtype judgment where the environment is omitted (NE: "no environment").
347467
\newcommand{\SubtypeNE}[2]{\ensuremath{{#1}\,<:\,{#2}}}
348468

349469
% Judgment expressing that a supertype relation exists.
350470
\newcommand{\Supertype}[3]{\ensuremath{{#1}\vdash{#2}\,:>\,{#3}}}
351-
\newcommand{\SupertypeStd}[2]{\Supertype{\Gamma}{#1}{#2}}
471+
\newcommand{\SupertypeStd}[2]{\Supertype{\Delta}{#1}{#2}}
352472

353473
% Judgment expressing that an assignability relation exists.
354474
\newcommand{\AssignableRelationSymbol}{\ensuremath{\Longleftrightarrow}}
@@ -394,6 +514,56 @@
394514
\ensuremath{{#2}}%
395515
}
396516

517+
\newcommand{\FlattenName}{\metavar{flatten}}
518+
\newcommand{\Flatten}[1]{\ensuremath{\FlattenName(\code{#1})}}
519+
520+
\newcommand{\NominalTypeDepthName}{\metavar{nominalTypeDepth}}
521+
\newcommand{\NominalTypeDepth}[1]{%
522+
\ensuremath{\NominalTypeDepthName(\code{#1})}}
523+
524+
\newcommand{\TopMergeTypeName}{\metavar{topMergeType}}
525+
\newcommand{\TopMergeType}[2]{%
526+
\ensuremath{\TopMergeTypeName(\code{{#1},\,\,{#2}})}}
527+
528+
\newcommand{\NonNullTypeName}{\metavar{nonNullType}}
529+
\newcommand{\NonNullType}[1]{\ensuremath{\NonNullTypeName(\code{#1})}}
530+
531+
\newcommand{\IsTopTypeName}{\metavar{isTopType}}
532+
\newcommand{\IsTopType}[1]{\ensuremath{\IsTopTypeName(\code{#1})}}
533+
534+
\newcommand{\IsObjectTypeName}{\metavar{isObjectType}}
535+
\newcommand{\IsObjectType}[1]{\ensuremath{\IsObjectTypeName(\code{#1})}}
536+
537+
\newcommand{\IsBottomTypeName}{\metavar{isBottomType}}
538+
\newcommand{\IsBottomType}[1]{\ensuremath{\IsBottomTypeName(\code{#1})}}
539+
540+
\newcommand{\IsNullTypeName}{\metavar{isNullType}}
541+
\newcommand{\IsNullType}[1]{\ensuremath{\IsNullTypeName(\code{#1})}}
542+
543+
\newcommand{\IsMoreTopTypeName}{\metavar{isMoreTopType}}
544+
\newcommand{\IsMoreTopType}[2]{%
545+
\ensuremath{\IsMoreTopTypeName(\code{{#1},\,\,{#2}})}}
546+
547+
\newcommand{\IsMoreBottomTypeName}{\metavar{isMoreBottomType}}
548+
\newcommand{\IsMoreBottomType}[2]{%
549+
\ensuremath{\IsMoreBottomTypeName(\code{{#1},\,\,{#2}})}}
550+
551+
\newcommand{\NormalizedTypeOfName}{\metavar{normalizedType}}
552+
\newcommand{\NormalizedTypeOf}[1]{%
553+
\ensuremath{\NormalizedTypeOfName(\code{#1})}}
554+
555+
\newcommand{\FutureValueTypeOfName}{\metavar{futureValueType}}
556+
\newcommand{\FutureValueTypeOf}[1]{%
557+
\ensuremath{\FutureValueTypeOfName(\code{#1})}}
558+
559+
\newcommand{\UpperBoundTypeName}{\metavar{standardUpperBound}}
560+
\newcommand{\UpperBoundType}[2]{%
561+
\ensuremath{\UpperBoundTypeName(\code{{#1},\,\,{#2}})}}
562+
563+
\newcommand{\LowerBoundTypeName}{\metavar{standardLowerBound}}
564+
\newcommand{\LowerBoundType}[2]{%
565+
\ensuremath{\LowerBoundTypeName(\code{{#1},\,\,{#2}})}}
566+
397567
% ----------------------------------------------------------------------
398568
% Support for hash valued Location Markers
399569

0 commit comments

Comments
 (0)