Fil-C on Nix

Filnix wiki

the formal campaign

rocq/theories/HelloModule.v

GNU Hello as the model sees it: one checked module, linked from the objects nanofil compiles for nanofil − hello − O (Campaign 7, docs/logic.md).

The fixture hello_term is the link rocq/link.pl makes of the real build's checked terms (nix/hello-fixture.nix regenerates it): each object's local items renamed OBJECT#NAME, the exported items shared, and only the items a run from main can name kept, 32 functions and their data. This file reads it as a module (hello_module), checks that the validator accepts it (hello_valid), names the functions a proof is about (hello_fn) and lists the calls the module leaves to libc (hello_externals): the contracts the proof needs.

From Stdlib Require Import String ZArith List
From Nanofil Require Import Term Syntax Transport Validate Semantics HelloCode
Import ListNotations
Open Scope string_scope

The module

The linked module (hello_term).

23Definition hello_module: module ≔
Somemd
⇒
md
None
⇒
[ ]

The fixture decodes to hello_module.

27Lemma hello_decodes
Proof 2 steps Qed
vm_compute
reflexivity

The validator accepts the linked module: every function of the core subset, every name unique (valid). Each object was valid alone; this is the link.

33Lemma hello_valid
validhello_module = Sometrue
Explore proof 2 tactics

Initial goal

⊢
validhello_module = Sometrue

vm_compute

⊢
Sometrue = Sometrue

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
vm_compute
reflexivity

The function of the module named n, or an empty one.

37Definition hello_fnn : string : func ≔
SomeDefinedf
⇒
f
_
⇒
mkFuncTAtom"none" TAtom"export" RVoid [ ] [ ]

What it leaves to libc

The names the function f calls directly.

46Definition calledf : func : listname ≔
flat_map
λ b  ⇒
flat_map
λ i  ⇒
match i with
⇒
g
_
⇒
[ ]

The names some function of md calls that md does not define, each once, in order of first call.

54Definition externalsmd : module : listname ≔
fold_left
λ acc g  ⇒
existsbname_eqbg acc
→
acc
else
appacc g
flat_map
λ it  ⇒
match it with
⇒
filter
λ g  ⇒
match find_directg md with
Some_
⇒
false
None
⇒
true
_
⇒
[ ]
md
[ ]

The 33 libc functions Hello calls: the contracts its proof needs. They are the plain entries, not the fortified ones (printf, not __printf_chk), and zmemmove is Fil-C's. The ones only quotearg calls (iswprint, mbrtoc32, __ctype_b_loc, __ctype_get_mb_cur_max, mbsinit, zmemmove, realloc) are reached only through close_stdout's diagnostic for a named file, which Hello never names.

71Definition hello_externals: liststring ≔
"iswprint"; "__fpending"; "ferror"; "fclose"; "__errno_location"; "error"; "_exit"; "mbrtoc32"; "mbrtowc"; "abort"; "memset"; "memcmp"; "strrchr"; "strncmp"; "__ctype_get_mb_cur_max"; "strlen"; "__ctype_b_loc"; "mbsinit"; "zmemmove"; "free"; "setlocale"; "memcpy"; "strcmp"; "memchr"; "fprintf"; "fputs"; "printf"; "malloc"; "realloc"; "atexit"; "getopt_long"; "exit"; "wprintf"

They are exactly the calls the module leaves undefined.

79Lemma hello_externals_exact
map
λ g  ⇒
match g with
⇒
s
_
⇒
""
=
Explore proof 2 tactics

Initial goal

⊢
map
λ g : term  ⇒
match g with
⇒
s
_
⇒
""
=

vm_compute

⊢
"iswprint"; "__fpending"; "ferror"; "fclose"; "__errno_location"; "error"; "_exit"; "mbrtoc32"; "mbrtowc"; "abort"; "memset"; "memcmp"; "strrchr"; "strncmp"; "__ctype_get_mb_cur_max"; "strlen"; "__ctype_b_loc"; "mbsinit"; "zmemmove"; "free"; "setlocale"; "memcpy"; "strcmp"; "memchr"; "fprintf"; "fputs"; "printf"; "malloc"; "realloc"; "atexit"; "getopt_long"; "exit"; "wprintf" = "iswprint"; "__fpending"; "ferror"; "fclose"; "__errno_location"; "error"; "_exit"; "mbrtoc32"; "mbrtowc"; "abort"; "memset"; "memcmp"; "strrchr"; "strncmp"; "__ctype_get_mb_cur_max"; "strlen"; "__ctype_b_loc"; "mbsinit"; "zmemmove"; "free"; "setlocale"; "memcpy"; "strcmp"; "memchr"; "fprintf"; "fputs"; "printf"; "malloc"; "realloc"; "atexit"; "getopt_long"; "exit"; "wprintf"

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
vm_compute
reflexivity