Skip to content

Commit 190ee7b

Browse files
authored
Remove unused Analyzer branches for resolving Vars (#503)
* Remove unused Analyzer branches for resolving Vars * Type fixes
1 parent 4b015aa commit 190ee7b

File tree

5 files changed

+134
-200
lines changed

5 files changed

+134
-200
lines changed

src/basilisp/lang/compiler/analyzer.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,53 +2376,8 @@ def _resolve_nested_symbol(ctx: AnalyzerContext, form: sym.Symbol) -> HostField:
23762376
)
23772377

23782378

2379-
def __fuzzy_resolve_namespace_reference(
2380-
ctx: AnalyzerContext, which_ns: runtime.Namespace, form: sym.Symbol
2381-
) -> Optional[VarRef]:
2382-
"""Resolve a symbol within `which_ns` based on any namespaces required or otherwise
2383-
referenced within `which_ns` (e.g. by a :refer).
2384-
2385-
When a required or resolved symbol is read by the reader in the context of a syntax
2386-
quote, the reader will fully resolve the symbol, so a symbol like `set/union` would be
2387-
expanded to `basilisp.set/union`. However, the namespace still does not maintain a
2388-
direct mapping of the symbol `basilisp.set` to the namespace it names, since the
2389-
namespace was required as `[basilisp.set :as set]`.
2390-
2391-
During macroexpansion, the Analyzer needs to resolve these transitive requirements,
2392-
so we 'fuzzy' resolve against any namespaces known to the current macro namespace."""
2393-
assert form.ns is not None
2394-
ns_name = form.ns
2395-
2396-
def resolve_ns_reference(
2397-
ns_map: Mapping[str, runtime.Namespace]
2398-
) -> Optional[VarRef]:
2399-
match: Optional[runtime.Namespace] = ns_map.get(ns_name)
2400-
if match is not None:
2401-
v = match.find(sym.symbol(form.name))
2402-
if v is not None:
2403-
return VarRef(
2404-
form=form, var=v, env=ctx.get_node_env(pos=ctx.syntax_position),
2405-
)
2406-
return None
2407-
2408-
# Try to match a required namespace
2409-
required_namespaces = {ns.name: ns for ns in which_ns.aliases.values()}
2410-
match = resolve_ns_reference(required_namespaces)
2411-
if match is not None:
2412-
return match
2413-
2414-
# Try to match a referred namespace
2415-
referred_namespaces = {
2416-
ns.name: ns for ns in {var.ns for var in which_ns.refers.values()}
2417-
}
2418-
return resolve_ns_reference(referred_namespaces)
2419-
2420-
24212379
def __resolve_namespaced_symbol_in_ns( # pylint: disable=too-many-branches
2422-
ctx: AnalyzerContext,
2423-
which_ns: runtime.Namespace,
2424-
form: sym.Symbol,
2425-
allow_fuzzy_macroexpansion_matching: bool = False,
2380+
ctx: AnalyzerContext, which_ns: runtime.Namespace, form: sym.Symbol,
24262381
) -> Optional[Union[MaybeHostForm, VarRef]]:
24272382
"""Resolve the symbol `form` in the context of the Namespace `which_ns`. If
24282383
`allow_fuzzy_macroexpansion_matching` is True and no match is made on existing
@@ -2432,14 +2387,6 @@ def __resolve_namespaced_symbol_in_ns( # pylint: disable=too-many-branches
24322387

24332388
ns_sym = sym.symbol(form.ns)
24342389
if ns_sym in which_ns.imports or ns_sym in which_ns.import_aliases:
2435-
# We still import Basilisp code, so we'll want to make sure
2436-
# that the symbol isn't referring to a Basilisp Var first
2437-
v = Var.find(form)
2438-
if v is not None:
2439-
return VarRef(
2440-
form=form, var=v, env=ctx.get_node_env(pos=ctx.syntax_position),
2441-
)
2442-
24432390
# Fetch the full namespace name for the aliased namespace/module.
24442391
# We don't need this for actually generating the link later, but
24452392
# we _do_ need it for fetching a reference to the module to check
@@ -2491,8 +2438,6 @@ def __resolve_namespaced_symbol_in_ns( # pylint: disable=too-many-branches
24912438
form=form,
24922439
)
24932440
return VarRef(form=form, var=v, env=ctx.get_node_env(pos=ctx.syntax_position),)
2494-
elif allow_fuzzy_macroexpansion_matching:
2495-
return __fuzzy_resolve_namespace_reference(ctx, which_ns, form)
24962441

24972442
return None
24982443

@@ -2550,12 +2495,6 @@ def __resolve_namespaced_symbol( # pylint: disable=too-many-branches
25502495
resolved = __resolve_namespaced_symbol_in_ns(ctx, current_ns, form)
25512496
if resolved is not None:
25522497
return resolved
2553-
elif ctx.current_macro_ns is not None:
2554-
resolved = __resolve_namespaced_symbol_in_ns(
2555-
ctx, ctx.current_macro_ns, form, allow_fuzzy_macroexpansion_matching=True
2556-
)
2557-
if resolved is not None:
2558-
return resolved
25592498

25602499
if "." in form.ns:
25612500
try:
@@ -2834,8 +2773,6 @@ def _analyze_form( # pylint: disable=too-many-branches
28342773
if form == llist.List.empty():
28352774
with ctx.quoted():
28362775
return _const_node(ctx, form)
2837-
elif ctx.is_quoted:
2838-
return _const_node(ctx, form)
28392776
else:
28402777
return _list_node(ctx, form)
28412778
elif isinstance(form, vec.Vector):

src/basilisp/lang/compiler/generator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,8 +2599,12 @@ def _const_record_to_py_ast(ctx: GeneratorContext, form: IRecord) -> GeneratedPy
25992599
tp.create
26002600
), "IRecord and IType must declare a .create class method"
26012601

2602-
keys, vals, vals_deps = [], [], []
2603-
for k, v in runtime.to_seq(form):
2602+
form_seq = runtime.to_seq(form)
2603+
assert form_seq is not None, "IRecord types must be iterable"
2604+
2605+
keys, vals = [], []
2606+
vals_deps: List[ast.AST] = []
2607+
for k, v in form_seq:
26042608
assert isinstance(k, kw.Keyword), "Record key in seq must be keyword"
26052609
key_nodes = _kw_to_py_ast(ctx, k)
26062610
keys.append(key_nodes.node)

0 commit comments

Comments
 (0)