diff --git a/builder/src/Build.hs b/builder/src/Build.hs index 95637994f..80cad33b4 100644 --- a/builder/src/Build.hs +++ b/builder/src/Build.hs @@ -113,7 +113,6 @@ fork work = _ <- forkIO $ putMVar mvar =<< work return mvar -{-# INLINE forkWithKey #-} forkWithKey :: (k -> a -> IO b) -> Map.Map k a -> IO (Map.Map k (MVar b)) forkWithKey func dict = Map.traverseWithKey (\k v -> fork (func k v)) dict diff --git a/builder/src/Deps/Diff.hs b/builder/src/Deps/Diff.hs index 2ac7f6f15..450582974 100644 --- a/builder/src/Deps/Diff.hs +++ b/builder/src/Deps/Diff.hs @@ -149,16 +149,6 @@ diffType oldType newType = diffFields fields fields' (Just oldExt, Just newExt) -> (:) (oldExt, newExt) <$> diffFields fields fields' - (Type.Unit, Type.Unit) -> - Just [] - (Type.Tuple a b cs, Type.Tuple x y zs) -> - if length cs /= length zs - then Nothing - else do - aVars <- diffType a x - bVars <- diffType b y - cVars <- concat <$> zipWithM diffType cs zs - return (aVars ++ bVars ++ cVars) (_, _) -> Nothing diff --git a/builder/src/Reporting/Task.hs b/builder/src/Reporting/Task.hs index 9b1b53854..7e1e35342 100644 --- a/builder/src/Reporting/Task.hs +++ b/builder/src/Reporting/Task.hs @@ -34,7 +34,6 @@ mapError func (Task task) = -- IO -{-# INLINE io #-} io :: IO a -> Task x a io work = Task $ \ok _ -> work >>= ok @@ -60,18 +59,15 @@ eio func work = -- INSTANCES instance Functor (Task x) where - {-# INLINE fmap #-} fmap func (Task taskA) = Task $ \ok err -> let okA arg = ok (func arg) in taskA okA err instance Applicative (Task x) where - {-# INLINE pure #-} pure a = Task $ \ok _ -> ok a - {-# INLINE (<*>) #-} (<*>) (Task taskFunc) (Task taskArg) = Task $ \ok err -> let okFunc func = @@ -80,10 +76,8 @@ instance Applicative (Task x) where in taskFunc okFunc err instance Monad (Task x) where - {-# INLINE return #-} return = pure - {-# INLINE (>>=) #-} (>>=) (Task taskA) callback = Task $ \ok err -> let okA a = diff --git a/cabal.config b/cabal.config deleted file mode 100644 index ea8f1197a..000000000 --- a/cabal.config +++ /dev/null @@ -1,2 +0,0 @@ -profiling: False -library-profiling: True diff --git a/compiler/src/AST/Canonical.hs b/compiler/src/AST/Canonical.hs index cc2282c6a..18e9e02cb 100644 --- a/compiler/src/AST/Canonical.hs +++ b/compiler/src/AST/Canonical.hs @@ -100,8 +100,6 @@ data Expr_ | Access Expr (A.Located Name) | Update Name Expr (Map.Map Name FieldUpdate) | Record (Map.Map Name Expr) - | Unit - | Tuple Expr Expr (Maybe Expr) data CaseBranch = CaseBranch Pattern Expr @@ -132,8 +130,6 @@ data Pattern_ | PVar Name | PRecord [PatternRecordField] | PAlias Pattern Name - | PUnit - | PTuple Pattern Pattern (Maybe Pattern) | PArray [Pattern] | PBool Union Bool | PChr ES.String @@ -175,8 +171,6 @@ data Type | TVar Name | TType ModuleName.Canonical Name [Type] | TRecord (Map.Map Name FieldType) (Maybe Name) - | TUnit - | TTuple Type Type (Maybe Type) | TAlias ModuleName.Canonical Name [(Name, Type)] AliasType deriving (Eq) @@ -307,18 +301,16 @@ instance Binary Type where TLambda a b -> putWord8 0 >> put a >> put b TVar a -> putWord8 1 >> put a TRecord a b -> putWord8 2 >> put a >> put b - TUnit -> putWord8 3 - TTuple a b c -> putWord8 4 >> put a >> put b >> put c - TAlias a b c d -> putWord8 5 >> put a >> put b >> put c >> put d + TAlias a b c d -> putWord8 3 >> put a >> put b >> put c >> put d TType home name ts -> - let potentialWord = length ts + 7 + let potentialWord = length ts + 5 in if potentialWord <= fromIntegral (maxBound :: Word8) then do putWord8 (fromIntegral potentialWord) put home put name mapM_ put ts - else putWord8 6 >> put home >> put name >> put ts + else putWord8 4 >> put home >> put name >> put ts get = do @@ -327,11 +319,9 @@ instance Binary Type where 0 -> liftM2 TLambda get get 1 -> liftM TVar get 2 -> liftM2 TRecord get get - 3 -> return TUnit - 4 -> liftM3 TTuple get get get - 5 -> liftM4 TAlias get get get get - 6 -> liftM3 TType get get get - n -> liftM3 TType get get (replicateM (fromIntegral (n - 7)) get) + 3 -> liftM4 TAlias get get get get + 4 -> liftM3 TType get get get + n -> liftM3 TType get get (replicateM (fromIntegral (n - 5)) get) instance Binary AliasType where put aliasType = diff --git a/compiler/src/AST/Optimized.hs b/compiler/src/AST/Optimized.hs index b24315aaf..1ca29ac38 100644 --- a/compiler/src/AST/Optimized.hs +++ b/compiler/src/AST/Optimized.hs @@ -64,8 +64,6 @@ data Expr | Access Expr Name | Update Expr (Map.Map Name Expr) | Record (Map.Map Name Expr) - | Unit - | Tuple Expr Expr (Maybe Expr) data Global = Global ModuleName.Canonical Name @@ -142,7 +140,6 @@ data EffectsType = Cmd | Sub | Fx -- GRAPHS -{-# NOINLINE empty #-} empty :: GlobalGraph empty = GlobalGraph Map.empty Map.empty @@ -232,8 +229,6 @@ instance Binary Expr where Access a b -> putWord8 21 >> put a >> put b Update a b -> putWord8 22 >> put a >> put b Record a -> putWord8 23 >> put a - Unit -> putWord8 24 - Tuple a b c -> putWord8 25 >> put a >> put b >> put c get = do @@ -263,8 +258,6 @@ instance Binary Expr where 21 -> liftM2 Access get get 22 -> liftM2 Update get get 23 -> liftM Record get - 24 -> pure Unit - 25 -> liftM3 Tuple get get get _ -> fail "problem getting Opt.Expr binary" instance Binary Def where diff --git a/compiler/src/AST/Source.hs b/compiler/src/AST/Source.hs index 93b03e4e7..38afdc018 100644 --- a/compiler/src/AST/Source.hs +++ b/compiler/src/AST/Source.hs @@ -62,8 +62,6 @@ data Expr_ | Access Expr (A.Located Name) | Update (A.Located Name) [(A.Located Name, Expr)] | Record [(A.Located Name, Expr)] - | Unit - | Tuple Expr Expr [Expr] data VarType = LowVar | CapVar @@ -82,8 +80,6 @@ data Pattern_ | PVar Name | PRecord [RecordFieldPattern] | PAlias Pattern (A.Located Name) - | PUnit - | PTuple Pattern Pattern [Pattern] | PCtor A.Region Name [Pattern] | PCtorQual A.Region Name Name [Pattern] | PArray [Pattern] @@ -106,8 +102,6 @@ data Type_ | TType A.Region Name [Type] | TTypeQual A.Region Name Name [Type] | TRecord [(A.Located Name, Type)] (Maybe (A.Located Name)) - | TUnit - | TTuple Type Type [Type] -- MODULE diff --git a/compiler/src/AST/Utils/Type.hs b/compiler/src/AST/Utils/Type.hs index 256d5be15..cbe69bb75 100644 --- a/compiler/src/AST/Utils/Type.hs +++ b/compiler/src/AST/Utils/Type.hs @@ -47,13 +47,6 @@ dealiasHelp typeTable tipe = TAlias home name (map (fmap (dealiasHelp typeTable)) args) t' TType home name args -> TType home name (map (dealiasHelp typeTable) args) - TUnit -> - TUnit - TTuple a b maybeC -> - TTuple - (dealiasHelp typeTable a) - (dealiasHelp typeTable b) - (fmap (dealiasHelp typeTable) maybeC) dealiasField :: Map.Map Name.Name Type -> FieldType -> FieldType dealiasField typeTable (FieldType index tipe) = @@ -74,10 +67,6 @@ deepDealias tipe = deepDealias (dealias args tipe') TType home name args -> TType home name (map deepDealias args) - TUnit -> - TUnit - TTuple a b c -> - TTuple (deepDealias a) (deepDealias b) (fmap deepDealias c) deepDealiasField :: FieldType -> FieldType deepDealiasField (FieldType index tipe) = diff --git a/compiler/src/Canonicalize/Effects.hs b/compiler/src/Canonicalize/Effects.hs index f913f42c4..fd8d920dd 100644 --- a/compiler/src/Canonicalize/Effects.hs +++ b/compiler/src/Canonicalize/Effects.hs @@ -142,17 +142,6 @@ checkPayload tipe = | isArray home name -> checkPayload arg _ -> Left (tipe, Error.UnsupportedType name) - Can.TUnit -> - Right () - Can.TTuple a b maybeC -> - do - checkPayload a - checkPayload b - case maybeC of - Nothing -> - Right () - Just c -> - checkPayload c Can.TVar name -> Left (tipe, Error.TypeVariable name) Can.TLambda _ _ -> diff --git a/compiler/src/Canonicalize/Environment/Local.hs b/compiler/src/Canonicalize/Environment/Local.hs index 287db70ad..8597627ce 100644 --- a/compiler/src/Canonicalize/Environment/Local.hs +++ b/compiler/src/Canonicalize/Environment/Local.hs @@ -137,10 +137,6 @@ getEdges edges (A.At _ tipe) = List.foldl' getEdges edges args Src.TRecord fields _ -> List.foldl' (\es (_, t) -> getEdges es t) edges fields - Src.TUnit -> - edges - Src.TTuple a b cs -> - List.foldl' getEdges (getEdges (getEdges edges a) b) cs -- CHECK FREE VARIABLES @@ -199,10 +195,6 @@ addFreeVars freeVars (A.At region tipe) = Just (A.At extRegion ext) -> Map.insert ext extRegion freeVars in List.foldl' (\fvs (_, t) -> addFreeVars fvs t) extFreeVars fields - Src.TUnit -> - freeVars - Src.TTuple a b cs -> - List.foldl' addFreeVars (addFreeVars (addFreeVars freeVars a) b) cs -- ADD CTORS diff --git a/compiler/src/Canonicalize/Expression.hs b/compiler/src/Canonicalize/Expression.hs index 5fe3e7b7b..bbdf27725 100644 --- a/compiler/src/Canonicalize/Expression.hs +++ b/compiler/src/Canonicalize/Expression.hs @@ -120,25 +120,6 @@ canonicalize env (A.At region expression) = do fieldDict <- Dups.checkFields fields Can.Record <$> traverse (canonicalize env) fieldDict - Src.Unit -> - Result.ok Can.Unit - Src.Tuple a b cs -> - Can.Tuple - <$> canonicalize env a - <*> canonicalize env b - <*> canonicalizeTupleExtras region env cs - --- CANONICALIZE TUPLE EXTRAS - -canonicalizeTupleExtras :: A.Region -> Env.Env -> [Src.Expr] -> Result FreeLocals [W.Warning] (Maybe Can.Expr) -canonicalizeTupleExtras region env extras = - case extras of - [] -> - Result.ok Nothing - [three] -> - Just <$> canonicalize env three - _ -> - Result.throw (Error.TupleLargerThanThree region) -- CANONICALIZE IF BRANCH @@ -262,10 +243,6 @@ addBindingsHelp bindings (A.At region pattern) = Dups.insert name region region bindings Src.PRecord fields -> List.foldl' addBindingsHelp bindings (map extractRecordFieldPattern fields) - Src.PUnit -> - bindings - Src.PTuple a b cs -> - List.foldl' addBindingsHelp bindings (a : b : cs) Src.PCtor _ _ patterns -> List.foldl' addBindingsHelp bindings patterns Src.PCtorQual _ _ _ patterns -> @@ -377,8 +354,6 @@ getPatternNames names (A.At region pattern) = Src.PRecord fields -> List.foldl' (\n f -> getPatternNames n (extractRecordFieldPattern f)) names fields Src.PAlias ptrn name -> getPatternNames (name : names) ptrn - Src.PUnit -> names - Src.PTuple a b cs -> List.foldl' getPatternNames (getPatternNames (getPatternNames names a) b) cs Src.PCtor _ _ args -> List.foldl' getPatternNames names args Src.PCtorQual _ _ _ args -> List.foldl' getPatternNames names args Src.PArray patterns -> List.foldl' getPatternNames names patterns @@ -487,7 +462,6 @@ logVar name value = Result.Result $ \freeLocals warnings _ good -> good (Map.insertWith combineUses name oneDirectUse freeLocals) warnings value -{-# NOINLINE oneDirectUse #-} oneDirectUse :: Uses oneDirectUse = Uses 1 0 diff --git a/compiler/src/Canonicalize/Pattern.hs b/compiler/src/Canonicalize/Pattern.hs index ab51922c2..2f6dd05d1 100644 --- a/compiler/src/Canonicalize/Pattern.hs +++ b/compiler/src/Canonicalize/Pattern.hs @@ -64,13 +64,6 @@ canonicalize env (A.At region pattern) = logVar name region (Can.PVar name) Src.PRecord fields -> Can.PRecord <$> canonicalizeRecordFields env fields - Src.PUnit -> - Result.ok Can.PUnit - Src.PTuple a b cs -> - Can.PTuple - <$> canonicalize env a - <*> canonicalize env b - <*> canonicalizeTuple region env cs Src.PCtor nameRegion name patterns -> canonicalizeCtor env region name patterns =<< Env.findCtor nameRegion env name Src.PCtorQual nameRegion home name patterns -> @@ -121,16 +114,6 @@ canonicalizeCtor env region name patterns ctor = Env.RecordCtor _ _ _ -> Result.throw (Error.PatternHasRecordCtor region name) -canonicalizeTuple :: A.Region -> Env.Env -> [Src.Pattern] -> Result DupsDict w (Maybe Can.Pattern) -canonicalizeTuple tupleRegion env extras = - case extras of - [] -> - Result.ok Nothing - [three] -> - Just <$> canonicalize env three - _ -> - Result.throw $ Error.TupleLargerThanThree tupleRegion - canonicalizeList :: Env.Env -> [Src.Pattern] -> Result DupsDict w [Can.Pattern] canonicalizeList env list = case list of diff --git a/compiler/src/Canonicalize/Type.hs b/compiler/src/Canonicalize/Type.hs index 89cd3f7f9..b9e1bf0f6 100644 --- a/compiler/src/Canonicalize/Type.hs +++ b/compiler/src/Canonicalize/Type.hs @@ -52,19 +52,6 @@ canonicalize env (A.At typeRegion tipe) = do cfields <- sequenceA =<< Dups.checkFields (canonicalizeFields env fields) return $ Can.TRecord cfields (fmap A.toValue ext) - Src.TUnit -> - Result.ok Can.TUnit - Src.TTuple a b cs -> - Can.TTuple - <$> canonicalize env a - <*> canonicalize env b - <*> case cs of - [] -> - Result.ok Nothing - [c] -> - Just <$> canonicalize env c - _ -> - Result.throw $ Error.TupleLargerThanThree typeRegion canonicalizeFields :: Env.Env -> [(A.Located Name.Name, Src.Type)] -> [(A.Located Name.Name, Result i w Can.FieldType)] canonicalizeFields env fields = @@ -109,14 +96,6 @@ addFreeVars freeVars tipe = Map.foldl addFieldFreeVars freeVars fields Can.TRecord fields (Just ext) -> Map.foldl addFieldFreeVars (Map.insert ext () freeVars) fields - Can.TUnit -> - freeVars - Can.TTuple a b maybeC -> - case maybeC of - Nothing -> - addFreeVars (addFreeVars freeVars a) b - Just c -> - addFreeVars (addFreeVars (addFreeVars freeVars a) b) c Can.TAlias _ _ args _ -> List.foldl' (\fvs (_, arg) -> addFreeVars fvs arg) freeVars args diff --git a/compiler/src/Data/Index.hs b/compiler/src/Data/Index.hs index b45f3beb6..5f5c1c033 100644 --- a/compiler/src/Data/Index.hs +++ b/compiler/src/Data/Index.hs @@ -35,7 +35,6 @@ third :: ZeroBased third = ZeroBased 2 -{-# INLINE next #-} next :: ZeroBased -> ZeroBased next (ZeroBased i) = ZeroBased (i + 1) @@ -52,17 +51,14 @@ toHuman (ZeroBased index) = -- INDEXED MAP -{-# INLINE indexedMap #-} indexedMap :: (ZeroBased -> a -> b) -> [a] -> [b] indexedMap func xs = zipWith func (map ZeroBased [0 .. length xs]) xs -{-# INLINE indexedTraverse #-} indexedTraverse :: (Applicative f) => (ZeroBased -> a -> f b) -> [a] -> f [b] indexedTraverse func xs = sequenceA (indexedMap func xs) -{-# INLINE indexedForA #-} indexedForA :: (Applicative f) => [a] -> (ZeroBased -> a -> f b) -> f [b] indexedForA xs func = sequenceA (indexedMap func xs) diff --git a/compiler/src/Data/Map/Utils.hs b/compiler/src/Data/Map/Utils.hs index 5fff1fd15..b31a2b593 100644 --- a/compiler/src/Data/Map/Utils.hs +++ b/compiler/src/Data/Map/Utils.hs @@ -26,7 +26,6 @@ fromValues toKey values = -- ANY -{-# INLINE any #-} any :: (v -> Bool) -> Map.Map k v -> Bool any isGood = go where diff --git a/compiler/src/Data/Name.hs b/compiler/src/Data/Name.hs index c3a8b939f..31d5a5ffe 100644 --- a/compiler/src/Data/Name.hs +++ b/compiler/src/Data/Name.hs @@ -39,15 +39,12 @@ module Data.Name result, array, dict, - tuple, - jsArray, task, router, cmd, sub, platform, virtualDom, - shader, debug, debugger, bitwise, @@ -112,7 +109,6 @@ toGrenString :: Name -> ES.String toGrenString = Coerce.coerce -{-# INLINE toBuilder #-} toBuilder :: Name -> B.Builder toBuilder = Utf8.toBuilder @@ -172,23 +168,18 @@ isAppendableType = Utf8.startsWith prefix_appendable isCompappendType :: Name -> Bool isCompappendType = Utf8.startsWith prefix_compappend -{-# NOINLINE prefix_kernel #-} prefix_kernel :: Name prefix_kernel = fromChars "Gren.Kernel." -{-# NOINLINE prefix_number #-} prefix_number :: Name prefix_number = fromChars "number" -{-# NOINLINE prefix_comparable #-} prefix_comparable :: Name prefix_comparable = fromChars "comparable" -{-# NOINLINE prefix_appendable #-} prefix_appendable :: Name prefix_appendable = fromChars "appendable" -{-# NOINLINE prefix_compappend #-} prefix_compappend :: Name prefix_compappend = fromChars "compappend" @@ -206,7 +197,6 @@ fromVarIndex n = freeze mba ) -{-# INLINE getIndexSize #-} getIndexSize :: Int -> Int getIndexSize n | n < 10 = 1 @@ -309,7 +299,6 @@ fromManyNames names = (# s, ba# #) -> (# s, Utf8.Utf8 ba# #) ) -{-# NOINLINE blank #-} blank :: Name blank = fromWords [0x5F, 0x4D, 0x24 {-_M$-}] @@ -360,28 +349,24 @@ sepBy (W8# sep#) (Utf8.Utf8 ba1#) (Utf8.Utf8 ba2#) = data MBA s = MBA# (MutableByteArray# s) -{-# INLINE newByteArray #-} newByteArray :: Int -> ST s (MBA s) newByteArray (I# len#) = ST $ \s -> case newByteArray# len# s of (# s, mba# #) -> (# s, MBA# mba# #) -{-# INLINE freeze #-} freeze :: MBA s -> ST s Name freeze (MBA# mba#) = ST $ \s -> case unsafeFreezeByteArray# mba# s of (# s, ba# #) -> (# s, Utf8.Utf8 ba# #) -{-# INLINE writeWord8 #-} writeWord8 :: MBA s -> Int -> Word8 -> ST s () writeWord8 (MBA# mba#) (I# offset#) (W8# w#) = ST $ \s -> case writeWord8Array# mba# offset# w# s of s -> (# s, () #) -{-# INLINE copyToMBA #-} copyToMBA :: Name -> MBA s -> ST s () copyToMBA (Utf8.Utf8 ba#) (MBA# mba#) = ST $ \s -> @@ -390,142 +375,98 @@ copyToMBA (Utf8.Utf8 ba#) (MBA# mba#) = -- COMMON NAMES -{-# NOINLINE int #-} int :: Name int = fromChars "Int" -{-# NOINLINE float #-} float :: Name float = fromChars "Float" -{-# NOINLINE bool #-} bool :: Name bool = fromChars "Bool" -{-# NOINLINE char #-} char :: Name char = fromChars "Char" -{-# NOINLINE string #-} string :: Name string = fromChars "String" -{-# NOINLINE maybe #-} maybe :: Name maybe = fromChars "Maybe" -{-# NOINLINE result #-} result :: Name result = fromChars "Result" -{-# NOINLINE array #-} array :: Name array = fromChars "Array" -{-# NOINLINE dict #-} dict :: Name dict = fromChars "Dict" -{-# NOINLINE tuple #-} -tuple :: Name -tuple = fromChars "Tuple" - -{-# NOINLINE jsArray #-} -jsArray :: Name -jsArray = fromChars "JsArray" - -{-# NOINLINE task #-} task :: Name task = fromChars "Task" -{-# NOINLINE router #-} router :: Name router = fromChars "Router" -{-# NOINLINE cmd #-} cmd :: Name cmd = fromChars "Cmd" -{-# NOINLINE sub #-} sub :: Name sub = fromChars "Sub" -{-# NOINLINE platform #-} platform :: Name platform = fromChars "Platform" -{-# NOINLINE virtualDom #-} virtualDom :: Name virtualDom = fromChars "VirtualDom" -{-# NOINLINE shader #-} -shader :: Name -shader = fromChars "Shader" - -{-# NOINLINE debug #-} debug :: Name debug = fromChars "Debug" -{-# NOINLINE debugger #-} debugger :: Name debugger = fromChars "Debugger" -{-# NOINLINE bitwise #-} bitwise :: Name bitwise = fromChars "Bitwise" -{-# NOINLINE basics #-} basics :: Name basics = fromChars "Basics" -{-# NOINLINE utils #-} utils :: Name utils = fromChars "Utils" -{-# NOINLINE negate #-} negate :: Name negate = fromChars "negate" -{-# NOINLINE true #-} true :: Name true = fromChars "True" -{-# NOINLINE false #-} false :: Name false = fromChars "False" -{-# NOINLINE value #-} value :: Name value = fromChars "Value" -{-# NOINLINE node #-} node :: Name node = fromChars "Node" -{-# NOINLINE program #-} program :: Name program = fromChars "Program" -{-# NOINLINE _main #-} _main :: Name _main = fromChars "main" -{-# NOINLINE _Main #-} _Main :: Name _Main = fromChars "Main" -{-# NOINLINE dollar #-} dollar :: Name dollar = fromChars "$" -{-# NOINLINE identity #-} identity :: Name identity = fromChars "identity" -{-# NOINLINE replModule #-} replModule :: Name replModule = fromChars "Gren_Repl" -{-# NOINLINE replValueToPrint #-} replValueToPrint :: Name replValueToPrint = fromChars "repl_input_value_" diff --git a/compiler/src/Data/Utf8.hs b/compiler/src/Data/Utf8.hs index d85e73cd0..ffd8346b0 100644 --- a/compiler/src/Data/Utf8.hs +++ b/compiler/src/Data/Utf8.hs @@ -69,7 +69,6 @@ data Utf8 tipe -- EMPTY -{-# NOINLINE empty #-} empty :: Utf8 t empty = runST (freeze =<< newByteArray 0) @@ -101,7 +100,6 @@ containsHelp word# ba# !offset# len# = -- STARTS WITH -{-# INLINE startsWith #-} startsWith :: Utf8 t -> Utf8 t -> Bool startsWith (Utf8 ba1#) (Utf8 ba2#) = let !len1# = sizeofByteArray# ba1# @@ -265,7 +263,6 @@ writeChars !mba !offset chars = where n = Char.ord char -{-# INLINE getWidth #-} getWidth :: Char -> Int getWidth char | code < 0x80 = 1 @@ -296,7 +293,6 @@ toCharsHelp ba# offset# len# = !newOffset# = offset# +# width# in char : toCharsHelp ba# newOffset# len# -{-# INLINE chr2 #-} chr2 :: ByteArray# -> Int# -> Word8# -> Char chr2 ba# offset# firstWord# = let !i1# = word8ToInt# firstWord# @@ -305,7 +301,6 @@ chr2 ba# offset# firstWord# = !c2# = i2# -# 0x80# in C# (chr# (c1# +# c2#)) -{-# INLINE chr3 #-} chr3 :: ByteArray# -> Int# -> Word8# -> Char chr3 ba# offset# firstWord# = let !i1# = word8ToInt# firstWord# @@ -316,7 +311,6 @@ chr3 ba# offset# firstWord# = !c3# = i3# -# 0x80# in C# (chr# (c1# +# c2# +# c3#)) -{-# INLINE chr4 #-} chr4 :: ByteArray# -> Int# -> Word8# -> Char chr4 ba# offset# firstWord# = let !i1# = word8ToInt# firstWord# @@ -335,12 +329,10 @@ word8ToInt# word8 = -- TO BUILDER -{-# INLINE toBuilder #-} toBuilder :: Utf8 t -> B.Builder toBuilder = \bytes -> B.builder (toBuilderHelp bytes) -{-# INLINE toBuilderHelp #-} toBuilderHelp :: Utf8 t -> B.BuildStep a -> B.BuildStep a toBuilderHelp !bytes@(Utf8 ba#) k = go 0 (I# (sizeofByteArray# ba#)) @@ -360,12 +352,10 @@ toBuilderHelp !bytes@(Utf8 ba#) k = -- TO ESCAPED BUILDER -{-# INLINE toEscapedBuilder #-} toEscapedBuilder :: Word8 -> Word8 -> Utf8 t -> B.Builder toEscapedBuilder before after = \name -> B.builder (toEscapedBuilderHelp before after name) -{-# INLINE toEscapedBuilderHelp #-} toEscapedBuilderHelp :: Word8 -> Word8 -> Utf8 t -> B.BuildStep a -> B.BuildStep a toEscapedBuilderHelp before after !name@(Utf8 ba#) k = go 0 (I# (sizeofByteArray# ba#)) @@ -456,7 +446,6 @@ getVeryLong = -- COPY FROM BYTESTRING -{-# INLINE copyFromByteString #-} copyFromByteString :: Int -> B.ByteString -> Utf8 t copyFromByteString len (B.PS fptr offset _) = unsafeDupablePerformIO @@ -502,14 +491,12 @@ copyToPtr (Utf8 ba#) (I# offset#) (Ptr mba#) (I# len#) = case copyByteArrayToAddr# ba# offset# mba# len# s of s -> (# s, () #) -{-# INLINE writeWord8 #-} writeWord8 :: MBA s -> Int -> Word8 -> ST s () writeWord8 (MBA# mba#) (I# offset#) (W8# w#) = ST $ \s -> case writeWord8Array# mba# offset# w# s of s -> (# s, () #) -{-# INLINE writeWordToPtr #-} writeWordToPtr :: Ptr a -> Int -> Word8 -> IO () writeWordToPtr (Ptr addr#) (I# offset#) (W8# word#) = IO $ \s -> diff --git a/compiler/src/Generate/JavaScript.hs b/compiler/src/Generate/JavaScript.hs index e6f51364a..0824b6f4d 100644 --- a/compiler/src/Generate/JavaScript.hs +++ b/compiler/src/Generate/JavaScript.hs @@ -346,7 +346,6 @@ generateBox mode global@(Opt.Global home name) = Mode.Prod _ -> JS.Ref (JsName.fromGlobal ModuleName.basics Name.identity) -{-# NOINLINE identity #-} identity :: Opt.Global identity = Opt.Global ModuleName.basics Name.identity @@ -386,7 +385,6 @@ generateLeaf home@(ModuleName.Canonical _ moduleName) name = JS.Var (JsName.fromGlobal home name) $ JS.Call leaf [JS.String (Name.toBuilder moduleName)] -{-# NOINLINE leaf #-} leaf :: JS.Expr leaf = JS.Ref (JsName.fromKernel Name.platform "leaf") diff --git a/compiler/src/Generate/JavaScript/Expression.hs b/compiler/src/Generate/JavaScript/Expression.hs index 2cfb3890f..151c855b3 100644 --- a/compiler/src/Generate/JavaScript/Expression.hs +++ b/compiler/src/Generate/JavaScript/Expression.hs @@ -117,28 +117,6 @@ generate mode expression = ] Opt.Record fields -> JsExpr $ generateRecord mode fields - Opt.Unit -> - case mode of - Mode.Dev _ -> - JsExpr $ JS.Ref (JsName.fromKernel Name.utils "Tuple0") - Mode.Prod _ -> - JsExpr $ JS.Int 0 - Opt.Tuple a b maybeC -> - JsExpr $ - case maybeC of - Nothing -> - JS.Call - (JS.Ref (JsName.fromKernel Name.utils "Tuple2")) - [ generateJsExpr mode a, - generateJsExpr mode b - ] - Just c -> - JS.Call - (JS.Ref (JsName.fromKernel Name.utils "Tuple3")) - [ generateJsExpr mode a, - generateJsExpr mode b, - generateJsExpr mode c - ] -- CODE CHUNKS @@ -180,7 +158,6 @@ codeToStmt code = -- CHARS -{-# NOINLINE toChar #-} toChar :: JS.Expr toChar = JS.Ref (JsName.fromKernel Name.utils "chr") @@ -275,7 +252,6 @@ generateFunction args body = codeToStmtList code in foldr addArg body args -{-# NOINLINE funcHelpers #-} funcHelpers :: IntMap.IntMap JS.Expr funcHelpers = IntMap.fromList $ @@ -320,7 +296,6 @@ generateNormalCall func args = Nothing -> List.foldl' (\f a -> JS.Call f [a]) func args -{-# NOINLINE callHelpers #-} callHelpers :: IntMap.IntMap JS.Expr callHelpers = IntMap.fromList $ @@ -335,31 +310,7 @@ generateCoreCall mode (Opt.Global home@(ModuleName.Canonical _ moduleName) name) else if moduleName == Name.bitwise then generateBitwiseCall home name (map (generateJsExpr mode) args) - else - if moduleName == Name.tuple - then generateTupleCall home name (map (generateJsExpr mode) args) - else - if moduleName == Name.jsArray - then generateJsArrayCall home name (map (generateJsExpr mode) args) - else generateGlobalCall home name (map (generateJsExpr mode) args) - -generateTupleCall :: ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr -generateTupleCall home name args = - case args of - [value] -> - case name of - "first" -> JS.Access value (JsName.fromLocal "a") - "second" -> JS.Access value (JsName.fromLocal "b") - _ -> generateGlobalCall home name args - _ -> - generateGlobalCall home name args - -generateJsArrayCall :: ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr -generateJsArrayCall home name args = - case args of - [entry] | name == "singleton" -> JS.Array [entry] - [index, array] | name == "unsafeGet" -> JS.Index array index - _ -> generateGlobalCall home name args + else generateGlobalCall home name (map (generateJsExpr mode) args) generateBitwiseCall :: ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr generateBitwiseCall home name args = @@ -710,8 +661,6 @@ generateIfTest mode root (path, test) = (JS.Int len) DT.IsRecord -> error "COMPILER BUG - there should never be tests on a record" - DT.IsTuple -> - error "COMPILER BUG - there should never be tests on a tuple" generateCaseBranch :: Mode.Mode -> Name.Name -> Name.Name -> (DT.Test, Opt.Decider Opt.Choice) -> JS.Case generateCaseBranch mode label root (test, subTree) = @@ -738,8 +687,6 @@ generateCaseValue mode test = error "COMPILER BUG - there should never be three tests on a boolean" DT.IsRecord -> error "COMPILER BUG - there should never be three tests on a record" - DT.IsTuple -> - error "COMPILER BUG - there should never be three tests on a tuple" generateCaseTest :: Mode.Mode -> Name.Name -> DT.Path -> DT.Test -> JS.Expr generateCaseTest mode root path exampleTest = @@ -775,8 +722,6 @@ generateCaseTest mode root path exampleTest = error "COMPILER BUG - there should never be three tests on a list" DT.IsRecord -> error "COMPILER BUG - there should never be three tests on a record" - DT.IsTuple -> - error "COMPILER BUG - there should never be three tests on a tuple" -- PATTERN PATHS diff --git a/compiler/src/Generate/JavaScript/Name.hs b/compiler/src/Generate/JavaScript/Name.hs index 40e445929..f18dd5f25 100644 --- a/compiler/src/Generate/JavaScript/Name.hs +++ b/compiler/src/Generate/JavaScript/Name.hs @@ -60,7 +60,6 @@ fromKernel :: Name.Name -> Name.Name -> Name fromKernel home name = Name ("_" <> Name.toBuilder home <> "_" <> Name.toBuilder name) -{-# INLINE homeToBuilder #-} homeToBuilder :: ModuleName.Canonical -> B.Builder homeToBuilder (ModuleName.Canonical (Pkg.Name author project) home) = usd @@ -98,7 +97,6 @@ usd = -- RESERVED NAMES -{-# NOINLINE reservedNames #-} reservedNames :: Set.Set Name.Name reservedNames = Set.union jsReservedWords grenReservedWords diff --git a/compiler/src/Gren/Compiler/Imports.hs b/compiler/src/Gren/Compiler/Imports.hs index 9c089b8a7..2279f5bc6 100644 --- a/compiler/src/Gren/Compiler/Imports.hs +++ b/compiler/src/Gren/Compiler/Imports.hs @@ -22,7 +22,6 @@ defaults = import_ ModuleName.result Nothing (typeOpen Name.result), import_ ModuleName.string Nothing (typeClosed Name.string), import_ ModuleName.char Nothing (typeClosed Name.char), - import_ ModuleName.tuple Nothing closed, import_ ModuleName.platform Nothing (typeClosed Name.program), import_ ModuleName.cmd (Just Name.cmd) (typeClosed Name.cmd), import_ ModuleName.sub (Just Name.sub) (typeClosed Name.sub) diff --git a/compiler/src/Gren/Compiler/Type.hs b/compiler/src/Gren/Compiler/Type.hs index f32a94fe5..8af0bb16f 100644 --- a/compiler/src/Gren/Compiler/Type.hs +++ b/compiler/src/Gren/Compiler/Type.hs @@ -34,8 +34,6 @@ data Type | Var Name.Name | Type Name.Name [Type] | Record [(Name.Name, Type)] (Maybe Name.Name) - | Unit - | Tuple Type Type [Type] data DebugMetadata = DebugMetadata { _message :: Type, @@ -58,13 +56,6 @@ toDoc localizer context tipe = in RT.lambda context a b cs Var name -> D.fromName name - Unit -> - "()" - Tuple a b cs -> - RT.tuple - (toDoc localizer RT.None a) - (toDoc localizer RT.None b) - (map (toDoc localizer RT.None) cs) Type name args -> RT.apply context @@ -106,13 +97,6 @@ fromRawType (A.At _ astType) = Lambda (fromRawType t1) (fromRawType t2) Src.TVar x -> Var x - Src.TUnit -> - Unit - Src.TTuple a b cs -> - Tuple - (fromRawType a) - (fromRawType b) - (map fromRawType cs) Src.TType _ name args -> Type name (map fromRawType args) Src.TTypeQual _ _ name args -> diff --git a/compiler/src/Gren/Compiler/Type/Extract.hs b/compiler/src/Gren/Compiler/Type/Extract.hs index 905060038..5c9484726 100644 --- a/compiler/src/Gren/Compiler/Type/Extract.hs +++ b/compiler/src/Gren/Compiler/Type/Extract.hs @@ -20,7 +20,6 @@ import qualified AST.Optimized as Opt import qualified AST.Utils.Type as Type import Data.Map ((!)) import qualified Data.Map as Map -import qualified Data.Maybe as Maybe import qualified Data.Name as Name import qualified Data.Set as Set import qualified Gren.Compiler.Type as T @@ -53,13 +52,6 @@ extract astType = do efields <- traverse (traverse extract) (Can.fieldsToList fields) pure (T.Record efields ext) - Can.TUnit -> - pure T.Unit - Can.TTuple a b maybeC -> - T.Tuple - <$> extract a - <*> extract b - <*> traverse extract (Maybe.maybeToList maybeC) Can.TAlias home name args aliasType -> do addAlias (Opt.Global home name) () @@ -164,7 +156,6 @@ data Deps = Deps _unions :: Set.Set Opt.Global } -{-# NOINLINE noDeps #-} noDeps :: Deps noDeps = Deps Set.empty Set.empty diff --git a/compiler/src/Gren/Float.hs b/compiler/src/Gren/Float.hs index 8267f743f..66a986dbe 100644 --- a/compiler/src/Gren/Float.hs +++ b/compiler/src/Gren/Float.hs @@ -29,7 +29,6 @@ fromPtr :: Ptr Word8 -> Ptr Word8 -> Float fromPtr = Utf8.fromPtr -{-# INLINE toBuilder #-} toBuilder :: Float -> B.Builder toBuilder = Utf8.toBuilder diff --git a/compiler/src/Gren/ModuleName.hs b/compiler/src/Gren/ModuleName.hs index 3a646b229..58c52ba12 100644 --- a/compiler/src/Gren/ModuleName.hs +++ b/compiler/src/Gren/ModuleName.hs @@ -20,7 +20,6 @@ module Gren.ModuleName result, array, dict, - tuple, platform, cmd, sub, @@ -134,66 +133,48 @@ instance Binary Canonical where -- CORE -{-# NOINLINE basics #-} basics :: Canonical basics = Canonical Pkg.core Name.basics -{-# NOINLINE char #-} char :: Canonical char = Canonical Pkg.core Name.char -{-# NOINLINE string #-} string :: Canonical string = Canonical Pkg.core Name.string -{-# NOINLINE maybe #-} maybe :: Canonical maybe = Canonical Pkg.core Name.maybe -{-# NOINLINE result #-} result :: Canonical result = Canonical Pkg.core Name.result -{-# NOINLINE array #-} array :: Canonical array = Canonical Pkg.core Name.array -{-# NOINLINE dict #-} dict :: Canonical dict = Canonical Pkg.core Name.dict -{-# NOINLINE tuple #-} -tuple :: Canonical -tuple = Canonical Pkg.core Name.tuple - -{-# NOINLINE platform #-} platform :: Canonical platform = Canonical Pkg.core Name.platform -{-# NOINLINE cmd #-} cmd :: Canonical cmd = Canonical Pkg.core "Platform.Cmd" -{-# NOINLINE sub #-} sub :: Canonical sub = Canonical Pkg.core "Platform.Sub" -{-# NOINLINE debug #-} debug :: Canonical debug = Canonical Pkg.core Name.debug -- HTML -{-# NOINLINE virtualDom #-} virtualDom :: Canonical virtualDom = Canonical Pkg.virtualDom Name.virtualDom -- JSON -{-# NOINLINE jsonDecode #-} jsonDecode :: Canonical jsonDecode = Canonical Pkg.json "Json.Decode" -{-# NOINLINE jsonEncode #-} jsonEncode :: Canonical jsonEncode = Canonical Pkg.json "Json.Encode" diff --git a/compiler/src/Gren/Package.hs b/compiler/src/Gren/Package.hs index abbe66b92..0ed67e7af 100644 --- a/compiler/src/Gren/Package.hs +++ b/compiler/src/Gren/Package.hs @@ -104,52 +104,42 @@ toName :: Author -> [Char] -> Name toName author project = Name author (Utf8.fromChars project) -{-# NOINLINE dummyName #-} dummyName :: Name dummyName = toName (Utf8.fromChars "author") "project" -{-# NOINLINE kernel #-} kernel :: Name kernel = toName gren "kernel" -{-# NOINLINE core #-} core :: Name core = toName gren "core" -{-# NOINLINE browser #-} browser :: Name browser = toName gren "browser" -{-# NOINLINE virtualDom #-} virtualDom :: Name virtualDom = toName gren "virtual-dom" -{-# NOINLINE html #-} html :: Name html = toName gren "html" -{-# NOINLINE json #-} json :: Name json = toName gren "json" -{-# NOINLINE http #-} http :: Name http = toName gren "http" -{-# NOINLINE url #-} url :: Name url = toName gren "url" -{-# NOINLINE gren #-} gren :: Author gren = Utf8.fromChars "gren-lang" diff --git a/compiler/src/Gren/String.hs b/compiler/src/Gren/String.hs index f515598aa..998448f86 100644 --- a/compiler/src/Gren/String.hs +++ b/compiler/src/Gren/String.hs @@ -36,7 +36,6 @@ toChars :: String -> [Char] toChars = Utf8.toChars -{-# INLINE toBuilder #-} toBuilder :: String -> B.Builder toBuilder = Utf8.toBuilder diff --git a/compiler/src/Json/Decode.hs b/compiler/src/Json/Decode.hs index 008283c73..292948e51 100644 --- a/compiler/src/Json/Decode.hs +++ b/compiler/src/Json/Decode.hs @@ -92,19 +92,16 @@ data DecodeExpectation -- INSTANCES instance Functor (Decoder x) where - {-# INLINE fmap #-} fmap func (Decoder decodeA) = Decoder $ \ast ok err -> let ok' a = ok (func a) in decodeA ast ok' err instance Applicative (Decoder x) where - {-# INLINE pure #-} pure a = Decoder $ \_ ok _ -> ok a - {-# INLINE (<*>) #-} (<*>) (Decoder decodeFunc) (Decoder decodeArg) = Decoder $ \ast ok err -> let okF func = @@ -113,7 +110,6 @@ instance Applicative (Decoder x) where in decodeFunc ast okF err instance Monad (Decoder x) where - {-# INLINE (>>=) #-} (>>=) (Decoder decodeA) callback = Decoder $ \ast ok err -> let ok' a = @@ -632,7 +628,6 @@ chompInt pos end n = else (# GoodInt, n, pos #) else (# GoodInt, n, pos #) -{-# INLINE isDecimalDigit #-} isDecimalDigit :: Word8 -> Bool isDecimalDigit word = word <= 0x39 {-9-} && word >= 0x30 {-0-} diff --git a/compiler/src/Json/String.hs b/compiler/src/Json/String.hs index 9792620f8..16bc43dfb 100644 --- a/compiler/src/Json/String.hs +++ b/compiler/src/Json/String.hs @@ -69,7 +69,6 @@ toChars :: String -> [Char] toChars = Utf8.toChars -{-# INLINE toBuilder #-} toBuilder :: String -> B.Builder toBuilder = Utf8.toBuilder diff --git a/compiler/src/Nitpick/Debug.hs b/compiler/src/Nitpick/Debug.hs index 64384ea93..06ddb50c0 100644 --- a/compiler/src/Nitpick/Debug.hs +++ b/compiler/src/Nitpick/Debug.hs @@ -54,8 +54,6 @@ hasDebug expression = Opt.Access r _ -> hasDebug r Opt.Update r fs -> hasDebug r || any hasDebug fs Opt.Record fs -> any hasDebug fs - Opt.Unit -> False - Opt.Tuple a b c -> hasDebug a || hasDebug b || maybe False hasDebug c defHasDebug :: Opt.Def -> Bool defHasDebug def = diff --git a/compiler/src/Nitpick/PatternMatches.hs b/compiler/src/Nitpick/PatternMatches.hs index 048ae42ac..ffbaeeb80 100644 --- a/compiler/src/Nitpick/PatternMatches.hs +++ b/compiler/src/Nitpick/PatternMatches.hs @@ -18,7 +18,6 @@ http://moscova.inria.fr/~maranget/papers/warn/warn.pdf -} import qualified AST.Canonical as Can -import qualified Data.Index as Index import qualified Data.List as List import Data.Map (Map) import qualified Data.Map as Map @@ -56,12 +55,6 @@ simplify (A.At _ pattern) = Anything Can.PRecord fields -> Record $ List.foldl' insertRecordField Map.empty fields - Can.PUnit -> - Ctor unit unitName [] - Can.PTuple a b Nothing -> - Ctor pair pairName [simplify a, simplify b] - Can.PTuple a b (Just c) -> - Ctor triple tripleName [simplify a, simplify b, simplify c] Can.PCtor _ _ union name _ args -> Ctor union name $ map (\(Can.PatternCtorArg _ _ arg) -> simplify arg) args @@ -82,41 +75,6 @@ insertRecordField :: Map Name.Name Pattern -> Can.PatternRecordField -> Map Name insertRecordField fields (A.At _ (Can.PRFieldPattern name pattern)) = Map.insert name (simplify pattern) fields --- BUILT-IN UNIONS - -{-# NOINLINE unit #-} -unit :: Can.Union -unit = - let ctor = - Can.Ctor unitName Index.first 0 [] - in Can.Union [] [ctor] 1 Can.Normal - -{-# NOINLINE pair #-} -pair :: Can.Union -pair = - let ctor = - Can.Ctor pairName Index.first 2 [Can.TVar "a", Can.TVar "b"] - in Can.Union ["a", "b"] [ctor] 1 Can.Normal - -{-# NOINLINE triple #-} -triple :: Can.Union -triple = - let ctor = - Can.Ctor tripleName Index.first 3 [Can.TVar "a", Can.TVar "b", Can.TVar "c"] - in Can.Union ["a", "b", "c"] [ctor] 1 Can.Normal - -{-# NOINLINE unitName #-} -unitName :: Name.Name -unitName = "#0" - -{-# NOINLINE pairName #-} -pairName :: Name.Name -pairName = "#2" - -{-# NOINLINE tripleName #-} -tripleName :: Name.Name -tripleName = "#3" - -- ERROR data Error @@ -225,16 +183,6 @@ checkExpr (A.At region expression) errors = checkExpr record $ Map.foldr checkField errors fields Can.Record fields -> Map.foldr checkExpr errors fields - Can.Unit -> - errors - Can.Tuple a b maybeC -> - checkExpr a $ - checkExpr b $ - case maybeC of - Nothing -> - errors - Just c -> - checkExpr c errors -- CHECK FIELD diff --git a/compiler/src/Optimize/DecisionTree.hs b/compiler/src/Optimize/DecisionTree.hs index 1d5a27c39..88cc387d0 100644 --- a/compiler/src/Optimize/DecisionTree.hs +++ b/compiler/src/Optimize/DecisionTree.hs @@ -64,7 +64,6 @@ data Test = IsCtor ModuleName.Canonical Name.Name Index.ZeroBased Int Can.CtorOpts | IsArray Int | IsRecord - | IsTuple | IsInt Int | IsChr ES.String | IsStr ES.String @@ -121,8 +120,6 @@ isComplete tests = False IsRecord -> True - IsTuple -> - True IsChr _ -> False IsStr _ -> @@ -155,16 +152,6 @@ flatten pathPattern@(path, A.At region pattern) otherPathPatterns = args -> foldr flatten otherPathPatterns (subPositions path args) else pathPattern : otherPathPatterns - Can.PTuple a b maybeC -> - flatten (Index Index.first path, a) $ - flatten (Index Index.second path, b) $ - case maybeC of - Nothing -> - otherPathPatterns - Just c -> - flatten (Index Index.third path, c) otherPathPatterns - Can.PUnit -> - otherPathPatterns Can.PAlias realPattern alias -> flatten (path, realPattern) $ (path, A.At region (Can.PVar alias)) : otherPathPatterns @@ -259,10 +246,6 @@ testAtPath selectedPath (Branch _ pathPatterns) = Just $ IsArray $ List.length elements Can.PRecord _ -> Just IsRecord - Can.PTuple _ _ _ -> - Just IsTuple - Can.PUnit -> - Just IsTuple Can.PVar _ -> Nothing Can.PAnything -> @@ -345,10 +328,6 @@ toRelevantBranch test path branch@(Branch goal pathPatterns) = Just (Branch goal (start ++ end)) _ -> Nothing - Can.PUnit -> - Just (Branch goal (start ++ end)) - Can.PTuple a b maybeC -> - Just (Branch goal (start ++ subPositions path (a : b : Maybe.maybeToList maybeC) ++ end)) Can.PVar _ -> Just branch Can.PAnything -> @@ -394,8 +373,6 @@ needsTests (A.At _ pattern) = Can.PCtor _ _ _ _ _ _ -> True Can.PArray _ -> True Can.PRecord _ -> True - Can.PUnit -> True - Can.PTuple _ _ _ -> True Can.PChr _ -> True Can.PStr _ -> True Can.PInt _ -> True @@ -460,11 +437,10 @@ instance Binary Test where IsCtor a b c d e -> putWord8 0 >> put a >> put b >> put c >> put d >> put e IsArray a -> putWord8 1 >> put a IsRecord -> putWord8 2 - IsTuple -> putWord8 3 - IsChr a -> putWord8 4 >> put a - IsStr a -> putWord8 5 >> put a - IsInt a -> putWord8 6 >> put a - IsBool a -> putWord8 7 >> put a + IsChr a -> putWord8 3 >> put a + IsStr a -> putWord8 4 >> put a + IsInt a -> putWord8 5 >> put a + IsBool a -> putWord8 6 >> put a get = do @@ -473,11 +449,10 @@ instance Binary Test where 0 -> liftM5 IsCtor get get get get get 1 -> liftM IsArray get 2 -> pure IsRecord - 3 -> pure IsTuple - 4 -> liftM IsChr get - 5 -> liftM IsStr get - 6 -> liftM IsInt get - 7 -> liftM IsBool get + 3 -> liftM IsChr get + 4 -> liftM IsStr get + 5 -> liftM IsInt get + 6 -> liftM IsBool get _ -> fail "problem getting DecisionTree.Test binary" instance Binary Path where diff --git a/compiler/src/Optimize/Expression.hs b/compiler/src/Optimize/Expression.hs index b79a7ad8d..04128a7af 100644 --- a/compiler/src/Optimize/Expression.hs +++ b/compiler/src/Optimize/Expression.hs @@ -131,13 +131,6 @@ optimize cycle (A.At region expression) = Can.Record fields -> Names.registerFieldDict fields Opt.Record <*> traverse (optimize cycle) fields - Can.Unit -> - Names.registerKernel Name.utils Opt.Unit - Can.Tuple a b maybeC -> - Names.registerKernel Name.utils Opt.Tuple - <*> optimize cycle a - <*> optimize cycle b - <*> traverse (optimize cycle) maybeC -- UPDATE @@ -205,23 +198,6 @@ destructHelp path (A.At _ pattern) revDs = Can.PAlias subPattern name -> destructHelp (Opt.Root name) subPattern $ Opt.Destructor name path : revDs - Can.PUnit -> - pure revDs - Can.PTuple a b Nothing -> - destructTwo path a b revDs - Can.PTuple a b (Just c) -> - case path of - Opt.Root _ -> - destructHelp (Opt.Index Index.third path) c - =<< destructHelp (Opt.Index Index.second path) b - =<< destructHelp (Opt.Index Index.first path) a revDs - _ -> - do - name <- Names.generate - let newRoot = Opt.Root name - destructHelp (Opt.Index Index.third newRoot) c - =<< destructHelp (Opt.Index Index.second newRoot) b - =<< destructHelp (Opt.Index Index.first newRoot) a (Opt.Destructor name path : revDs) Can.PRecord [] -> pure revDs Can.PRecord [(A.At _ (Can.PRFieldPattern name fieldPattern))] -> @@ -280,19 +256,6 @@ destructHelp path (A.At _ pattern) revDs = (Opt.Destructor name path : revDs) args -destructTwo :: Opt.Path -> Can.Pattern -> Can.Pattern -> [Opt.Destructor] -> Names.Tracker [Opt.Destructor] -destructTwo path a b revDs = - case path of - Opt.Root _ -> - destructHelp (Opt.Index Index.second path) b - =<< destructHelp (Opt.Index Index.first path) a revDs - _ -> - do - name <- Names.generate - let newRoot = Opt.Root name - destructHelp (Opt.Index Index.second newRoot) b - =<< destructHelp (Opt.Index Index.first newRoot) a (Opt.Destructor name path : revDs) - destructRecordField :: Opt.Path -> [Opt.Destructor] -> Can.PatternRecordField -> Names.Tracker [Opt.Destructor] destructRecordField path revDs (A.At _ (Can.PRFieldPattern name pattern)) = destructHelp (Opt.Field name path) pattern revDs diff --git a/compiler/src/Optimize/Names.hs b/compiler/src/Optimize/Names.hs index a1e11f3e3..e2b64b932 100644 --- a/compiler/src/Optimize/Names.hs +++ b/compiler/src/Optimize/Names.hs @@ -120,7 +120,6 @@ instance Functor Tracker where in kv n d f ok1 instance Applicative Tracker where - {-# INLINE pure #-} pure value = Tracker $ \n d f ok -> ok n d f value diff --git a/compiler/src/Optimize/Port.hs b/compiler/src/Optimize/Port.hs index 008ee24d9..fa508d819 100644 --- a/compiler/src/Optimize/Port.hs +++ b/compiler/src/Optimize/Port.hs @@ -12,7 +12,6 @@ import qualified AST.Canonical as Can import qualified AST.Optimized as Opt import qualified AST.Utils.Type as Type import Control.Monad (foldM) -import qualified Data.Index as Index import qualified Data.Map as Map import qualified Data.Name as Name import qualified Gren.ModuleName as ModuleName @@ -30,10 +29,6 @@ toEncoder tipe = error "toEncoder: function" Can.TVar _ -> error "toEncoder: type variable" - Can.TUnit -> - Opt.Function [Name.dollar] <$> encode "null" - Can.TTuple a b c -> - encodeTuple a b c Can.TType _ name args -> case args of [] @@ -54,7 +49,12 @@ toEncoder tipe = do encoder <- toEncoder fieldType let value = Opt.Call encoder [Opt.Access (Opt.VarLocal Name.dollar) name] - return $ Opt.Tuple (Opt.Str (Name.toGrenString name)) value Nothing + return $ + Opt.Record $ + Map.fromList + [ (Name.fromChars "key", Opt.Str (Name.toGrenString name)), + (Name.fromChars "value", value) + ] in do object <- encode "object" keyValuePairs <- traverse encodeField (Map.toList fields) @@ -80,49 +80,11 @@ encodeArray tipe = encoder <- toEncoder tipe return $ Opt.Call array [encoder] -encodeTuple :: Can.Type -> Can.Type -> Maybe Can.Type -> Names.Tracker Opt.Expr -encodeTuple a b maybeC = - let let_ arg index body = - Opt.Destruct (Opt.Destructor arg (Opt.Index index (Opt.Root Name.dollar))) body - - encodeArg arg tipe = - do - encoder <- toEncoder tipe - return $ Opt.Call encoder [Opt.VarLocal arg] - in do - list <- encode "list" - identity <- Names.registerGlobal ModuleName.basics Name.identity - arg1 <- encodeArg "a" a - arg2 <- encodeArg "b" b - - case maybeC of - Nothing -> - return $ - Opt.Function [Name.dollar] $ - let_ "a" Index.first $ - let_ "b" Index.second $ - Opt.Call list [identity, Opt.Array [arg1, arg2]] - Just c -> - do - arg3 <- encodeArg "c" c - return $ - Opt.Function [Name.dollar] $ - let_ "a" Index.first $ - let_ "b" Index.second $ - let_ "c" Index.third $ - Opt.Call list [identity, Opt.Array [arg1, arg2, arg3]] - -- FLAGS DECODER toFlagsDecoder :: Can.Type -> Names.Tracker Opt.Expr toFlagsDecoder tipe = - case tipe of - Can.TUnit -> - do - succeed <- decode "succeed" - return $ Opt.Call succeed [Opt.Unit] - _ -> - toDecoder tipe + toDecoder tipe -- DECODE @@ -135,10 +97,6 @@ toDecoder tipe = error "type variables should not be allowed through input ports" Can.TAlias _ _ args alias -> toDecoder (Type.dealias args alias) - Can.TUnit -> - decodeTuple0 - Can.TTuple a b c -> - decodeTuple a b c Can.TType _ name args -> case args of [] @@ -189,46 +147,6 @@ decodeArray tipe = decoder <- toDecoder tipe return $ Opt.Call array [decoder] --- DECODE TUPLES - -decodeTuple0 :: Names.Tracker Opt.Expr -decodeTuple0 = - do - null <- decode "null" - return (Opt.Call null [Opt.Unit]) - -decodeTuple :: Can.Type -> Can.Type -> Maybe Can.Type -> Names.Tracker Opt.Expr -decodeTuple a b maybeC = - do - succeed <- decode "succeed" - case maybeC of - Nothing -> - let tuple = Opt.Tuple (toLocal 0) (toLocal 1) Nothing - in indexAndThen 0 a - =<< indexAndThen 1 b (Opt.Call succeed [tuple]) - Just c -> - let tuple = Opt.Tuple (toLocal 0) (toLocal 1) (Just (toLocal 2)) - in indexAndThen 0 a - =<< indexAndThen 1 b - =<< indexAndThen 2 c (Opt.Call succeed [tuple]) - -toLocal :: Int -> Opt.Expr -toLocal index = - Opt.VarLocal (Name.fromVarIndex index) - -indexAndThen :: Int -> Can.Type -> Opt.Expr -> Names.Tracker Opt.Expr -indexAndThen i tipe decoder = - do - andThen <- decode "andThen" - index <- decode "index" - typeDecoder <- toDecoder tipe - return $ - Opt.Call - andThen - [ Opt.Function [Name.fromVarIndex i] decoder, - Opt.Call index [Opt.Int i, typeDecoder] - ] - -- DECODE RECORDS decodeRecord :: Map.Map Name.Name Can.FieldType -> Names.Tracker Opt.Expr diff --git a/compiler/src/Parse/Declaration.hs b/compiler/src/Parse/Declaration.hs index e5997d9f8..c379d9d28 100644 --- a/compiler/src/Parse/Declaration.hs +++ b/compiler/src/Parse/Declaration.hs @@ -59,7 +59,6 @@ chompDocComment = -- DEFINITION and ANNOTATION -{-# INLINE valueDecl #-} valueDecl :: Maybe Src.Comment -> A.Position -> Space.Parser E.Decl Decl valueDecl maybeDocs start = do @@ -115,7 +114,6 @@ chompMatchingName expectedName = -- TYPE DECLARATIONS -{-# INLINE typeDecl #-} typeDecl :: Maybe Src.Comment -> A.Position -> Space.Parser E.Decl Decl typeDecl maybeDocs start = inContext E.DeclType (Keyword.type_ E.DeclStart) $ @@ -199,7 +197,6 @@ chompVariants variants end = -- PORT -{-# INLINE portDecl #-} portDecl :: Maybe Src.Comment -> Space.Parser E.Decl Decl portDecl maybeDocs = inContext E.Port (Keyword.port_ E.DeclStart) $ diff --git a/compiler/src/Parse/Expression.hs b/compiler/src/Parse/Expression.hs index 2d42d0db0..98a36c4aa 100644 --- a/compiler/src/Parse/Expression.hs +++ b/compiler/src/Parse/Expression.hs @@ -32,9 +32,9 @@ term = [ variable start >>= accessible start, string start, number start, + parenthesizedExpr start >>= accessible start, array start, record start >>= accessible start, - tuple start >>= accessible start, accessor start, character start ] @@ -60,6 +60,44 @@ number start = Number.Int int -> Src.Int int Number.Float float -> Src.Float float +parenthesizedExpr :: A.Position -> Parser E.Expr Src.Expr +parenthesizedExpr start@(A.Position row col) = + inContext E.Parenthesized (word1 0x28 {-(-} E.Start) $ + do + Space.chompAndCheckIndent E.ParenthesizedSpace E.ParenthesizedIndentOpen + oneOf + E.ParenthesizedOpen + [ do + op <- Symbol.operator E.ParenthesizedOpen E.ParenthesizedOperatorReserved + if op == "-" + then + oneOf + E.ParenthesizedOperatorClose + [ do + word1 0x29 {-)-} E.ParenthesizedOperatorClose + addEnd start (Src.Op op), + do + (expr, end) <- + specialize E.ParenthesizedExpr $ + do + negatedExpr@(A.At (A.Region _ end) _) <- term + Space.chomp E.Space + let exprStart = A.Position row (col + 2) + let expr = A.at exprStart end (Src.Negate negatedExpr) + chompExprEnd exprStart (State [] expr [] end) + Space.checkIndent end E.ParenthesizedIndentEnd + word1 0x29 {-)-} E.ParenthesizedOperatorClose + return expr + ] + else do + word1 0x29 {-)-} E.ParenthesizedOperatorClose + addEnd start (Src.Op op), + do + (expr, _) <- specialize E.ParenthesizedExpr expression + word1 0x29 {-)-} E.ParenthesizedEnd + return expr + ] + accessor :: A.Position -> Parser E.Expr Src.Expr accessor start = do @@ -119,75 +157,6 @@ chompArrayEnd start entries = addEnd start (Src.Array (reverse entries)) ] --- TUPLES - -tuple :: A.Position -> Parser E.Expr Src.Expr -tuple start@(A.Position row col) = - inContext E.Tuple (word1 0x28 {-(-} E.Start) $ - do - before <- getPosition - Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExpr1 - after <- getPosition - if before /= after - then do - (entry, end) <- specialize E.TupleExpr expression - Space.checkIndent end E.TupleIndentEnd - chompTupleEnd start entry [] - else - oneOf - E.TupleIndentExpr1 - [ do - op <- Symbol.operator E.TupleIndentExpr1 E.TupleOperatorReserved - if op == "-" - then - oneOf - E.TupleOperatorClose - [ do - word1 0x29 {-)-} E.TupleOperatorClose - addEnd start (Src.Op op), - do - (entry, end) <- - specialize E.TupleExpr $ - do - negatedExpr@(A.At (A.Region _ end) _) <- term - Space.chomp E.Space - let exprStart = A.Position row (col + 2) - let expr = A.at exprStart end (Src.Negate negatedExpr) - chompExprEnd exprStart (State [] expr [] end) - Space.checkIndent end E.TupleIndentEnd - chompTupleEnd start entry [] - ] - else do - word1 0x29 {-)-} E.TupleOperatorClose - addEnd start (Src.Op op), - do - word1 0x29 {-)-} E.TupleIndentExpr1 - addEnd start Src.Unit, - do - (entry, end) <- specialize E.TupleExpr expression - Space.checkIndent end E.TupleIndentEnd - chompTupleEnd start entry [] - ] - -chompTupleEnd :: A.Position -> Src.Expr -> [Src.Expr] -> Parser E.Tuple Src.Expr -chompTupleEnd start firstExpr revExprs = - oneOf - E.TupleEnd - [ do - word1 0x2C {-,-} E.TupleEnd - Space.chompAndCheckIndent E.TupleSpace E.TupleIndentExprN - (entry, end) <- specialize E.TupleExpr expression - Space.checkIndent end E.TupleIndentEnd - chompTupleEnd start firstExpr (entry : revExprs), - do - word1 0x29 {-)-} E.TupleEnd - case reverse revExprs of - [] -> - return firstExpr - secondExpr : otherExprs -> - addEnd start (Src.Tuple firstExpr secondExpr otherExprs) - ] - -- RECORDS record :: A.Position -> Parser E.Expr Src.Expr diff --git a/compiler/src/Parse/Number.hs b/compiler/src/Parse/Number.hs index db2cf3ace..a63f82969 100644 --- a/compiler/src/Parse/Number.hs +++ b/compiler/src/Parse/Number.hs @@ -27,7 +27,6 @@ isDirtyEnd :: Ptr Word8 -> Ptr Word8 -> Word8 -> Bool isDirtyEnd pos end word = Var.getInnerWidthHelp pos end word > 0 -{-# INLINE isDecimalDigit #-} isDecimalDigit :: Word8 -> Bool isDecimalDigit word = word <= 0x39 {-9-} && word >= 0x30 {-0-} @@ -187,7 +186,6 @@ chompHexInt pos end = -- Return -1 if it has NO digits -- Return -2 if it has BAD digits -{-# INLINE chompHex #-} chompHex :: Ptr Word8 -> Ptr Word8 -> (# Ptr Word8, Int #) chompHex pos end = chompHexHelp pos end (-1) 0 @@ -203,7 +201,6 @@ chompHexHelp pos end answer accumulator = then (# pos, if newAnswer == -1 then answer else -2 #) else chompHexHelp (plusPtr pos 1) end newAnswer newAnswer -{-# INLINE stepHex #-} stepHex :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int -> Int stepHex pos end word acc | 0x30 {-0-} <= word && word <= 0x39 {-9-} = 16 * acc + fromIntegral (word - 0x30 {-0-}) diff --git a/compiler/src/Parse/Pattern.hs b/compiler/src/Parse/Pattern.hs index 8e785119c..51af8ac35 100644 --- a/compiler/src/Parse/Pattern.hs +++ b/compiler/src/Parse/Pattern.hs @@ -32,8 +32,8 @@ term = oneOf E.PStart [ record start, - tuple start, array start, + parenthesized, termHelp start ] @@ -94,6 +94,18 @@ wildcard = let !newState = P.State src newPos end indent row newCol in cok () newState +-- PARENTHESIZED PATTERNS + +parenthesized :: Parser E.Pattern Src.Pattern +parenthesized = + inContext E.PParenthesized (word1 0x28 {-(-} E.PStart) $ + do + Space.chompAndCheckIndent E.PParenthesizedSpace E.PParenthesizedIndentPattern + (pattern, end) <- P.specialize E.PParenthesizedPattern expression + Space.checkIndent end E.PParenthesizedIndentEnd + word1 0x29 {-)-} E.PParenthesizedEnd + return pattern + -- RECORDS record :: A.Position -> Parser E.Pattern Src.Pattern @@ -149,43 +161,6 @@ recordContinuationHelp start revPatterns = addEnd start (Src.PRecord (reverse revPatterns)) ] --- TUPLES - -tuple :: A.Position -> Parser E.Pattern Src.Pattern -tuple start = - inContext E.PTuple (word1 0x28 {-(-} E.PStart) $ - do - Space.chompAndCheckIndent E.PTupleSpace E.PTupleIndentExpr1 - oneOf - E.PTupleOpen - [ do - (pattern, end) <- P.specialize E.PTupleExpr expression - Space.checkIndent end E.PTupleIndentEnd - tupleHelp start pattern [], - do - word1 0x29 {-)-} E.PTupleEnd - addEnd start Src.PUnit - ] - -tupleHelp :: A.Position -> Src.Pattern -> [Src.Pattern] -> Parser E.PTuple Src.Pattern -tupleHelp start firstPattern revPatterns = - oneOf - E.PTupleEnd - [ do - word1 0x2C {-,-} E.PTupleEnd - Space.chompAndCheckIndent E.PTupleSpace E.PTupleIndentExprN - (pattern, end) <- P.specialize E.PTupleExpr expression - Space.checkIndent end E.PTupleIndentEnd - tupleHelp start firstPattern (pattern : revPatterns), - do - word1 0x29 {-)-} E.PTupleEnd - case reverse revPatterns of - [] -> - return firstPattern - secondPattern : otherPatterns -> - addEnd start (Src.PTuple firstPattern secondPattern otherPatterns) - ] - -- ARRAY array :: A.Position -> Parser E.Pattern Src.Pattern diff --git a/compiler/src/Parse/Primitives.hs b/compiler/src/Parse/Primitives.hs index c3e5e24ea..7d70178b9 100644 --- a/compiler/src/Parse/Primitives.hs +++ b/compiler/src/Parse/Primitives.hs @@ -71,7 +71,6 @@ type Col = Word16 -- FUNCTOR instance Functor (Parser x) where - {-# INLINE fmap #-} fmap f (Parser parser) = Parser $ \state cok eok cerr eerr -> let cok' a s = cok (f a) s @@ -81,12 +80,10 @@ instance Functor (Parser x) where -- APPLICATIVE instance Applicative.Applicative (Parser x) where - {-# INLINE pure #-} pure value = Parser $ \state _ eok _ _ -> eok value state - {-# INLINE (<*>) #-} (<*>) (Parser parserFunc) (Parser parserArg) = Parser $ \state cok eok cerr eerr -> let cokF func s1 = @@ -101,7 +98,6 @@ instance Applicative.Applicative (Parser x) where -- ONE OF -{-# INLINE oneOf #-} oneOf :: (Row -> Col -> x) -> [Parser x a] -> Parser x a oneOf toError parsers = Parser $ \state cok eok cerr eerr -> @@ -128,7 +124,6 @@ oneOfHelp state cok eok cerr eerr toError parsers = -- ONE OF WITH FALLBACK -{-# INLINE oneOfWithFallback #-} oneOfWithFallback :: [Parser x a] -> a -> Parser x a -- PERF is this function okay? Worried about allocation/laziness with fallback values. oneOfWithFallback parsers fallback = Parser $ \state cok eok cerr _ -> @@ -154,7 +149,6 @@ oowfHelp state cok eok cerr parsers fallback = -- MONAD instance Monad (Parser x) where - {-# INLINE (>>=) #-} (Parser parserA) >>= callback = Parser $ \state cok eok cerr eerr -> let cok' a s = @@ -217,7 +211,6 @@ getCol = Parser $ \state@(State _ _ _ _ _ col) _ eok _ _ -> eok col state -{-# INLINE getPosition #-} getPosition :: Parser x A.Position getPosition = Parser $ \state@(State _ _ _ _ row col) _ eok _ _ -> @@ -308,7 +301,6 @@ unsafeIndex :: Ptr Word8 -> Word8 unsafeIndex ptr = B.accursedUnutterablePerformIO (peek ptr) -{-# INLINE isWord #-} isWord :: Ptr Word8 -> Ptr Word8 -> Word8 -> Bool isWord pos end word = pos < end && unsafeIndex pos == word diff --git a/compiler/src/Parse/String.hs b/compiler/src/Parse/String.hs index 2245563c3..8fad4c018 100644 --- a/compiler/src/Parse/String.hs +++ b/compiler/src/Parse/String.hs @@ -100,7 +100,6 @@ string toExpectation toError = cerr r c (toError x) else eerr row col toExpectation -{-# INLINE isDoubleQuote #-} isDoubleQuote :: Ptr Word8 -> Ptr Word8 -> Bool isDoubleQuote pos end = pos < end && P.unsafeIndex pos == 0x22 {- " -} @@ -253,27 +252,22 @@ eatUnicode pos end row col = code else EscapeUnicode (numDigits + 4) code -{-# NOINLINE singleQuote #-} singleQuote :: ES.Chunk singleQuote = ES.Escape 0x27 {-'-} -{-# NOINLINE doubleQuote #-} doubleQuote :: ES.Chunk doubleQuote = ES.Escape 0x22 {-"-} -{-# NOINLINE newline #-} newline :: ES.Chunk newline = ES.Escape 0x6E {-n-} -{-# NOINLINE carriageReturn #-} carriageReturn :: ES.Chunk carriageReturn = ES.Escape 0x72 {-r-} -{-# NOINLINE placeholder #-} placeholder :: ES.Chunk placeholder = ES.CodePoint 0xFFFD {-replacement character-} diff --git a/compiler/src/Parse/Symbol.hs b/compiler/src/Parse/Symbol.hs index f7b9d7d9e..8b4931633 100644 --- a/compiler/src/Parse/Symbol.hs +++ b/compiler/src/Parse/Symbol.hs @@ -50,17 +50,14 @@ chompOps pos end = then chompOps (plusPtr pos 1) end else pos -{-# INLINE isBinopCharHelp #-} isBinopCharHelp :: Word8 -> Bool isBinopCharHelp word = word < 128 && Vector.unsafeIndex binopCharVector (fromIntegral word) -{-# NOINLINE binopCharVector #-} binopCharVector :: Vector.Vector Bool binopCharVector = Vector.generate 128 (\i -> IntSet.member i binopCharSet) -{-# NOINLINE binopCharSet #-} binopCharSet :: IntSet.IntSet binopCharSet = IntSet.fromList (map Char.ord "+-/*=.<>:&|^?%!") diff --git a/compiler/src/Parse/Type.hs b/compiler/src/Parse/Type.hs index 631aa4248..b77e10cc8 100644 --- a/compiler/src/Parse/Type.hs +++ b/compiler/src/Parse/Type.hs @@ -39,19 +39,14 @@ term = do var <- Var.lower E.TStart addEnd start (Src.TVar var), - -- tuples - inContext E.TTuple (word1 0x28 {-(-} E.TStart) $ - oneOf - E.TTupleOpen - [ do - word1 0x29 {-)-} E.TTupleOpen - addEnd start Src.TUnit, - do - Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentType1 - (tipe, end) <- specialize E.TTupleType expression - Space.checkIndent end E.TTupleIndentEnd - chompTupleEnd start tipe [] - ], + -- parenthesis + inContext E.TParenthesis (word1 0x28 {-(-} E.TStart) $ + do + Space.chompAndCheckIndent E.TParenthesisSpace E.TParenthesisIndentOpen + (tipe, end) <- specialize E.TParenthesisType expression + Space.checkIndent end E.TParenthesisIndentEnd + word1 0x29 {-)-} E.TParenthesisEnd + return tipe, -- records inContext E.TRecord (word1 0x7B {- { -} E.TStart) $ do @@ -142,27 +137,6 @@ chompArgs args end = ] (reverse args, end) --- TUPLES - -chompTupleEnd :: A.Position -> Src.Type -> [Src.Type] -> Parser E.TTuple Src.Type -chompTupleEnd start firstType revTypes = - oneOf - E.TTupleEnd - [ do - word1 0x2C {-,-} E.TTupleEnd - Space.chompAndCheckIndent E.TTupleSpace E.TTupleIndentTypeN - (tipe, end) <- specialize E.TTupleType expression - Space.checkIndent end E.TTupleIndentEnd - chompTupleEnd start firstType (tipe : revTypes), - do - word1 0x29 {-)-} E.TTupleEnd - case reverse revTypes of - [] -> - return firstType - secondType : otherTypes -> - addEnd start (Src.TTuple firstType secondType otherTypes) - ] - -- RECORD type Field = (A.Located Name.Name, Src.Type) diff --git a/compiler/src/Parse/Variable.hs b/compiler/src/Parse/Variable.hs index 751485202..cbaa7d0da 100644 --- a/compiler/src/Parse/Variable.hs +++ b/compiler/src/Parse/Variable.hs @@ -59,8 +59,7 @@ lower toError = P.State src newPos end indent row newCol in cok name newState -{-# NOINLINE reservedWords #-} -reservedWords :: Set.Set Name.Name -- PERF try using a trie instead +reservedWords :: Set.Set Name.Name reservedWords = Set.fromList [ "if", @@ -183,7 +182,6 @@ foreignAlphaHelp pos end col = -- DOTS -{-# INLINE isDot #-} isDot :: Ptr Word8 -> Ptr Word8 -> Bool isDot pos end = pos < end && unsafeIndex pos == 0x2e {- . -} @@ -197,14 +195,12 @@ chompUpper pos end col = then (# pos, col #) else chompInnerChars (plusPtr pos width) end (col + 1) -{-# INLINE getUpperWidth #-} getUpperWidth :: Ptr Word8 -> Ptr Word8 -> Int getUpperWidth pos end = if pos < end then getUpperWidthHelp pos end (unsafeIndex pos) else 0 -{-# INLINE getUpperWidthHelp #-} getUpperWidthHelp :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int getUpperWidthHelp pos _ word | 0x41 {- A -} <= word && word <= 0x5A {- Z -} = 1 @@ -223,14 +219,12 @@ chompLower pos end col = then (# pos, col #) else chompInnerChars (plusPtr pos width) end (col + 1) -{-# INLINE getLowerWidth #-} getLowerWidth :: Ptr Word8 -> Ptr Word8 -> Int getLowerWidth pos end = if pos < end then getLowerWidthHelp pos end (unsafeIndex pos) else 0 -{-# INLINE getLowerWidthHelp #-} getLowerWidthHelp :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int getLowerWidthHelp pos _ word | 0x61 {- a -} <= word && word <= 0x7A {- z -} = 1 @@ -255,7 +249,6 @@ getInnerWidth pos end = then getInnerWidthHelp pos end (unsafeIndex pos) else 0 -{-# INLINE getInnerWidthHelp #-} getInnerWidthHelp :: Ptr Word8 -> Ptr Word8 -> Word8 -> Int getInnerWidthHelp pos _ word | 0x61 {- a -} <= word && word <= 0x7A {- z -} = 1 @@ -270,7 +263,6 @@ getInnerWidthHelp pos _ word -- EXTRACT CHARACTERS -{-# INLINE chr2 #-} chr2 :: Ptr Word8 -> Word8 -> Char chr2 pos firstWord = let !i1# = unpack firstWord @@ -279,7 +271,6 @@ chr2 pos firstWord = !c2# = i2# -# 0x80# in C# (chr# (c1# +# c2#)) -{-# INLINE chr3 #-} chr3 :: Ptr Word8 -> Word8 -> Char chr3 pos firstWord = let !i1# = unpack firstWord @@ -290,7 +281,6 @@ chr3 pos firstWord = !c3# = i3# -# 0x80# in C# (chr# (c1# +# c2# +# c3#)) -{-# INLINE chr4 #-} chr4 :: Ptr Word8 -> Word8 -> Char chr4 pos firstWord = let !i1# = unpack firstWord diff --git a/compiler/src/Reporting/Error/Canonicalize.hs b/compiler/src/Reporting/Error/Canonicalize.hs index f1751cfe4..6a36b06ae 100644 --- a/compiler/src/Reporting/Error/Canonicalize.hs +++ b/compiler/src/Reporting/Error/Canonicalize.hs @@ -69,7 +69,6 @@ data Error | RecursiveDecl A.Region Name.Name [Name.Name] | RecursiveLet (A.Located Name.Name) [Name.Name] | Shadowing Name.Name A.Region A.Region - | TupleLargerThanThree A.Region | TypeVarsUnboundInUnion A.Region Name.Name [Name.Name] (Name.Name, A.Region) [(Name.Name, A.Region)] | TypeVarsMessedUpInAlias A.Region Name.Name [Name.Name] [(Name.Name, A.Region)] [(Name.Name, A.Region)] @@ -559,7 +558,7 @@ toReport source err = D.indent 4 $ D.reflow $ "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\ - \ tuples, records, and JSON values.", + \ records, and JSON values.", D.reflow $ "Since JSON values can flow through, you can use JSON encoders and decoders\ \ to allow other types through as well. More advanced users often just do\ @@ -591,8 +590,8 @@ toReport source err = CmdExtraArgs n -> ( "The `" <> Name.toChars name <> "` port can only send ONE value out to JavaScript.", let theseItemsInSomething - | n == 2 = "both of these items into a tuple or record" - | n == 3 = "these " ++ show n ++ " items into a tuple or record" + | n == 2 = "both of these items into a record" + | n == 3 = "these " ++ show n ++ " items into a record" | True = "these " ++ show n ++ " items into a record" in D.reflow $ "You can put " ++ theseItemsInSomething ++ " to send them out though." @@ -735,24 +734,6 @@ toReport source err = "shadowing" "for more details on this choice." ] - TupleLargerThanThree region -> - Report.Report "BAD TUPLE" region [] $ - Code.toSnippet - source - region - Nothing - ( "I only accept tuples with two or three items. This has too many:", - D.stack - [ D.reflow $ - "I recommend switching to records. Each item will be named, and you can use\ - \ the `point.x` syntax to access them.", - D.link - "Note" - "Read" - "tuples" - "for more comprehensive advice on working with large chunks of data in Gren." - ] - ) TypeVarsUnboundInUnion unionRegion typeName allVars unbound unbounds -> unboundTypeVars source unionRegion ["type"] typeName allVars unbound unbounds TypeVarsMessedUpInAlias aliasRegion typeName allVars unusedVars unboundVars -> diff --git a/compiler/src/Reporting/Error/Main.hs b/compiler/src/Reporting/Error/Main.hs index d8a22f6cd..3da7f911a 100644 --- a/compiler/src/Reporting/Error/Main.hs +++ b/compiler/src/Reporting/Error/Main.hs @@ -97,7 +97,7 @@ toReport localizer source err = D.indent 4 $ D.reflow $ "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\ - \ tuples, records, and JSON values.", + \ records, and JSON values.", D.reflow $ "Since JSON values can flow through, you can use JSON encoders and decoders\ \ to allow other types through as well. More advanced users often just do\ diff --git a/compiler/src/Reporting/Error/Syntax.hs b/compiler/src/Reporting/Error/Syntax.hs index 0239f665c..46510d3eb 100644 --- a/compiler/src/Reporting/Error/Syntax.hs +++ b/compiler/src/Reporting/Error/Syntax.hs @@ -16,8 +16,8 @@ module Reporting.Error.Syntax Port (..), -- Expr (..), + Parenthesized (..), Record (..), - Tuple (..), Array (..), Func (..), Case (..), @@ -27,13 +27,13 @@ module Reporting.Error.Syntax Destruct (..), -- Pattern (..), + PParenthesized (..), PRecord (..), - PTuple (..), PArray (..), -- Type (..), + TParenthesis (..), TRecord (..), - TTuple (..), -- Char (..), String (..), @@ -189,9 +189,9 @@ data Expr = Let Let Row Col | Case Case Row Col | If If Row Col + | Parenthesized Parenthesized Row Col | Array Array Row Col | Record Record Row Col - | Tuple Tuple Row Col | Func Func Row Col | -- Dot Row Col @@ -204,8 +204,6 @@ data Expr | String String Row Col | Number Number Row Col | Space Space Row Col - | EndlessShader Row Col - | ShaderProblem [Char.Char] Row Col | IndentOperatorRight Name.Name Row Col data Record @@ -222,17 +220,6 @@ data Record | RecordIndentEquals Row Col | RecordIndentExpr Row Col -data Tuple - = TupleExpr Expr Row Col - | TupleSpace Space Row Col - | TupleEnd Row Col - | TupleOperatorClose Row Col - | TupleOperatorReserved BadOperator Row Col - | -- - TupleIndentExpr1 Row Col - | TupleIndentExprN Row Col - | TupleIndentEnd Row Col - data Array = ArraySpace Space Row Col | ArrayOpen Row Col @@ -296,6 +283,18 @@ data Let | LetIndentIn Row Col | LetIndentBody Row Col +data Parenthesized + = ParenthesizedOpen Row Col + | ParenthesizedEnd Row Col + | ParenthesizedExpr Expr Row Col + | ParenthesizedOperatorReserved BadOperator Row Col + | ParenthesizedOperatorClose Row Col + | ParenthesizedSpace Space Row Col + | -- + ParenthesizedIndentOpen Row Col + | ParenthesizedIndentEnd Row Col + | ParenthesizedIndentExpr Row Col + data Def = DefSpace Space Row Col | DefType Type Row Col @@ -320,8 +319,8 @@ data Destruct -- PATTERNS data Pattern - = PRecord PRecord Row Col - | PTuple PTuple Row Col + = PParenthesized PParenthesized Row Col + | PRecord PRecord Row Col | PArray PArray Row Col | -- PStart Row Col @@ -336,6 +335,13 @@ data Pattern PIndentStart Row Col | PIndentAlias Row Col +data PParenthesized + = PParenthesizedSpace Space Row Col + | PParenthesizedIndentPattern Row Col + | PParenthesizedPattern Pattern Row Col + | PParenthesizedIndentEnd Row Col + | PParenthesizedEnd Row Col + data PRecord = PRecordOpen Row Col | PRecordEnd Row Col @@ -348,16 +354,6 @@ data PRecord | PRecordIndentEnd Row Col | PRecordIndentField Row Col -data PTuple - = PTupleOpen Row Col - | PTupleEnd Row Col - | PTupleExpr Pattern Row Col - | PTupleSpace Space Row Col - | -- - PTupleIndentEnd Row Col - | PTupleIndentExpr1 Row Col - | PTupleIndentExprN Row Col - data PArray = PArrayOpen Row Col | PArrayEnd Row Col @@ -372,7 +368,7 @@ data PArray data Type = TRecord TRecord Row Col - | TTuple TTuple Row Col + | TParenthesis TParenthesis Row Col | -- TStart Row Col | TSpace Space Row Col @@ -395,15 +391,13 @@ data TRecord | TRecordIndentType Row Col | TRecordIndentEnd Row Col -data TTuple - = TTupleOpen Row Col - | TTupleEnd Row Col - | TTupleType Type Row Col - | TTupleSpace Space Row Col +data TParenthesis + = TParenthesisEnd Row Col + | TParenthesisType Type Row Col + | TParenthesisSpace Space Row Col | -- - TTupleIndentType1 Row Col - | TTupleIndentTypeN Row Col - | TTupleIndentEnd Row Col + TParenthesisIndentOpen Row Col + | TParenthesisIndentEnd Row Col -- LITERALS @@ -975,12 +969,11 @@ toWeirdEndReport source row col = "I got stuck on this comma:", D.stack [ D.reflow $ - "I do not think I am parsing a list or tuple right now. Try deleting the comma?", + "I do not think I am parsing an array right now. Try deleting the comma?", D.toSimpleNote $ - "If this is supposed to be part of a list, the problem may be a bit earlier.\ - \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\ - \ closing ] that is making me think the list ended earlier? The same kinds of\ - \ things could be going wrong if this is supposed to be a tuple." + "If this is supposed to be part of an array, the problem may be a bit earlier.\ + \ Perhaps the opening [ is missing? Or perhaps some value in the array has an extra\ + \ closing ] that is making me think the array ended earlier?" ] ) Just '`' -> @@ -2294,7 +2287,7 @@ toDeclDefReport source name declDef startRow startCol = "pattern", "matches", "like", - "((x,y)", + "([x,y]", D.cyan "as", "point)", "where", @@ -2302,8 +2295,8 @@ toDeclDefReport source name declDef startRow startCol = "want", "to", "name", - "a", - "tuple", + "an", + "array", "and", "the", "values", @@ -2567,12 +2560,12 @@ toExprReport source context expr startRow startCol = toCaseReport source context case_ row col If if_ row col -> toIfReport source context if_ row col - Array list row col -> - toArrayReport source context list row col + Parenthesized parenthesizedExpr row col -> + toParenthesizedReport source context parenthesizedExpr row col + Array array row col -> + toArrayReport source context array row col Record record row col -> toRecordReport source context record row col - Tuple tuple row col -> - toTupleReport source context tuple row col Func func row col -> toFuncReport source context func row col Dot row col -> @@ -2711,7 +2704,7 @@ toExprReport source context expr startRow startCol = InDef name r c -> (r, c, "the `" ++ Name.toChars name ++ "` definition") InNode NRecord r c _ -> (r, c, "a record") InNode NParens r c _ -> (r, c, "some parentheses") - InNode NArray r c _ -> (r, c, "a list") + InNode NArray r c _ -> (r, c, "an array") InNode NFunc r c _ -> (r, c, "an anonymous function") InNode NCond r c _ -> (r, c, "an `if` expression") InNode NThen r c _ -> (r, c, "an `if` expression") @@ -2769,33 +2762,6 @@ toExprReport source context expr startRow startCol = toNumberReport source number row col Space space row col -> toSpaceReport source space row col - EndlessShader row col -> - let region = toWiderRegion row col 6 - in Report.Report "ENDLESS SHADER" region [] $ - Code.toSnippet - source - region - Nothing - ( D.reflow "I cannot find the end of this shader:", - D.reflow "Add a |] somewhere after this to end the shader." - ) - ShaderProblem problem row col -> - let region = toRegion row col - in Report.Report "SHADER PROBLEM" region [] $ - Code.toSnippet - source - region - Nothing - ( D.reflow $ - "I ran into a problem while parsing this GLSL block.", - D.stack - [ D.reflow $ - "I use a 3rd party GLSL parser for now, and I did my best to extract their error message:", - D.indent 4 $ - D.vcat $ - map D.fromChars (filter (/= "") (lines problem)) - ] - ) IndentOperatorRight op row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col @@ -3531,7 +3497,7 @@ toLetDefReport source name def startRow startCol = "pattern", "matches", "like", - "((x,y)", + "([x,y]", D.cyan "as", "point)", "where", @@ -3539,8 +3505,8 @@ toLetDefReport source name def startRow startCol = "want", "to", "name", - "a", - "tuple", + "an", + "array", "and", "the", "values", @@ -4629,16 +4595,54 @@ noteForRecordIndentError = \ This is the stylistic convention in the Gren ecosystem!" ] --- TUPLE +-- PARENTHESIZED -toTupleReport :: Code.Source -> Context -> Tuple -> Row -> Col -> Report.Report -toTupleReport source context tuple startRow startCol = - case tuple of - TupleExpr expr row col -> +toParenthesizedReport :: Code.Source -> Context -> Parenthesized -> Row -> Col -> Report.Report +toParenthesizedReport source context parenthesized startRow startCol = + case parenthesized of + ParenthesizedExpr expr row col -> toExprReport source (InNode NParens startRow startCol context) expr row col - TupleSpace space row col -> + ParenthesizedSpace space row col -> toSpaceReport source space row col - TupleEnd row col -> + ParenthesizedOpen row col -> + let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) + region = toRegion row col + in Report.Report "UNFINISHED PARENTHESIS" region [] $ + Code.toSnippet + source + surroundings + (Just region) + ( D.reflow $ + "I am partway through parsing an expression, but I got stuck here:", + D.stack + [ D.fillSep + [ "I", + "was", + "expecting", + "to", + "see", + "a", + "closing", + "parenthesis", + "before", + "this,", + "so", + "try", + "adding", + "a", + D.dullyellow ")", + "and", + "see", + "if", + "that", + "helps?" + ], + D.toSimpleNote $ + "When I get stuck like this, it usually means that there is a missing parenthesis\ + \ or bracket somewhere earlier. It could also be a stray keyword or operator." + ] + ) + ParenthesizedEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -4656,7 +4660,7 @@ toTupleReport source context tuple startRow startCol = \ or missing brackets) that is confusing me." ] ) - TupleOperatorClose row col -> + ParenthesizedOperatorClose row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED OPERATOR FUNCTION" region [] $ @@ -4673,7 +4677,7 @@ toTupleReport source context tuple startRow startCol = \ no extra spaces." ] ) - TupleOperatorReserved operator row col -> + ParenthesizedOperatorReserved operator row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNEXPECTED SYMBOL" region [] $ @@ -4689,9 +4693,9 @@ toTupleReport source context tuple startRow startCol = BadPipe -> ["Try", D.dullyellow "(||)", "instead?", "To", "turn", "boolean", "OR", "into", "a", "function?"] BadArrow -> ["Maybe", "you", "wanted", D.dullyellow "(>)", "or", D.dullyellow "(>=)", "instead?"] BadEquals -> ["Try", D.dullyellow "(==)", "instead?", "To", "make", "a", "function", "that", "checks", "equality?"] - BadHasType -> ["Try", D.dullyellow "(::)", "instead?", "To", "add", "values", "to", "the", "front", "of", "lists?"] + BadHasType -> ["Maybe", "you", "wanted", D.dullyellow "Array.pushFront", "instead?"] ) - TupleIndentExpr1 row col -> + ParenthesizedIndentExpr row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -4723,41 +4727,24 @@ toTupleReport source context tuple startRow startCol = \ maybe you have an expression but it is not indented enough?" ] ) - TupleIndentExprN row col -> + ParenthesizedIndentOpen row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED TUPLE" region [] $ + in Report.Report "UNFINISHED PARENTHESES" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I think I am in the middle of parsing a tuple. I just saw a comma, so I was expecting to see an expression next.", + "I was expecting to see a closing parenthesis next:", D.stack - [ D.fillSep $ - [ "A", - "tuple", - "looks", - "like", - D.dullyellow "(3,4)", - "or", - D.dullyellow "(\"Tom\",42)" <> ",", - "so", - "I", - "think", - "there", - "is", - "an", - "expression", - "missing", - "here?" - ], + [ D.fillSep ["Try", "adding", "a", D.dullyellow ")", "to", "see", "if", "that", "helps!"], D.toSimpleNote $ "I can get confused by indentation in cases like this, so\ - \ maybe you have an expression but it is not indented enough?" + \ maybe you have a closing parenthesis but it is not indented enough?" ] ) - TupleIndentEnd row col -> + ParenthesizedIndentEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -4776,20 +4763,20 @@ toTupleReport source context tuple startRow startCol = ) toArrayReport :: Code.Source -> Context -> Array -> Row -> Col -> Report.Report -toArrayReport source context list startRow startCol = - case list of +toArrayReport source context array startRow startCol = + case array of ArraySpace space row col -> toSpaceReport source space row col ArrayOpen row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED LIST" region [] $ + in Report.Report "UNFINISHED ARRAY" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I am partway through parsing a list, but I got stuck here:", + "I am partway through parsing an array, but I got stuck here:", D.stack [ D.fillSep [ "I", @@ -4824,18 +4811,18 @@ toArrayReport source context list startRow startCol = Start r c -> let surroundings = A.Region (A.Position startRow startCol) (A.Position r c) region = toRegion r c - in Report.Report "UNFINISHED LIST" region [] $ + in Report.Report "UNFINISHED ARRAY" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I was expecting to see another list entry after that last comma:", + "I was expecting to see another array entry after that last comma:", D.stack [ D.reflow $ - "Trailing commas are not allowed in lists, so the fix may be to delete the comma?", + "Trailing commas are not allowed in arrays, so the fix may be to delete the comma?", D.toSimpleNote - "I recommend using the following format for lists that span multiple lines:", + "I recommend using the following format for arrays that span multiple lines:", D.indent 4 $ D.vcat $ [ "[ " <> D.dullyellow "\"Alice\"", @@ -4853,13 +4840,13 @@ toArrayReport source context list startRow startCol = ArrayEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED LIST" region [] $ + in Report.Report "UNFINISHED ARRAY" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I am partway through parsing a list, but I got stuck here:", + "I am partway through parsing an array, but I got stuck here:", D.stack [ D.fillSep [ "I", @@ -4892,13 +4879,13 @@ toArrayReport source context list startRow startCol = ArrayIndentOpen row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED LIST" region [] $ + in Report.Report "UNFINISHED ARRAY" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I cannot find the end of this list:", + "I cannot find the end of this array:", D.stack [ D.fillSep $ [ "You", @@ -4929,7 +4916,7 @@ toArrayReport source context list startRow startCol = "elements", "of", "the", - "list", + "array", "are", "separated", "by", @@ -4937,7 +4924,7 @@ toArrayReport source context list startRow startCol = ], D.toSimpleNote "I may be confused by indentation. For example, if you are trying to define\ - \ a list across multiple lines, I recommend using this format:", + \ an array across multiple lines, I recommend using this format:", D.indent 4 $ D.vcat $ [ "[ " <> D.dullyellow "\"Alice\"", @@ -4953,13 +4940,13 @@ toArrayReport source context list startRow startCol = ArrayIndentEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED LIST" region [] $ + in Report.Report "UNFINISHED ARRAY" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I cannot find the end of this list:", + "I cannot find the end of this array:", D.stack [ D.fillSep $ [ "You", @@ -4980,7 +4967,7 @@ toArrayReport source context list startRow startCol = ], D.toSimpleNote "I may be confused by indentation. For example, if you are trying to define\ - \ a list across multiple lines, I recommend using this format:", + \ an array across multiple lines, I recommend using this format:", D.indent 4 $ D.vcat $ [ "[ " <> D.dullyellow "\"Alice\"", @@ -4996,18 +4983,18 @@ toArrayReport source context list startRow startCol = ArrayIndentExpr row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED LIST" region [] $ + in Report.Report "UNFINISHED ARRAY" region [] $ Code.toSnippet source surroundings (Just region) ( D.reflow $ - "I was expecting to see another list entry after this comma:", + "I was expecting to see another array entry after this comma:", D.stack [ D.reflow $ - "Trailing commas are not allowed in lists, so the fix may be to delete the comma?", + "Trailing commas are not allowed in arrays, so the fix may be to delete the comma?", D.toSimpleNote - "I recommend using the following format for lists that span multiple lines:", + "I recommend using the following format for arrays that span multiple lines:", D.indent 4 $ D.vcat $ [ "[ " <> D.dullyellow "\"Alice\"", @@ -5200,10 +5187,10 @@ toPatternReport source context pattern startRow startCol = case pattern of PRecord record row col -> toPRecordReport source context record row col - PTuple tuple row col -> - toPTupleReport source context tuple row col - PArray list row col -> - toPArrayReport source context list row col + PArray array row col -> + toPArrayReport source context array row col + PParenthesized parenthesizedPattern row col -> + toPParenthesizedReport source context parenthesizedPattern row col PStart row col -> case Code.whatIsNext source row col of Code.Keyword keyword -> @@ -5335,7 +5322,7 @@ toPatternReport source context pattern startRow startCol = "write", "patterns", "like", - "((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")", + "([" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> "] " <> D.cyan "as" <> D.dullyellow " point" <> ")", "so", "you", "can", @@ -5345,7 +5332,7 @@ toPatternReport source context pattern startRow startCol = "parts", "of", "the", - "tuple", + "array", "with", D.dullyellow "x", "and", @@ -5464,7 +5451,7 @@ toPatternReport source context pattern startRow startCol = "write", "patterns", "like", - "((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")", + "([" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> "] " <> D.cyan "as" <> D.dullyellow " point" <> ")", "so", "you", "can", @@ -5474,7 +5461,7 @@ toPatternReport source context pattern startRow startCol = "parts", "of", "the", - "tuple", + "array", "with", D.dullyellow "x", "and", @@ -5608,10 +5595,10 @@ toUnfinishRecordPatternReport source row col startRow startCol message = ] ) -toPTupleReport :: Code.Source -> PContext -> PTuple -> Row -> Col -> Report.Report -toPTupleReport source context tuple startRow startCol = - case tuple of - PTupleOpen row col -> +toPArrayReport :: Code.Source -> PContext -> PArray -> Row -> Col -> Report.Report +toPArrayReport source context array startRow startCol = + case array of + PArrayOpen row col -> case Code.whatIsNext source row col of Code.Keyword keyword -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) @@ -5622,43 +5609,80 @@ toPTupleReport source context tuple startRow startCol = surroundings (Just region) ( D.reflow $ - "It looks like you are trying to use `" ++ keyword ++ "` as a variable name:", + "It looks like you are trying to use `" ++ keyword ++ "` to name an element of an array:", D.reflow $ - "This is a reserved word! Try using some other name?" + "This is a reserved word though! Try using some other name?" ) _ -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col - in Report.Report "UNFINISHED PARENTHESES" region [] $ - Code.toSnippet - source - surroundings - (Just region) + in Report.Report "UNFINISHED ARRAY PATTERN" region [] $ + Code.toSnippet source surroundings (Just region) $ ( D.reflow $ - "I just saw an open parenthesis, but I got stuck here:", - D.fillSep - [ "I", - "was", - "expecting", - "to", - "see", - "a", - "pattern", - "next.", - "Maybe", - "it", - "will", - "end", - "up", - "being", - "something", - "like", - D.dullyellow "(x,y)", - "or", - D.dullyellow "(name, _)" <> "?" - ] + "I just saw an open square bracket, but then I got stuck here:", + D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"] ) - PTupleEnd row col -> + PArrayEnd row col -> + let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) + region = toRegion row col + in Report.Report "UNFINISHED ARRAY PATTERN" region [] $ + Code.toSnippet source surroundings (Just region) $ + ( D.reflow $ + "I was expecting a closing square bracket to end this array pattern:", + D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"] + ) + PArrayExpr pattern row col -> + toPatternReport source context pattern row col + PArraySpace space row col -> + toSpaceReport source space row col + PArrayIndentOpen row col -> + let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) + region = toRegion row col + in Report.Report "UNFINISHED ARRAY PATTERN" region [] $ + Code.toSnippet source surroundings (Just region) $ + ( D.reflow $ + "I just saw an open square bracket, but then I got stuck here:", + D.stack + [ D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"], + D.toSimpleNote $ + "I can get confused by indentation in cases like this, so\ + \ maybe there is something next, but it is not indented enough?" + ] + ) + PArrayIndentEnd row col -> + let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) + region = toRegion row col + in Report.Report "UNFINISHED ARRAY PATTERN" region [] $ + Code.toSnippet source surroundings (Just region) $ + ( D.reflow $ + "I was expecting a closing square bracket to end this array pattern:", + D.stack + [ D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"], + D.toSimpleNote $ + "I can get confused by indentation in cases like this, so\ + \ maybe you have a closing square bracket but it is not indented enough?" + ] + ) + PArrayIndentExpr row col -> + let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) + region = toRegion row col + in Report.Report "UNFINISHED ARRAY PATTERN" region [] $ + Code.toSnippet source surroundings (Just region) $ + ( D.reflow $ + "I am partway through parsing an array pattern, but I got stuck here:", + D.stack + [ D.reflow $ + "I was expecting to see another pattern next. Maybe a variable name.", + D.toSimpleNote $ + "I can get confused by indentation in cases like this, so\ + \ maybe there is more to this pattern but it is not indented enough?" + ] + ) + +toPParenthesizedReport :: Code.Source -> PContext -> PParenthesized -> Row -> Col -> Report.Report +toPParenthesizedReport source context parenthesizedPattern startRow startCol = + case parenthesizedPattern of + PParenthesizedEnd row col -> case Code.whatIsNext source row col of Code.Keyword keyword -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) @@ -5678,9 +5702,7 @@ toPTupleReport source context tuple startRow startCol = ( D.reflow $ "I ran into the " ++ op ++ " symbol unexpectedly in this pattern:", D.reflow $ - "Only the :: symbol that works in patterns. It is useful if you\ - \ are pattern matching on lists, trying to get the first element\ - \ off the front. Did you want that instead?" + "Symbols don't work in patterns." ) Code.Close term bracket -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) @@ -5719,11 +5741,11 @@ toPTupleReport source context tuple startRow startCol = "helps?" ] ) - PTupleExpr pattern row col -> + PParenthesizedPattern pattern row col -> toPatternReport source context pattern row col - PTupleSpace space row col -> + PParenthesizedSpace space row col -> toSpaceReport source space row col - PTupleIndentEnd row col -> + PParenthesizedIndentEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -5737,7 +5759,7 @@ toPTupleReport source context tuple startRow startCol = \ maybe you have a closing parenthesis but it is not indented enough?" ] ) - PTupleIndentExpr1 row col -> + PParenthesizedIndentPattern row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -5752,138 +5774,7 @@ toPTupleReport source context tuple startRow startCol = "see", "a", "pattern", - "next.", - "Maybe", - "it", - "will", - "end", - "up", - "being", - "something", - "like", - D.dullyellow "(x,y)", - "or", - D.dullyellow "(name, _)" <> "?" - ] - ) - PTupleIndentExprN row col -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED TUPLE PATTERN" region [] $ - Code.toSnippet source surroundings (Just region) $ - ( D.reflow $ - "I am partway through parsing a tuple pattern, but I got stuck here:", - D.stack - [ D.fillSep - [ "I", - "was", - "expecting", - "to", - "see", - "a", - "pattern", - "next.", - "I", - "am", - "expecting", - "the", - "final", - "result", - "to", - "be", - "something", - "like", - D.dullyellow "(x,y)", - "or", - D.dullyellow "(name, _)" <> "." - ], - D.toSimpleNote $ - "I can get confused by indentation in cases like this, so the problem\ - \ may be that the next part is not indented enough?" - ] - ) - -toPArrayReport :: Code.Source -> PContext -> PArray -> Row -> Col -> Report.Report -toPArrayReport source context list startRow startCol = - case list of - PArrayOpen row col -> - case Code.whatIsNext source row col of - Code.Keyword keyword -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toKeywordRegion row col keyword - in Report.Report "RESERVED WORD" region [] $ - Code.toSnippet - source - surroundings - (Just region) - ( D.reflow $ - "It looks like you are trying to use `" ++ keyword ++ "` to name an element of a list:", - D.reflow $ - "This is a reserved word though! Try using some other name?" - ) - _ -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED LIST PATTERN" region [] $ - Code.toSnippet source surroundings (Just region) $ - ( D.reflow $ - "I just saw an open square bracket, but then I got stuck here:", - D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"] - ) - PArrayEnd row col -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED LIST PATTERN" region [] $ - Code.toSnippet source surroundings (Just region) $ - ( D.reflow $ - "I was expecting a closing square bracket to end this list pattern:", - D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"] - ) - PArrayExpr pattern row col -> - toPatternReport source context pattern row col - PArraySpace space row col -> - toSpaceReport source space row col - PArrayIndentOpen row col -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED LIST PATTERN" region [] $ - Code.toSnippet source surroundings (Just region) $ - ( D.reflow $ - "I just saw an open square bracket, but then I got stuck here:", - D.stack - [ D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"], - D.toSimpleNote $ - "I can get confused by indentation in cases like this, so\ - \ maybe there is something next, but it is not indented enough?" - ] - ) - PArrayIndentEnd row col -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED LIST PATTERN" region [] $ - Code.toSnippet source surroundings (Just region) $ - ( D.reflow $ - "I was expecting a closing square bracket to end this list pattern:", - D.stack - [ D.fillSep ["Try", "adding", "a", D.dullyellow "]", "to", "see", "if", "that", "helps?"], - D.toSimpleNote $ - "I can get confused by indentation in cases like this, so\ - \ maybe you have a closing square bracket but it is not indented enough?" - ] - ) - PArrayIndentExpr row col -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED LIST PATTERN" region [] $ - Code.toSnippet source surroundings (Just region) $ - ( D.reflow $ - "I am partway through parsing a list pattern, but I got stuck here:", - D.stack - [ D.reflow $ - "I was expecting to see another pattern next. Maybe a variable name.", - D.toSimpleNote $ - "I can get confused by indentation in cases like this, so\ - \ maybe there is more to this pattern but it is not indented enough?" + "next." ] ) @@ -5900,8 +5791,8 @@ toTypeReport source context tipe startRow startCol = case tipe of TRecord record row col -> toTRecordReport source context record row col - TTuple tuple row col -> - toTTupleReport source context tuple row col + TParenthesis parenthesizedType row col -> + toTParenthesisReport source context parenthesizedType row col TStart row col -> case Code.whatIsNext source row col of Code.Keyword keyword -> @@ -6411,54 +6302,10 @@ noteForRecordTypeIndentError = \ This is the stylistic convention in the Gren ecosystem." ] -toTTupleReport :: Code.Source -> TContext -> TTuple -> Row -> Col -> Report.Report -toTTupleReport source context tuple startRow startCol = - case tuple of - TTupleOpen row col -> - case Code.whatIsNext source row col of - Code.Keyword keyword -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toKeywordRegion row col keyword - in Report.Report "RESERVED WORD" region [] $ - Code.toSnippet - source - surroundings - (Just region) - ( D.reflow $ - "I ran into a reserved word unexpectedly:", - D.reflow $ - "It looks like you are trying to use `" ++ keyword - ++ "` as a variable name, but \ - \ it is a reserved word. Try using a different name!" - ) - _ -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED PARENTHESES" region [] $ - Code.toSnippet - source - surroundings - (Just region) - ( D.reflow $ - "I just saw an open parenthesis, so I was expecting to see a type next.", - D.fillSep $ - [ "Something", - "like", - D.dullyellow "(Maybe Int)", - "or", - D.dullyellow "(Array Person)" <> ".", - "Anything", - "where", - "you", - "are", - "putting", - "parentheses", - "around", - "normal", - "types." - ] - ) - TTupleEnd row col -> +toTParenthesisReport :: Code.Source -> TContext -> TParenthesis -> Row -> Col -> Report.Report +toTParenthesisReport source context parenthesizedType startRow startCol = + case parenthesizedType of + TParenthesisEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -6476,11 +6323,11 @@ toTTupleReport source context tuple startRow startCol = \ or missing brackets) that is confusing me." ] ) - TTupleType tipe row col -> + TParenthesisType tipe row col -> toTypeReport source context tipe row col - TTupleSpace space row col -> + TParenthesisSpace space row col -> toSpaceReport source space row col - TTupleIndentType1 row col -> + TParenthesisIndentOpen row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ @@ -6512,42 +6359,7 @@ toTTupleReport source context tuple startRow startCol = \ maybe you have a type but it is not indented enough?" ] ) - TTupleIndentTypeN row col -> - let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) - region = toRegion row col - in Report.Report "UNFINISHED TUPLE TYPE" region [] $ - Code.toSnippet - source - surroundings - (Just region) - ( D.reflow $ - "I think I am in the middle of parsing a tuple type. I just saw a comma, so I was expecting to see a type next.", - D.stack - [ D.fillSep $ - [ "A", - "tuple", - "type", - "looks", - "like", - D.dullyellow "(Float,Float)", - "or", - D.dullyellow "(String,Int)" <> ",", - "so", - "I", - "think", - "there", - "is", - "a", - "type", - "missing", - "here?" - ], - D.toSimpleNote $ - "I can get confused by indentation in cases like this, so\ - \ maybe you have an expression but it is not indented enough?" - ] - ) - TTupleIndentEnd row col -> + TParenthesisIndentEnd row col -> let surroundings = A.Region (A.Position startRow startCol) (A.Position row col) region = toRegion row col in Report.Report "UNFINISHED PARENTHESES" region [] $ diff --git a/compiler/src/Reporting/Error/Type.hs b/compiler/src/Reporting/Error/Type.hs index a5e193cff..9511b309c 100644 --- a/compiler/src/Reporting/Error/Type.hs +++ b/compiler/src/Reporting/Error/Type.hs @@ -86,9 +86,6 @@ data Category | Accessor Name.Name | Access Name.Name | Record - | Tuple - | Unit - | Shader | Effects | Local Name.Name | Foreign Name.Name @@ -107,8 +104,6 @@ data PContext data PCategory = PRecord - | PUnit - | PTuple | PArray | PCtor Name.Name | PInt @@ -266,8 +261,6 @@ addPatternCategory iAmTryingToMatch category = iAmTryingToMatch <> case category of PRecord -> " record values of type:" - PUnit -> " unit values:" - PTuple -> " tuples of type:" PArray -> " arrays of type:" PCtor name -> " `" <> Name.toChars name <> "` values of type:" PInt -> " integers:" @@ -317,9 +310,6 @@ addCategory thisIs category = Char -> thisIs <> " a character of type:" Lambda -> thisIs <> " an anonymous function of type:" Record -> thisIs <> " a record of type:" - Tuple -> thisIs <> " a tuple of type:" - Unit -> thisIs <> " a unit value:" - Shader -> thisIs <> " a GLSL shader of type:" Effects -> thisIs <> " a thing for CORE LIBRARIES ONLY." CallResult maybeName -> case maybeName of @@ -474,8 +464,6 @@ problemToHint problem = T.RigidSuper s _ -> badRigidSuper s (toASuperThing super) T.Type _ _ _ -> badFlexSuper direction super tipe T.Record _ _ -> badFlexSuper direction super tipe - T.Unit -> badFlexSuper direction super tipe - T.Tuple _ _ _ -> badFlexSuper direction super tipe T.Alias _ _ _ _ -> badFlexSuper direction super tipe T.BadRigidVar x tipe -> case tipe of @@ -488,8 +476,6 @@ problemToHint problem = T.RigidSuper _ y -> badDoubleRigid x y T.Type _ n _ -> badRigidVar x ("a `" ++ Name.toChars n ++ "` value") T.Record _ _ -> badRigidVar x "a record" - T.Unit -> badRigidVar x "a unit value" - T.Tuple _ _ _ -> badRigidVar x "a tuple" T.Alias _ n _ _ -> badRigidVar x ("a `" ++ Name.toChars n ++ "` value") T.BadRigidSuper super x tipe -> case tipe of @@ -502,8 +488,6 @@ problemToHint problem = T.RigidSuper _ y -> badDoubleRigid x y T.Type _ n _ -> badRigidSuper super ("a `" ++ Name.toChars n ++ "` value") T.Record _ _ -> badRigidSuper super "a record" - T.Unit -> badRigidSuper super "a unit value" - T.Tuple _ _ _ -> badRigidSuper super "a tuple" T.Alias _ n _ _ -> badRigidSuper super ("a `" ++ Name.toChars n ++ "` value") T.FieldsMissing fields -> case map (D.green . D.fromName) fields of @@ -581,7 +565,7 @@ badFlexSuper direction super tipe = [ D.link "Hint" "I do not know how to compare records. I can only compare ints, floats,\ - \ chars, strings, arrays of comparable values, and tuples of comparable values.\ + \ chars, strings and arrays of comparable values.\ \ Check out" "comparing-records" "for ideas on how to proceed." @@ -590,8 +574,7 @@ badFlexSuper direction super tipe = [ D.toSimpleHint $ "I do not know how to compare `" ++ Name.toChars name ++ "` values. I can only\ - \ compare ints, floats, chars, strings, arrays of comparable values, and tuples\ - \ of comparable values.", + \ compare ints, floats, chars, strings and arrays of comparable values.", D.reflowLink "Check out" "comparing-custom-types" @@ -599,8 +582,7 @@ badFlexSuper direction super tipe = ] _ -> [ D.toSimpleHint $ - "I only know how to compare ints, floats, chars, strings, arrays of\ - \ comparable values, and tuples of comparable values." + "I only know how to compare ints, floats, chars, strings and arrays of comparable values." ] T.Appendable -> [ D.toSimpleHint "I only know how to append strings and arrays." @@ -627,7 +609,7 @@ badRigidSuper super aThing = let (superType, manyThings) = case super of T.Number -> ("number", "ints AND floats") - T.Comparable -> ("comparable", "ints, floats, chars, strings, arrays, and tuples") + T.Comparable -> ("comparable", "ints, floats, chars, strings and arrays") T.Appendable -> ("appendable", "strings AND arrays") T.CompAppend -> ("compappend", "strings AND arrays") in [ D.toSimpleHint $ @@ -1742,8 +1724,6 @@ badCompLeft localizer category op direction tipe expected = "work", "on", "arrays", - "and", - "tuples", "of", "comparable", "values", diff --git a/compiler/src/Reporting/Render/Type.hs b/compiler/src/Reporting/Render/Type.hs index 1c3dc7773..5fab9bf94 100644 --- a/compiler/src/Reporting/Render/Type.hs +++ b/compiler/src/Reporting/Render/Type.hs @@ -5,7 +5,6 @@ module Reporting.Render.Type ( Context (..), lambda, apply, - tuple, record, vrecordSnippet, vrecord, @@ -16,7 +15,6 @@ where import qualified AST.Canonical as Can import qualified AST.Source as Src -import qualified Data.Maybe as Maybe import qualified Data.Name as Name import qualified Reporting.Annotation as A import Reporting.Doc (Doc, (<+>)) @@ -52,12 +50,6 @@ apply context name args = Func -> applyDoc None -> applyDoc -tuple :: Doc -> Doc -> [Doc] -> Doc -tuple a b cs = - let entries = - zipWith (<+>) ("(" : repeat ",") (a : b : cs) - in D.align $ D.sep [D.cat entries, ")"] - record :: [(Doc, Doc)] -> Maybe Doc -> Doc record entries maybeExt = case (map entryToDoc entries, maybeExt) of @@ -136,13 +128,6 @@ srcToDoc context (A.At _ tipe) = record (map srcFieldToDocs fields) (fmap (D.fromName . A.toValue) ext) - Src.TUnit -> - "()" - Src.TTuple a b cs -> - tuple - (srcToDoc None a) - (srcToDoc None b) - (map (srcToDoc None) cs) srcFieldToDocs :: (A.Located Name.Name, Src.Type) -> (Doc, Doc) srcFieldToDocs (A.At _ fieldName, fieldType) = @@ -182,13 +167,6 @@ canToDoc localizer context tipe = record (map (canFieldToDoc localizer) (Can.fieldsToList fields)) (fmap D.fromName ext) - Can.TUnit -> - "()" - Can.TTuple a b maybeC -> - tuple - (canToDoc localizer None a) - (canToDoc localizer None b) - (map (canToDoc localizer None) (Maybe.maybeToList maybeC)) Can.TAlias home name args _ -> apply context diff --git a/compiler/src/Type/Constrain/Expression.hs b/compiler/src/Type/Constrain/Expression.hs index dc61bddef..f8937968a 100644 --- a/compiler/src/Type/Constrain/Expression.hs +++ b/compiler/src/Type/Constrain/Expression.hs @@ -117,10 +117,6 @@ constrain rtv (A.At region expression) expected = constrainUpdate rtv region name expr fields expected Can.Record fields -> constrainRecord rtv region fields expected - Can.Unit -> - return $ CEqual region Unit UnitN expected - Can.Tuple a b maybeC -> - constrainTuple rtv region a b maybeC expected -- CONSTRAIN LAMBDA @@ -393,37 +389,6 @@ constrainUpdateField rtv region field (Can.FieldUpdate _ expr) = con <- constrain rtv expr (FromContext region (RecordUpdateValue field) tipe) return (var, tipe, con) --- CONSTRAIN TUPLE - -constrainTuple :: RTV -> A.Region -> Can.Expr -> Can.Expr -> Maybe Can.Expr -> Expected Type -> IO Constraint -constrainTuple rtv region a b maybeC expected = - do - aVar <- mkFlexVar - bVar <- mkFlexVar - let aType = VarN aVar - let bType = VarN bVar - - aCon <- constrain rtv a (NoExpectation aType) - bCon <- constrain rtv b (NoExpectation bType) - - case maybeC of - Nothing -> - do - let tupleType = TupleN aType bType Nothing - let tupleCon = CEqual region Tuple tupleType expected - return $ exists [aVar, bVar] $ CAnd [aCon, bCon, tupleCon] - Just c -> - do - cVar <- mkFlexVar - let cType = VarN cVar - - cCon <- constrain rtv c (NoExpectation cType) - - let tupleType = TupleN aType bType (Just cType) - let tupleCon = CEqual region Tuple tupleType expected - - return $ exists [aVar, bVar, cVar] $ CAnd [aCon, bCon, cCon, tupleCon] - -- CONSTRAIN DESTRUCTURES constrainDestruct :: RTV -> A.Region -> Can.Pattern -> Can.Expr -> Constraint -> IO Constraint @@ -505,7 +470,6 @@ data Info = Info _headers :: Map.Map Name.Name (A.Located Type) } -{-# NOINLINE emptyInfo #-} emptyInfo :: Info emptyInfo = Info [] [] Map.empty diff --git a/compiler/src/Type/Constrain/Pattern.hs b/compiler/src/Type/Constrain/Pattern.hs index 494f9e896..92b764991 100644 --- a/compiler/src/Type/Constrain/Pattern.hs +++ b/compiler/src/Type/Constrain/Pattern.hs @@ -42,13 +42,6 @@ add (A.At region pattern) expectation state = Can.PAlias realPattern name -> add realPattern expectation $ addToHeaders region name expectation state - Can.PUnit -> - do - let (State headers vars revCons) = state - let unitCon = CPattern region E.PUnit UnitN expectation - return $ State headers vars (unitCon : revCons) - Can.PTuple a b maybeC -> - addTuple region a b maybeC expectation state Can.PCtor home typeName (Can.Union typeVars _ _ _) ctorName _ args -> addCtor region home typeName typeVars ctorName args expectation state Can.PArray patterns -> @@ -111,7 +104,6 @@ add (A.At region pattern) expectation state = -- STATE HELPERS -{-# NOINLINE emptyState #-} emptyState :: State emptyState = State Map.empty [] [] @@ -128,7 +120,11 @@ getType expectation = E.PNoExpectation tipe -> tipe E.PFromContext _ _ tipe -> tipe --- CONSTRAIN LIST +simpleAdd :: Can.Pattern -> Type -> State -> IO State +simpleAdd pattern patternType state = + add pattern (E.PNoExpectation patternType) state + +-- CONSTRAIN ARRAY addEntry :: A.Region -> Type -> State -> (Index.ZeroBased, Can.Pattern) -> IO State addEntry listRegion tipe state (index, pattern) = @@ -136,44 +132,6 @@ addEntry listRegion tipe state (index, pattern) = E.PFromContext listRegion (E.PArrayEntry index) tipe in add pattern expectation state --- CONSTRAIN TUPLE - -addTuple :: A.Region -> Can.Pattern -> Can.Pattern -> Maybe Can.Pattern -> E.PExpected Type -> State -> IO State -addTuple region a b maybeC expectation state = - do - aVar <- mkFlexVar - bVar <- mkFlexVar - let aType = VarN aVar - let bType = VarN bVar - - case maybeC of - Nothing -> - do - (State headers vars revCons) <- - simpleAdd b bType - =<< simpleAdd a aType state - - let tupleCon = CPattern region E.PTuple (TupleN aType bType Nothing) expectation - - return $ State headers (aVar : bVar : vars) (tupleCon : revCons) - Just c -> - do - cVar <- mkFlexVar - let cType = VarN cVar - - (State headers vars revCons) <- - simpleAdd c cType - =<< simpleAdd b bType - =<< simpleAdd a aType state - - let tupleCon = CPattern region E.PTuple (TupleN aType bType (Just cType)) expectation - - return $ State headers (aVar : bVar : cVar : vars) (tupleCon : revCons) - -simpleAdd :: Can.Pattern -> Type -> State -> IO State -simpleAdd pattern patternType state = - add pattern (E.PNoExpectation patternType) state - -- CONSTRAIN CONSTRUCTORS addCtor :: A.Region -> ModuleName.Canonical -> Name.Name -> [Name.Name] -> Name.Name -> [Can.PatternCtorArg] -> E.PExpected Type -> State -> IO State diff --git a/compiler/src/Type/Error.hs b/compiler/src/Type/Error.hs index f95bc7412..789d6eef9 100644 --- a/compiler/src/Type/Error.hs +++ b/compiler/src/Type/Error.hs @@ -20,7 +20,6 @@ where import qualified Data.Bag as Bag import qualified Data.Map as Map -import qualified Data.Maybe as Maybe import qualified Data.Name as Name import qualified Gren.ModuleName as ModuleName import qualified Reporting.Doc as D @@ -39,8 +38,6 @@ data Type | RigidSuper Super Name.Name | Type ModuleName.Canonical Name.Name [Type] | Record (Map.Map Name.Name Type) Extension - | Unit - | Tuple Type Type (Maybe Type) | Alias ModuleName.Canonical Name.Name [(Name.Name, Type)] Type data Super @@ -93,13 +90,6 @@ toDoc localizer ctx tipe = (map (toDoc localizer RT.App) args) Record fields ext -> RT.record (fieldsToDocs localizer fields) (extToDoc ext) - Unit -> - "()" - Tuple a b maybeC -> - RT.tuple - (toDoc localizer RT.None a) - (toDoc localizer RT.None b) - (map (toDoc localizer RT.None) (Maybe.maybeToList maybeC)) Alias home name args _ -> aliasToDoc localizer ctx home name args @@ -189,7 +179,6 @@ toComparison localizer tipe1 tipe2 = toDiff :: L.Localizer -> RT.Context -> Type -> Type -> Diff D.Doc toDiff localizer ctx tipe1 tipe2 = case (tipe1, tipe2) of - (Unit, Unit) -> same localizer ctx tipe1 (Error, Error) -> same localizer ctx tipe1 (Infinite, Infinite) -> same localizer ctx tipe1 (FlexVar x, FlexVar y) | x == y -> same localizer ctx tipe1 @@ -213,16 +202,6 @@ toDiff localizer ctx tipe1 tipe2 = (D.dullyellow (RT.lambda ctx (f a) (f b) (map f cs))) (D.dullyellow (RT.lambda ctx (f x) (f y) (map f zs))) (Bag.one (ArityMismatch (2 + length cs) (2 + length zs))) - (Tuple a b Nothing, Tuple x y Nothing) -> - RT.tuple - <$> toDiff localizer RT.None a x - <*> toDiff localizer RT.None b y - <*> pure [] - (Tuple a b (Just c), Tuple x y (Just z)) -> - RT.tuple - <$> toDiff localizer RT.None a x - <*> toDiff localizer RT.None b y - <*> ((: []) <$> toDiff localizer RT.None c z) (Record fields1 ext1, Record fields2 ext2) -> diffRecord localizer fields1 ext1 fields2 ext2 (Type home1 name1 args1, Type home2 name2 args2) @@ -371,12 +350,6 @@ isSuper super tipe = Comparable -> isInt h n || isFloat h n || isString h n || isChar h n || isArray h n && isSuper super (head args) Appendable -> isString h n || isArray h n CompAppend -> isString h n || isArray h n && isSuper Comparable (head args) - Tuple a b maybeC -> - case super of - Number -> False - Comparable -> isSuper super a && isSuper super b && maybe True (isSuper super) maybeC - Appendable -> False - CompAppend -> False _ -> False diff --git a/compiler/src/Type/Instantiate.hs b/compiler/src/Type/Instantiate.hs index 0714c9584..d725a7b2e 100644 --- a/compiler/src/Type/Instantiate.hs +++ b/compiler/src/Type/Instantiate.hs @@ -40,13 +40,6 @@ fromSrcType freeVars sourceType = fromSrcType freeVars realType Can.Holey realType -> fromSrcType (Map.fromList targs) realType - Can.TTuple a b maybeC -> - TupleN - <$> fromSrcType freeVars a - <*> fromSrcType freeVars b - <*> traverse (fromSrcType freeVars) maybeC - Can.TUnit -> - return UnitN Can.TRecord fields maybeExt -> RecordN <$> traverse (fromSrcFieldType freeVars) fields diff --git a/compiler/src/Type/Occurs.hs b/compiler/src/Type/Occurs.hs index 45d4d6d3a..8b77e7e52 100644 --- a/compiler/src/Type/Occurs.hs +++ b/compiler/src/Type/Occurs.hs @@ -45,17 +45,6 @@ occursHelp seen var foundCycle = Record1 fields ext -> occursHelp newSeen ext =<< foldrM (occursHelp newSeen) foundCycle (Map.elems fields) - Unit1 -> - return foundCycle - Tuple1 a b maybeC -> - case maybeC of - Nothing -> - occursHelp newSeen a - =<< occursHelp newSeen b foundCycle - Just c -> - occursHelp newSeen a - =<< occursHelp newSeen b - =<< occursHelp newSeen c foundCycle Alias _ _ args _ -> foldrM (occursHelp (var : seen)) foundCycle (map snd args) Error -> diff --git a/compiler/src/Type/Solve.hs b/compiler/src/Type/Solve.hs index 463193c16..79b19f6e6 100644 --- a/compiler/src/Type/Solve.hs +++ b/compiler/src/Type/Solve.hs @@ -40,7 +40,6 @@ run constraint = e : es -> return $ Left (NE.List e es) -{-# NOINLINE emptyState #-} emptyState :: State emptyState = State Map.empty (nextMark noMark) [] @@ -358,18 +357,6 @@ adjustRankContent youngMark visitMark groupRank content = do extRank <- go extension foldM (\rank field -> max rank <$> go field) extRank fields - Unit1 -> - -- THEORY: a unit never needs to get generalized - return outermostRank - Tuple1 a b maybeC -> - do - ma <- go a - mb <- go b - case maybeC of - Nothing -> - return (max ma mb) - Just c -> - max (max ma mb) <$> go c Alias _ _ args _ -> -- THEORY: anything in the realVar would be outermostRank foldM (\rank (_, argVar) -> max rank <$> go argVar) outermostRank args @@ -428,14 +415,6 @@ typeToVar rank pools aliasDict tipe = register rank pools (Structure (Record1 fieldVars extVar)) EmptyRecordN -> register rank pools emptyRecord1 - UnitN -> - register rank pools unit1 - TupleN a b c -> - do - aVar <- go a - bVar <- go b - cVar <- traverse go c - register rank pools (Structure (Tuple1 aVar bVar cVar)) register :: Int -> Pools -> Content -> IO Variable register rank pools content = @@ -444,16 +423,10 @@ register rank pools content = MVector.modify pools (var :) rank return var -{-# NOINLINE emptyRecord1 #-} emptyRecord1 :: Content emptyRecord1 = Structure EmptyRecord1 -{-# NOINLINE unit1 #-} -unit1 :: Content -unit1 = - Structure Unit1 - -- SOURCE TYPE TO VARIABLE srcTypeToVariable :: Int -> Pools -> Map.Map Name.Name () -> Can.Type -> IO Variable @@ -495,14 +468,6 @@ srcTypeToVar rank pools flexVars srcType = Nothing -> register rank pools emptyRecord1 Just ext -> return (flexVars ! ext) register rank pools (Structure (Record1 fieldVars extVar)) - Can.TUnit -> - register rank pools unit1 - Can.TTuple a b c -> - do - aVar <- go a - bVar <- go b - cVar <- traverse go c - register rank pools (Structure (Tuple1 aVar bVar cVar)) Can.TAlias home name args aliasType -> do argVars <- traverse (traverse go) args @@ -620,15 +585,6 @@ restoreContent content = do mapM_ restore fields restore ext - Unit1 -> - return () - Tuple1 a b maybeC -> - do - restore a - restore b - case maybeC of - Nothing -> return () - Just c -> restore c Alias _ _ args var -> do mapM_ (traverse restore) args @@ -649,7 +605,3 @@ traverseFlatType f flatType = pure EmptyRecord1 Record1 fields ext -> liftM2 Record1 (traverse f fields) (f ext) - Unit1 -> - pure Unit1 - Tuple1 a b cs -> - liftM3 Tuple1 (f a) (f b) (traverse f cs) diff --git a/compiler/src/Type/Type.hs b/compiler/src/Type/Type.hs index dff547e60..5bb278f2a 100644 --- a/compiler/src/Type/Type.hs +++ b/compiler/src/Type/Type.hs @@ -79,8 +79,6 @@ data FlatType | Fun1 Variable Variable | EmptyRecord1 | Record1 (Map.Map Name.Name Variable) Variable - | Unit1 - | Tuple1 Variable Variable (Maybe Variable) data Type = PlaceHolder Name.Name @@ -90,8 +88,6 @@ data Type | FunN Type Type | EmptyRecordN | RecordN (Map.Map Name.Name Type) Type - | UnitN - | TupleN Type Type (Maybe Type) -- DESCRIPTORS @@ -149,7 +145,6 @@ getVarNamesMark :: Mark getVarNamesMark = Mark 0 -{-# INLINE nextMark #-} nextMark :: Mark -> Mark nextMark (Mark mark) = Mark (mark + 1) @@ -158,34 +153,27 @@ nextMark (Mark mark) = infixr 9 ==> -{-# INLINE (==>) #-} (==>) :: Type -> Type -> Type (==>) = FunN -- PRIMITIVE TYPES -{-# NOINLINE int #-} int :: Type int = AppN ModuleName.basics "Int" [] -{-# NOINLINE float #-} float :: Type float = AppN ModuleName.basics "Float" [] -{-# NOINLINE char #-} char :: Type char = AppN ModuleName.char "Char" [] -{-# NOINLINE string #-} string :: Type string = AppN ModuleName.string "String" [] -{-# NOINLINE bool #-} bool :: Type bool = AppN ModuleName.basics "Bool" [] -{-# NOINLINE never #-} never :: Type never = AppN ModuleName.basics "Never" [] @@ -195,12 +183,10 @@ mkFlexVar :: IO Variable mkFlexVar = UF.fresh flexVarDescriptor -{-# NOINLINE flexVarDescriptor #-} flexVarDescriptor :: Descriptor flexVarDescriptor = makeDescriptor unnamedFlexVar -{-# NOINLINE unnamedFlexVar #-} unnamedFlexVar :: Content unnamedFlexVar = FlexVar Nothing @@ -211,7 +197,6 @@ mkFlexNumber :: IO Variable mkFlexNumber = UF.fresh flexNumberDescriptor -{-# NOINLINE flexNumberDescriptor #-} flexNumberDescriptor :: Descriptor flexNumberDescriptor = makeDescriptor (unnamedFlexSuper Number) @@ -319,13 +304,6 @@ termToCanType term = Can.TRecord canFields (Just name) _ -> error "Used toAnnotation on a type that is not well-formed" - Unit1 -> - return Can.TUnit - Tuple1 a b maybeC -> - Can.TTuple - <$> variableToCanType a - <*> variableToCanType b - <*> traverse variableToCanType maybeC fieldToCanType :: Variable -> StateT NameState IO Can.FieldType fieldToCanType variable = @@ -428,13 +406,6 @@ termToErrorType term = ET.Record errFields (ET.RigidOpen ext) _ -> error "Used toErrorType on a type that is not well-formed" - Unit1 -> - return ET.Unit - Tuple1 a b maybeC -> - ET.Tuple - <$> variableToErrorType a - <*> variableToErrorType b - <*> traverse variableToErrorType maybeC -- MANAGE FRESH VARIABLE NAMES @@ -543,12 +514,6 @@ getVarNames var takenNames = Record1 fields extension -> getVarNames extension =<< foldrM getVarNames takenNames (Map.elems fields) - Unit1 -> - return takenNames - Tuple1 a b Nothing -> - getVarNames a =<< getVarNames b takenNames - Tuple1 a b (Just c) -> - getVarNames a =<< getVarNames b =<< getVarNames c takenNames -- REGISTER NAME / RENAME DUPLICATES diff --git a/compiler/src/Type/Unify.hs b/compiler/src/Type/Unify.hs index a04160c97..355677efd 100644 --- a/compiler/src/Type/Unify.hs +++ b/compiler/src/Type/Unify.hs @@ -37,7 +37,6 @@ onSuccess :: [Variable] -> () -> IO Answer onSuccess vars () = return (Ok vars) -{-# NOINLINE errorDescriptor #-} errorDescriptor :: Descriptor errorDescriptor = Descriptor Error noRank noMark Nothing @@ -310,23 +309,6 @@ unifyFlexSuperStructure context super flatType = comparableOccursCheck context unifyComparableRecursive variable merge context (Structure flatType) - Tuple1 a b maybeC -> - case super of - Number -> - mismatch - Appendable -> - mismatch - Comparable -> - do - comparableOccursCheck context - unifyComparableRecursive a - unifyComparableRecursive b - case maybeC of - Nothing -> return () - Just c -> unifyComparableRecursive c - merge context (Structure flatType) - CompAppend -> - mismatch _ -> mismatch @@ -443,19 +425,6 @@ unifyStructure context flatType content otherContent = case unifyRecord context structure1 structure2 of Unify k -> k vars ok err - (Tuple1 a b Nothing, Tuple1 x y Nothing) -> - do - subUnify a x - subUnify b y - merge context otherContent - (Tuple1 a b (Just c), Tuple1 x y (Just z)) -> - do - subUnify a x - subUnify b y - subUnify c z - merge context otherContent - (Unit1, Unit1) -> - merge context otherContent _ -> mismatch Error -> diff --git a/gren.cabal b/gren.cabal index 8deb0da3e..173eb5309 100644 --- a/gren.cabal +++ b/gren.cabal @@ -37,7 +37,7 @@ Executable gren if flag(dev) ghc-options: -O0 -Wall -Werror else - ghc-options: -O2 -rtsopts -threaded "-with-rtsopts=-N -qg -A128m" + ghc-options: -O2 -threaded "-with-rtsopts=-N" Hs-Source-Dirs: compiler/src diff --git a/hints/imports.md b/hints/imports.md index a41be2a3d..179974f32 100644 --- a/hints/imports.md +++ b/hints/imports.md @@ -109,7 +109,6 @@ import List exposing (List, (::)) import Maybe exposing (Maybe(..)) import Result exposing (Result(..)) import String -import Tuple import Debug diff --git a/hints/tuples.md b/hints/tuples.md deleted file mode 100644 index 635949d66..000000000 --- a/hints/tuples.md +++ /dev/null @@ -1,18 +0,0 @@ -# From Tuples to Records - -The largest tuple possible in Gren has three entries. Once you get to four, it is best to make a record with named entries. - -For example, it is _conceivable_ to represent a rectangle as four numbers like `(10,10,100,100)` but it would be more self-documenting to use a record like this: - -```gren -type alias Rectangle = - { x : Float - , y : Float - , width : Float - , height : Float - } -``` - -Now it is clear that the dimensions should be `Float` values. It is also clear that we are not using the convention of specifying the top-left and bottom-right corners. It could be clearer about whether the `x` and `y` is the point in the top-left or in the middle though! - -Anyway, using records like this also gives you access to syntax like `rect.x`, `.x`, and `{ rect | x = 40 }`. It is not clear how to design features like that for arbitrarily sized tuples, so we did not. We already have a way, and it is more self-documenting! diff --git a/hints/type-annotations.md b/hints/type-annotations.md index 262628449..c8230aa91 100644 --- a/hints/type-annotations.md +++ b/hints/type-annotations.md @@ -10,15 +10,15 @@ This document is going to outline the various things that can go wrong and show The most common issue is with user-defined type variables that are too general. So let's say you have defined a function like this: ```gren -addPair : (a, a) -> a -addPair (x, y) = +addPair : a -> a -> a +addPair x y = x + y ``` -The issue is that the type annotation is saying "I will accept a tuple containing literally *anything*" but the definition is using `(+)` which requires things to be numbers. So the compiler is going to infer that the true type of the definition is this: +The issue is that the type annotation is saying "I will accept two parameters that can be literally *anything*" but the definition is using `(+)` which requires things to be numbers. So the compiler is going to infer that the true type of the definition is this: ```gren -addPair : (number, number) -> number +addPair : number -> number -> -> number ``` So you will probably see an error saying "I cannot match `a` with `number`" which is essentially saying, you are trying to provide a type annotation that is **too general**. You are saying `addPair` accepts anything, but in fact, it can only handle numbers. @@ -31,8 +31,8 @@ In cases like this, you want to go with whatever the compiler inferred. It is go It is also possible to have a type annotation that clashes with itself. This is probably more rare, but someone will run into it eventually. Let's use another version of `addPair` with problems: ```gren -addPair : (Int, Int) -> number -addPair (x, y) = +addPair : Int -> Int -> number +addPair x y = x + y ```