Skip to content

Commit

Permalink
fix a bunch of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Apr 28, 2024
1 parent 060b786 commit ca5bada
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Elara/AST/Generic/Instances/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ instance
where
prettyFields = hsep . punctuate "," . map (\(name, value) -> pretty name <+> ":" <+> pretty value) . toList

instance (Show (ValueDeclAnnotations ast), RUnlocate ast) => Pretty (ValueDeclAnnotations ast) where
instance RUnlocate ast => Pretty (ValueDeclAnnotations ast) where
pretty (ValueDeclAnnotations v) = braces ("Operator fixity:" <+> maybe "None" pretty v)

instance RUnlocate (ast :: b) => Pretty (InfixDeclaration ast) where
Expand Down
2 changes: 1 addition & 1 deletion src/Elara/AST/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ prettyValueTypeDef :: (Pretty a1, Pretty a2) => a1 -> a2 -> Doc AnsiStyle
prettyValueTypeDef name t = "def" <+> pretty name <+> "=" <+> pretty t

prettyTypeDeclaration :: (Pretty a1, Pretty a2, Pretty a3) => a1 -> [a2] -> a3 -> TypeDeclAnnotations ast -> Doc AnsiStyle
prettyTypeDeclaration name vars t ann =
prettyTypeDeclaration name vars t _ =
vsep
[ keyword "type" <+> typeName (pretty name)
, keyword "type" <+> typeName (pretty name) <+> hsep (varName . pretty <$> vars)
Expand Down
1 change: 0 additions & 1 deletion src/Elara/Core.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Elara.Core where

import Control.Lens (Plated (plate), transform)
import Control.Monad.State hiding (StateT)
import Data.Data
import Elara.AST.Name (Qualified)
import Elara.AST.VarRef (UnlocatedVarRef)
Expand Down
2 changes: 1 addition & 1 deletion src/Elara/Emit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Elara.Data.TopologicalGraph (TopologicalGraph, traverseGraphRevTopologica
import Elara.Data.Unique
import Elara.Emit.Error
import Elara.Emit.Expr
import Elara.Emit.Lambda (createLambda, etaExpand, etaExpandN)
import Elara.Emit.Lambda (etaExpandN)
import Elara.Emit.Method (createMethod, createMethodWith, createMethodWithCodeBuilder, etaExpandNIntoMethod)
import Elara.Emit.Operator (translateOperatorName)
import Elara.Emit.Params
Expand Down
3 changes: 1 addition & 2 deletions src/Elara/Emit/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module Elara.Emit.Expr where

import Control.Lens
import Data.Text qualified as Text
import Data.Traversable (for)
import Elara.AST.Name
Expand Down Expand Up @@ -265,7 +264,7 @@ generateAppInstructions f x = do
Log.debug $ "Collected type args: " <> showPretty typeArgs

case approximateTypeAndNameOf f' of
Left (local, localType) -> do
Left (local, _) -> do
Log.debug $ "Function is a local variable: " <> showPretty local
emit $ ALoad local
generateInstructions x
Expand Down
11 changes: 5 additions & 6 deletions src/Elara/Emit/Lambda.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
-- | Utility functions for creating JVM lambdas
module Elara.Emit.Lambda where

import Data.Hashable (hash)
import Data.List.NonEmpty qualified as NE
import Elara.AST.VarRef
import Elara.Core
Expand All @@ -25,9 +24,9 @@ import Polysemy
import Polysemy.Error
import Polysemy.Log (Log)
import Polysemy.Log qualified as Log
import Print (debugPretty, showPretty)
import Print (showPretty)

import Control.Lens (Field1 (_1), Field2 (_2), cosmos, filtered, filteredBy, to, (^..), _Just)
import Control.Lens (Field2 (_2), cosmos, filtered, (^..), _Just)
import Control.Lens qualified as Lens
import Data.Generics.Sum (AsAny (_As))
import Data.Traversable (for)
Expand Down Expand Up @@ -133,9 +132,9 @@ createLambda baseParams returnType thisClassName body = do
createMethod thisClassName lambdaMethodDescriptor lambdaMethodName body'
let (functionalInterface, invoke, baseMethodDescriptor, methodDescriptor) =
case baseParams of
(n1, t) :| [] -> ("Elara/Func", "run", MethodDescriptor [ObjectFieldType "java/lang/Object"] (TypeReturn (ObjectFieldType "java/lang/Object")), MethodDescriptor [t] (TypeReturn returnType))
(n1, t1) :| [(n2, t2)] -> ("Elara/Func2", "run", MethodDescriptor (replicate 2 (ObjectFieldType "java/lang/Object")) (TypeReturn (ObjectFieldType "java/lang/Object")), MethodDescriptor [t1, t2] (TypeReturn returnType))
(n1, t1) :| [(n2, t2), (n3, t3)] -> ("Elara/Func3", "run", MethodDescriptor (replicate 3 (ObjectFieldType "java/lang/Object")) (TypeReturn (ObjectFieldType "java/lang/Object")), MethodDescriptor [t1, t2, t3] (TypeReturn returnType))
(_, t) :| [] -> ("Elara/Func", "run", MethodDescriptor [ObjectFieldType "java/lang/Object"] (TypeReturn (ObjectFieldType "java/lang/Object")), MethodDescriptor [t] (TypeReturn returnType))
(_, t1) :| [(_, t2)] -> ("Elara/Func2", "run", MethodDescriptor (replicate 2 (ObjectFieldType "java/lang/Object")) (TypeReturn (ObjectFieldType "java/lang/Object")), MethodDescriptor [t1, t2] (TypeReturn returnType))
(_, t1) :| [(_, t2), (_, t3)] -> ("Elara/Func3", "run", MethodDescriptor (replicate 3 (ObjectFieldType "java/lang/Object")) (TypeReturn (ObjectFieldType "java/lang/Object")), MethodDescriptor [t1, t2, t3] (TypeReturn returnType))
other -> error $ "createLambda: " <> show other <> " parameters not supported"

let inst =
Expand Down
9 changes: 4 additions & 5 deletions src/Elara/Emit/Method.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ import JVM.Data.Abstract.Descriptor (MethodDescriptor (..), ReturnDescriptor (..
import JVM.Data.Abstract.Instruction

import Data.List.NonEmpty qualified as NE
import Elara.Core (CoreExpr, Expr (..), Type, functionTypeArgs, functionTypeResult)
import Elara.Core (CoreExpr, Expr (..), Type, functionTypeArgs)
import Elara.Core.Analysis (declaredLambdaArity, estimateArity)
import Elara.Data.Unique
import Elara.Emit.Error
import Elara.Emit.Params
import Elara.Emit.Utils (generateFieldType)
import JVM.Data.Abstract.Name
import Polysemy
import Polysemy.Error
import Polysemy.Internal.Union (Union)
import Polysemy.Log (Log)
import Polysemy.Log qualified as Log
import Polysemy.Reader
Expand Down Expand Up @@ -136,12 +134,13 @@ analyseMaxStack instructions = maximum $ scanl (+) 0 (stackChange <$> instructio
stackChange IfGt{} = -1
stackChange IfLe{} = -1
stackChange Goto{} = 0
stackChange ILoad{} = 1
stackChange IStore{} = -1
stackChange Label{} = 0 -- labels have no representation in the bytecode

etaExpandNIntoMethod ::
( HasCallStack
, Member UniqueGen r
, Member (Error EmitError) r
, Member (Reader GenParams) r
, Member Log r
) =>
Expand All @@ -155,7 +154,7 @@ etaExpandNIntoMethod funcCall exprType thisClassName = do
Just x -> x
Nothing -> error $ "etaExpandNIntoMethod: " <> show exprType <> " is not a function type"
Log.debug $ "etaExpandNIntoMethod: " <> showPretty ((funcCall, arity), exprType, thisClassName, args)
params <- traverse (\_ -> makeUnique "param") args
params <- traverse (\_ -> makeUnique ("param" :: Text)) args
let paramTypes = zip params args

local (\x -> x{checkCasts = False}) $
Expand Down
1 change: 0 additions & 1 deletion src/Elara/Emit/Var.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Elara.Core.Pretty (PrettyVar (prettyVarArg), prettyVar)
import Elara.Data.Pretty
import Elara.Emit.Utils (generateFieldType)
import JVM.Data.Abstract.Type (FieldType)
import Print (debugPretty)

data JVMBinder
= JVMLocal !Word8 (Maybe JVMLocalType)
Expand Down
4 changes: 4 additions & 0 deletions src/Elara/Parse/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ parseErrorSources :: ElaraParseError -> [SourceRegion]
parseErrorSources (KeywordUsedAsName l) = [view sourceRegion l]
parseErrorSources (EmptyRecord sr) = [sr]
parseErrorSources (EmptyLambda sr) = [sr]
parseErrorSources (InfixPrecTooHigh l) = [view sourceRegion l]

instance HasHints ElaraParseError (Doc AnsiStyle) where
hints (KeywordUsedAsName kw) =
Expand All @@ -46,11 +47,14 @@ instance HasHints ElaraParseError (Doc AnsiStyle) where
]
hints (EmptyLambda _) =
[Note "Lambda expressions cannot be empty."]
hints (InfixPrecTooHigh _) =
[Note "The precedence of an infix operator must be between 0 and 9."]

instance ShowErrorComponent ElaraParseError where
showErrorComponent (KeywordUsedAsName kw) = "Keyword " <> show kw <> " used as name"
showErrorComponent (EmptyRecord _) = "Empty record"
showErrorComponent (EmptyLambda _) = "Empty lambda"
showErrorComponent (InfixPrecTooHigh l) = "Infix precedence too high: " <> show l

newtype WParseErrorBundle e m = WParseErrorBundle {unWParseErrorBundle :: ParseErrorBundle e m}

Expand Down
1 change: 0 additions & 1 deletion src/Elara/Rename.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import Polysemy.Reader hiding (Local)
import Polysemy.State
import Polysemy.State.Extra
import Polysemy.Utils (withModified)
import Print (debugPretty)
import TODO (todo)

data RenameError
Expand Down
2 changes: 1 addition & 1 deletion src/Elara/TypeInfer/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ applicableTyApp :: Show s => Type s -> Type s -> [Type s]
-- applicableTyApp x y | traceShow ("ata", pretty x, pretty y) False = undefined
-- If x and y are the same, there's no instantiation to be done
applicableTyApp x y | x `structuralEq` y = []
applicableTyApp _ y@(UnsolvedType{}) = []
applicableTyApp _ (UnsolvedType{}) = []
-- If x is forall a. a, and y is x, then we need to instantiate x with a
applicableTyApp (Forall{name, type_ = VariableType{name = n}}) y | name == n = [y]
-- If x is forall a. a -> _, and y is c -> _, then we need to instantiate x with c
Expand Down

0 comments on commit ca5bada

Please sign in to comment.