binding_compiler_candidate.py (4038B)
1 #!/usr/bin/env python3 2 """Build an UNPUBLISHED source compiler with the screened binding pass. 3 4 Copies authenticated shipped source snapshots into a private workspace. No 5 accepted source, artifact, fixture or checkpoint is modified or promoted. 6 """ 7 import argparse,json,time 8 from pathlib import Path 9 from float_multiply import Runner,sha 10 from bundle_dag import read,Intern 11 from binding_substitution import ROOT 12 13 14 def main(): 15 p=argparse.ArgumentParser(description=__doc__) 16 p.add_argument('tricu',type=Path);p.add_argument('--previous',type=Path,required=True) 17 p.add_argument('--semantics',type=Path,required=True);p.add_argument('--directory',type=Path,required=True) 18 args=p.parse_args();root=args.directory.resolve();previous=args.previous.resolve() 19 evidence=json.loads((args.semantics/'report.json').read_text()) 20 old=json.loads((previous/'report.json').read_text()) 21 assert evidence['complete'] and not evidence['blocked'] 22 assert sha(previous/'report.json')==evidence['prior_report_sha256'] 23 assert sha(args.tricu)==old['runtime_sha256'] 24 metadata=json.loads((ROOT/'bootstrap/stable-compiler.json').read_text()) 25 assert sha(ROOT/metadata['bundle'])==metadata['sha256']==old['compiler_sha256'] 26 root.mkdir(parents=True,exist_ok=False);workspace=root/'workspace';workspace.mkdir() 27 runner=Runner(args.tricu,root,1800,memory_mib=8192) 28 report=dict(complete=False,promoted=False,runtime_sha256=sha(args.tricu), 29 harness_sha256=sha(Path(__file__)),compiler_sha256=metadata['sha256'], 30 semantic_evidence_sha256=sha(args.semantics/'report.json'),sources={}) 31 try: 32 tool=runner.imported(ROOT/metadata['bundle'],'accepted') 33 for row in metadata['sources']: 34 raw=(ROOT/row['snapshot']).read_bytes() 35 import hashlib 36 assert hashlib.sha256(raw).hexdigest()==row['sha256'] 37 target=workspace/(row['alias']+'.tri');target.write_bytes(raw) 38 report['sources'][row['alias']]=sha(target) 39 for alias,path in [('substitution','bench/binding-substitution.tri'),('analysis','bench/binding-analysis.tri'), 40 ('kernels','bench/float-significands.tri')]: 41 assert sha(ROOT/path)==old['sources'][alias+'.tri'] 42 (workspace/(alias+'.tri')).write_bytes((ROOT/path).read_bytes()) 43 report['sources'][alias]=sha(workspace/(alias+'.tri')) 44 helper=runner.imported(previous/'helpers.arboricx','certificates') 45 (workspace/'certificates.tri').write_text('!export * from '+helper+'\n') 46 report['certificates_bundle_sha256']=sha(previous/'helpers.arboricx') 47 stable=workspace/'source_stable.tri';raw=stable.read_text() 48 oldline='stableCompileCore core = sourceRunTerm (stableEliminate core)' 49 newline='stableCompileCore core = sourceRunTerm (stableEliminate (Binding.transform Certificates.choose Certificates.negate core))' 50 assert raw.count(oldline)==1 51 stable.write_text('!import substitution as Binding\n!import certificates as Certificates\n'+raw.replace(oldline,newline)) 52 report['candidate_stable_sha256']=sha(stable) 53 (workspace/'driver.tri').write_text('!import source_build as B\n!export sourceBuildGraph\nsourceBuildGraph = B.sourceBuildGraphStable\n') 54 began=time.monotonic() 55 runner.run('build-candidate',['compile','--file',workspace/'driver.tri','--toolchain',tool, 56 '--tool-store',runner.store,'--store',runner.store,'--output',root/'candidate.arboricx', 57 '--compile-timeout','1500'],1560) 58 report['build_wall_seconds']=time.monotonic()-began 59 report['candidate_sha256']=sha(root/'candidate.arboricx') 60 # The current gate is not claimed to be a full compiler acceptance gate. 61 report['complete']=True 62 print('BUILT unpublished candidate:',root/'candidate.arboricx') 63 finally:(root/'report.json').write_text(json.dumps(report,indent=2)+'\n') 64 65 66 if __name__=='__main__':main()