Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit e58dea9

Browse files
committed
Factor out how we extend bindings.
1 parent 100d6a1 commit e58dea9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

semantic-core/src/Analysis/ScopeGraph.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ scopeGraphAnalysis = Analysis{..}
103103
ref <- asks Ref
104104
bindLoc <- asks (Map.lookup addr)
105105
cell <- gets (Map.lookup addr >=> nonEmpty . Set.toList)
106-
maybe (pure Nothing) (foldMapA (pure . Just . mappend (ScopeGraph (maybe Map.empty (\ bindLoc -> Map.singleton (Decl addr bindLoc) (Set.singleton ref)) bindLoc)))) cell
106+
maybe (pure Nothing) (foldMapA (pure . Just . mappend (extendBinding addr ref bindLoc))) cell
107107
assign addr v = do
108108
ref <- asks Ref
109109
bindLoc <- asks (Map.lookup addr)
110-
modify (Map.insertWith (<>) addr (Set.singleton (ScopeGraph (maybe Map.empty (\ bindLoc -> Map.singleton (Decl addr bindLoc) (Set.singleton ref)) bindLoc) <> v)))
110+
modify (Map.insertWith (<>) addr (Set.singleton (extendBinding addr ref bindLoc <> v)))
111111
abstract eval name body = do
112112
addr <- alloc name
113113
assign name (mempty @ScopeGraph)
@@ -126,3 +126,5 @@ scopeGraphAnalysis = Analysis{..}
126126
(k, v') <$ assign addr v'
127127
pure (foldMap snd fields')
128128
_ ... m = pure (Just m)
129+
130+
extendBinding addr ref bindLoc = ScopeGraph (maybe Map.empty (\ bindLoc -> Map.singleton (Decl addr bindLoc) (Set.singleton ref)) bindLoc)

0 commit comments

Comments
 (0)