Fil-C on Nix

Filnix wiki

mbrock/filnix/nanofil

provenance.pl

Explanatory context, separate from executable IR and safety evidence.

A context(Function, Records) item accompanies a func/5. Bindings and origins have function-local identities. Origins are shallow typed nodes at the enclosing statement's location, not expression spans. Values retain their original identities and hints even when removed; alias/4 records substitution without renaming the surviving value.

site(inst(Label, Index), Origins) uses a zero-based index in THIS stage's instruction list. Passes produce explicit old-to-new site maps while rewriting. Phis and jumps have stable sites phi(Temp) and jump(Label). Context never participates in CFG or safety proofs.

Records

RecordMeaning
bindingId, Name, CType, Locationdeclaration identity and spelling; shadowed names have distinct IDs
originId, Location, Description, Parentsa typed lowering node, enclosing statement, or generated operation, linked by origin IDs
valueTemp, Hint, Originsoriginal definition, retained as history if eliminated
siteSite, Originsprovenance of a live instruction, phi or terminator
aliasTemp, Replacement, Hint, Originscopy/phi substitution, including replacement by a constant
historyId, Temp, Hint, Origins, Replacementretired definition when an executable name is reused; Replacement is none or replaced(Value)

Location is at(File, Line) or none. A typed description is typed(val|obj|fun, CType, ShallowForm), a statement is statement(Kind), and a synthesized operation is generated(Pass, Reason). Parents express containment or contributing origins, not executable uses. Hint is none or named(BindingId, value|address|piece). C types are explanations of source nodes, never substitutes for IR classes.

If a pass reuses a deleted temporary's spelling, its old definition moves to history/5. Incoming alias/history replacements then use historical(Id), referencing that history record, not the new value. This metadata-only reference can never be an executable operand.

Promotion conservatively cites the slot's declaration/initial value and stores, not an assertion that every store reaches every phi. Copies preserve the survivor's primary name. Raw accesses and their adjacent checks inherit the same access origin; checks and poll edges additionally have generated origins. Erasure cannot authorize an otherwise-invalid check/access pair.

useslists
usesassoc
51code_itemsItems, Code ←
excludeis_context, Items, Code
52is_contextcontext_, _
54context_recordsItems, Name, Records ←
memberchkcontextName, Rs, Items
→
Records = Rs
else
Records = []
57with_contextF, [], F ←
!
58with_contextF, Rs, F, contextName, Rs ←
F = funcName, _, _, _, _
60site_indexRs, Sites ←
findallS−Os, membersiteS, Os, Rs, Pairs
list_to_assocPairs, Sites
63site_originsSites, Site, Os ←
get_assocSite, Sites, Origins
→
Os = Origins
else
Os = []
66origin_idsRs, Ids ←
findallId−true, memberoriginId, _, _, _, Rs, Pairs
list_to_assocPairs, Ids

Only metadata names consult metadata. Executable fresh names remain exactly what the metadata-free transformation would choose.

71fresh_originBase, Ids0, Ids, Id ←
get_assocBase, Ids0, _
→
unused_originBase, 0, Ids0, Id
else
Id = Base
put_assocId, Ids0, true, Ids
74unused_originBase, N, Ids, Id ←
Candidate = derivedBase, N
get_assocCandidate, Ids, _
→
N1 is N + 1
unused_originBase, N1, Ids, Id
else
Id = Candidate
79retire_valuesRs0, Temps, Ids0, Ids, Rs ←
findallT−true, memberT, Temps, NewPairs
list_to_assocNewPairs, New
findallT−V, memberaliasT, V, _, _, Rs0, APairs
list_to_assocAPairs, Aliases
findallT−true, membervalueT, _, _, Rs0, VPairs
list_to_assocVPairs, Values
findallT,
memberR, Rs0
get_assocT, New, _
,
Ts0
sortTs0, Ts
retirement_idsTs, Ids0, Ids, Pairs
list_to_assocPairs, Retired
retire_recordsRs0, Retired, Aliases, Values, Records
findallRs1,
memberT−Id, Pairs
¬get_assocT, Values, _
¬get_assocT, Aliases, _
retiredT, none, [], none, Id, Rs1, []
,
Missing
appendRecords|Missing, All
maplistretired_referenceRetired, All, Rs
historical_temp
90valueT, _, _T
91aliasT, _, _, _T
92alias_, tmpT, _, _T
93history_, _, _, _, replacedtmpTT
95retirement_ids[], Ids, Ids, []
96retirement_idsT|Ts, Ids0, Ids, T−Id|Pairs ←
fresh_originretiredT, Ids0, Ids1, Id
retirement_idsTs, Ids1, Ids, Pairs
99retire_records[], _, _, _, []
100retire_recordsvalueT, H, Os|Rs0, New, As, Vs, Rs ←
get_assocT, New, Id
!
get_assocT, As, V
→
Replacement = replacedV
else
Replacement = none
retiredT, H, Os, Replacement, Id, Rs, Rest
retire_recordsRs0, New, As, Vs, Rest
105retire_recordsaliasT, V, H, Os|Rs0, New, As, Vs, Rs ←
get_assocT, New, Id
!
get_assocT, Vs, _
→
Rs = Rest
else
retiredT, H, Os, replacedV, Id, Rs, Rest
retire_recordsRs0, New, As, Vs, Rest
110retire_recordsR|Rs0, New, As, Vs, R|Rs ←
retire_recordsRs0, New, As, Vs, Rs
113retiredT, H, Os, Replacement, Id, originId, none, generatedcontext, retiredT, Os, historyId, T, H, Os, Replacement|Rest, Rest

