Problem
Three functions solve overlapping scope resolution problems with different approaches:
| Function |
Location |
Approach |
Handles nested blocks? |
walk_scope |
examples/ideal/main/scope_annotation.mbt |
Recursive walk with scope stack |
yes |
resolve_binder |
lang/lambda/edits/scope.mbt |
Ad-hoc FlatProj + source positions |
no |
free_vars |
lang/lambda/edits/free_vars.mbt |
Recursive walk with bound-name set |
yes |
walk_scope and free_vars follow the same pattern (recursive descent maintaining scope context) and handle nested blocks correctly. resolve_binder is ad-hoc and broken for nested blocks.
Ideal architecture
A single scope resolution phase in lang/lambda/ that produces a binding map:
Input: ProjNode tree (or Term)
Output: Map[NodeId, BindingInfo] — every Var → its binder
This replaces:
resolve_binder — just look up the binding map
free_vars — vars not in the binding map are free
walk_scope in the ideal editor — reads the binding map and adds UI metadata (color, usage_ids)
Dependencies
Scope
- Move
walk_scope's algorithm to lang/lambda/edits/ as a proper compiler phase
- Replace
resolve_binder call sites (scope.mbt, text_edit_refactor.mbt)
- Replace
free_vars with a derived query on the binding map
- Keep
walk_scope in the ideal editor as a thin wrapper that reads the phase output
Problem
Three functions solve overlapping scope resolution problems with different approaches:
walk_scopeexamples/ideal/main/scope_annotation.mbtresolve_binderlang/lambda/edits/scope.mbtfree_varslang/lambda/edits/free_vars.mbtwalk_scopeandfree_varsfollow the same pattern (recursive descent maintaining scope context) and handle nested blocks correctly.resolve_binderis ad-hoc and broken for nested blocks.Ideal architecture
A single scope resolution phase in
lang/lambda/that produces a binding map:This replaces:
resolve_binder— just look up the binding mapfree_vars— vars not in the binding map are freewalk_scopein the ideal editor — reads the binding map and adds UI metadata (color, usage_ids)Dependencies
walk_scopeapproach)Scope
walk_scope's algorithm tolang/lambda/edits/as a proper compiler phaseresolve_bindercall sites (scope.mbt, text_edit_refactor.mbt)free_varswith a derived query on the binding mapwalk_scopein the ideal editor as a thin wrapper that reads the phase output