tracker
All repositories: gitoria
1.9 KB
# refparams.py <app dir> [--apply] [files...]: lambda parameters that a body only READS get `&` (hybriel#48: a lambda parameter# copies its argument since 4371b7aa; before it was a reference — `&` restores exactly that for read-only params, without the copy).# Skipped: params assigned (p = …), field-assigned (p.x = / p[k] =), list-mutated (p.push …), aliased (let x = p), defaults.import re,sys,glob,osos.chdir(sys.argv[1]); apply='--apply' in sys.argvfiles=[a for a in sys.argv[2:] if a!='--apply'] or (glob.glob('*.hl')+glob.glob('lib/*.hl')+glob.glob('components/*.hl')+glob.glob('tools/*.hl'))total=0; changed_files=0for f in sorted(files):src=open(f,encoding='utf-8').read(); out=[]; last=0; n=0for m in re.finditer(r'\(([^()]*)\)(\s*=>\s*\{)',src):params=[p.strip() for p in m.group(1).split(',')]if params==[''] : continueif not all(re.match(r'^&?\w+$',p) for p in params): continuei=m.end(); depth=1while depth and i<len(src):c=src[i]; depth += (c=='{') - (c=='}'); i+=1body=src[m.end():i-1]new=[]for p in params:if p.startswith('&'): new.append(p); continuebad = re.search(r'(?<![\w.])%s\s*=(?!=)'%p,body) or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])+\s*=(?!=)'%p,body) \or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])*\.(push|pop|shift|unshift|splice|sort|reverse)\('%p,body) \or re.search(r'=\s*%s\s*$'%p,body,re.M) or re.search(r'=\s*%s\s*[;}]'%p,body) or re.search(r'(?<![\w.])%s\s*(\+\+|--)'%p,body)new.append(p if bad else '&'+p)if new!=params:n+=1out.append(src[last:m.start()]); out.append('('+', '.join(new)+')'); last=m.start()+1+len(m.group(1))+1out.append(src[last:])if n:total+=n; changed_files+=1print(f'{f}: {n} lambdas')if apply: open(f,'w',encoding='utf-8').write(''.join(out))print('total lambdas changed',total,'files',changed_files)
Branches
Latest commits
- 73010cc0HM52: report replace-navigation search draft regressionmre
- 1742e92bstatus: DP64 and HM52 runningmre
- 29ad5b58log: #64 merged, DP64 and HM52 startedmre
- fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
- b2e2206dlog: #63 livemre
- 5831e0e0log: HM64 donemre
- 4042b923Flatten catalog membership rows into paired slotsmre
- ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
- 40439456Merge hm63-searchtext: tracker#63 packed search textmre
- b7e6b48ePack normalized search text behind numeric offsetsmre
- b35f53e1log: DP62 stale runtime decisionmre
- f9593602log: Apollo deploy rule correctionmre
- 3c95f7f3log: DP62 and HM63 startedmre
- 9c4397c9mission HM63mre
- 8dfe42c8mission DP62mre
- e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre
- 8274bcf1log: RV44 done, deploy held for the usage windowmre
- 1ef7a3b1RV44: report day44 gates and migration/restart proofsmre
- a5f62f6cRV44: re-vendor Hybriel set day44 (source 222edef7, bin 4f0f263e)mre
- 6159a248Merge branch 'hm62-personindex' into rv44mre