|
| 1 | +"""H-26B base-typed virtual resolvability census (derived from the H-25 runner; corrected environment; H-25 row files) (derived from the H-24 runner; harness invariant 0: the corrected environment is the default) over the kept H-23A scan clones (e3h23/<tag>): the SAME project/TFM units, reference |
| 2 | +directories and trusted row files the OFF/ON scans used; runs the extractor once per unit with OWEN_RE_ORACLE=<unit |
| 3 | +rows> and OWEN_H24_CENSUS=<unit>/h24.jsonl (census only, no engines), then aggregates one record per disposable local |
| 4 | +with nested writes. usage: h24census.py <repo> [<repo> ...]""" |
| 5 | +import json, os, sys, subprocess, glob, re, hashlib, time, collections |
| 6 | +S='/tmp/claude-0/-home-user/8a9da608-aa27-5449-8306-1fae9426f9b9/scratchpad'; R='/home/user/Own.NET'; E=f'{S}/lab/sc/e3h23'; E2=f'{S}/lab/sc/e2h23' |
| 7 | +FIX=True # corrected compilation environment: SDK implicit global usings + the ASP.NET Core ref pack (erratum 2) |
| 8 | +XD={'net8':f'{S}/ext8q/ownsharp-extract.dll','net10':f'{S}/ext10q/ownsharp-extract.dll'} |
| 9 | +OUT=f'{S}/lab/h26b/census'; os.makedirs(OUT,exist_ok=True) |
| 10 | +sys.path.insert(0,f'{S}/lab/h24'); from implicit_usings import implicit_usings |
| 11 | +def aspnet_ref(major): |
| 12 | + c=sorted(glob.glob(f'/root/.dotnet/packs/Microsoft.AspNetCore.App.Ref/{major}.*/ref/net{major}.0')) |
| 13 | + return c[-1] if c else None |
| 14 | +env={**os.environ,'PATH':'/root/.dotnet:'+os.environ['PATH'],'DOTNET_NOLOGO':'1','DOTNET_CLI_TELEMETRY_OPTOUT':'1','DOTNET_SKIP_FIRST_TIME_EXPERIENCE':'1'} |
| 15 | +for k in ('OWEN_RE_ORACLE','OWEN_H23A','OWEN_RE_BODY','OWEN_RE_MINTED_RETURN','OWEN_RE_MIXED_RETURN','OWEN_LAB_THROWEXIT','OWEN_LAB_NULLINIT','OWEN_LAB_NULLGUARD','OWEN_P037X_GUARDED','OWEN_P037X_RELATIONAL','OWEN_RE_ORACLE_HITLOG','OWEN_H24_CENSUS','OWEN_H25_CENSUS','OWEN_H26B_CENSUS'): env.pop(k,None) |
| 16 | +EXCL=re.compile(r'(^|/)(tests?|testing|samples?|benchmarks?|examples?|docs?|demo)(/|\.|$)',re.I) |
| 17 | +TESTP=re.compile(r'(test|tests|testing|benchmark|bench|sample|samples|example|examples|demo|playground)',re.I) |
| 18 | +def assets_of(p,W): |
| 19 | + c=os.path.join(os.path.dirname(p),'obj','project.assets.json') |
| 20 | + if os.path.exists(c): return c |
| 21 | + pn=os.path.splitext(os.path.basename(p))[0] |
| 22 | + for c in glob.glob(f'{W}/**/artifacts/obj/{pn}/project.assets.json',recursive=True): return c |
| 23 | + return None |
| 24 | +for repo in sys.argv[1:]: |
| 25 | + tag=repo.replace('/','__'); W=f'{E}/{tag}'; t0=time.time() |
| 26 | + e2=json.load(open(f'{E2}/{tag}.e2.json')) |
| 27 | + projs=sorted(p for p in glob.glob(f'{W}/**/*.csproj',recursive=True)); prod=[p for p in projs if not EXCL.search(os.path.relpath(p,W))] |
| 28 | + units=0; recs=[]; fails=0 |
| 29 | + for p in prod: |
| 30 | + rel=os.path.relpath(p,W); assets=assets_of(p,W) |
| 31 | + if not assets or rel not in e2['per_project'] or 'targets' not in e2['per_project'][rel]: continue |
| 32 | + a=json.load(open(assets)) |
| 33 | + for tfm in a['targets']: |
| 34 | + tfm0=tfm.split('/')[0] |
| 35 | + if tfm0 not in e2['per_project'][rel]['targets']: continue |
| 36 | + refdir=f'{W}/.refs/{hashlib.sha256((rel+tfm).encode()).hexdigest()[:10]}'; keyf=f'{refdir}/rows.json' |
| 37 | + if not os.path.exists(keyf): continue |
| 38 | + srcs=sorted(x for x in glob.glob(os.path.join(os.path.dirname(p),'**','*.cs'),recursive=True) if '/obj/' not in x and '/bin/' not in x) |
| 39 | + if not srcs: continue |
| 40 | + m=re.match(r'net(\d+)\.',tfm0); major=int(m.group(1)) if m else 0; xd=XD['net10'] if major>=9 else XD['net8'] |
| 41 | + sfx='h26b'; out=f'{refdir}/{sfx}.jsonl'; open(out,'w').close(); hits=f'{refdir}/{sfx}hits.jsonl'; open(hits,'w').close() |
| 42 | + e={**env,'OWEN_RE_ORACLE':keyf,'OWEN_H26B_CENSUS':out,'OWEN_RE_ORACLE_HITLOG':hits}; extra=[] |
| 43 | + if FIX: |
| 44 | + ns=implicit_usings(p) or [] |
| 45 | + if ns: |
| 46 | + gu=f'{refdir}/GlobalUsings.g.cs'; open(gu,'w').write(''.join(f'global using {n};\n' for n in ns)); extra.append(gu) |
| 47 | + ar=aspnet_ref(major if major else 8) |
| 48 | + if ar: e['OWN_EXTRA_REF_DIRS']=ar |
| 49 | + try: pr=subprocess.run(['dotnet',xd,'--flow-locals',*srcs,*extra,'--ref-dir',refdir,'-o',f'{refdir}/{sfx}.facts.json'],cwd=R,capture_output=True,text=True,env=e,timeout=1500); rc=pr.returncode |
| 50 | + except subprocess.TimeoutExpired: rc='timeout' |
| 51 | + if rc!=0: fails+=1 |
| 52 | + units+=1 |
| 53 | + for l in open(out): |
| 54 | + if not l.strip(): continue |
| 55 | + j=json.loads(l); j['project']=rel; j['tfm']=tfm0; j['kind']='test' if TESTP.search(os.path.basename(rel)) or TESTP.search(os.path.relpath(j['file'],W) if j['file'].startswith(W) else j['file']) else 'production' |
| 56 | + j['file']=os.path.relpath(j['file'],W) if j['file'].startswith(W) else j['file']; recs.append(j) |
| 57 | + json.dump({'repo':repo,'sha':e2['sha'],'units':units,'extractor_failures':fails,'seconds':round(time.time()-t0),'environment':'corrected (implicit usings + aspnet ref pack)' if FIX else 'as-is','records':recs},open(f'{OUT}/{tag}.h26b.json','w'),indent=1) |
| 58 | + c=collections.Counter((r['kind'],r['provenance']) for r in recs if r['is_virtual_member']) |
| 59 | + print('H26B_DONE',repo,'units',units,'fails',fails,'disposable-returning library calls',len(recs),'virtual-member sites by kind/provenance',dict(c),flush=True) |
0 commit comments