IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.57k stars 479 forks source link

`resizeByteString` broken #851

Closed j-mueller closed 5 years ago

j-mueller commented 5 years ago

Compiling this program:

{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Test where

import Language.PlutusTx.Plugin
import qualified Language.PlutusTx            as P

f :: CompiledCode (P.SizedByteString 0 -> P.SizedByteString 1)
f = $$(P.compile [|| $$(P.resizeByteString) ||])

results in

[6 of 6] Compiling Test             ( Test.hs, interpreted )
GHC Core to PLC plugin: Error: Error from the PLC compiler:
       Type mismatch at () in term
         '(builtin resizeByteString)'.
       Expected type
         '(all s0_80 (size) (all s1_81 (size) (fun [(con size) s1_81] (fun [(con bytestring) s0_80] [(con bytestring) s1_81]))))',
       found type
         '(all s1_76 (size) (all s2_77 (size) (fun [(con bytestring) s1_76] [(con bytestring) s2_77])))'
Context: Converting expr at "plutus-tx-0.1.0.0-inplace:Test:(11,8)-(11,48)"

To reproduce, checkout the resize-bytestring branch, then

nix-shell
cabal new-repl plutus-tx:plutus-tx
:l Test.hs
michaelpj commented 5 years ago

Ugh, I forgot that the resize functions need to pass term-level size values...

michaelpj commented 5 years ago

Argh, this is actually somewhat difficult.

michaelpj commented 5 years ago

So, term-level sizes are a pain because they're multi-part constants including a constant natural size that we can't supply separately. This makes them a complete pain.

So here's my horrible idea:

michaelpj commented 5 years ago

Producing integer literals at a particular size is essentially just as hard, oy vey.

j-mueller commented 5 years ago

Closing this as we don't have sizes in Plutus Core anymore.