-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemantics.tex
1252 lines (1085 loc) · 48.6 KB
/
semantics.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
The three interpretations of the surface syntax, dubbed \Nname{}, \Tname{},
and \Aname{}, are defined via three reduction semantics.
The first three subsections introduce the {\em notions of reduction\/};
the last one generates the compatible closure with respect to evaluation contexts of
these relations in a reasonably standard fashion~\cite{barendregt-1981,fff:redex}.
The three semantics utilize some common extensions to the surface syntax
and common meta functions; see figures~\ref{fig:evaluation-language},
\ref{fig:evaluation-metafunctions},\footnote{The judgment $\svalue_0 \in \snat$
holds when the value $\svalue_0$ is a member of the set of natural numbers,
and similarly for other objects and sets.
By convention: a variable without a subscript typically refers to a set, and a
term containing a set describes a comprehension.
For example, $(\efun{\svar}{\svalue}) = \eset{(\efun{\svar_i}{\svalue_j}) \mid \svar_i \in \svar \mbox{ and } \svalue_j \in \svalue}$.}
and \ref{fig:delta}.
In particular, each
recognizes the same errors ($\eerr$), uses the same type
constructors ($\stag$) for tag checks,
and assigns the same meaning ($\sdelta$) to primitive
operations.
A program evaluation may signal four kinds of errors, defined in
\figref{fig:evaluation-language}.
First, a dynamic
tag error ($\tagerrorD{}$) is the outcome of an evaluation that applies an
elimination form to a misshaped argument. For
example, the first projection of an integer signals such an error.
A static tag error ($\tagerrorS{}$) results from similar applications in typed
code, and from any other redex that contradicts the static typing judgment.
Intuitively, type soundness eliminates the possibility of such contradictions.
Third,
a division-by-zero error ($\divisionbyzeroerror$) may be raised by an
application of the $\squotient$ primitive; $\squotient$ is one representative
example of the partial primitives in a full language.
Lastly, a boundary error ($\boundaryerror{\sbset}{\svalue}$)
indicates a type mismatch between two components and comes with both a set of
boundaries and a witness value.\footnote{A boundary error is comparable to a
blame error~\cite{wf-esop-2009}; however, a boundary error emphasizes that
either an untyped component or a type specification may be at fault.
Type specifications---whether written by a programmer or inferred~\cite{cc-snapl-2019}---can have bugs.}
The error $\boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}}{\svalue_0}$,
for example, says that a mismatch between value $\svalue_0$ and type $\stype_0$
prevented the value sent by the $\sowner_1$ component from entering the $\sowner_0$ component.
\begin{figure}[t]
\begin{minipage}[t]{0.60\columnwidth}
\lbl{\fbox{\sevallang{}}}{
\begin{langarray}
\eerr & \BNFeq &
\tagerrorD \mid \tagerrorS \mid
\divisionbyzeroerror \mid
\boundaryerror{\sbset}{\svalue}
\\
\sexpr & \BNFeq &
\ldots \mid \eerr
\\
\stag & \BNFeq &
\knat \mid \kint \mid \kpair \mid \kfun
\end{langarray}
}
\end{minipage}\begin{minipage}[t]{0.40\columnwidth}
\lbl{\fbox{$\stypeenv \sWT \sexpr : \stype$} \missingrules{}}{\vspace{-1mm}\begin{mathpar}
\inferrule*{
}{
\stypeenv_0 \sWT \eerr : \stype_0
}
\end{mathpar}}
\medskip
\lbl{\fbox{$\stypeenv \sWT \sexpr : \tdyn$} \missingrules{}}{\vspace{-1mm}\begin{mathpar}
\inferrule*{
}{
\stypeenv_0 \sWT \eerr : \tdyn
}
\end{mathpar}}
\end{minipage}
\Description[Grammar and types for error expressions.]{An extended grammar
for error expressions, and typing judgments to state that an error is well-typed
in any context.
}
\caption{Syntax for basic errors and type constuctors, common typing judgments}
\label{fig:evaluation-language}
\end{figure}
\begin{figure}[t]\flushleft\(
\begin{array}{l@{\quad}l}
\begin{array}{l@{~~}c@{~~}l@{}}
\fshallow{\stag_0}{\svalue_0} & \feq &
\left\{\begin{array}{l@{~~}l}
\makebox[2pt][l]{$\ftrue$}
\\ & \mbox{\makebox[\widthof{or}][l]{if} $\stag_0 \eeq \knat$ and $\svalue_0 \in \snat$}
\\ & \mbox{or $\stag_0 \eeq \kint$ and $\svalue_0 \in \sint$}
\\ & \mbox{or $\stag_0 \eeq \kpair$ and}
\\ & \quad\, \svalue_0 \in \epair{\svalue}{\svalue} \cup{}
\\ & \zerowidth{\qquad\, \quad (\emon{\obnd{\sowner}{(\tpair{\stype}{\stype})}{\sowner}}{\svalue})}
\\ & \mbox{or $\stag_0 \eeq \kfun$ and}
\\ & \quad\, \svalue_0 \in (\efun{\svar}{\sexpr}) \cup (\efun{\tann{\svar}{\stype}}{\sexpr}) \cup{}
\\ & \zerowidth{\qquad\, \quad (\emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\svalue})}
\\
\zerowidth{\fshallow{\stag_0}{\svalue_1}}
\\ & \mbox{\makebox[\widthof{or}][l]{if} $\svalue_0 \eeq \ehist{\sbset_0}{\svalue_1}$}
\\
\zerowidth{\ffalse}
\\ & \mbox{otherwise}
\end{array}\right.
\end{array}
&
\begin{array}{l@{~~}c@{~~}l}
\tagof{\stype_0} & \feq &
\left\{\begin{array}{ll}
\knat & \mbox{if $\stype_0 \eeq \tnat$}
\\
\kint & \mbox{if $\stype_0 \eeq \tint$}
\\
\kpair & \mbox{if $\stype_0 \in \tpair{\stype}{\stype}$}
\\
\kfun & \mbox{if $\stype_0 \in \tfun{\stype}{\stype}\!\!$}
\end{array}\right.
\\[3.6cm]
\frev{\sbset_0} & \feq &
\eset{\obnd{\sowner_1}{\stype_0}{\sowner_0} \\
& & \,{}\mid \obnd{\sowner_0}{\stype_0}{\sowner_1} \in \sbset_0}
\end{array}
\end{array}\)
\Description[Three metafunctions.]{Metafunctions for the evaluation language.
The `tag-match' metafunction matches a type-tag against a value. The
`floor of` metafunction reduces a type to a type tag. The `rev' metafunction
reverses the labels in every boundary of a set.
}
\caption{Common metafunctions}
\label{fig:evaluation-metafunctions}
\end{figure}
\begin{figure}[t]\flushleft
\begin{minipage}[t]{0.48\columnwidth}\(
\begin{array}{l@{~~}c@{~~}l}
\sdelta(\sunop, \epair{\svalue_0}{\svalue_1}) & \feq &
\left\{\begin{array}{l@{~~}l}
\makebox[2pt][l]{$\svalue_0$}
\\ & \mbox{if $\sunop \eeq \tinst{\sfst}{\toptional}$}
\\
\zerowidth{\svalue_1}
\\ & \mbox{if $\sunop \eeq \tinst{\ssnd}{\toptional}$}
\end{array}\right.
\end{array}\)
\end{minipage}\begin{minipage}[t]{0.52\columnwidth}\(
\begin{array}{l@{~~}c@{~~}l}
\sdelta(\sbinop, \sint_0, \sint_1) & \feq &
\left\{\begin{array}{l@{~~~}l}
\makebox[2pt][l]{$\sint_0 + \sint_1$}
\\ & \mbox{if $\sbinop \eeq \tinst{\ssum}{\stoptional}$}
\\
\zerowidth{\divisionbyzeroerror}
\\ & \mbox{if $\sbinop \eeq \tinst{\squotient}{\stoptional}$}
\\ & \mbox{and $\sint_1 \eeq 0$}
\\
\zerowidth{\floorof{\sint_0 / \sint_1}}
\\ & \mbox{if $\sbinop \eeq \tinst{\squotient}{\stoptional}$}
\\ & \mbox{and $\sint_1 \neq 0$}
\end{array}\right.
\end{array}\)
\end{minipage}
\Description[Two metafunctions]{The `delta' metafunctions assign meaning to
the primitive operations: `fst' and `snd' get elements from a pair value;
`sum' and `quotient' perform integer arithmetic.}
\caption{Specification for primitive operations}
\label{fig:delta}
\end{figure}
%% ------------------------------------------------------------------------------
\subsection{\Nname{} Notions of Reduction} \label{sub:ho}
\Figref{fig:natural-language} extends the base grammar of evaluation expressions
with monitor wrappers. While the grammar is somewhat liberal, \Nname{} only
ever pairs a function-type boundary with a (possibly-monitored) function value in a
monitor. Thus the monitors that arise during evaluation are members of the
following two mutually-recursive sets:
\smallskip\hspace{-6mm}
\begin{array}[t]{ll}
\begin{array}[t]{lcl}
\Nstawrapper & \BNFeq & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\efun{\svar}{\sexpr}} \\
& \mid & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\Ndynwrapper}
\end{array} &
\begin{array}[t]{lcl}
\Ndynwrapper & \BNFeq & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\efun{\tann{\svar}{\stype}}{\sexpr}} \\
& \mid & \emon{\obnd{\sowner}{(\tfun{\stype}{\stype})}{\sowner}}{\wideas{\Nstawrapper}{\Ndynwrapper}}
\end{array}
\end{array}
\smallskip
\noindent If any other monitor arises, the notions of reduction raise a static
tag error. These rules appear in the \techreport{} along with a proof that
well-typed expressions never raise static tag errors.
\begin{figure}[t]\flushleft
\lbl{\fbox{\Nname{} \sevallang{}}}{
\begin{langarray}
\svalue & \BNFeq &
\snat
\mid \sint
\mid \epair{\svalue}{\svalue}
\mid \efun{\svar}{\sexpr}
\mid \efun{\tann{\svar}{\stype}}{\sexpr}
\mid \emon{\sbnd}{\svalue}
\\
\sexpr & \BNFeq &
\ldots \mid \emon{\sbnd}{\svalue}
\end{langarray}
}
\smallskip
\begin{minipage}[t]{0.5\columnwidth}
\lbl{\fbox{$\stypeenv \sWTN \sexpr : \stype$} \missingrules{}}{\begin{mathpar}
\inferrule*{
\stypeenv_0 \sWTN \svalue_0 : \tdyn
}{
\stypeenv_0 \sWTN \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0} : \tfun{\stype_0}{\stype_1}
}
\end{mathpar}}
\end{minipage}\begin{minipage}[t]{0.5\columnwidth}
\lbl{\fbox{$\tenv \sWTN \sexpr : \tdyn$} \missingrules{}}{\begin{mathpar}
\inferrule*{
\tenv_0 \sWTN \svalue_0 : \tfun{\stype_0}{\stype_1}
}{
\stypeenv_0 \sWTN \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0} : \tdyn
}
\end{mathpar}}
\end{minipage}
\Description[Grammar and typing judgments.]{Extends the evaluation grammar
with monitor values and adds typing rules for monitors. The typing
rules are similar to the dyn and stat rules.
}
\caption{\Nname{} language extensions}
\label{fig:natural-language}
\end{figure}
%% -----------------------------------------------------------------------------
\subsubsection{\Nname{}, Statically-Typed} \label{sec:n-static}
The $\sdelta$ metafunction (\figref{fig:delta}) defines the semantics
of the unary and binary operators.
If $\sdelta$ is undefined for the argument values, a tag error results:
\begin{rrpage}
\rhsbox{2pt}{\sexpr \nredNS \sexpr}
\\[-2ex]
\begin{inlinerrarray}
\eunopt{\stype_0}{\svalue_0}
& \nredNS
& \tagerrorS
\\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is undefined}
\\[0.3ex]
\eunopt{\stype_0}{\svalue_0}
& \nredNS
& \sdelta(\sunop, {\svalue_0})
\\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is defined}
\\[0.3ex]
\ebinopt{\stype_0}{\svalue_0}{\svalue_1}
& \nredNS
& \tagerrorS
\\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is undefined}
\\[0.3ex]
\ebinopt{\stype_0}{\svalue_0}{\svalue_1}
& \nredNS
& \sdelta(\sbinop, {\svalue_0}, {\svalue_1})
\\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is defined}
\end{inlinerrarray}
\end{rrpage}
%\noindent Recall that a $\delta$ reduction issues errors for partially-defined primitive
%operations.
Only a typed function or monitor may be applied to an argument in a statically-typed context.
Any other application is a tag error:
\begin{inlinerrarray}
\eapp{\stype_0}{\svalue_0}{\svalue_1}
& \nredNS
& \tagerrorS
\\\sidecond{if $\svalue_0 \not\in (\efun{\tann{\svar}{\stype}}{\sexpr}) \cup (\emon{\sbnd}{\svalue})$}
\end{inlinerrarray}
\noindent
The application of a typed lambda to an argument is standard:
\begin{inlinerrarray}
\eapp{\stype_0}{(\efun{\tann{\svar_0}{\stype_1}}{\sexpr_0})}{\svalue_0}
& \nredNS
& \esubst{\sexpr_0}{\svar_0}{\svalue_0}
\end{inlinerrarray}
\noindent
The application of a monitored, untyped function unfolds the monitor proxy into
two new boundary terms.
One $\ssta$ boundary protects the typed argument
from improper use by the body of the dynamically-typed function; one
$\sdyn$ boundary checks the result:
\begin{inlinerrarray}
\eapp{\stype_0}{(\emon{\obnd{\sowner_0}{(\tfun{\stype_1}{\stype_2})}{\sowner_1}}{\svalue_0})}{\svalue_1}
& \nredNS
& \edynb{\sbnd_0}{(\eapp{\tdyn}{\svalue_0}{(\estab{\sbnd_1}{\svalue_1})})}
\\\sidecond{where \(\sbnd_0 \sassign \obnd{\sowner_0}{\stype_2}{\sowner_1}\)
and \(\sbnd_1 \sassign \obnd{\sowner_1}{\stype_1}{\sowner_0}\)}
\end{inlinerrarray}
\noindent
Both boundaries use the type $(\tfun{\stype_1}{\stype_2})$ from
the monitored function and ignore the annotation $\stype_0$ that decorates the application.
The annotations are relevant only for \Tname{} and \Aname{}.
The remaining four rules define the behavior of $\sdyn$ boundaries.
These rules initially check a dynamically-typed value against a static type
using the $\sshallow$ metafunction.
For functions, a successful check entails the creation of a new monitor:
\begin{inlinerrarray}
\edynb{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
& \nredNS
& \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
\\\sidecond{if $\fshallow{\ftagof{\tfun{\stype_0}{\stype_1}}}{\svalue_0}$}
\end{inlinerrarray}
\noindent
For pairs, \Nname{} creates a new typed pair containing new $\sdyn$ boundaries.
The evaluation of these boundaries validates the elements of the original,
untyped pair:
\begin{inlinerrarray}
\edynb{\obnd{\sowner_0}{(\tpair{\stype_0}{\stype_1})}{\sowner_1}}{\epair{\svalue_0}{\svalue_1}}
& \nredNS
& \epair{\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}}{\edynb{\obnd{\sowner_0}{\stype_1}{\sowner_1}}{\svalue_1}}
\end{inlinerrarray}
\noindent For base types, a successful check is a complete proof that the
value matches the type:
\begin{inlinerrarray}
\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\sint_0}
& \nredNS
& \sint_0
\\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\sint_0}\)}
\end{inlinerrarray}
\noindent
Otherwise, if the $\sshallow$ check fails, the reduction ends in a type mismatch.
The error message reports the current boundary and the incompatible value:
\begin{inlinerrarray}
\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
& \nredNS
& \boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}}{\svalue_0}
\\\sidecond{if \(\neg \fshallow{\ftagof{\stype_0}}{\svalue_0}\)}
\end{inlinerrarray}
%% -----------------------------------------------------------------------------
\subsubsection{\Nname{}, Dynamically-Typed}
Applications of primitives end in a dynamic tag error if $\sdelta$ is
undefined for the given values:
\begin{rrpage}
\rhsbox{2pt}{\sexpr \nredND \sexpr}
\\[-2ex]
\begin{inlinerrarray}
\eunopt{\tdyn}{\svalue_0} & \nredND & \tagerrorD
\\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is undefined}
\\[0.3ex]
\eunopt{\tdyn}{\svalue_0}
& \nredND
& \sdelta(\sunop, {\svalue_0})
\\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is defined}
\\[0.3ex]
\ebinopt{\tdyn}{\svalue_0}{\svalue_1}
& \nredND
& \tagerrorD{}
\\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is undefined}
\\[0.3ex]
\ebinopt{\tdyn}{\svalue_0}{\svalue_1}
& \nredND
& \sdelta(\sbinop, {\svalue_0}, {\svalue_1})
\\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is defined}
\end{inlinerrarray}
\end{rrpage}
Function application follows the tag of the operator:
substitution for an untyped function,
decomposition for a monitor,
and a tag error for anything else:
\begin{inlinerrarray}
\eapp{\tdyn}{\svalue_0}{\svalue_1}
& \nredND
& \tagerrorD
\\\sidecond{if $\svalue_0 \not\in (\efun{\svar}{\sexpr}) \cup (\emon{\sbnd}{\svalue})$}
\\[0.3ex]
\eapp{\tdyn}{(\efun{\svar_0}{\sexpr_0})}{\svalue_0}
& \nredND
& \esubst{\sexpr_0}{\svar_0}{\svalue_0}
\\[0.3ex]
\eapp{\tdyn}{(\emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0})}{\svalue_1}
& \nredND
& \estab{\sbnd_0}{(\eapp{\stype_1}{\svalue_0}{(\edynb{\sbnd_1}{\svalue_1})})}
\\\sidecond{where \(\sbnd_0 \sassign \obnd{\sowner_0}{\stype_1}{\sowner_1}\)
and \(\sbnd_1 \sassign \obnd{\sowner_1}{\stype_0}{\sowner_0}\)}
\end{inlinerrarray}
\noindent
In the monitor case, a $\sdyn$ boundary checks the
argument and a $\ssta$ boundary protects the result.
The rules for $\ssta$ boundaries protect typed values from untyped contexts.
Protection is crucial for typed functions because an untyped context may
supply type-incorrect arguments:
\begin{inlinerrarray}
\estab{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
& \nredND
& \emon{\obnd{\sowner_0}{(\tfun{\stype_0}{\stype_1})}{\sowner_1}}{\svalue_0}
\\\sidecond{if $\fshallow{\ftagof{\tfun{\stype_0}{\stype_1}}}{\svalue_0}$}
\end{inlinerrarray}
\noindent
For typed pairs, a traversal protects higher-order members:
\begin{inlinerrarray}
\estab{\obnd{\sowner_0}{(\tpair{\stype_0}{\stype_1})}{\sowner_1}}{\epair{\svalue_0}{\svalue_1}}
& \nredND
& \epair{\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}}{\estab{\obnd{\sowner_0}{\stype_1}{\sowner_1}}{\svalue_1}}
\end{inlinerrarray}
\noindent
Base values do not require protection:
\begin{inlinerrarray}
\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\sint_0}
& \nredND
& \sint_0
\\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\sint_0}\)}
\end{inlinerrarray}
\noindent
Any other combination of type and value indicates a type mismatch within a
statically-typed component, and results in a static tag error:
\begin{inlinerrarray}
\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0}
& \nredND
& \tagerrorS
\\\sidecond{if \(\neg \fshallow{\ftagof{\stype_0}}{\svalue_0}\)}
\end{inlinerrarray}
\noindent
The $\ssta$ rules do not output a boundary error because a type mismatch in
typed code contradicts the static typing judgment, which is meant to be an
invariant.
%% -----------------------------------------------------------------------------
\subsection{\Tname{} Notion of Reduction} \label{sub:first}
\Figref{fig:transient-language} extends the base evaluation language with
pre-values, heaps, and tag-check expressions.
The goal is to allocate one
instance of every function and pair on a value heap.
Technically, a value heap $\vstore$ maps addresses ($\eloc$) to pre-values ($\sprevalue$).
A blame heap $\bstore$ maps addresses to sets of boundaries according to the
blame strategy of Transient Reticulated~\cite{vss-popl-2017,v-thesis-2019}.
A check expression
$(\echecktwo{\stoptional}{\sexpr}{\eloc})$ validates the result of an
elimination form: $\stoptional$ is the expected type, $\sexpr$ is the
result, and $\eloc$ is the address of the previously-eliminated value.
The typing judgments {$\vstoretype; \stypeenv \sWTT \sexpr : \stag$} and
{$\vstoretype; \stypeenv \sWTT \sexpr : \tdyn$} validate type-tags.
Both judgments accept all kinds of values and have analogous rules;
refer to the \techreport{} for details.
The figure also defines three meta-functions: $\fmapref{\cdot}{\cdot}$,
$\fmapreplace{\cdot}{\cdot}{\cdot}$, and $\fmapupdate{\cdot}{\cdot}{\cdot}$.
The first gets an item from a finite map,
the second replaces a blame heap entry,
and the third extends a blame heap entry.
Because maps are sets, set union suffices to add new entries.
\begin{figure}[t]
\begin{minipage}[t]{0.42\columnwidth}
\lbl{\fbox{\Tname{} \sevallang{}}}{
\begin{langarray}
\eloc & \BNFeq & % \locations
\textrm{\scountable{} set of heap locations}
\\
\svalue & \BNFeq &
\sint \mid \snat \mid \eloc
\\
\sprevalue & \BNFeq &
{\efun{\svar}{\sexpr}}
\mid {\efun{\tann{\svar}{\stype}}{\sexpr}}
\mid {\epair{\svalue}{\svalue}}
\\
\sexpr & \BNFeq &
\ldots \mid \eloc \mid \echecktwo{\stoptional}{\sexpr}{\eloc}
\\
\vstore & \BNFeq &
\powerset{(\vrecord{\eloc}{\sprevalue})}
\\
\bstore & \BNFeq &
\powerset{(\brecord{\eloc}{\sbset})}
\\
\vstoretype & \BNFeq &
\snil \mid \fcons{\tann{\eloc}{\stoptional}}{\vstoretype}
\end{langarray}
}
\end{minipage}\begin{minipage}[t][][c]{0.70\columnwidth}
\vspace{-3mm}
\begin{flushleft}\(\begin{array}[t]{l@{~~}c@{~~}l}
\fmapref{\vstore_0}{\svalue_0} & \feq &
\left\{\begin{array}{l@{\quad}l}
\sprevalue_0 & \mbox{if $\svalue_0 \in \eloc$ and $(\vrecord{\svalue_0}{\sprevalue_0}) \in \vstore_0$}
\\
\svalue_0 & \mbox{if $\svalue_0 \not\in \eloc$}
\end{array}\right.
\\[4mm]
\fmapref{\bstore_0}{\svalue_0} & \feq &
\left\{\begin{array}{l@{\quad}l}
\sbset_0 & \mbox{if $\svalue_0 \in \eloc$ and $(\brecord{\svalue_0}{\sbset_0}) \in \bstore_0$}
\\
\semptymap & \mbox{otherwise}
\end{array}\right.
\\[4mm]
\fmapreplace{\bstore_0}{\svalue_0}{\sbset_0} & \feq &
\left\{\begin{array}{l@{\quad}l}
\zerowidth{\eset{\vrecord{\svalue_0}{\sbset_0}} \cup {(\bstore_0 \setminus (\vrecord{\svalue_0}{\sbset_1}))}}
\\
& \mbox{if $\svalue_0 \in \eloc$ and $(\vrecord{\svalue_0}{\sbset_1}) \in \bstore_0$}
\\
\bstore_0 & \mbox{otherwise}
\end{array}\right.
\\[6mm]
\fmapupdate{\bstore_0}{\svalue_0}{\sbset_0} & \feq &
\quad \fmapreplace{\bstore_0}{\svalue_0}{\bappend{\sbset_0}{\fmapref{\bstore_0}{\svalue_0}}}
\end{array}\)\end{flushleft}
\end{minipage}
\lbl{\fbox{$\vstoretype; \stypeenv \sWTT \sexpr : \stag$} \missingrules{}}{\begin{mathpar} % (selected rules)
% \inferrule*{
% \vstoretype_0; \fcons{\tann{\svar_0}{\stype_0}}{\stypeenv_0} \sWTT \sexpr_0 : \stag_0
% }{
% \vstoretype_0; \stypeenv_0 \sWTT \efun{\tann{\svar_0}{\stype_0}}{\sexpr_0} : \kfun
% }
%
\inferrule*{
\vstoretype_0; \fcons{\tann{\svar_0}{\tdyn}}{\stypeenv_0} \sWTT \sexpr_0 : \tdyn
}{
\vstoretype_0; \stypeenv_0 \sWTT \efun{\svar_0}{\sexpr_0} : \kfun
}
\inferrule*{
\vstoretype_0; \stypeenv_0 \sWTT \sexpr_0 : \stag_0
}{
\vstoretype_0; \stypeenv_0 \sWTT \echecktwo{\stype_0}{\sexpr_0}{\eloc_0} : \tagof{\stype_0}
}
\inferrule*{
\vstoretype_0; \stypeenv_0 \sWTT \sexpr_0 : \tdyn
}{
\vstoretype_0; \stypeenv_0 \sWTT \echecktwo{\stype_0}{\sexpr_0}{\eloc_0} : \tagof{\stype_0}
}
\end{mathpar}}
\medskip
\lbl{\fbox{$\vstoretype; \stypeenv \sWTT \sexpr : \tdyn$} \missingrules{}}{\begin{mathpar} % (selected rules)
\inferrule*{
\vstoretype_0; \fcons{\tann{\svar_0}{\tdyn}}{\stypeenv_0} \sWTT \sexpr_0 : \tdyn
}{
\vstoretype_0; \stypeenv_0 \sWTT \efun{\svar_0}{\sexpr_0} : \tdyn
}
\inferrule*{
\vstoretype_0; \fcons{\tann{\svar_0}{\stype_0}}{\stypeenv_0} \sWTT \sexpr_0 : \stag_0
}{
\vstoretype_0; \stypeenv_0 \sWTT \efun{\tann{\svar_0}{\stype_0}}{\sexpr_0} : \tdyn
}
\inferrule*{
\tann{\eloc_0}{\tdyn} \in \vstoretype_0
}{
\vstoretype_0; \stypeenv_0 \sWTT \eloc_0 : \tdyn
}
\end{mathpar}}
\Description[Grammar, metafunctions, and typing judgments.]{A grammar
defines heap locations, heap-allocated values, heaps, tag-check expressions,
blame heaps, and heap typings. Four metafunctions help with heap references
and updates. Two new typing judgments match an expression to a type tag.
}
\caption{\Tname{} language extensions and metafunctions}
\label{fig:transient-language}
\end{figure}
%% -----------------------------------------------------------------------------
\subsubsection{\Tname{}}
The first rule allocates a new heap address for a pre-value:
\begin{rrpage}
\rhsbox{-2pt}{\conf{\sexpr}{\vstore}{\bstore} \nredTX \conf{\sexpr}{\vstore}{\bstore}}
\\[-2.5ex]
\begin{inlinerrarray}
\conf{\sprevalue_0}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\eloc_0}{(\eset{\vrecord{\eloc_0}{\sprevalue_0}} \cup \vstore_0)}{(\eset{\brecord{\eloc_0}{\semptymap}} \cup {\bstore_0})}
\\\sidecond{where $\ffresh{\eloc_0}{\vstore_0\mbox{ and }\bstore_0}$}
\end{inlinerrarray}
\end{rrpage}
A pair projection extracts a component from a (heap allocated) value.
Because projection is an elimination form, the next step is to tag-check the
result against the expected type:
\begin{inlinerrarray}
\conf{(\eunopt{\stype_0}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorS}{\vstore_0}{\bstore_0}
\\\sidecond{if $\sdelta(\sunop, {\vstore_0(\svalue_0)})$ is undefined}
\\
\conf{(\eunopt{\tdyn}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorD}{\vstore_0}{\bstore_0}
\\\sidecond{if $\sdelta(\sunop, {\vstore_0(\svalue_0)})$ is undefined}
\\
\conf{(\eunopt{\stoptional}{\eloc_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{(\echecktwo{\stoptional}{\sdelta(\sunop, \vstore_0(\eloc_0))}{\eloc_0})}{\vstore_0}{\bstore_0}
\\\sidecond{if $\sdelta(\sunop, \vstore_0(\eloc_0))$ is defined}
\end{inlinerrarray}
Binary operations yield new integers, and therefore do not require result checks:
\begin{inlinerrarray}
\conf{(\ebinopt{\stype_0}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorS}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\sdelta(\sbinop, \svalue_0, \svalue_1)\) is undefined}
\\
\conf{(\ebinopt{\tdyn}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorD}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\sdelta(\sbinop, \svalue_0, \svalue_1)\) is undefined}
\\
\conf{(\ebinopt{\toptional}{\sint_0}{\sint_1})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\sdelta(\sbinop, \sint_0, \sint_1)}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\sdelta(\sbinop, \sint_0, \sint_1)\) is defined}
\end{inlinerrarray}
The application of a typed function first confirms the tag of the argument value
against the domain of the function.
If they match, the rule:
(1) extends the blame for the argument with reversed boundaries, to record the
flow into the function;
(2) substitutes the argument into the function body;
and (3) guards the result expression with a codomain check for the expected type:
\begin{inlinerrarray}
\conf{(\eapp{\stoptional}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{(\echecktwo{\stoptional}{\esubst{\sexpr_0}{\svar_0}{\svalue_0}}{\eloc_0})}{\vstore_0}{\fmapupdate{\bstore_0}{\svalue_0}{\frev{\bstore_0(\eloc_0)}}}
\\\sidecond{if $\fmapref{\vstore_{0}}{\eloc_0}=\efun{\tann{\svar_0}{{\stype_0}}}{\sexpr_0}$
and $\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}
\noindent If the domain check fails, then \Tname{} reports a boundary error
containing $\svalue_0$ and the boundaries associated with the procedure
$\fmapref{\vstore_0}{\eloc_0}$:
\begin{inlinerrarray}
\conf{(\eapp{\stoptional}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\boundaryerror{\fmapref{\bstore_0}{\eloc_0}}{\svalue_0}}{\vstore_0}{\bstore_0}
\\\sidecond{if $\fmapref{\vstore_{0}}{\eloc_0}=\efun{\tann{\svar_0}{{\stype_0}}}{\sexpr_0}$
and $\neg \fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}
The application of an untyped function in a typed context inserts a check that the function
computes a value matching the expected type. In anticipation of a possible check error, the
rule updates the blame map:
\begin{inlinerrarray}
\conf{(\eapp{\stype_0}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{(\echecktwo{\stype_0}{\esubst{\sexpr_0}{\svar_0}{\svalue_0}}{\eloc_0})}{\vstore_0}{\fmapupdate{\bstore_0}{\svalue_0}{\frev{\fmapref{\bstore_0}{\eloc_0}}}}
\\\sidecond{if \(\fmapref{\vstore_{0}}{\eloc_0}=\efun{\svar_0}{\sexpr_0}\)}
\end{inlinerrarray}
\noindent In an untyped context, the reduction merely performs the required substitution:
\begin{inlinerrarray}
\conf{(\eapp{\tdyn}{\eloc_0}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{(\esubst{\sexpr_0}{\svar_0}{\svalue_0})}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\fmapref{\vstore_{0}}{\eloc_0}=\efun{\svar_0}{\sexpr_0}\)}
\end{inlinerrarray}
\noindent
Invalid applications signal a static or dynamic tag error, depending on the context:
\begin{inlinerrarray}
\conf{(\eapp{\stype_0}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorS}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\fmapref{\vstore_{0}}{\svalue_0} \not\in (\efun{\svar}{\sexpr}) \cup (\efun{\tann{\svar}{\stype}}{\sexpr})\)}
\\
\conf{(\eapp{\tdyn}{\svalue_0}{\svalue_1})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorD}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\fmapref{\vstore_{0}}{\svalue_0} \not\in (\efun{\svar}{\sexpr}) \cup (\efun{\tann{\svar}{\stype}}{\sexpr})\)}
\end{inlinerrarray}
A $\sdyn$ boundary checks the tag of a value.
If successful, the value crosses the boundary and the blame map records the event.
Otherwise, the rule reports the current boundary:
\begin{inlinerrarray}
\conf{(\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\svalue_0}{\vstore_0}{(\fmapupdate{\bstore_0}{\svalue_0}{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}})}
\\\sidecond{if $\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\\
\conf{(\edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\boundaryerror{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}}{\svalue_0}}{\vstore_0}{\bstore_0}
\\\sidecond{if $\neg\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}
A $\ssta$ boundary must check the tag of a value to guard against incorrect
types.
If the type is incorrect, evaluation ends in a static tag error.
\begin{inlinerrarray}
\conf{(\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\svalue_0}{\vstore_0}{(\fmapupdate{\bstore_0}{\svalue_0}{\eset{\obnd{\sowner_0}{\stype_0}{\sowner_1}}})}
\\\sidecond{if $\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\\
\conf{(\estab{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\tagerrorS}{\vstore_0}{\bstore_0}
\\\sidecond{if $\neg\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}$}
\end{inlinerrarray}
The rules for check expressions are similar to those for $\sdyn$ boundaries,
but have additional information about the source of the target value.
A check for the dynamic type $\tdyn$ is a no-op:
\begin{inlinerrarray}
\conf{(\echecktwo{\tdyn}{\svalue_0}{\eloc_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\svalue_0}{\vstore_0}{\bstore_0}
\end{inlinerrarray}
\noindent
Any other check expression matches the value against the type.
If the check fails, the error reports the boundary information for both the
value and the $\eloc_0$ address because either set may contain the boundary at
the root of the issue:
\begin{inlinerrarray}
\conf{(\echecktwo{\stype_0}{\svalue_0}{\eloc_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\svalue_0}{\vstore_0}{(\fmapupdate{\bstore_0}{\svalue_0}{\fmapref{\bstore_0}{\eloc_0}})}
\\\sidecond{if \(\fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}\)}
\\
\conf{(\echecktwo{\stype_0}{\svalue_0}{\eloc_0})}{\vstore_0}{\bstore_0}
& \nredTX
& \conf{\boundaryerror{\bappend{\fmapref{\bstore_0}{\svalue_0}}{\fmapref{\bstore_0}{\eloc_0}}}{\svalue_0}}{\vstore_0}{\bstore_0}
\\\sidecond{if \(\neg \fshallow{\ftagof{\stype_0}}{\fmapref{\vstore_0}{\svalue_0}}\)}
\end{inlinerrarray}
%% -----------------------------------------------------------------------------
\subsection{\Aname{} Notions of Reduction} \label{sub:wrapper}
\Figref{fig:amnesic-language} adds monitors and trace wrappers to
the base evaluation language, along with metafunctions to
extend, inspect, and remove the trace history associated with a value.
During evaluation, \Aname{} limits the number of wrappers on a value
by removing monitors when the value flows to an untyped component.
An originally-untyped value gets at most one trace and one temporary ``outer'' monitor.
An originally-typed value gets at most two monitors---one permanent ``inner''
and one temporary ``outer''---and one trace.
Using the abbreviation $(\ehopt{\sbset}{\svalue})$ for an optionally-traced
value (bottom of \figref{fig:amnesic-language}), these wrapped values
match the following grammars during evaluation:
\medskip\hspace{-6mm}
\begin{array}[t]{ll}
\begin{array}[t]{lcl}
\Astawrapper
& \BNFeq & \emon{\sbnd}{(\ehopt{\sbset}{\epair{\svalue}{\svalue}})} \\[1pt]
& \mid & \emon{\sbnd}{(\ehopt{\sbset}{\efun{\svar}{\sexpr}})} \\[1pt]
& \mid & \emon{\sbnd}{(\ehopt{\sbset}{(\emon{\sbnd}{\epair{\svalue}{\svalue}})})} \\[1pt]
& \mid & \zerowidth{\emon{\sbnd}{(\ehopt{\sbset}{(\emon{\sbnd}{\efun{\tann{\svar}{\stype}}{\sexpr}})})}}
\end{array}
\begin{array}[t]{lcl}
\Adynwrapper
& \BNFeq & \ehist{\sbset}{\sint} \\
& \mid & \ehist{\sbset}{\epair{\svalue}{\svalue}} \\
& \mid & \ehist{\sbset}{\efun{\svar}{\sexpr}} \\
& \mid & \ehopt{\sbset}{(\emon{\sbnd}{\epair{\svalue}{\svalue}})} \\
& \mid & \ehopt{\sbset}{(\emon{\sbnd}{\efun{\tann{\svar}{\stype}}{\sexpr}})}
\end{array}
\end{array}
\smallskip
\noindent The number of boundaries in a trace may grow without bound.
\begin{figure}[t]
\begin{minipage}[t]{0.4\columnwidth}
\lbl{\fbox{\Aname{} \sevallang{}}}{
\begin{langarray}
\svalue & \BNFeq &
\snat
\mid \sint
\mid \epair{\svalue}{\svalue}
\mid \efun{\svar}{\sexpr}
\mid \efun{\tann{\svar}{\stype}}{\sexpr}
\mid
\\ & &
\emon{\sbnd}{\svalue}
\mid \etrace{\sbset}{\svalue} \mid u
\\
\sexpr & \BNFeq &
\ldots
\mid \emon{\sbnd}{\svalue}
\mid \etrace{\sbset}{\svalue} \mid
\\
& & \esuffix{\sbset}{\sexpr}
\end{langarray}
}
\bigskip
\lbl{\fbox{$\stypeenv \sWTA \sexpr : \stype$} \missingrules{}}{\begin{mathpar}
\inferrule*{
\stypeenv_0 \sWTA \svalue_0 : \tdyn
}{
\stypeenv_0 \sWTA \emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0} : \stype_0
}
\end{mathpar}}
\end{minipage}\begin{minipage}[t][][c]{0.6\columnwidth}
\vspace{-3mm}
\begin{flushleft}\(\begin{array}[t]{l@{~}c@{~}l}
\faddtrace{\sbset_0}{\svalue_0} & \feq &
\left\{\begin{array}{ll}
\svalue_0
\\ & \mbox{if $\sbset_0 \eeq \emptyset$}
\\
\zerowidth{\ehist{(\sbset_0 \cup \sbset_1)\,}{\svalue_1}}
\\ & \mbox{if $\svalue_0 \eeq \ehist{\sbset_1}{\svalue_1}$}
\\
\zerowidth{\ehist{\sbset_0}{\svalue_0}}
\\ & \mbox{if $\svalue_0 \not\in \ehist{\sbset}{\svalue}$ and $\sbset_0 \neq \emptyset\!\!\!\!$}
\end{array}\right.
\\[13mm]
\fgettrace{\svalue_0} & \feq &
\left\{\begin{array}{ll}
\sbset_0
& \mbox{if $\svalue_0 \eeq \ehist{\sbset_0}{\svalue_1}$}
\\
\emptyset
& \mbox{if $\svalue_0 \not\in \ehist{\sbset}{\svalue}$}
\end{array}\right.
\\[5mm]
\fremtrace{\svalue_0} & \feq &
\left\{\begin{array}{ll}
\svalue_1
& \mbox{if $\svalue_0 \eeq \ehist{\sbset_0}{\svalue_1}$}
\\
\svalue_0
& \mbox{if $\svalue_0 \not\in \ehist{\sbset}{\svalue}$}
\end{array}\right.
\end{array} \) \end{flushleft}
\end{minipage}
\lbl{\fbox{$\tenv \sWTA \sexpr : \tdyn$} \missingrules{}}{\begin{mathpar}
\inferrule*{
\tenv_0 \sWTA \svalue_0 : \stype_0
}{
\stypeenv_0 \sWTA \emon{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{\svalue_0} : \tdyn
}
\inferrule*{
\tenv_0 \sWTA \svalue_0 : \tdyn
}{
\stypeenv_0 \sWTA \ehist{\sbset_0}{\svalue_0} : \tdyn
}
\inferrule*{
\tenv_0 \sWTA \sexpr_0 : \tdyn
}{
\stypeenv_0 \sWTA \esuffix{\sbset_0}{\sexpr_0} : \tdyn
}
\end{mathpar}}
\bigskip
\lbl{~}{\(\quad
(\ehopt{\sbset_0}{\svalue_1}) \eeq \svalue_0 \sabbreveq
\mbox{$\fremtrace{\svalue_0} \eeq \svalue_1$ and $\fgettrace{\svalue_0} \eeq \sbset_0$}
\)}
\Description[Grammar, metafunctions, and typing judgments.]{A grammar adds
monitor values, trace values, and trace expressions. Three metafunctions
add, get, and remove a trace around a value. Two typing judgments accomodate
monitor and trace wrappers. Lastly, there is an abbreviation for optionally-traced
values.
}
\caption{\Aname{} language extensions, metafunctions, and $\ehopt{\!}{\!}$ abbreviation}
\label{fig:amnesic-language}
\end{figure}
\subsubsection{\Aname{}, Statically-Typed}
Two groups of rules handle primitive operations.
One group applies the $\sdelta$ metafunction:
\begin{rrpage}
\rhsbox{2pt}{\sexpr \nredAS \sexpr}
\\[-2ex]
\begin{inlinerrarray}
\eunopt{\stype_0}{\svalue_0}
& \nredAS
& \tagerrorS
\\\sidecond{if \(\svalue_0 \not\in (\emon{\obnd{\sowner}{(\tpair{\stype}{\stype})}{\sowner}}{\svalue})\)
and \(\sdelta(\sunop, {\svalue_0})\) is undefined}
\\[0.3ex]
\eunopt{\stype_0}{\svalue_0} & \nredAS & \sdelta(\sunop, {\svalue_0})
\\\sidecond{if \(\sdelta(\sunop, {\svalue_0})\) is defined}
\\[0.3ex]
\ebinopt{\stype_0}{\svalue_0}{\svalue_1}
& \nredAS
& \tagerrorS
\\\sidecond{if \(\sdelta(\sbinop, {\svalue_0}, {\svalue_1})\) is undefined}
\\[0.3ex]
\ebinopt{\stype_0}{\svalue_0}{\svalue_1}
& \nredAS
& \sdelta(\sbinop, \svalue_0, \svalue_1)
\\\sidecond{if \(\sdelta(\sbinop, \svalue_0, \svalue_1)\) is defined}
\end{inlinerrarray}
\end{rrpage}
\noindent
The other group handles monitored pair values:
\begin{inlinerrarray}
\efst{\stype_0}{(\emon{\obnd{\sowner_0}{(\tpair{\stype_1}{\stype_2})}{\sowner_1}}{\svalue_0})}
& \nredAS
& \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\efst{\tdyn}{\svalue_0})}
\\[0.3ex]
\esnd{\stype_0}{(\emon{\obnd{\sowner_0}{(\tpair{\stype_1}{\stype_2})}{\sowner_1}}{\svalue_0})}
& \nredAS
& \edynb{\obnd{\sowner_0}{\stype_0}{\sowner_1}}{(\esnd{\tdyn}{\svalue_0})}
\end{inlinerrarray}
\noindent
The projection of an element from a monitored pair creates a boundary
term to check the untyped value.
The new boundary uses the annotation $\stype_0$ from the operator,
exactly like \Tname{}.
Type $\stype_0$ may be weaker than the corresponding type in the monitor,
but this weaker guarantee is all that the context explicitly relies on.
An invalid application in typed code yields a tag error:
\begin{inlinerrarray}
\eapp{\stype_0}{\svalue_0}{\svalue_1}
& \nredAS
& \tagerrorS
\\\sidecond{if $\svalue_0 \not\in (\efun{\tann{\svar}{\stype}}{\sexpr}) \cup (\emon{\sbnd}{\svalue})$}