From cd7a8ce770f93b1ce7c07af40af5a2fd2915c753 Mon Sep 17 00:00:00 2001 From: Arya Irani Date: Thu, 9 Jan 2025 13:24:15 -0500 Subject: [PATCH 1/3] seems to want the file extension now --- scripts/make-release.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/make-release.sh b/scripts/make-release.sh index 19a2b99785..43d2e7efaf 100755 --- a/scripts/make-release.sh +++ b/scripts/make-release.sh @@ -52,16 +52,16 @@ echo "Kicking off release workflow in unisonweb/unison" git fetch origin trunk git tag "${tag}" "${src}" git push origin "${tag}" -gh workflow run release --repo unisonweb/unison \ +gh workflow run release.yaml --repo unisonweb/unison \ --ref "${tag}" \ --field "version=${version}" echo "Kicking off Homebrew update task" -gh workflow run release --repo unisonweb/homebrew-unison --field "version=${version}" +gh workflow run release.yaml --repo unisonweb/homebrew-unison --field "version=${version}" echo "Opening relevant workflows in browser" -gh workflow view release --web --repo unisonweb/homebrew-unison || true -gh workflow view release --web --repo unisonweb/unison || true +gh workflow view release.yaml --web --repo unisonweb/homebrew-unison || true +gh workflow view release.yaml --web --repo unisonweb/unison || true echo "Okay! All the work has been kicked off, it may take several hours to complete." echo "Run '$0 --status' to see job status." From 89b2c60268b3f797cdde05372486a5c2c90650ef Mon Sep 17 00:00:00 2001 From: Mitchell Dalvi Rosen Date: Mon, 13 Jan 2025 13:42:25 -0500 Subject: [PATCH 2/3] don't call Name.splits on absolute argument --- .../src/Unison/Syntax/TermPrinter.hs | 43 ++++++++++--------- unison-core/src/Unison/Name.hs | 13 +++--- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/parser-typechecker/src/Unison/Syntax/TermPrinter.hs b/parser-typechecker/src/Unison/Syntax/TermPrinter.hs index 99969f09a2..0cd9659476 100644 --- a/parser-typechecker/src/Unison/Syntax/TermPrinter.hs +++ b/parser-typechecker/src/Unison/Syntax/TermPrinter.hs @@ -72,18 +72,18 @@ import Unison.Var qualified as Var type SyntaxText = S.SyntaxText' Reference -pretty :: (Var v) => PrettyPrintEnv -> Term v a -> Pretty ColorText +pretty :: (HasCallStack, Var v) => PrettyPrintEnv -> Term v a -> Pretty ColorText pretty ppe tm = PP.syntaxToColor . runPretty (avoidShadowing tm ppe) $ pretty0 emptyAc $ printAnnotate ppe tm prettyBlock :: (Var v) => Bool -> PrettyPrintEnv -> Term v a -> Pretty ColorText prettyBlock elideUnit ppe = PP.syntaxToColor . prettyBlock' elideUnit ppe -prettyBlock' :: (Var v) => Bool -> PrettyPrintEnv -> Term v a -> Pretty SyntaxText +prettyBlock' :: (HasCallStack, Var v) => Bool -> PrettyPrintEnv -> Term v a -> Pretty SyntaxText prettyBlock' elideUnit ppe tm = runPretty (avoidShadowing tm ppe) . pretty0 (emptyBlockAc {elideUnit = elideUnit}) $ printAnnotate ppe tm -pretty' :: (Var v) => Maybe Width -> PrettyPrintEnv -> Term v a -> ColorText +pretty' :: (HasCallStack, Var v) => Maybe Width -> PrettyPrintEnv -> Term v a -> ColorText pretty' (Just width) n t = PP.render width . PP.syntaxToColor . runPretty (avoidShadowing t n) $ pretty0 emptyAc (printAnnotate n t) pretty' Nothing n t = @@ -819,8 +819,8 @@ groupCases :: [MatchCase' () (Term3 v ann)] -> [([Pattern ()], [v], [(Maybe (Term3 v ann), ([v], Term3 v ann))])] groupCases = \cases - [] -> [] - ms@((p1, _, AbsN' vs1 _) : _) -> go (p1, vs1) [] ms + [] -> [] + ms@((p1, _, AbsN' vs1 _) : _) -> go (p1, vs1) [] ms where go (p0, vs0) acc [] = [(p0, vs0, reverse acc)] go (p0, vs0) acc ms@((p1, g1, AbsN' vs body) : tl) @@ -973,7 +973,7 @@ prettyBinding' ppe width v t = PP.render width . PP.syntaxToColor $ prettyBinding ppe v t prettyBinding0 :: - (MonadPretty v m) => + (HasCallStack, MonadPretty v m) => AmbientContext -> HQ.HashQualified Name -> Term2 v at ap v a -> @@ -1314,7 +1314,7 @@ instance Semigroup PrintAnnotation where instance Monoid PrintAnnotation where mempty = PrintAnnotation {usages = Map.empty} -suffixCounterTerm :: (Var v) => PrettyPrintEnv -> Set Name -> Set Name -> Term2 v at ap v a -> PrintAnnotation +suffixCounterTerm :: (HasCallStack, Var v) => PrettyPrintEnv -> Set Name -> Set Name -> Term2 v at ap v a -> PrintAnnotation suffixCounterTerm n usedTm usedTy = \case Ref' r -> countHQ usedTm $ PrettyPrintEnv.termName n (Referent.Ref r) Constructor' r | noImportRefs (r ^. ConstructorReference.reference_) -> mempty @@ -1326,14 +1326,14 @@ suffixCounterTerm n usedTm usedTy = \case in foldMap (countPatternUsages n usedTm . pat) bs _ -> mempty -suffixCounterType :: (Var v) => PrettyPrintEnv -> Set Name -> Type v a -> PrintAnnotation +suffixCounterType :: (HasCallStack, Var v) => PrettyPrintEnv -> Set Name -> Type v a -> PrintAnnotation suffixCounterType n used = \case Type.Var' v -> countHQ used $ HQ.unsafeFromVar v Type.Ref' r | noImportRefs r || r == Type.listRef -> mempty Type.Ref' r -> countHQ used $ PrettyPrintEnv.typeName n r _ -> mempty -printAnnotate :: (Var v, Ord v) => PrettyPrintEnv -> Term2 v at ap v a -> Term3 v PrintAnnotation +printAnnotate :: (HasCallStack, Var v, Ord v) => PrettyPrintEnv -> Term2 v at ap v a -> Term3 v PrintAnnotation printAnnotate n tm = fmap snd (go (reannotateUp (suffixCounterTerm n usedTermNames usedTypeNames) tm)) where @@ -1350,7 +1350,7 @@ printAnnotate n tm = countTypeUsages :: (Var v, Ord v) => PrettyPrintEnv -> Set Name -> Type v a -> PrintAnnotation countTypeUsages n usedTy t = snd $ annotation $ reannotateUp (suffixCounterType n usedTy) t -countPatternUsages :: PrettyPrintEnv -> Set Name -> Pattern loc -> PrintAnnotation +countPatternUsages :: (HasCallStack) => PrettyPrintEnv -> Set Name -> Pattern loc -> PrintAnnotation countPatternUsages n usedTm = Pattern.foldMap' f where f = \case @@ -1372,22 +1372,23 @@ countPatternUsages n usedTm = Pattern.foldMap' f then mempty else countHQ usedTm $ PrettyPrintEnv.patternName n r -countHQ :: Set Name -> HQ.HashQualified Name -> PrintAnnotation +countHQ :: (HasCallStack) => Set Name -> HQ.HashQualified Name -> PrintAnnotation countHQ used (HQ.NameOnly n) -- Names that are marked 'used' aren't considered for `use` clause insertion -- So if a variable 'foo' is used, then we won't insert a `use` clause for -- the reference `Qux.quaffle.foo`. | Just n' <- Set.lookupLE n used, Name.endsWith n n' = mempty -countHQ _ hq = foldMap countName (HQ.toName hq) - -countName :: Name -> PrintAnnotation -countName n = - PrintAnnotation - { usages = - Map.fromList do - (p, s) <- Name.splits n - pure (Name.toText s, Map.singleton (map NameSegment.toEscapedText p) 1) - } +countHQ _ hq = + HQ.toName hq & foldMap \n -> + if Name.isRelative n + then + PrintAnnotation + { usages = + Map.fromList do + (p, s) <- Name.splits n + pure (Name.toText s, Map.singleton (map NameSegment.toEscapedText p) 1) + } + else mempty joinName :: Prefix -> Suffix -> Name joinName p s = Name.unsafeParseText $ dotConcat $ p ++ [s] diff --git a/unison-core/src/Unison/Name.hs b/unison-core/src/Unison/Name.hs index 2b8cb8f83d..ee4c63cfcf 100644 --- a/unison-core/src/Unison/Name.hs +++ b/unison-core/src/Unison/Name.hs @@ -453,11 +453,14 @@ sortNames toText = -- /Precondition/: the name is relative. splits :: (HasCallStack) => Name -> [([NameSegment], Name)] splits (Name p ss0) = - ss0 - & List.NonEmpty.toList - & reverse - & splits0 - & over (mapped . _2) (Name p . List.NonEmpty.reverse) + case p of + Absolute -> error (reportBug "E243149" ("Name.splits called with an absolute name: " ++ show ss0)) + Relative -> + ss0 + & List.NonEmpty.toList + & reverse + & splits0 + & over (mapped . _2) (Name p . List.NonEmpty.reverse) where -- splits a.b.c -- ([], a.b.c) : over (mapped . _1) (a.) (splits b.c) From 82038406f56c95a65d0cab7d04cfdbcc13907375 Mon Sep 17 00:00:00 2001 From: Chris Penner Date: Mon, 13 Jan 2025 11:13:05 -0800 Subject: [PATCH 3/3] Ensure units are all created with matching tags --- unison-runtime/src/Unison/Runtime/Builtin.hs | 3 +- .../src/Unison/Runtime/Foreign/Function.hs | 9 ++--- .../src/Unison/Runtime/Interface.hs | 34 ++++++++++--------- unison-runtime/src/Unison/Runtime/Machine.hs | 4 +-- unison-runtime/src/Unison/Runtime/TypeTags.hs | 13 +++++++ 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/unison-runtime/src/Unison/Runtime/Builtin.hs b/unison-runtime/src/Unison/Runtime/Builtin.hs index 6752dcbd34..d378b722a9 100644 --- a/unison-runtime/src/Unison/Runtime/Builtin.hs +++ b/unison-runtime/src/Unison/Runtime/Builtin.hs @@ -38,6 +38,7 @@ import Unison.Runtime.Builtin.Types import Unison.Runtime.Foreign.Function.Type (ForeignFunc (..), foreignFuncBuiltinName) import Unison.Runtime.Stack (UnboxedTypeTag (..), Val (..), unboxedTypeTagToInt) import Unison.Runtime.Stack qualified as Closure +import Unison.Runtime.TypeTags qualified as TT import Unison.Symbol import Unison.Type qualified as Ty import Unison.Util.EnumContainers as EC @@ -1709,7 +1710,7 @@ declareForeign sand op func = do in (Map.insert func (sand, code) funcs) unitValue :: Val -unitValue = BoxedVal $ Closure.Enum Ty.unitRef (PackedTag 0) +unitValue = BoxedVal $ Closure.Enum Ty.unitRef TT.unitTag natValue :: Word64 -> Val natValue w = NatVal w diff --git a/unison-runtime/src/Unison/Runtime/Foreign/Function.hs b/unison-runtime/src/Unison/Runtime/Foreign/Function.hs index f4404ccfb7..80d59994b2 100644 --- a/unison-runtime/src/Unison/Runtime/Foreign/Function.hs +++ b/unison-runtime/src/Unison/Runtime/Foreign/Function.hs @@ -137,7 +137,7 @@ import Unison.Builtin.Decls qualified as Ty import Unison.Prelude hiding (Text, some) import Unison.Reference import Unison.Referent (Referent, pattern Ref) -import Unison.Runtime.ANF (Code, PackedTag (..), Value, internalBug) +import Unison.Runtime.ANF (Code, Value, internalBug) import Unison.Runtime.ANF qualified as ANF import Unison.Runtime.ANF.Rehash (checkGroupHashes) import Unison.Runtime.ANF.Serialize qualified as ANF @@ -150,6 +150,7 @@ import Unison.Runtime.Foreign qualified as F import Unison.Runtime.Foreign.Function.Type (ForeignFunc (..)) import Unison.Runtime.MCode import Unison.Runtime.Stack +import Unison.Runtime.TypeTags qualified as TT import Unison.Symbol import Unison.Type ( iarrayRef, @@ -1764,10 +1765,10 @@ toUnisonPair :: toUnisonPair (x, y) = DataC Ty.pairRef - (PackedTag 0) - [BoxedVal $ wr x, BoxedVal $ DataC Ty.pairRef (PackedTag 0) [BoxedVal $ wr y, BoxedVal $ un]] + TT.pairTag + [BoxedVal $ wr x, BoxedVal $ DataC Ty.pairRef TT.pairTag [BoxedVal $ wr y, BoxedVal $ un]] where - un = DataC Ty.unitRef (PackedTag 0) [] + un = DataC Ty.unitRef TT.unitTag [] wr z = Foreign $ wrapBuiltin z unwrapForeignClosure :: Closure -> a diff --git a/unison-runtime/src/Unison/Runtime/Interface.hs b/unison-runtime/src/Unison/Runtime/Interface.hs index dfa54e01e4..caa054e1ff 100644 --- a/unison-runtime/src/Unison/Runtime/Interface.hs +++ b/unison-runtime/src/Unison/Runtime/Interface.hs @@ -143,6 +143,7 @@ import Unison.Runtime.Machine import Unison.Runtime.Pattern import Unison.Runtime.Serialize as SER import Unison.Runtime.Stack +import Unison.Runtime.TypeTags qualified as TT import Unison.Symbol (Symbol) import Unison.Syntax.HashQualified qualified as HQ (toText) import Unison.Syntax.NamePrinter (prettyHashQualified) @@ -1063,7 +1064,7 @@ executeMainComb :: CCache -> IO (Either (Pretty ColorText) ()) executeMainComb init cc = do - rSection <- resolveSection cc $ Ins (Pack RF.unitRef (PackedTag 0) ZArgs) $ Call True init init (VArg1 0) + rSection <- resolveSection cc $ Ins (Pack RF.unitRef TT.unitTag ZArgs) $ Call True init init (VArg1 0) result <- UnliftIO.try . eval0 cc Nothing $ rSection case result of @@ -1440,18 +1441,19 @@ buildSCache crsrc cssrc cacheableCombs trsrc ftm fty int rtmsrc rtysrc sndbx = restrictTyR m = Map.restrictKeys m typeRefs standalone :: CCache -> Word64 -> IO StoredCache -standalone cc init = readTVarIO (combRefs cc) >>= \crs -> - case EC.lookup init crs of - Just rinit -> - buildSCache crs - <$> readTVarIO (srcCombs cc) - <*> readTVarIO (cacheableCombs cc) - <*> readTVarIO (tagRefs cc) - <*> readTVarIO (freshTm cc) - <*> readTVarIO (freshTy cc) - <*> (readTVarIO (intermed cc) >>= traceNeeded rinit) - <*> readTVarIO (refTm cc) - <*> readTVarIO (refTy cc) - <*> readTVarIO (sandbox cc) - Nothing -> - die $ "standalone: unknown combinator: " ++ show init +standalone cc init = + readTVarIO (combRefs cc) >>= \crs -> + case EC.lookup init crs of + Just rinit -> + buildSCache crs + <$> readTVarIO (srcCombs cc) + <*> readTVarIO (cacheableCombs cc) + <*> readTVarIO (tagRefs cc) + <*> readTVarIO (freshTm cc) + <*> readTVarIO (freshTy cc) + <*> (readTVarIO (intermed cc) >>= traceNeeded rinit) + <*> readTVarIO (refTm cc) + <*> readTVarIO (refTy cc) + <*> readTVarIO (sandbox cc) + Nothing -> + die $ "standalone: unknown combinator: " ++ show init diff --git a/unison-runtime/src/Unison/Runtime/Machine.hs b/unison-runtime/src/Unison/Runtime/Machine.hs index bfc7ab0c00..f45e793378 100644 --- a/unison-runtime/src/Unison/Runtime/Machine.hs +++ b/unison-runtime/src/Unison/Runtime/Machine.hs @@ -285,7 +285,7 @@ unitValue = BoxedVal $ unitClosure {-# NOINLINE unitValue #-} unitClosure :: Closure -unitClosure = Enum Ty.unitRef (PackedTag 0) +unitClosure = Enum Ty.unitRef TT.unitTag {-# NOINLINE unitClosure #-} litToVal :: MLit -> Val @@ -691,7 +691,7 @@ eval env !denv !activeThreads !stk !k r (NMatch _mr i br) = do eval env denv activeThreads stk k r $ selectBranch n br eval env !denv !activeThreads !stk !k r (RMatch i pu br) = do (t, stk) <- dumpDataNoTag Nothing stk =<< peekOff stk i - if t == PackedTag 0 + if t == TT.pureEffectTag then eval env denv activeThreads stk k r pu else case ANF.unpackTags t of (ANF.rawTag -> e, ANF.rawTag -> t) diff --git a/unison-runtime/src/Unison/Runtime/TypeTags.hs b/unison-runtime/src/Unison/Runtime/TypeTags.hs index e489138414..0cd6ab11b0 100644 --- a/unison-runtime/src/Unison/Runtime/TypeTags.hs +++ b/unison-runtime/src/Unison/Runtime/TypeTags.hs @@ -15,6 +15,8 @@ module Unison.Runtime.TypeTags rightTag, falseTag, trueTag, + pairTag, + pureEffectTag, ) where @@ -143,6 +145,17 @@ leftTag, rightTag :: PackedTag (packTags et lt, packTags et rt) | otherwise = error "internal error: either tags" +pairTag :: PackedTag +pairTag + | Just n <- Map.lookup Ty.pairRef builtinTypeNumbering, + pt <- toEnum (fromIntegral n) = + packTags pt 0 + | otherwise = internalBug "internal error: pairTag" + +-- | A tag we use to represent the 'pure' effect case. +pureEffectTag :: PackedTag +pureEffectTag = PackedTag 0 + -- | Construct a tag for a single-constructor builtin type mkSimpleTag :: String -> Reference -> PackedTag mkSimpleTag msg r = mkEnumTag msg r 0