Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions debug_probe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

p = r'/home/evin/pyrefly/pyrefly/lib/alt/narrow.rs'
s = open(p, 'rb').read()
nl = b'\r\n' if s.count(b'\r\n') > s.count(b'\n') // 2 else b'\n'
old = nl.join([
b' // Cheaply reject callees that cannot produce a `TypeGuard`/`TypeIs` result before',
b' // paying for full call resolution.',
b' if !func_ty.is_typeis() && !func_ty.is_typeguard() {',
b' return None;',
b' }',
b' let CallTargetLookup::Ok(call_target) = self.as_call_target(func_ty.clone()) else {',
b' return None;',
b' };'])
new = nl.join([
b' eprintln!("DBG resolve: func_ty={} typeis={} typeguard={}", self.for_display(func_ty.clone()), func_ty.is_typeis(), func_ty.is_typeguard());',
b' // Cheaply reject callees that cannot produce a `TypeGuard`/`TypeIs` result before',
b' // paying for full call resolution.',
b' if !func_ty.is_typeis() && !func_ty.is_typeguard() {',
b' eprintln!("DBG resolve: cheap-reject");',
b' return None;',
b' }',
b' let CallTargetLookup::Ok(call_target) = self.as_call_target(func_ty.clone()) else {',
b' eprintln!("DBG resolve: no call target");',
b' return None;',
b' };'])
assert s.count(old) == 1, s.count(old)
s = s.replace(old, new)
old2 = nl.join([
b' match outcome.ty {',
b' Type::TypeIs(narrowed) => {'])
new2 = nl.join([
b' eprintln!("DBG resolve: outcome-ty={} subject={:?}", self.for_display(outcome.ty.clone()), outcome.guard_subject);',
b' match outcome.ty {',
b' Type::TypeIs(narrowed) => {'])
assert s.count(old2) == 1
s = s.replace(old2, new2)
open(p, 'wb').write(s)
print('debug probes inserted')
Loading
Loading