Incoming references identify the old definition, not a new proof that happens to reuse its spelling. Historical references are not IR values.

119retired_referenceIds, aliasT, tmpOld, H, Os, aliasT, historicalId, H, Os ←
get_assocOld, Ids, Id
!
121retired_referenceIds, historyHId, T, H, Os, replacedtmpOld, historyHId, T, H, Os, replacedhistoricalId ←
get_assocOld, Ids, Id
!
124retired_reference_, R, R

Map is OldSite-NewSite, with one pair per emitted instruction. An instruction that expands has several destinations; one erased has none.

128remap_sitesRs0, Map, Rs ←
site_indexRs0, Sites
excludeinstruction_site, Rs0, Kept
findallsiteNew, Os,
memberOld−New, Map
get_assocOld, Sites, Os
,
NewSites
appendKept, NewSites, Rs
135instruction_sitesiteinst_, _, _

The rewriting loop calls this with the instructions it just emitted.

138emission_sites_, _, J, [], Rest, Rest, J
139emission_sitesL, I, J, _|Is, instL, I−instL, J|Ms, Rest, End ←
J1 is J + 1
emission_sitesL, I, J1, Is, Ms, Rest, End

Legacy loc markers remain valid input. At unchecked transformation boundaries they become context, never before checked-IR validation.

