Carp icon indicating copy to clipboard operation
Carp copied to clipboard

[refactor]: add resolvers; refactor evaluator

Open scolsen opened this issue 3 years ago • 1 comments

This PR does two things:

  1. Add a new Resolver abstraction. Resolvers dictate the order in which lookups should be performed. They're a new layer between the Environment lookup functions and provide a means of performing lookups at a slightly higher level--each Resolver is a combination of lookup techniques and Resolvers themselves can be flexibly chained together. For example, localShadowResolver <> globalDynamicResolver will return a resolver that first attempts to find shadowed symbols in the local environment and then attempts to find globally defined dynamic symbols. The comments in Resolver.hs explain this in a bit more detail.
  2. The Resolvers allow us to remove all the inline lookup code in the main eval loops in favor of Resolvers. In addition, I've moved all the local evaluator functions out of the main eval loop and into the top level. Instead of relying on implicitly closured state, one has to pass additional state directly--but this should make the primary loop much more modular and should make the individual evaluators easier to modify.

I'm hoping (2.) makes it a bit easier to start debugging potential performance hotspots in the evaluation loop (see #1215)

scolsen avatar Feb 17 '22 21:02 scolsen

Oh, also, Resolver's Show instance makes it significantly easier to debug lookup problems. Each resolver has a given name, and if you Show any resolver it will display the order in which the Resolvers combined to build it (with the semigroup) are run:

"GlobalDynamic -> DynamicFull -> LocalFull -> GlobalFull -> CurrentModule -> Type -> UseModule ..." 

etc. so, doing trace (show resolver) helps quite a bit when there's lookup issues.

scolsen avatar Feb 17 '22 21:02 scolsen