@@ -362,25 +362,27 @@ \subsection{Variables, typed holes and literals}\label{subsec:zilch-grammar-expr
362
362
\label {fig:zilch-grammar-expressions-atom-grammar }
363
363
\end {figure }
364
364
365
- The by-ref operator \texttt {\& id } is only allowed if it appears within the top-most application in a \texttt {let } local binding.
366
- For example, these uses of the by-ref operator are valid:
367
- \begin {listing }[H]
368
- \inputminted {\zilchlexer }{examples/correct-byref.zc}
369
-
370
- \captionsetup {style=invisible}
371
- \caption {Correct usage of by-ref operator.}
372
- \end {listing }
373
- \vspace *{-\baselineskip }
374
-
375
- Hoewver, these uses are invalid:
376
- \begin {listing }[H]
377
- \inputminted {\zilchlexer }{examples/incorrect-byref.zc}
378
-
379
- \captionsetup {style=invisible}
380
- \caption {Incorrect usage of by-ref operator.}
381
- \end {listing }
382
- \vspace *{-\baselineskip }
383
- In \texttt {test2 }, the by-ref operator is in fact used in the application of \texttt {+ } (recall that \texttt {a + b } is \texttt {\_ +\_ (a, b) }), which is not the top-most application in this local binding.
365
+ % NOTE: &x now denotes making a reference
366
+ %
367
+ % The by-ref operator \texttt{\&id} is only allowed if it appears within the top-most application in a \texttt{let} local binding.
368
+ % For example, these uses of the by-ref operator are valid:
369
+ % \begin{listing}[H]
370
+ % \inputminted{\zilchlexer}{examples/correct-byref.zc}
371
+
372
+ % \captionsetup{style=invisible}
373
+ % \caption{Correct usage of by-ref operator.}
374
+ % \end{listing}
375
+ % \vspace*{-\baselineskip}
376
+
377
+ % Hoewver, these uses are invalid:
378
+ % \begin{listing}[H]
379
+ % \inputminted{\zilchlexer}{examples/incorrect-byref.zc}
380
+
381
+ % \captionsetup{style=invisible}
382
+ % \caption{Incorrect usage of by-ref operator.}
383
+ % \end{listing}
384
+ % \vspace*{-\baselineskip}
385
+ % In \texttt{test2}, the by-ref operator is in fact used in the application of \texttt{+} (recall that \texttt{a + b} is \texttt{\_+\_(a, b)}), which is not the top-most application in this local binding.
384
386
385
387
\subsection {Additive and multiplicative pairs }\label {subsec:zilch-grammar-expressions-pairs }
386
388
@@ -1007,7 +1009,7 @@ \subsection{Local bindings and effect handling}\label{subsec:zilch-staticsem-exp
1007
1009
It is important because we disallow erasing function calls which cannot be guaranteed to always terminate (to prevent from making the type-checker loop indefinitely).
1008
1010
In the case of non-erased terms, we use termination checking to put the builtin $ \Ediv $ \ effect on functions which may not terminate (which are not \textit {total }).
1009
1011
1010
- The predicate $ \Eterminates {x}$ is left undefined as it is an implementation detail\footnote {There are many ways to detect termination, either through termination metrics as in ATS, or structural recursion as in Coq or Agda, or just never allow recursion, etc.}.
1012
+ The predicate $ \Eterminates {x}$ is left undefined as it is an implementation detail\footnote {There are many ways to detect termination, either through termination metrics as in ATS, or structural recursion as in Coq or Agda, or just never allow recursion, etc. There are many ways to handle this and none is objectively better than all others. }.
1011
1013
However it must be present to ensure consistency and non-looping static behaviors.
1012
1014
1013
1015
\begin {figure }[H]
@@ -1309,22 +1311,23 @@ \subsection{Atomic expressions}\label{subsec:zilch-staticsem-exprs-atoms}
1309
1311
1310
1312
\begin {prooftree }
1311
1313
\hypo {\TypeSequent {\scale {0}{\Gamma }}{A}{0}{\Etype {\ell }}{\Etotal }}
1312
- \infer 1[\textsc {[Ptr-F]}]{\TypeSequent {\scale {0}{\Gamma }}{\Eptr {A}}{0}{\Etype {\ell }}{\Etotal }}
1314
+ \hypo {\TypeSequent {\scale {0}{\Gamma }}{\rho }{0}{\Eregion }{\Etotal }}
1315
+ \infer 2[\textsc {[Ref-F]}]{\TypeSequent {\scale {0}{\Gamma }}{\Eref {A }{\rho }}{0}{\Etype {\ell }}{\Etotal }}
1313
1316
\end {prooftree }
1314
1317
\hspace {1.5em}
1315
1318
\begin {prooftree }
1316
- \hypo {\TypeSequent {\Gamma }{p}{\pi }{\Eptr {A }}{\epsilon }}
1317
- \infer 1[\textsc {[Ptr -E]}]{\TypeSequent {\Gamma }{\Ederef {p }}{\pi }{A}{\epsilon }}
1319
+ \hypo {\TypeSequent {\Gamma }{p}{\pi }{\Eref { A }{ \rho }}{\epsilon }}
1320
+ \infer 1[\textsc {[Ref -E]}]{\TypeSequent {\Gamma }{\Ederef {p }}{\pi }{A}{\epsilon }}
1318
1321
\end {prooftree }
1319
1322
\\ \vspace *{\baselineskip }
1320
1323
\begin {prooftree }
1321
1324
\hypo {\TypeSequent {\Gamma }{e}{\pi }{A}{\epsilon }}
1322
- \infer 1[\textsc {[Ptr -I]}]{\TypeSequent {\Gamma }{\Emkptr {e}}{\pi }{\Eptr {A }}{\epsilon }}
1323
- \end {prooftree } % do we really want to allow this?
1325
+ \infer 1[\textsc {[Ref -I]}]{\TypeSequent {\Gamma }{\Emkref {e }}{\pi }{\Eref { A }{ \rho }}{\epsilon }}
1326
+ \end {prooftree }
1324
1327
}
1325
1328
}
1326
1329
1327
- \caption {Type inference rules for pointers .}
1330
+ \caption {Type inference rules for references .}
1328
1331
\label {fig:zilch-staticsem-exprs-atoms-ptr-typerules }
1329
1332
\end {figure }
1330
1333
@@ -1374,32 +1377,33 @@ \section{A few notes}\label{sec:zilch-staticsem-notes}
1374
1377
\begin {description }[itemindent=0pt,left=0pt]
1375
1378
\item [For expressions]
1376
1379
\begin {align* }
1377
- \D {\lambda () \Rightarrow e} & \equiv \core {\D {\lambda (\omega \ \_ : \mathbf {1}) \Rightarrow e}} \\
1378
- \D {\lambda (\vec {\rho \ x : A}) \Rightarrow e} & \equiv \core {\lambda (\rho _0\ x_0 : \D {A_0}) \Rightarrow \ldots \Rightarrow \lambda (\rho _n\ x_n : \D {A_n}) \Rightarrow \D {e}} \\
1379
- \D {f(\vec {x})} & \equiv \core {\D {f}(\D {x_0})(\ldots )(\D {x_n})} \\
1380
- \D {() \to e} & \equiv \core {\D {(\omega \ \_ : \mathbf {1}) \to e}} \\
1381
- \D {(\vec {\rho \ x : A}) \to e} & \equiv \core {(\rho _0\ x_0 : \D {A_0}) \to \ldots \to (\rho _n\ x_n : \D {A_n}) \to \D {e}} \\
1382
- \D {if\ c\ then\ t\ else\ e} & \equiv \core {if\ \D {c}\ then\ \D {t}\ else\ \D {e}} \\
1383
- \D {(\vec {\rho \ x : A}) \otimes B} & \equiv \core {(\rho _0\ x_0 : \D {A_0}) \otimes \ldots \otimes (\rho _n\ x_n : \D {A_n}) \otimes \D {B}} \\
1384
- \D {()} & \equiv \core {()} \\
1385
- \D {(e)} & \equiv \core {\D {e}} \\
1386
- \D {(x_0, x_1, \ldots , x_n)} & \equiv \core {(\D {x_0}, (\D {x_1}, (\ldots , (\D {x_{n-1}}, \D {x_n})\ldots ))} \\
1387
- \D {let\ (\vec {x}) \coloneqq e; f} & \equiv \core {let\ (x_0, \_ _0) \coloneqq \D {e};\ldots ; let\ (x_{n-1},x_n) \coloneqq \_ _{n-1}; \D {f}} \\
1388
- \D {(\vec {x : A}) \mathbin {\& } B} & \equiv \core {(x_0 : \D {A_0}) \mathbin {\& } \ldots \mathbin {\& } (x_n : \D {A_n}) \mathbin {\& } \D {B}} \\
1389
- \D {\langle\rangle } & \equiv \core {\langle\rangle } \\
1390
- \D {\langle e\rangle } & \equiv \core {\D {e}} \\
1391
- \D {\langle x_0, x_1, \ldots , x_n\rangle } & \equiv \core {\langle\D {x_0}, \langle\D {x_1}, \langle\ldots , \langle\D {x_{n-1}}, \D {x_n}\rangle\ldots\rangle\rangle } \\
1392
- \D {let\ \rho \ f(\vec {\sigma \ x : A}) : \epsilon \ B \coloneqq e; g} & \equiv \core {let\ \rho \ f : \D {(\vec {\sigma \ x : A}) \to \epsilon \ B} \coloneqq \D {\lambda (\vec {\sigma \ x : A}) \Rightarrow e}; \D {g}} \\
1393
- \D {rec\ \rho \ f(\vec {\sigma \ x : A}) : \epsilon \ B \coloneqq e; g} & \equiv \core {rec\ \rho \ f : \D {(\vec {\sigma \ x : A}) \to \epsilon \ B} \coloneqq \D {\lambda (\vec {\sigma \ x : A}) \Rightarrow e}; \D {g}} \\
1394
- \D {let\ \rho \ x \coloneqq f(\vec {x}, \& a, \vec {y}); e} & \equiv \core {\D {let\ \rho \ (a, x) \coloneqq f(\vec {x}, a, \vec {y}); e}} \\
1395
- \D {e} & \equiv \core {e} \\
1380
+ \D {\lambda () \Rightarrow e} & \equiv \core {\D {\lambda (\omega \ \_ : \mathbf {1}) \Rightarrow e}} \\
1381
+ \D {\lambda (\overline {\rho \ x : A}) \Rightarrow e} & \equiv \core {\lambda (\rho _0\ x_0 : \D {A_0}) \Rightarrow \ldots \Rightarrow \lambda (\rho _n\ x_n : \D {A_n}) \Rightarrow \D {e}} \\
1382
+ \D {f(\overline {x})} & \equiv \core {\D {f}(\D {x_0})(\ldots )(\D {x_n})} \\
1383
+ \D {() \to e} & \equiv \core {\D {(\omega \ \_ : \mathbf {1}) \to e}} \\
1384
+ \D {(\overline {\rho \ x : A}) \to e} & \equiv \core {(\rho _0\ x_0 : \D {A_0}) \to \ldots \to (\rho _n\ x_n : \D {A_n}) \to \D {e}} \\
1385
+ \D {if\ c\ then\ t\ else\ e} & \equiv \core {if\ \D {c}\ then\ \D {t}\ else\ \D {e}} \\
1386
+ \D {(\overline {\rho \ x : A}) \otimes B} & \equiv \core {(\rho _0\ x_0 : \D {A_0}) \otimes \ldots \otimes (\rho _n\ x_n : \D {A_n}) \otimes \D {B}} \\
1387
+ \D {()} & \equiv \core {()} \\
1388
+ \D {(e)} & \equiv \core {\D {e}} \\
1389
+ \D {(x_0, x_1, \ldots , x_n)} & \equiv \core {(\D {x_0}, (\D {x_1}, (\ldots , (\D {x_{n-1}}, \D {x_n})\ldots ))} \\
1390
+ \D {let\ (\overline {x}) \coloneqq e; f} & \equiv \core {let\ (x_0, \_ _0) \coloneqq \D {e};\ldots ; let\ (x_{n-1},x_n) \coloneqq \_ _{n-1}; \D {f}} \\
1391
+ \D {(\overline {x : A}) \mathbin {\& } B} & \equiv \core {(x_0 : \D {A_0}) \mathbin {\& } \ldots \mathbin {\& } (x_n : \D {A_n}) \mathbin {\& } \D {B}} \\
1392
+ \D {\langle\rangle } & \equiv \core {\langle\rangle } \\
1393
+ \D {\langle e\rangle } & \equiv \core {\D {e}} \\
1394
+ \D {\langle x_0, x_1, \ldots , x_n\rangle } & \equiv \core {\langle\D {x_0}, \langle\D {x_1}, \langle\ldots , \langle\D {x_{n-1}}, \D {x_n}\rangle\ldots\rangle\rangle } \\
1395
+ \D {let\ \rho \ f(\overline {\sigma \ x : A}) : \epsilon \ B \coloneqq e; g} & \equiv \core {let\ \rho \ f : \D {(\overline {\sigma \ x : A}) \to \epsilon \ B} \coloneqq \D {\lambda (\overline {\sigma \ x : A}) \Rightarrow e}; \D {g}} \\
1396
+ \D {rec\ \rho \ f(\overline {\sigma \ x : A}) : \epsilon \ B \coloneqq e; g} & \equiv \core {rec\ \rho \ f : \D {(\overline {\sigma \ x : A}) \to \epsilon \ B} \coloneqq \D {\lambda (\overline {\sigma \ x : A}) \Rightarrow e}; \D {g}} \\
1397
+ % \D{let\ \rho\ x \coloneqq f(\overline{x}, \&a, \overline{y}); e} & \equiv \core{\D{let\ \rho\ (a, x) \coloneqq f(\overline{x}, a, \overline{y}); e}} \\
1398
+ % TODO: change \& to something else
1399
+ \D {e} & \equiv \core {e} \\
1396
1400
\end {align* }
1397
1401
1398
1402
\item [For the top-level]
1399
1403
\begin {align* }
1400
- \D {let\ \rho \ f(\vec {\sigma \ x : A}) : \epsilon \ B \coloneqq e} & \equiv \core {let\ \rho \ f : \D {\vec {(\sigma \ x : A)} \to \epsilon \ B} \coloneqq \D {\lambda (\vec {\sigma \ x : A}) \Rightarrow e}} \\
1401
- \D {rec\ \rho \ f(\vec {\sigma \ x : A}) : \epsilon \ B \coloneqq e} & \equiv \core {rec\ \rho \ f : \D {\vec {(\sigma \ x : A)} \to \epsilon \ B} \coloneqq \D {\lambda (\vec {\sigma \ x : A}) \Rightarrow e}} \\
1402
- \D {val\ \rho \ f(\vec {\sigma \ x : A}) : \epsilon \ B} & \equiv \core {val\ \rho \ f : (\sigma _0\ x_0 : \D {A_0}) \to \ldots \to (\sigma _n\ x_n : \D {A_n}) \to \epsilon \ \D {B}} \\
1404
+ \D {let\ \rho \ f(\overline {\sigma \ x : A}) : \epsilon \ B \coloneqq e} & \equiv \core {let\ \rho \ f : \D {\overline {(\sigma \ x : A)} \to \epsilon \ B} \coloneqq \D {\lambda (\overline {\sigma \ x : A}) \Rightarrow e}} \\
1405
+ \D {rec\ \rho \ f(\overline {\sigma \ x : A}) : \epsilon \ B \coloneqq e} & \equiv \core {rec\ \rho \ f : \D {\overline {(\sigma \ x : A)} \to \epsilon \ B} \coloneqq \D {\lambda (\overline {\sigma \ x : A}) \Rightarrow e}} \\
1406
+ \D {val\ \rho \ f(\overline {\sigma \ x : A}) : \epsilon \ B} & \equiv \core {val\ \rho \ f : (\sigma _0\ x_0 : \D {A_0}) \to \ldots \to (\sigma _n\ x_n : \D {A_n}) \to \epsilon \ \D {B}} \\
1403
1407
\end {align* }
1404
1408
\end {description }
1405
1409
0 commit comments