144legacy_contextM, M ←
ir:module_stageM, checked
!
145legacy_contextmoduleIs0, moduleIs ←
maplistlegacy_itemIs0, Is0, Groups
appendGroups, Is
148legacy_itemAll, funcN, L, R, Ps, Bs0, Items ←
!
context_recordsAll, N, Rs0
origin_idsRs0, Ids
legacy_blocksBs0, Bs, Ids, _, Added, Map
remap_sitesRs0, Map, Rs1
site_indexRs1, Sites0
foldllegacy_site, Added, Sites0, Sites
assoc_to_listSites, Pairs
findallsiteS, Os, memberS−Os, Pairs, SiteRecords
appendRs1, Added, AllRecords
excludeis_site, AllRecords, Kept
appendKept, SiteRecords, Rs
with_contextfuncN, L, R, Ps, Bs, Rs, Items
157legacy_item_, context_, _, [] ←
!
158legacy_item_, I, I
160is_sitesite_, _
161legacy_sitesiteS, Os, Sites0, Sites ←
!
site_originsSites0, S, Before
appendBefore, Os, Both
sortBoth, Merged
put_assocS, Sites0, Merged, Sites
164legacy_site_, Sites, Sites
166legacy_blocks[], [], Ids, Ids, [], []
167legacy_blocksblockL, Ps, Is0, J|Bs0, blockL, Ps, Is, J|Bs, Ids0, Ids, Rs, Map ←
legacy_instsIs0, L, 0, 0, none, Is, IRs, Last, Ids0, Ids1, M0
Is0 = loc_, _|_
IRs = originFirst, _, _, _|_
→
findallsitephiT, First, memberphitmpT, _, _, Ps, PRs
else
PRs = []
Last ≡ none
→
JRs = []
else
JRs = sitejumpL, Last
legacy_blocksBs0, Bs, Ids1, Ids, Rest, M1
appendPRs, IRs, JRs, Rest, Rs
appendM0, M1, Map
176legacy_insts[], _, _, _, Loc, [], [], Loc, Ids, Ids, []
177legacy_instslocF, Line|Is0, L, Old, New, _, Is, originId, atF, Line, statementlegacy, []|Rs, Last, Ids0, Ids, Map ←
!
fresh_originlegacyL, Old, Ids0, Ids1, Id
Next is Old + 1
legacy_instsIs0, L, Next, New, Id, Is, Rs, Last, Ids1, Ids, Map
181legacy_instsInst|Is0, L, Old, New, Loc, Inst|Is, Rs, Last, Ids0, Ids, instL, Old−instL, New|Map ←
Loc ≡ none
→
Rs = Rest
else
Rs = siteinstL, New, Loc|Rest
Old1 is Old + 1
New1 is New + 1
legacy_instsIs0, L, Old1, New1, Loc, Is, Rest, Last, Ids0, Ids, Map
187valid_contextsItems ←
findallN, membercontextN, _, Items, Names
sortNames, Unique
lengthNames, Count
lengthUnique, Count
maplistvalid_contextItems, Names
192valid_contextItems, Name ←
memberchkfuncName, _, _, _, Bs, Items
memberchkcontextName, Rs, Items
groundRs
is_listRs
findallId−true, memberoriginId, _, _, _, Rs, Ids
unique_assocIds, Origins
findallB−true, memberbindingB, _, _, _, Rs, Bindings0
unique_assocBindings0, Bindings
findallT−true, membervalueT, _, _, Rs, Values
unique_assocValues, _
findallT−true, memberaliasT, _, _, _, Rs, Aliases
unique_assocAliases, _
findallId−true, memberhistoryId, _, _, _, _, Rs, Hs
unique_assocHs, Histories
findallS−true, membersiteS, _, Rs, Sites
unique_assocSites, _
findallL−N,
memberblockL, _, Is, _, Bs
lengthIs, N
,
Sizes
list_to_assocSizes, Blocks
findallT−true,
memberblock_, Ps, _, _, Bs
memberphitmpT, _, _, Ps
,
Phis0
list_to_assocPhis0, Phis
maplistvalid_recordindexOrigins, Bindings, Histories, sitesBlocks, Phis, Rs
206unique_assocPairs, Assoc ←
findallK, memberK−_, Pairs, Keys
sortKeys, Unique
lengthKeys, N
lengthUnique, N
list_to_assocPairs, Assoc
210valid_record_, _, binding_, Name, _, Loc ←
atomName
211valid_recordRs, _, origin_, Loc, Description, Parents ←
descriptionDescription
originsRs, Parents
213valid_recordRs, _, valueT, Hint, Os ←
atomT
hintRs, Hint
originsRs, Os
214valid_recordRs, _, aliasT, V, Hint, Os ←
atomT
hintRs, Hint
originsRs, Os
216valid_recordRs, _, historyId, T, Hint, Os, Replacement ←
atomT
hintRs, Hint
originsRs, Os
Replacement ≡ none
or
Replacement = replacedV
219valid_recordRs, Bs, siteS, Os ←
221locationnone
222locationatF, L ←
atomF
integerL
L ≥ 0
223descriptionstatementK ←
atomK
224descriptiontypedC, _, _ ←
memberchkC, val, obj, fun
225descriptiongeneratedP, _ ←
atomP
226hint_, none
227hintindex_, Bs, _, namedB, Role ←
memberchkRole, value, address, piece
get_assocB, Bs, _
229originsRs, Os ←
is_listOs
maplistorigin_existsRs, Os
230origin_existsindexOrigins, _, _, O ←
get_assocO, Origins, _
231replacement_, tmpT ←
atomT
232replacement_, constN ←
integerN
233replacement_, globalN ←
atomN
234replacementindex_, _, Hs, historicalId ←
get_assocId, Hs, _
235valid_sitesitesBs, _, instL, I ←
get_assocL, Bs, N
integerI
I ≥ 0
I < N
237valid_sitesites_, Ps, phiT ←
get_assocT, Ps, _
238valid_sitesitesBs, _, jumpL ←
get_assocL, Bs, _