rocq/backend/NfbRead.v
NFB's term reader gives back what its writer wrote (NfbTerm.v, docs/nfb.md): for every module term t that encode_term writes with NAMES, read_term reads the words back as t itself, says whether they had NAMES, and those are words encode_term writes for t with that answer, which module_words keeps whole (read_encode_term).
The proof goes up in layers. First the words: integers written as two or three words, inline constants, codes, tables numbered by number and read by index_map, sorted string tables, bytes packed four to a word, and sections. Then one instruction: a term matched by its form's pattern is filled again from the holes its fields read back, given the reader's tables invert the writer's. The facts about the forms table, such as distinct opcodes and every hole read by a field, are checked once by computation. Then the groups of a block, the blocks and the body of a function, its temporaries named in the order of their first definitions; the data items, the side section of names, the items, and the module.
Words
words_eqb is equality of word lists.
Proof 6 steps Qed
A signed 64-bit integer, written as two words, reads back.
Proof 18 steps Qed
A signed 96-bit integer, written as three words, reads back.
Proof 22 steps Qed
An inline constant's operand word reads back as the constant, whatever the tables: tag 1, the constant in the payload.
Proof 22 steps Qed
Whether each key and each value of the table xs occurs once.
A table whose keys and values each occur once gives back the key of the value of a key.
Proof 13 steps Qed
Every enumeration's table has each atom once and each code once.
Proof 1 step Qed
The code of an atom in an enumeration reads back as the atom.
Proof 5 steps Qed
A class's code is from 1 to 8.
Proof 5 steps Qed
The two words of a signed 64-bit integer, read as two words.
Proof 4 steps Qed
The three words of a signed 96-bit integer.
Proof 4 steps Qed
Small facts
The arguments app_args finds are those of the compound.
Proof 7 steps Qed
The atom is_atom recognizes.
Proof 5 steps Qed
mapo relates each element to its image.
Proof 8 steps Qed
mapo over two lists joined.
Proof 11 steps Qed
mapo gives as many images as elements.
Proof 4 steps Qed
take_acc the first part of two joined lists, after what it took.
Proof 7 steps Qed
take the first part of two joined lists.
Proof 4 steps Qed
An integer that take counts.
Proof 3 steps Qed
at_least n is whether there are n words or more.
Proof 1 step Qed
at_least of a count, as a comparison of integers.
Proof 3 steps Qed
A ZMap lookup after an add.
Proof 6 steps Qed
A lookup in the empty ZMap.
Proof 2 steps Qed
Tables
index_map's fold leaves the keys below its start alone.
Proof 5 steps Qed
index_map's fold maps the key n + k to the k-th element.
Proof 13 steps Qed
index_map maps i to the i-th element.
The table of wide constants maps a constant to an index of it.
Proof 15 steps Qed
number never renumbers a name.
Proof 9 steps Qed
What number makes: the names newly numbered come after those numbered before, each name's number is its place in the list of both, and the count is that list's length.
Proof 74 steps Qed
number from nothing: each name's number is its place among the names newly numbered.
Proof 10 steps Qed
Names that differ are all numbered anew, in order.
Proof 16 steps Qed
Distinct names numbered from nothing: the number of each is its place in the list.
Proof 12 steps Qed
Names numbered from nothing, as many as the names: they differ, and each one's number is its place.
Proof 5 steps Qed
The places that nth_error finds for two names in a list without duplicates differ when the names do.
Proof 6 steps Qed
Sorted tables
One step of merge_uniq on two lists that are not empty.
Proof 1 step Qed
merge_uniq with an empty side.
Proof 1 step Qed
Every element of a merge is an element of one side.
Proof 11 steps Qed
The merge of two strictly sorted lists is strictly sorted.
Proof 28 steps Qed
Merging the runs in pairs keeps each strictly sorted, and leaves fewer of them.
Proof 6 steps Qed
With enough rounds, merging leaves one strictly sorted run.
Proof 5 steps Qed
sort_uniq gives a strictly sorted list.
Proof 9 steps Qed
sort_uniq gives each element once.
Proof 8 steps Qed
Strings compare equal to themselves.
Proof 4 steps Qed
The order of strings is transitive.
Proof 13 steps Qed
A sorted table of strings has each string once.
Proof 20 steps Qed
The atoms of distinct strings are distinct.
Proof 6 steps Qed
Bytes
A byte: from 0 to 255.
The four bytes of a packed word come back.
Proof 13 steps Qed
Bytes packed and unpacked come back first, and the packed words are a quarter as many, rounded up.
Proof 25 steps Qed
A byte string's words read back.
Proof 14 steps Qed
The bytes of a string are bytes.
Proof 9 steps Qed
A string's bytes give the string back.
Proof 8 steps Qed
Readers
read_n reads back the elements whose words follow one another.
Proof 6 steps Qed
Elements whose words are not empty are fewer than their words.
Proof 6 steps Qed
read_counted reads back the count and the elements.
Proof 16 steps Qed
A Forall2 of a map.
Proof 2 steps Qed
A string table's words read back.
Proof 12 steps Qed
A table of wide constants reads back.
Proof 13 steps Qed
Sections
The sections' words split back into the sections.
Proof 13 steps Qed
The sections of a module in their order: the core ones present, then NAMES if any.
What the reader finds in a module's sections.
Proof 3 steps Qed
Patterns
The holes of a pattern, in order.
match_pat on the patterns ps and the terms ts in turn.
fill_pat on the patterns ps in turn.
match_pat, one level unfolded.
Proof 1 step Qed
fill_pat, one level unfolded.
Proof 1 step Qed
Induction on patterns, with the hypothesis on every pattern of a list.
Every key of the bindings nw is one of the holes hs.
Bindings in front of others do not hide a hole they do not bind.
Proof 4 steps Qed
A list without duplicates, split in two.
Proof 9 steps Qed
What a pattern's match makes: bindings of its holes in front of the old ones; and the term, filled again from any bindings that agree on its holes, if the holes differ.
pat_ok for a list of patterns.
Proof 31 steps Qed
Every pattern is pat_ok.
Proof 43 steps Qed
The term a pattern matched is filled again from bindings that agree with the match on its holes, when they differ.
Proof 2 steps Qed
Fields
The hole a field reads.
The hole an instruction's field reads.
The reader's tables invert the writer's: each id maps back to the name, string or constant it was written for.
| ok_syms | ||
| ok_strs | ||
| ok_consts | ||
| ok_temps | ||
| ok_labels | ||
| ok_locals |
Reading the definitions ds, the reader's rebind words and next id going from rb and n to rb' and n', names each in turn.
defs_read of two lists joined.
Proof 7 steps Qed
The reader's locals from the id x on are xs, up to the id x'.
locals_read of two lists joined.
Proof 7 steps Qed
The local a field defines, if it is FLocalDef.
Bindings e1 that the bindings e agree with.
A binding env_get finds is in the list.
Proof 2 steps Qed
A bound key has a value.
Proof 3 steps Qed
An operand word reads back: tag 1 or 2 for a constant.
Proof 21 steps Qed
An operand reads back from its one word.
Proof 37 steps Qed
The temporaries a call's result defines, and its one word, read back.
Proof 66 steps Qed
The next word of the reader's state.
Proof 1 step Qed
The hole of a local's definition, which writes no word, is bound.
One field reads back into its hole the value it was written from.
Proof 128 steps Qed
FDef
FClass
FEnum
FU32
FI64
FOpnd
FLabel
FTarget
FLocal
FLocalDef
FStr
FResult
FLower
FFlightArg
The fields fs read back into their holes the values they were written from.
Proof 32 steps Qed
Whether a field writes a word.
Whether a field defines a local.
Whether a field defines temporaries.
A field's temporaries defined less its words: at most this.
The sum of the fields' fcost.
An operand's word.
Proof 11 steps Qed
A call result's word and the temporaries it defines.
Proof 34 steps Qed
A field defines at most its words plus its fcost.
Proof 35 steps Qed
A field that writes a word writes one at least.
Proof 7 steps Qed
The fields define at most their words plus their fscost.
Proof 19 steps Qed
The conditions on a list's element: its holes differ and are read by its fields, which define no local, write a word and define no more temporaries than words.
The elements of a list define no more temporaries than their words, and write as many words as elements at least.
Proof 16 steps Qed
Fields that define no local define none.
Proof 3 steps Qed
The elements of a list read back, given their count.
Proof 30 steps Qed
The elements of a list read back to the end of its words.
Proof 36 steps Qed
The fields of an instruction that define locals.
Whether a list to the end of the words comes last, if at all.
Whether no list goes to the end of the words.
The conditions on one field of an instruction.
An instruction's fields read back into their holes the values they were written from.
Proof 83 steps Qed
An instruction's fields define at most its words plus their costs; a list's elements cost nothing more.
The sum of an instruction's fields' lcost.
The cost bound of an instruction's fields.
Proof 37 steps Qed
What an instruction defines
The temporaries a field's words define.
What a field writes defines its field_defs.
Proof 30 steps Qed
A value names no temporary it defines.
Proof 6 steps Qed
What a field holds defines its field_defs.
Proof 12 steps Qed
The temporaries some fields define are the same whether their words or their parts say so.
Proof 16 steps Qed
The same for the elements of a list.
Proof 18 steps Qed
The temporaries an instruction defines are the same whether its words or its parts say so.
Proof 41 steps Qed
The table of forms
Whether the numbers of l differ.
nodupb is sound.
Proof 11 steps Qed
Whether every number of hs is one of ks.
coveredb is sound.
Proof 8 steps Qed
elem_ok as a computation.
elem_okb is sound.
Proof 13 steps Qed
Whether an instruction's field defines a local.
Whether an instruction's field defines temporaries.
Whether a pattern can match a local_alloc/2.
The form of local_alloc(X, Size), the one that defines a local.
What every form satisfies, as a computation.
Whether the integers of cs differ.
The table of forms, checked: every form satisfies form_okb, the opcodes differ, and opcode 100 is local_form.
Proof 1 step Qed
The form find_form picks is in the table and matches.
Proof 5 steps Qed
With distinct opcodes, a form is the form of its opcode.
Proof 12 steps Qed
What a form of the table satisfies.
| fo_nodup | ||
| fo_cover | : ∀h, Inh pat_holesf_patf → Inh maplfield_hole f_fieldsf | |
| fo_rest | ||
| fo_elems | ||
| fo_cost | ||
| fo_local | : f = local_form ∨ existsblf_localdef f_fieldsf = false ∧ top_localf_patf = false | |
| fo_jump | : groupf_codef = 2 → existsblf_defines f_fieldsf = false | |
| fo_code | : 2 ≤ f_codef < 65536 | |
| fo_of_code | : form_of_codeforms f_codef = Somef |
Every form of the table is form_ok.
Proof 41 steps Qed
The locals an instruction defines: one for local_alloc(X, _).
A list of patterns matches as many terms.
Proof 5 steps Qed
The fields of a form that matched t define t's locals, and each is lfield_ok.
Proof 55 steps Qed
Temporaries
The writer's temporaries M and count N come from numbering, from the map m and the count n, the definitions q still to come; the numbers so far are below n.
The rebind words of definitions read back as the definitions, with the prefix or, if every word is 0, without it.
Proof 78 steps Qed
One instruction
The reader's locals from the id x on are those of ql.
The first locals of ql read, and the rest after them.
Proof 21 steps Qed
The header word of an instruction of opcode c and length len.
Proof 8 steps Qed
An instruction without a rebind prefix reads back.
Proof 21 steps Qed
An instruction with a rebind prefix reads back.
Proof 32 steps Qed
The words of an instruction: its form's fields' words, its opcode first, and words enough for the temporaries it defines.
Proof 55 steps Qed
One instruction reads back, its definitions named as the writer numbered them and its locals in turn.
Proof 51 steps Qed
Groups and blocks
The temporaries a phi or an instruction defines, as body_words gathers them.
What defs_of gathers is what the instruction's words define.
Proof 8 steps Qed
Fields that define no temporary define none.
Proof 51 steps Qed
A jump defines no temporary.
Proof 7 steps Qed
A phi or a jump defines no local.
Proof 15 steps Qed
The reader stops a group before the words ws.
The first opcode of a group's words that are not empty.
Proof 13 steps Qed
A group of instructions reads back, as many as its words hold.
Proof 42 steps Qed
The locals a block's instructions define.
The reader's labels from the index b on are those of the blocks.
A block's parts make the block.
Proof 6 steps Qed
The phis of a group define no local.
Proof 9 steps Qed
The blocks read back from their index, the temporaries of their phis and instructions named in order of definition.
Proof 77 steps Qed
the phis
the instructions
the jump
A function's body
Some is injective; unlike injection, this leaves the terms as they are.
Proof 2 steps Qed
A function's return type reads back from its word.
Proof 29 steps Qed
The class of a parameter, as the reader checks it.
A function's parameters read back from their classes and their temporaries.
Proof 28 steps Qed
Two Forall2 chained.
Proof 3 steps Qed
The labels of the blocks, numbered from b.
Proof 14 steps Qed
The locals the writer numbers are the blocks' locals.
Proof 7 steps Qed
The module's tables a function is written and read with: symbols, strings and constants.
A function's body reads back, its names from NAMES.
Proof 129 steps Qed
Data
A character's code is not negative.
Proof 15 steps Qed
A signed 64-bit integer reads back.
Proof 6 steps Qed
The module's tables that data items are written with invert the reader's: symbols and constants.
The bytes of a string item's characters are bytes, and give the characters back.
Proof 17 steps Qed
A data item reads back from its words, which are not empty.
Proof 74 steps Qed
Names
Proof 4 steps Qed
The words of a list of side terms, joined.
Proof 11 steps Qed
A side term's words are not empty.
Proof 16 steps Qed
One joined part's length bounds each part's.
Proof 6 steps Qed
A side term reads back from its words, given enough fuel and a pool that inverts the ids.
Proof 54 steps Qed
A counted list of side terms reads back, given enough fuel.
Proof 14 steps Qed
The NAMES section reads back.
Proof 41 steps Qed
Items
A symbol's kind and linkage code come back out of its word.
Proof 8 steps Qed
A function's linkage code reads back.
Proof 3 steps Qed
An alias's linkage code reads back.
Proof 3 steps Qed
A data linkage of the table reads back from its code.
Proof 5 steps Qed
A data object's linkage reads back from its code and word.
Proof 18 steps Qed
The function names a part of NAMES adds before the rest.
A function, data object or alias reads back from its symbol's words, its DATA words and its FUNCTIONS words, before the items after it.
Proof 114 steps Qed
a function
a data object
an alias
The reader's view of a symbol: its words hold the string id of its name, then its kind word and extra word.
The items read back from their symbols, DATA words and FUNCTIONS words, before the items after them.
Proof 56 steps Qed
The symbols a module names without defining read back, and the reader skips them.
Proof 25 steps Qed
A name first_ids numbers is at its place in the names, or was already in the map it started from.
Proof 16 steps Qed
The reader's tables of a module invert the writer's: symbols, strings and constants.
Proof 40 steps Qed
The module
The SYMBOLS words read back as the reader's symbols.
Proof 15 steps Qed
A section's payload, or the words of an empty table when the section is absent because the table is empty.
Proof 1 step Qed
The words encode_term writes read back as the module, with NAMES exactly when the module has functions; they are also what encode_term writes without NAMES in that case, and module_words keeps them all.