Experiments, investigations and curiosities #7294
Replies: 5 comments
-
#7278 was an attempt to ditch relying on laziness for building partial builtin applications in the CEK machine and instead just keeping the arguments directly as values without discharging them. The gist of the change: +data PartialBuiltinApp uni fun
+ = PartialBuiltinHead fun
+ | PartialBuiltinTyInst (PartialBuiltinApp uni fun) (Type TyName uni ())
+ | PartialBuiltinApply (PartialBuiltinApp uni fun) (CkValue uni fun)
enterComputeCek = computeCek where
applyEvaluate !ctx (VBuiltin fun app runtime) arg = do
- let argTerm = dischargeResultToTerm $ dischargeCekValue arg
- app' = Apply () app argTerm
+ let app' = PartialBuiltinApply app arg
case runtime of
BuiltinExpectArgument f ->
evalBuiltinApp ctx fun app' $ f arg But apparently constructing that |
Beta Was this translation helpful? Give feedback.
-
#7210 made UPLC case-of-case less restrictive by allowing it to produce duplicate branches if they're small enough. Quoting
So in UPLC we disallowed
entirely because of the double occurrence of The gist of the PR for reference: +-- >>> annotateIsDuplicatedOn id "abacdeffdbdg"
+-- [('a',True),('b',True),('a',True),('c',False),('d',True),('e',False),('f',True),('f',True),('d',True),('b',True),('d',True),('g',False)]
+annotateIsDuplicatedOn :: (Functor f, Foldable f, Hashable b) => (a -> b) -> f a -> f (a, Bool)
+annotateIsDuplicatedOn = <...>
processTerm = \case
original@(Case annOuter (Case annInner scrut altsInner) altsOuter) ->
maybe
original
(Case annInner scrut)
(do
- constrs <- for altsInner $ \case
+ constrsDupl <- fmap (annotateIsDuplicatedOn fst) . for altsInner $ \case
c@(Constr _ i _) -> Just (Left i, c)
c@(Constant _ val) -> Just (Right val, c)
_ -> Nothing
- guard $ length (nub . toList $ fmap fst constrs) == length constrs
- pure $ constrs <&> \(_, c) -> CaseReduce.processTerm $ Case annOuter c altsOuter)
+ for constrsDupl $ \((_, c), dupl) -> do
+ let alt = CaseReduce.processTerm $ Case annOuter c altsOuter
+ guard $ not dupl || termSize alt <= 300 -- Not duplicated or size is under a certain threshold.
+ pure alt) |
Beta Was this translation helpful? Give feedback.
-
#6793 was an attempt to add
The implementation was made as fast as possible with some really complicated tie-the-know implementation:
The conclusion was:
|
Beta Was this translation helpful? Give feedback.
-
#6706 was an experiment replacing The conclusion:
We do need to come back to this at some point, if only to explain this weirdness. |
Beta Was this translation helpful? Give feedback.
-
#4462, #4463 and #6352 were all attempts to speed up DefaultUniApply co6_i8od6 f4_i8od7 x12_i8od8 ->
case geqRec $WDefaultUniProtoList f4_i8od7 of
Nothing -> builtinRuntimeFailure <...>
Just x9_i8odc ->
let! { Refl co7_i8odf ~ <- x9_i8odc } in
case geqRec $WDefaultUniData x12_i8od8 of
Nothing -> builtinRuntimeFailure <...>
Just x10_i8odj ->
let! { Refl co8_i8odm ~ <- x10_i8odj } in
<...> Inlining those turned out to be a pretty annoying thing to do. #4462 is the most successful attempt and it's fairly simple too, it amounts to changing
to a custom +class GEqL f a where
+ geqL :: f b -> Maybe (a :~: b)
-type KnownBuiltinTypeIn uni val a = (HasConstantIn uni val, GShow uni, GEq uni, uni `Contains` a)
+type KnownBuiltinTypeIn uni val a = (HasConstantIn uni val, GShow uni, GEqL uni (Esc a), uni `Contains` a) (while we're here, we should probably use the strict It created some pretty annoying boilerplate though, e.g. +instance GEqL DefaultUni (Esc Bool) where
+ geqL DefaultUniBool = Just Refl
+ geqL _ = Nothing
+instance (GEqL DefaultUni (Esc a), GEqL DefaultUni (Esc b)) => GEqL DefaultUni (Esc (a, b)) where
+ geqL (DefaultUniPair a b) = do
+ Refl <- geqL @DefaultUni @(Esc a) a
+ Refl <- geqL @DefaultUni @(Esc b) b
+ Just Refl
+ geqL _ = Nothing The boilerplate is tolerable and the speedup is an okayish 1-2% for the validation benchmarks, but all of that will be irrelevant once we split the universe into two as per #4781. I dunno, maybe we should still do the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Dump here everything that fits the description of the discussion.
Beta Was this translation helpful? Give feedback.
All reactions