Fil-C on Nix

Filnix wiki

the formal campaign

rocq/backend/PlanTerm.v

A plan as the term the Prolog compiler writes for it (filc_abi.pl's abi_function/10), and a module's thunks as its thunks(List). nanofilabi − terms prints both, so the plans Abi.v builds are compared with the Prolog compiler's as terms, on every function of the corpus.

From Stdlib Require Import String ZArith List Bool
From Nanofil Require Import Term Syntax Validate
From Backend Require Import IrTerm Plan FrameSlots Abi
Import ListNotations
Open Scope Z_scope
Open Scope list_scope

Keys, words and cells

The atom of a term with no arguments.

17Definition atoma : string : term ≔

As A − B, a pair.

20Definition pair_terma b : term : term ≔
TApp"-" a; b

The name of a pool: scalar, pointer or wide.

23Definition pool_termp : pool : term ≔
match p with
⇒
"scalar"
⇒
"pointer"
⇒
"wide"

A key of a frame.

27Fixpoint key_termk : key : term ≔
match k with
⇒
TApp"tmp" n
⇒
TApp"shadow" n
⇒
TApp"storage" pool_termp; TInti
⇒
atom"thread"
⇒
atom"aux"
⇒
atom"retbuf"
KLocalx size
⇒
TApp"local" x; TIntsize
KLowerk′
⇒
TApp"lower" key_termk′
⇒
TApp"stack_aux" x

A return protocol: registers or buffer(N).

41Definition protocol_termp : protocol : term ≔
match p with
⇒
atom"registers"
⇒
TApp"buffer" TIntn

The source of a fast word.

48Definition source_terms : source : term ≔
match s with

As wf(K, Source).

60Definition word_termw : word : term ≔
match w with

As cell(I, K, Source, Lower): the lower of a value is lower(V), that of a saved word the saved(W) beside it, and none if the cell holds no pointer.

66Definition cell_termc : cell : term ≔
match c with
Celli k s lower
⇒
TApp"cell" TInti; eclassk; match s with CellValuev ⇒ enc_valuev | CellSavedw ⇒ TApp"saved" TIntw end; match lower with None ⇒ atom"none" | SomeCellValuev ⇒ TApp"lower" enc_valuev | SomeCellSavedw ⇒ TApp"saved" TIntw end

The channels of a fast result.

82Definition channels_termc : channels : term ≔
match c with
⇒
TApp"slots" TListmapkey_term ks
⇒
TApp"float" eclassk; TApp"tmp" d
⇒
TApp"typed" TListmapλs ⇒ pair_termeclassfsts key_termsnds ks

As result(R, Channels).

90Definition result_termr : protocol c : channels : term ≔

What a direct call invokes.

94Definition target_termt : call_target : term ≔
match t with
⇒
TApp"implementation" f; TIntsig
TEntryf sig
⇒
TApp"entry" f; sigref_termsig

A getter.

101Definition getter_termg : getter : term ≔
match g with
⇒
TApp"local_getter" s
⇒
TApp"weak_getter" s
⇒
TApp"external_getter" s

Actions and instructions

An ABI action.

111Definition action_terma : action : term ≔
match a with
⇒
TApp"origin" atom"c"
⇒
TApp"reserve_result" protocol_termr
⇒
TApp"release_result" protocol_termr
ACopyFilterd s n res
⇒
⇒
atom"copy_join"
ADispatchp sig r ws c size cells need results
⇒
TApp"dispatch" enc_valuep; TIntsig; protocol_termr; TListmapword_term ws; result_termr c; TIntsize; TListmapcell_term cells; TApp"receive_generic" TIntneed; TListmapcell_term results
⇒
TApp"getter" getter_termg; atom"c"; d
⇒
TApp"snapshot_cursor" TApp"tmp" va_snapshot; TIntoff; d
AConsumeVak p size d
⇒
TApp"consume_va" eclassk; enc_valuep; TIntsize; d
⇒
TApp"initialize_local" x

The place of a fused access: the checked pointer, or local(X, Off).

134Definition place_termp : place : term ≔
match p with
AtLocalx off
⇒
TApp"local" x; TIntoff

A fused access: the raw load or store, its proof replaced by its place.

142Definition access_terma : access : term ≔
match a with
ALoadd k t off p
⇒
AStorew off v p
⇒
TApp"raw_store" enc_widthw; TIntoff; enc_valuev; place_termp
AStorePointeroff v p es
⇒
TApp"raw_store_pointer" TIntoff; enc_valuev; place_termp; enc_effectses

An instruction after fusion.

155Definition finst_termi : finst : term ≔
match i with
FPlaini′
⇒
⇒
FCallr p args
⇒
TApp"fused" atom"check_function"; TApp"call" enc_call_resultr; enc_valuep; TListmapenc_arg args

An instruction of a plan.

166Definition pinst_termi : pinst : term ≔
match i with
PInsti′
⇒
PAbiacts
⇒
TApp"abi" TListmapaction_term acts

The jump of a plan's block: a jump of the IR, or abi_return(Actions).

174Definition pjump_termj : pjump : term ≔
let returns ≔ λacts ⇒ TApp"abi_return" TListacts in
let success ≔ λp ⇒ TApp"success" protocol_termp in
match j with
PJumpj′
⇒
⇒
returnsTApp"return_value" eretr; enc_valuev; atom"pop_frame"; successp
⇒
returnsTApp"return_buffer" TListmapword_term ws; atom"success_buffer"; atom"pop_frame"; atom"native_return"
⇒
returnsTApp"return_typed" TListmapeclass ks; TListmapenc_value vs; atom"pop_frame"; successRegisters
⇒
returnsTApp"return_registers" TListmapenc_value vs; atom"pop_frame"; successRegisters
⇒
returnsatom"pop_frame"; successp

As block(L, Phis, Insts, Jump).

194Definition pblock_termb : pblock : term ≔

Public objects and thunks

As adapter_result(R, Channel, Size, packet(Copies, Zeros)).

201Definition adapter_result_termr : adapter_result : term ≔
TApp"adapter_result" protocol_termar_returnr; match ar_channelr with AdVoid ⇒ atom"void" | AdFloatk ⇒ TApp"float" eclassk | AdTypedks ⇒ TApp"typed" TListmapeclass ks | AdWords ⇒ atom"words" end; TIntar_sizer; TApp"packet" TListmapsource_term ar_copiesr; TListmapsource_term ar_zerosr

A public object.

214Definition object_termo : object : term ≔
match o with
FastAndGenericsig need ws r
⇒
TApp"fast_and_generic" TIntsig; TApp"adapt" TIntneed; TListmapword_term ws; adapter_result_termr
GenericOnlyneed ws r
⇒
TApp"generic_only" TApp"promote_incoming" TIntneed; TListmapword_term ws; adapter_result_termr

As thunk(F, Ref, Sig, Words, Cells, ArgsSize, Result, Need).

225Definition thunk_termt : thunk : term ≔

As thunks(List), what nanofilabi − terms prints last.

235Definition thunks_termts : listthunk : term ≔
TApp"thunks" TListmapthunk_term ts

The plan

As abi_function(Name, Linkage, Ret, Sig, Frame, Entry, Blocks, Exit, Object, Origins). The entry receives the fast words and has no setjmp sites to snapshot; the exit is the exception's; the two origins, catching and not, count the roots and the named locals.

244Definition plan_termp : plan : term ≔
let ret ≔ protocol_termpl_returnp in
let fr ≔ pl_framep in
let nroots ≔ TIntZlengthfr_rootsfr in
let origin ≔ λwhich catch ⇒ TApp"origin" atomwhich; atomcatch; nroots; TInt0; TIntpl_nlocalsp in
TApp"abi_function" pl_namep; pl_linkagep; eretpl_retp; TIntpl_sigp; TApp"frame" TListmapkey_term fr_plainfr; TListmapkey_term fr_rootsfr; TListmapλa ⇒ pair_termkey_termfsta key_termsnda fr_aliasesfr; TListTApp"native_frame" ret; atom"stack_check"; atom"save_thread"; TApp"save_return" ret; TApp"zero_roots" nroots; TApp"push_frame" atom"c"; TApp"receive" ret; TListmapword_term pl_incomingp; TApp"snapshots" TList[ ]; TListmapkey_term pl_payloadp; TListmappblock_term pl_blocksp; TListatom"pop_frame"; TApp"exception" ret; object_termpl_objectp; TListorigin"c" "catches"; origin"n" "no_catch"