From 110146284952ab8d985ca86875c4594eef9375ca Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Fri, 15 Nov 2024 12:51:18 +0100 Subject: [PATCH] style --- .../Concrete/Data/InfoTableBuilder.hs | 18 ++++++++----- .../FromParsed/Analysis/Scoping.hs | 26 ++++++++++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/Juvix/Compiler/Concrete/Data/InfoTableBuilder.hs b/src/Juvix/Compiler/Concrete/Data/InfoTableBuilder.hs index 288cf107b7..775edf35ca 100644 --- a/src/Juvix/Compiler/Concrete/Data/InfoTableBuilder.hs +++ b/src/Juvix/Compiler/Concrete/Data/InfoTableBuilder.hs @@ -28,7 +28,7 @@ data InfoTableBuilder :: Effect where RegisterRecordInfo :: S.NameId -> RecordInfo -> InfoTableBuilder m () RegisterAlias :: S.NameId -> PreSymbolEntry -> InfoTableBuilder m () RegisterLocalModule :: ScopedModule -> InfoTableBuilder m () - GetInfoTable :: InfoTableBuilder m InfoTable + GetBuilderInfoTable :: InfoTableBuilder m InfoTable GetBuiltinSymbol' :: Interval -> BuiltinPrim -> InfoTableBuilder m S.Symbol RegisterBuiltin' :: BuiltinPrim -> S.Symbol -> InfoTableBuilder m () @@ -92,7 +92,7 @@ runInfoTableBuilder ini = reinterpret (runState ini) $ \case modify (over infoScoperAlias (HashMap.insert uid a)) RegisterLocalModule m -> mapM_ (uncurry registerBuiltinHelper) (m ^. scopedModuleInfoTable . infoBuiltins . to HashMap.toList) - GetInfoTable -> + GetBuilderInfoTable -> get GetBuiltinSymbol' i b -> do tbl <- get @InfoTable @@ -153,16 +153,22 @@ anameFromScopedIden s = _anameVerbatim = s ^. scopedIdenSrcName . nameVerbatim } -lookupInfo :: (Members '[InfoTableBuilder, Reader InfoTable] r) => (InfoTable -> Maybe a) -> Sem r a +getInfo :: (Members '[InfoTableBuilder, Reader InfoTable] r) => (InfoTable -> Maybe a) -> Sem r a +getInfo f = do + tab1 <- ask + fromMaybe (fromJust (f tab1)) . f <$> getBuilderInfoTable + +lookupInfo :: (Members '[InfoTableBuilder, Reader InfoTable] r) => (InfoTable -> Maybe a) -> Sem r (Maybe a) lookupInfo f = do tab1 <- ask - fromMaybe (fromJust (f tab1)) . f <$> getInfoTable + tab2 <- getBuilderInfoTable + return (f tab1 <|> f tab2) lookupFixity :: (Members '[InfoTableBuilder, Reader InfoTable] r) => S.NameId -> Sem r FixityDef -lookupFixity uid = lookupInfo (HashMap.lookup uid . (^. infoFixities)) +lookupFixity uid = getInfo (^. infoFixities . at uid) getPrecedenceGraph :: (Members '[InfoTableBuilder, Reader InfoTable] r) => Sem r PrecedenceGraph getPrecedenceGraph = do tab <- ask - tab' <- getInfoTable + tab' <- getBuilderInfoTable return $ combinePrecedenceGraphs (tab ^. infoPrecedenceGraph) (tab' ^. infoPrecedenceGraph) diff --git a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs index c44db9a0cc..cd1048d6e3 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs @@ -726,7 +726,11 @@ lookupQualifiedSymbol :: ([Symbol], Symbol) -> Sem r (HashSet PreSymbolEntry, HashSet ModuleSymbolEntry, HashSet FixitySymbolEntry) lookupQualifiedSymbol sms = do - (es, (ms, fs)) <- runOutputHashSet . runOutputHashSet . execOutputHashSet $ go sms + (es, (ms, fs)) <- + runOutputHashSet + . runOutputHashSet + . execOutputHashSet + $ go sms return (es, ms, fs) where go :: @@ -1156,7 +1160,21 @@ checkInductiveParameters params = do checkInductiveDef :: forall r. - (Members '[HighlightBuilder, Reader ScopeParameters, Error ScoperError, State Scope, State ScoperState, InfoTableBuilder, Reader InfoTable, NameIdGen, Reader PackageId, State ScoperSyntax, Reader BindingStrategy] r) => + ( Members + '[ HighlightBuilder, + Reader ScopeParameters, + Error ScoperError, + State Scope, + State ScoperState, + InfoTableBuilder, + Reader InfoTable, + NameIdGen, + Reader PackageId, + State ScoperSyntax, + Reader BindingStrategy + ] + r + ) => InductiveDef 'Parsed -> Sem r (InductiveDef 'Scoped) checkInductiveDef InductiveDef {..} = do @@ -1824,9 +1842,9 @@ checkLocalModule :: Sem r (Module 'Scoped 'ModuleLocal) checkLocalModule md@Module {..} = do tab1 <- ask @InfoTable - tab2 <- getInfoTable + tab2 <- getBuilderInfoTable (tab, (moduleExportInfo, moduleBody', moduleDoc')) <- - withLocalScope $ runReader (tab1 <> tab2) $ runInfoTableBuilder mempty $ do + withLocalScope . runReader (tab1 <> tab2) . runInfoTableBuilder mempty $ do inheritScope (e, b) <- checkModuleBody _moduleBody doc' <- mapM checkJudoc _moduleDoc