1 | \documentclass[11pt,epsf,a4wide]{article} |
---|
2 | \usepackage[mathletters]{ucs} |
---|
3 | \usepackage[utf8x]{inputenc} |
---|
4 | \usepackage{listings} |
---|
5 | \usepackage{../../style/cerco} |
---|
6 | \newcommand{\ocaml}{OCaml} |
---|
7 | \newcommand{\clight}{Clight} |
---|
8 | \newcommand{\matita}{Matita} |
---|
9 | \newcommand{\sdcc}{\texttt{sdcc}} |
---|
10 | |
---|
11 | \newcommand{\textSigma}{\ensuremath{\Sigma}} |
---|
12 | |
---|
13 | % LaTeX Companion, p 74 |
---|
14 | \newcommand{\todo}[1]{\marginpar{\raggedright - #1}} |
---|
15 | |
---|
16 | \lstdefinelanguage{coq} |
---|
17 | {keywords={Definition,Lemma,Theorem,Remark,Qed,Save,Inductive,Record}, |
---|
18 | morekeywords={[2]if,then,else}, |
---|
19 | } |
---|
20 | |
---|
21 | \lstdefinelanguage{matita} |
---|
22 | {keywords={definition,lemma,theorem,remark,inductive,record,qed,let,rec,match,with,Type,and,on}, |
---|
23 | morekeywords={[2]whd,normalize,elim,cases,destruct}, |
---|
24 | mathescape=true, |
---|
25 | morecomment=[n]{(*}{*)}, |
---|
26 | } |
---|
27 | |
---|
28 | \lstset{language=matita,basicstyle=\small\tt,columns=flexible,breaklines=false, |
---|
29 | keywordstyle=\color{red}\bfseries, |
---|
30 | keywordstyle=[2]\color{blue}, |
---|
31 | commentstyle=\color{green}, |
---|
32 | stringstyle=\color{blue}, |
---|
33 | showspaces=false,showstringspaces=false} |
---|
34 | |
---|
35 | \lstset{extendedchars=false} |
---|
36 | \lstset{inputencoding=utf8x} |
---|
37 | \DeclareUnicodeCharacter{8797}{:=} |
---|
38 | \DeclareUnicodeCharacter{10746}{++} |
---|
39 | \DeclareUnicodeCharacter{9001}{\ensuremath{\langle}} |
---|
40 | \DeclareUnicodeCharacter{9002}{\ensuremath{\rangle}} |
---|
41 | |
---|
42 | |
---|
43 | \title{ |
---|
44 | INFORMATION AND COMMUNICATION TECHNOLOGIES\\ |
---|
45 | (ICT)\\ |
---|
46 | PROGRAMME\\ |
---|
47 | \vspace*{1cm}Project FP7-ICT-2009-C-243881 \cerco{}} |
---|
48 | |
---|
49 | \date{ } |
---|
50 | \author{} |
---|
51 | |
---|
52 | \begin{document} |
---|
53 | \thispagestyle{empty} |
---|
54 | |
---|
55 | \vspace*{-1cm} |
---|
56 | \begin{center} |
---|
57 | \includegraphics[width=0.6\textwidth]{../../style/cerco_logo.png} |
---|
58 | \end{center} |
---|
59 | |
---|
60 | \begin{minipage}{\textwidth} |
---|
61 | \maketitle |
---|
62 | \end{minipage} |
---|
63 | |
---|
64 | |
---|
65 | \vspace*{0.5cm} |
---|
66 | \begin{center} |
---|
67 | \begin{LARGE} |
---|
68 | \bf |
---|
69 | Report n. D3.3\\ |
---|
70 | Executable Formal Semantics of front end intermediate languages\\ |
---|
71 | \end{LARGE} |
---|
72 | \end{center} |
---|
73 | |
---|
74 | \vspace*{2cm} |
---|
75 | \begin{center} |
---|
76 | \begin{large} |
---|
77 | Version 1.0 |
---|
78 | \end{large} |
---|
79 | \end{center} |
---|
80 | |
---|
81 | \vspace*{0.5cm} |
---|
82 | \begin{center} |
---|
83 | \begin{large} |
---|
84 | Main Authors:\\ |
---|
85 | Brian~Campbell |
---|
86 | \end{large} |
---|
87 | \end{center} |
---|
88 | |
---|
89 | \vspace*{\fill} |
---|
90 | \noindent |
---|
91 | Project Acronym: \cerco{}\\ |
---|
92 | Project full title: Certified Complexity\\ |
---|
93 | Proposal/Contract no.: FP7-ICT-2009-C-243881 \cerco{}\\ |
---|
94 | |
---|
95 | \clearpage \pagestyle{myheadings} \markright{\cerco{}, FP7-ICT-2009-C-243881} |
---|
96 | |
---|
97 | \newpage |
---|
98 | |
---|
99 | \vspace*{7cm} |
---|
100 | \paragraph{Abstract} |
---|
101 | We report on the formalization of the front end intermediate languages for the |
---|
102 | \cerco{} project's compiler using executable semantics in the \matita{} proof |
---|
103 | assistant. This includes common definitions for fresh identifier handling, |
---|
104 | $n$-bit arithmetic and operations and testing of the smeantics. We also |
---|
105 | consider embedding invariants into the semantics for showing correctness |
---|
106 | properties. |
---|
107 | |
---|
108 | \newpage |
---|
109 | |
---|
110 | \tableofcontents |
---|
111 | |
---|
112 | % TODO: clear up any -ize vs -ise |
---|
113 | % TODO: clear up any "front end" vs "front-end" |
---|
114 | % TODO: clear up any mentions of languages that aren't textsf'd. |
---|
115 | % TODO: mention the restricted form of types after Clight |
---|
116 | % TODO: fix unicode in listings |
---|
117 | % TODO: say something about what CIC is, and why we're doing this. |
---|
118 | |
---|
119 | \section{Introduction} |
---|
120 | |
---|
121 | This work formalizes the front end intermediate languages from the \cerco{} |
---|
122 | prototype compiler, described in previous deliverables~\cite{d2.1,d2.2}. The |
---|
123 | front end of the compiler is summarized in Figure~\ref{fig:summary} including |
---|
124 | the intermediate languages and the compiler passes described in the |
---|
125 | accompanying deliverable 3.2. We have also refined parts of the formal |
---|
126 | development that are used for several of the languages in the compiler. |
---|
127 | |
---|
128 | The input language to the formalized front end is the \textsf{Clight} |
---|
129 | language. The executable semantics for this language were presented in a |
---|
130 | previous deliverable~\cite{d3.1}. Here we will report on some |
---|
131 | minor changes to its semantics made to better align it with the whole |
---|
132 | development. |
---|
133 | |
---|
134 | Finally, we will report on work to add several invariants to the |
---|
135 | languages. This activity overlaps with task 3.4 on the correctness of the |
---|
136 | compiler front end. However, the use of dependent types mean that this work |
---|
137 | is tied closely to the definition of the languages and the transformations of |
---|
138 | the front end in task 3.2. By considering it now we can experiment with and |
---|
139 | judge its impact on the formal semantics, and how feasible retrofitting such |
---|
140 | invariants is. |
---|
141 | |
---|
142 | \begin{figure} |
---|
143 | \begin{center} |
---|
144 | \begin{minipage}{.8\linewidth} |
---|
145 | \begin{tabbing} |
---|
146 | \quad \= $\downarrow$ \quad \= \kill |
---|
147 | \textsf{C} (unformalized)\\ |
---|
148 | \> $\downarrow$ \> CIL parser (unformalized \ocaml)\\ |
---|
149 | \textsf{Clight}\\ |
---|
150 | \> $\downarrow$ \> cast removal\\ |
---|
151 | \> $\downarrow$ \> add runtime functions\\ |
---|
152 | \> $\downarrow$ \> labelling\\ |
---|
153 | \> $\downarrow$ \> stack variable allocation and control structure |
---|
154 | simplification\\ |
---|
155 | \textsf{Cminor}\\ |
---|
156 | \> $\downarrow$ \> generate global variable initialisation code\\ |
---|
157 | \> $\downarrow$ \> transform to RTL graph\\ |
---|
158 | \textsf{RTLabs}\\ |
---|
159 | \> $\downarrow$ \> start of target specific backend\\ |
---|
160 | \>\quad \vdots |
---|
161 | \end{tabbing} |
---|
162 | \end{minipage} |
---|
163 | \end{center} |
---|
164 | \caption{Front end languages and transformations} |
---|
165 | \label{fig:summary} |
---|
166 | \end{figure} |
---|
167 | |
---|
168 | \subsection{Revisions to the prototype compiler} |
---|
169 | |
---|
170 | Ongoing work to maintain and improve the prototype compiler has resulted in |
---|
171 | several changes, mostly minor. The most important change is that the |
---|
172 | transformations to replace 16 and 32 bit types have been moved from the |
---|
173 | \textsf{Clight} language to the target-specific stage between \textsf{RTLabs} |
---|
174 | and \textsf{RTL} to help generate better code, and the addition of a |
---|
175 | \textsf{Clight} cast removal transformation to reduce the number of 16 and 32 |
---|
176 | bit operations. |
---|
177 | |
---|
178 | The formalized semantics have tracked these changes, and in this report we |
---|
179 | describe them as they currently stand. |
---|
180 | |
---|
181 | \section{Definitions common to several languages} |
---|
182 | |
---|
183 | The semantics for many of the languages in the compiler share some core parts: |
---|
184 | the memory model, environments, runtime values, definitions of operations and |
---|
185 | a monad for encapsulating failure and I/O (using resumptions). The executable |
---|
186 | memory model was ported from CompCert as part of the work on \textsf{Clight} |
---|
187 | and was reused for the front end languages\footnote{However, it is likely that |
---|
188 | we will revise the memory model to make it better suited for describing the |
---|
189 | back-end of our compiler.}. The failure and I/O monad was introduced in the |
---|
190 | previous deliverable on \textsf{Clight}~\cite[\S4.2]{d3.1}. In all of the |
---|
191 | languages except \textsf{Clight} we have a basic form of type, \lstinline'typ' |
---|
192 | identifying integers and pointers along with their sizes. The other parts |
---|
193 | are discussed below, with the only change to the runtime values being the |
---|
194 | representation of integers. |
---|
195 | |
---|
196 | \subsection{Identifiers} |
---|
197 | |
---|
198 | Each language features one or more kinds of names to represent variables, such |
---|
199 | as registers, \texttt{goto} labels or RTL graph labels. We also need to |
---|
200 | describe various maps whose domain is a set of identifiers when defining the |
---|
201 | semantics and compilation. |
---|
202 | |
---|
203 | Previous work on the executable semantics of the target machine |
---|
204 | code included bit vectors and bit vector tries to define various integers in |
---|
205 | the semantics, and give a low level view of memory~\cite{d4.1}. To keep the |
---|
206 | size of the development down we have reused these data structures for |
---|
207 | identifiers and maps respectively. |
---|
208 | |
---|
209 | One difficulty with using fixed size bit vectors for identifiers is that |
---|
210 | fresh name generation can fail if generate too many. While we use an error |
---|
211 | monad to deal with failures, we wish to minimize its use in the compiler. |
---|
212 | Thus we add a flag to detect overflows, and check it after the phase of the |
---|
213 | compiler is complete to report exhaustion. The rest of the phase can then be |
---|
214 | written as if name generation always succeeds. In practice this will never |
---|
215 | occur on normal programs because more identifiers of each sort are available |
---|
216 | than bytes of code memory on the target. |
---|
217 | |
---|
218 | Given the wide variety of identifiers used in the compiler we also |
---|
219 | wish to separate the different classes of identifier. Thus we encapsulate the |
---|
220 | bit vector representing the identifier in a datatype that also carries a tag |
---|
221 | identifying which class of identifier we are using: |
---|
222 | \begin{lstlisting} |
---|
223 | inductive identifier (tag:String) : Type[0] ≝ |
---|
224 | an_identifier : Word → identifier tag. |
---|
225 | \end{lstlisting} |
---|
226 | The tries are also tagged in the same manner. These tags have also proved |
---|
227 | useful during testing by making the resulting terms more readable. |
---|
228 | |
---|
229 | \subsection{Machine integers and arithmetic} |
---|
230 | |
---|
231 | The bit vectors in~\cite{d4.1} also came equipped with some basic arithmetic |
---|
232 | for the target semantics. The front end required these operations to be |
---|
233 | generalized and extended. |
---|
234 | |
---|
235 | % TODO: expand, note need to sufficiently good performance for testing |
---|
236 | |
---|
237 | \subsection{Front end operations} |
---|
238 | |
---|
239 | The two front end intermediate languages, \textsf{Cminor} and \textsf{RTLabs}, |
---|
240 | share the same set of operations on values. They differ from |
---|
241 | \textsf{Clight}'s operations by incorporating casts and by having a separate |
---|
242 | operation for each type of data operated upon. For example, subtraction of |
---|
243 | pointers is treated as a different operation from subtraction of integers. |
---|
244 | |
---|
245 | A common semantics is given for these operations in the form of simple |
---|
246 | CIC functions on the operation and runtime values. |
---|
247 | |
---|
248 | \section{\textsf{Clight} modifications} |
---|
249 | |
---|
250 | The \textsf{Clight} input language remained largely the same as in the |
---|
251 | previous deliverable~\cite{d3.1}. The principal changes were to use the |
---|
252 | identifiers and arithmetic described above in place of the arbitrarily large |
---|
253 | integers used before. For the identifiers, this relieved us of the burden of |
---|
254 | adding an efficient datatype for maps by reusing the bit vector tries instead. |
---|
255 | |
---|
256 | The arithmetic replaced a dependent pair of an arbitrary integer and a proof |
---|
257 | that it was in range of 32 bit integers by the exact bit vector for each |
---|
258 | size of integer. This direct approach is closer to the implementation and |
---|
259 | more obviously correct --- no extra precision can be left in by accident. |
---|
260 | |
---|
261 | \section{\textsf{Cminor}} |
---|
262 | |
---|
263 | The \textsf{Cminor} language does not store local variables in memory, and has |
---|
264 | simpler control structures than \textsf{Clight}. It is similar in nature to |
---|
265 | the \textsf{Cminor} language in CompCert, although the semantics have been |
---|
266 | based on the \cerco{} prototype rather than ported from CompCert. The syntax |
---|
267 | is similar to the prototype, except that the types attached to expressions are |
---|
268 | restricted so that some corner cases are ruled out in the \textsf{Cminor} to |
---|
269 | \textsf{RTLabs} stage (see the accompanying deliverable 3.2 for details): |
---|
270 | \begin{lstlisting} |
---|
271 | inductive expr : typ → Type[0] ≝ |
---|
272 | | Id : ∀t. ident → expr t |
---|
273 | | Cst : ∀t. constant → expr t |
---|
274 | | Op1 : ∀t,t'. unary_operation → expr t → expr t' |
---|
275 | | Op2 : ∀t1,t2,t'. binary_operation → expr t1 → expr t2 → expr t' |
---|
276 | | Mem : ∀t,r. memory_chunk → expr (ASTptr r) → expr t |
---|
277 | | Cond : ∀sz,sg,t. expr (ASTint sz sg) → expr t → expr t → expr t |
---|
278 | | Ecost : ∀t. costlabel → expr t → expr t. |
---|
279 | \end{lstlisting} |
---|
280 | For example, note that conditional expressions only switch on integer |
---|
281 | expressions. |
---|
282 | In principle we could extend this to statically ensure that only well-typed |
---|
283 | \textsf{Cminor} expressions are considered, and we will consider this as part |
---|
284 | of the work on correctness in task 3.4. |
---|
285 | |
---|
286 | We also provide a variant of the syntax where the only initialization data is |
---|
287 | the size of each global variable, for use after the initialization code has |
---|
288 | been generated. |
---|
289 | |
---|
290 | The definition of the semantics is routine: a functional definition of a |
---|
291 | single small step of the machine is given, reusing the memory model, |
---|
292 | environments, arithmetic and operations mentioned above. |
---|
293 | |
---|
294 | \section{\textsf{RTLabs}} |
---|
295 | |
---|
296 | The \textsf{RTLabs} language provides a target independent Register Transfer |
---|
297 | Language, where programs are represented as control flow graphs. We use the |
---|
298 | identifiers described above for the graph labels and the maps for the graph |
---|
299 | itself. The tagging mechanism ensures that labels cannot be mixed up with |
---|
300 | other identifiers in the program (in particular, we cannot accidentally reuse |
---|
301 | a \texttt{goto} label from Cminor where a graph label should appear). |
---|
302 | |
---|
303 | Otherwise, the syntax and semantics of \textsf{RTLabs} mirrors that of the |
---|
304 | prototype compiler. The same common elements are used as for \textsf{Cminor}, |
---|
305 | including the front end operations mentioned above. |
---|
306 | |
---|
307 | % TODO: give fragment of syntax, in particular the type of the graph |
---|
308 | |
---|
309 | \section{Testing} |
---|
310 | |
---|
311 | To provide some assurance that the semantics were properly implemented, and to |
---|
312 | support the testing described in the accompanying deliverable 3.2, we have |
---|
313 | adapted the pretty printers in the prototype compiler to produce \matita{} |
---|
314 | terms for the syntax of each language described above. |
---|
315 | |
---|
316 | A few common definitions were added for animating the small step semantics |
---|
317 | definitions for any of the front end languages in \matita. We then used a |
---|
318 | small selection of test cases to ensure basic functionality. However, this is |
---|
319 | still a time consuming process, so more testing will carried out once the |
---|
320 | extraction of CIC terms to \ocaml{} programs is implemented in \matita. |
---|
321 | |
---|
322 | \section{Embedding invariants} |
---|
323 | |
---|
324 | Each phase of the prototype compiler can fail in a number of places if the |
---|
325 | input language permits programs that are badly structured in some sense: a |
---|
326 | missing label in a \texttt{goto} statement or CFG, an undefined variable name, |
---|
327 | a \texttt{break} statement outside of a loop or \texttt{switch}, and so on. |
---|
328 | We wish to restrict our intermediate languages using dependent types to remove |
---|
329 | as many `junk' programs as possible to rule out such failures. We also hope |
---|
330 | that such restrictions will help in other correctness proofs. |
---|
331 | |
---|
332 | This goal lies in the overlap between several tasks in the project: it |
---|
333 | involves manipulating the syntax and semantics of the intermediate languages |
---|
334 | (the present work), the encoding of the front-end compiler phases in \matita{} |
---|
335 | (task 3.2) and the correctness of the front-end (task 3.4). Thus this work is |
---|
336 | rather experimental; it is being carried out on branches in our source code |
---|
337 | repository and the final form will be decided and merged in during task 3.4. |
---|
338 | |
---|
339 | So far we have tried adding two forms of invariant --- one using dependent |
---|
340 | types to index statements in \textsf{Cminor} by their block depth, and the |
---|
341 | other asserts that variables and labels are present in the appropriate |
---|
342 | environments by adding a separate invariant to each function. Note that these |
---|
343 | do not yet cover all of the properties that a program in these languages is |
---|
344 | expected to enjoy; for example, there are currently no checks that references |
---|
345 | to globals are well-defined. |
---|
346 | |
---|
347 | \subsection{\textsf{Cminor} block depth} |
---|
348 | |
---|
349 | The \textsf{Cminor} language has relatively simple control structures. |
---|
350 | Statements are provided for infinite loops, non-looping blocks and |
---|
351 | exiting an arbitrary number of blocks (for \texttt{break}, failing loop guards |
---|
352 | and the switch statement\footnote{We are considering replacing the |
---|
353 | \textsf{Cminor} switch statement with one that uses \texttt{goto}-like labels |
---|
354 | in both the prototype and the formalized compilers, but for now we stick with |
---|
355 | this CompCert-style arrangement.}). |
---|
356 | |
---|
357 | However, this means that there are badly-formed \textsf{Cminor} programs such |
---|
358 | as |
---|
359 | \begin{lstlisting}[language={}] |
---|
360 | int main() { |
---|
361 | block { |
---|
362 | loop { |
---|
363 | exit 5 |
---|
364 | } |
---|
365 | } |
---|
366 | } |
---|
367 | \end{lstlisting} |
---|
368 | where we attempt to exit more blocks than exist. To rule these out (including |
---|
369 | demonstrating that the previous phase of the compiler does not generate them) |
---|
370 | we can index the statements of the language by the depth of the enclosing |
---|
371 | blocks. |
---|
372 | |
---|
373 | The adaption of the syntax adds the depth to every statement, and uses bounded |
---|
374 | integers in the exit and switch statements: |
---|
375 | \begin{lstlisting}[language=matita] |
---|
376 | inductive stmt : ∀blockdepth:nat. Type[0] ≝ |
---|
377 | | St_skip : ∀n. stmt n |
---|
378 | ... |
---|
379 | | St_loop : ∀n. stmt n → stmt n |
---|
380 | | St_block : ∀n. stmt (S n) → stmt n |
---|
381 | | St_exit : ∀n. Fin n → stmt n |
---|
382 | (* expr to switch on, table of <switch value, #blocks to exit>, default *) |
---|
383 | | St_switch : expr → ∀n. list (int × (Fin n)) → Fin n → stmt n |
---|
384 | ... |
---|
385 | \end{lstlisting} |
---|
386 | where \texttt{stmt n} is a statement enclosed in \texttt{n} blocks, |
---|
387 | and \texttt{Fin n} is a standard construction for a natural number which is at |
---|
388 | most \texttt{n}. |
---|
389 | |
---|
390 | In the semantics the number of blocks is also added to the continuations and |
---|
391 | state, and the function to find the continuation from an exit statement can be |
---|
392 | made failure-free. |
---|
393 | We note in passing that adding this parameter detected a small mistake in the |
---|
394 | semantics concerning continuations and tail calls, although the mistake itself |
---|
395 | was benign. |
---|
396 | |
---|
397 | \subsection{Identifier invariants} |
---|
398 | |
---|
399 | To show that the variables and labels occurring in the body of a function |
---|
400 | are present in the relevant structures we add an additional invariant to the |
---|
401 | function records. |
---|
402 | |
---|
403 | For \textsf{Cminor} we use a higher-order predicate which recursively applies |
---|
404 | a predicate to all substatements: |
---|
405 | \begin{lstlisting}[language=matita] |
---|
406 | let rec stmt_P (P:stmt → Prop) (s:stmt) on s : Prop ≝ |
---|
407 | match s with |
---|
408 | [ St_seq s1 s2 ⇒ P s ∧ stmt_P P s1 ∧ stmt_P P s2 |
---|
409 | | St_ifthenelse _ _ _ s1 s2 ⇒ P s ∧ stmt_P P s1 ∧ stmt_P P s2 |
---|
410 | | St_loop s' ⇒ P s ∧ stmt_P P s' |
---|
411 | | St_block s' ⇒ P s ∧ stmt_P P s' |
---|
412 | | St_label _ s' ⇒ P s ∧ stmt_P P s' |
---|
413 | | St_cost _ s' ⇒ P s ∧ stmt_P P s' |
---|
414 | | _ ⇒ P s |
---|
415 | ]. |
---|
416 | \end{lstlisting} |
---|
417 | Dependent pattern matching on statements thus allows an accompanying |
---|
418 | \lstinline'stmt_P' fact to be unfold to the predicate on the current statement |
---|
419 | and the predicate applied to all substatements. |
---|
420 | |
---|
421 | We require two properties to hold in \textsf{Cminor} functions: |
---|
422 | \begin{enumerate} |
---|
423 | \item All variables in the body are present in the list of parameters or the |
---|
424 | list of variables for the function (this also uses a similar recursive |
---|
425 | predicate on expressions). |
---|
426 | \item All labels in \texttt{goto} statements appear in a label statement. |
---|
427 | \end{enumerate} |
---|
428 | The function definition thus becomes: |
---|
429 | \begin{lstlisting}[language=matita] |
---|
430 | record internal_function : Type[0] ≝ |
---|
431 | { f_return : option typ |
---|
432 | ; f_params : list (ident × typ) |
---|
433 | ; f_vars : list (ident × typ) |
---|
434 | ; f_stacksize : nat |
---|
435 | ; f_body : stmt |
---|
436 | ; f_inv : stmt_P (λs.stmt_vars (λi.Exists ? (λx.\fst x = i) (f_params @ f_vars)) s ∧ |
---|
437 | stmt_labels (λl.Exists ? (λl'.l' = l) (labels_of f_body)) s) f_body |
---|
438 | }. |
---|
439 | \end{lstlisting} |
---|
440 | where \lstinline'stmt_vars' and \lstinline'stmt_labels' constrain the |
---|
441 | variables and labels that appear directly in a statement (but not |
---|
442 | substatements) to appear in the given list, and |
---|
443 | \lstinline'labels_of' returns a list of all the labels defined in a |
---|
444 | statement. |
---|
445 | |
---|
446 | The \textsf{Clight} semantics can be amended to use these invariants, although |
---|
447 | the main benefit is for the compiler stages (see the accompanying deliverable |
---|
448 | 3.2 for details). The semantics require the invariants to be added to the |
---|
449 | state and continuations. It was convenient to split the continuations between |
---|
450 | the local continuation representing the rest of the code to be executed within |
---|
451 | the function, and the stack of function calls. |
---|
452 | % TODO: because??? |
---|
453 | The invariant for variables is |
---|
454 | slightly different --- we require that every variable appear in the local |
---|
455 | environment. We use \lstinline'f_inv' from the function to establish this |
---|
456 | invariant when the environment is set up on function entry. |
---|
457 | |
---|
458 | It is unclear whether changing the semantics is really worthwhile. It |
---|
459 | witnesses that the invariants are those we wanted, but makes no difference to |
---|
460 | the actual execution of the program, especially as the execution can still |
---|
461 | fail due to genuine runtime errors. Moreover, it is unclear what effect the |
---|
462 | presence of proof terms and more dependent pattern matching in the semantics |
---|
463 | will have on the complexity of future correctness proofs. We plan to examine |
---|
464 | this issue during task 3.4. |
---|
465 | |
---|
466 | We use a similar method to specify the invariant that the \textsf{RTLabs} |
---|
467 | graph is closed --- that is, any successor labels in a statement in the graph |
---|
468 | are present in the graph. The definition is simpler in \textsf{RTLabs} |
---|
469 | because the flat representation of the graph does not require recursive |
---|
470 | definitions like \lstinline'stmt_P' above. |
---|
471 | |
---|
472 | \section{Conclusion} |
---|
473 | |
---|
474 | \bibliographystyle{plain} |
---|
475 | \bibliography{report} |
---|
476 | |
---|
477 | \end{document} |
---|