-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value representation rework #734
Conversation
2e2539a
to
84bbaa6
Compare
84bbaa6
to
7d6557e
Compare
What's your idea? |
Have So let's say data MyPMaybe s a
= MyJust (Term s a)
| MyNothing
deriving stock (GHC.Generic)
instance SOP.Generic (MyPMaybe s a)
type S' = forall s. s
type MyPMaybeRepr a = UnTermStruct (MyPMaybe S' a)
test :: PStruct (MyPMaybeRepr PInteger) s
test = PStruct $ hcoerce $ from $ MyJust (10 :: Term s PInteger)
testData :: Term s (PDataStruct (MyPMaybeRepr PInteger))
testData = pconDataStruct test
testScott :: Term s (PScottStruct (MyPMaybeRepr PInteger))
testScott = pconScottStruct test
handler :: MyPMaybe s PInteger -> Term s PInteger
handler (MyJust x) = 1 + x
handler MyNothing = 0
matchTestData :: Term s PInteger
matchTestData = pmatchDataStruct @(MyPMaybeRepr PInteger) testData (handler . to . hcoerce . unPStruct)
matchTestScott :: Term s PInteger
matchTestScott = pmatchScottStruct @(MyPMaybeRepr PInteger) testScott (handler . to . hcoerce . unPStruct)
|
Having to deal with
is kind of annoying : / Any suggestions are welcome |
Plutarch/Internal.hs
Outdated
hashRawTerm' (RPlaceHolder hash) = addHashIndex 9 . flip hashUpdate hash | ||
hashRawTerm' (RCompiled code) = addHashIndex 10 . flip hashUpdate (hashUTerm @alg code hashInit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we kept existing hashing choices the same. It probably doesn't matter, but I'd rather the hash index of RCompiled
stayed as 9
.
class PDataRepresentable (a :: S -> Type) | ||
instance PDataRepresentable (PDataStruct struct) | ||
instance PDataRepresentable PInteger | ||
instance PDataRepresentable PByteString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this type class actually mean?
Why does I also think you can do this without having it in the types at all. |
Also, I'm somewhat sure this can be done without embedding these into types, but I don't want to use Haskell's generics, they are pain to deal with. Also don't want TH for similar reasons |
You can change the AST a bit such that operations over data types are more abstract. Everything could be SOP-like in the AST. When you lower it to UPLC you could choose at each site what is most convenient, and according to user preference. There are multiple strategies here, some optimize size, some performance, and some of the problems are in NP. |
(hash :: Dig) <- hashOpenTerm t | ||
pure (hash, Term $ const $ pure $ TermResult (RPlaceHolder hash) []) | ||
|
||
pletSmart :: Term s a -> (Term s a -> Term s b) -> Term s b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this account for stuff like
let x = ... in map (\_ -> x) list
Note that UPLC is strict.
EDIT: Consider the above as pseudo-UPLC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it won't be able to figure out if bound term will be used multiple times or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution is to cover a small set of cases that are useful and happen in practice and are easy enough to detect.
You can replace it with checking whether the bound variable ever appears under a delay
or lam
. If it does not, that should mean it's always only evaluated exactly once, hence you can inline it without changing almost anything.
Three properties to uphold:
- Algorithmic complexities must not change
- What errs without optimizations must not err with optimizations.
- What succeeds without optimizations must succeed with optimizations.
The bottom two are a very unfortunate side effect of UPLC's design. I made a CIP cardano-foundation/CIPs#469 to fix this, but it wasn't very popular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The topmost one wouldn't be affected by doing laziness like Haskell though, since sharing doesn't happen under lambdas. It does though on HVM and stuff like that AFAIU.
2b54a3a
to
71d0dae
Compare
71d0dae
to
98ca227
Compare
Waiting on module restructuring |
superceeded by #767 |
nothing much yet
closes #630 and probably bunch more