Skip to content

Commit 600e96d

Browse files
committed
use fully qualified names instead of aliases
1 parent eca6041 commit 600e96d

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/Juvix/Compiler/Backend/Isabelle/Translation/FromTyped.hs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ goModule onlyTypes infoTable Internal.Module {..} =
196196
}
197197
where
198198
argnames =
199-
map (overNameText quote) $ filterTypeArgs 0 ty $ map (fromMaybe (defaultName (getLoc name) "_") . (^. Internal.argInfoName)) argsInfo
200-
name' = overNameText quote name
199+
map quoteName $ filterTypeArgs 0 ty $ map (fromMaybe (defaultName (getLoc name) "_") . (^. Internal.argInfoName)) argsInfo
200+
name' = quoteName name
201201
loc = getLoc name
202202

203203
isFunction :: [Name] -> Internal.Expression -> Maybe Internal.Expression -> Bool
@@ -377,18 +377,18 @@ goModule onlyTypes infoTable Internal.Module {..} =
377377

378378
goTypeIden :: Internal.Iden -> Type
379379
goTypeIden = \case
380-
Internal.IdenFunction name -> mkIndType (overNameText quote name) []
380+
Internal.IdenFunction name -> mkIndType (quoteName name) []
381381
Internal.IdenConstructor name -> error ("unsupported type: constructor " <> Internal.ppTrace name)
382-
Internal.IdenVar name -> TyVar $ TypeVar (overNameText quote name)
383-
Internal.IdenAxiom name -> mkIndType (overNameText quote name) []
384-
Internal.IdenInductive name -> mkIndType (overNameText quote name) []
382+
Internal.IdenVar name -> TyVar $ TypeVar (quoteName name)
383+
Internal.IdenAxiom name -> mkIndType (quoteName name) []
384+
Internal.IdenInductive name -> mkIndType (quoteName name) []
385385

386386
goTypeApp :: Internal.Application -> Type
387387
goTypeApp app = mkIndType name params
388388
where
389389
(ind, args) = Internal.unfoldApplication app
390390
params = map goType (toList args)
391-
name = overNameText quote $ case ind of
391+
name = quoteName $ case ind of
392392
Internal.ExpressionIden (Internal.IdenFunction n) -> n
393393
Internal.ExpressionIden (Internal.IdenAxiom n) -> n
394394
Internal.ExpressionIden (Internal.IdenInductive n) -> n
@@ -417,8 +417,8 @@ goModule onlyTypes infoTable Internal.Module {..} =
417417
setNameText "None" name
418418
Just Internal.BuiltinMaybeJust ->
419419
setNameText "Some" name
420-
_ -> overNameText quote name
421-
Nothing -> overNameText quote name
420+
_ -> quoteName name
421+
Nothing -> quoteName name
422422

423423
getArgtys :: Internal.ConstructorInfo -> [Internal.FunctionParameter]
424424
getArgtys ctrInfo = fst $ Internal.unfoldFunType $ ctrInfo ^. Internal.constructorInfoType
@@ -431,8 +431,8 @@ goModule onlyTypes infoTable Internal.Module {..} =
431431
Just funInfo ->
432432
case funInfo ^. Internal.functionInfoPragmas . pragmasIsabelleFunction of
433433
Just PragmaIsabelleFunction {..} -> setNameText _pragmaIsabelleFunctionName name
434-
Nothing -> overNameText quote name
435-
Nothing -> overNameText quote name
434+
Nothing -> quoteName name
435+
Nothing -> quoteName name
436436
x -> x
437437

438438
lookupName :: forall r. (Member (Reader NameMap) r) => Name -> Sem r Expression
@@ -491,8 +491,8 @@ goModule onlyTypes infoTable Internal.Module {..} =
491491
Nothing -> return $ ExprIden (goConstrName name)
492492
Internal.IdenVar name -> do
493493
lookupName name
494-
Internal.IdenAxiom name -> return $ ExprIden (overNameText quote name)
495-
Internal.IdenInductive name -> return $ ExprIden (overNameText quote name)
494+
Internal.IdenAxiom name -> return $ ExprIden (quoteName name)
495+
Internal.IdenInductive name -> return $ ExprIden (quoteName name)
496496

497497
goApplication :: Internal.Application -> Sem r Expression
498498
goApplication app@Internal.Application {..}
@@ -1218,6 +1218,20 @@ goModule onlyTypes infoTable Internal.Module {..} =
12181218
++ map (^. Internal.inductiveInfoName . namePretty) (HashMap.elems (infoTable ^. Internal.infoInductives))
12191219
++ map (^. Internal.axiomInfoDef . Internal.axiomName . namePretty) (HashMap.elems (infoTable ^. Internal.infoAxioms))
12201220

1221+
quoteName :: Name -> Name
1222+
quoteName name = overNameText goNameText name
1223+
where
1224+
goNameText :: Text -> Text
1225+
goNameText txt
1226+
| Text.elem '.' txt =
1227+
let idenName = snd $ Text.breakOnEnd "." txt
1228+
modulePath = name ^. nameId . nameIdModuleId . moduleIdPath
1229+
modulePathText = Text.intercalate "." (modulePath ^. modulePathKeyDir ++ [modulePath ^. modulePathKeyName])
1230+
moduleName' = toIsabelleTheoryName modulePathText
1231+
idenName' = quote idenName
1232+
in moduleName' <> "." <> idenName'
1233+
| otherwise = quote txt
1234+
12211235
quote :: Text -> Text
12221236
quote txt0
12231237
| Text.elem '.' txt0 = moduleName' <> "." <> idenName'

0 commit comments

Comments
 (0)