Skip to content
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

[Test] [Bug] Trigger the overpruned dependency bug #6517

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 67298332
| mem: 216002})
({cpu: 70146332
| mem: 233802})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 34304100
| mem: 214500})
({cpu: 37152100
| mem: 232300})
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,17 @@
UpperBound : Extended a -> Bool -> UpperBound a
data (Interval :: * -> *) a | Interval_match where
Interval : LowerBound a -> UpperBound a -> Interval a
Vote = all a. a -> a
ScriptPurpose = all a. a -> a
data ScriptPurpose | ScriptPurpose_match where
Certifying : integer -> TxCert -> ScriptPurpose
Minting : bytestring -> ScriptPurpose
Proposing : integer -> ProposalProcedure -> ScriptPurpose
Rewarding : Credential -> ScriptPurpose
Spending : TxOutRef -> ScriptPurpose
Voting : Voter -> ScriptPurpose
data Vote | Vote_match where
Abstain : Vote
VoteNo : Vote
VoteYes : Vote
data TxInfo | TxInfo_match where
TxInfo :
List TxInInfo ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,17 @@
UpperBound : Extended a -> Bool -> UpperBound a
data (Interval :: * -> *) a | Interval_match where
Interval : LowerBound a -> UpperBound a -> Interval a
Vote = all a. a -> a
ScriptPurpose = all a. a -> a
data ScriptPurpose | ScriptPurpose_match where
Certifying : integer -> TxCert -> ScriptPurpose
Minting : bytestring -> ScriptPurpose
Proposing : integer -> ProposalProcedure -> ScriptPurpose
Rewarding : Credential -> ScriptPurpose
Spending : TxOutRef -> ScriptPurpose
Voting : Voter -> ScriptPurpose
data Vote | Vote_match where
Abstain : Vote
VoteNo : Vote
VoteYes : Vote
data TxInfo | TxInfo_match where
TxInfo :
List TxInInfo ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 51650332
| mem: 118202})
({cpu: 54498332
| mem: 136002})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 18656100
| mem: 116700})
({cpu: 21504100
| mem: 134500})
21 changes: 4 additions & 17 deletions plutus-core/plutus-ir/src/PlutusIR/Analysis/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,10 @@ bindingDeps b = case b of
vDeps <- tyVarDeclDeps d
tvDeps <- traverse tyVarDeclDeps tvs
cstrDeps <- traverse varDeclDeps constrs
-- Destructors depend on the datatype and the argument types of all the constructors,
-- because e.g. a destructor for Maybe looks like:
-- forall a . Maybe a -> (a -> r) -> r -> r
-- i.e. the argument type of the Just constructor appears as the argument to the branch.
--
-- We can get the effect of that by having it depend on all the constructor types
-- (which also include the datatype).
-- This is more diligent than currently necessary since we're going to make all the
-- term-level parts depend on each other later, but it's good practice and will be
-- useful if we ever stop doing that.
destrDeps <-
G.overlays
<$> (withCurrent destr $ traverse (typeDeps . _varDeclType) constrs)
let tus = fmap (view PLC.theUnique) (destr : fmap _varDeclName constrs)
-- See Note [Dependencies for datatype bindings, and pruning them]
let nonDatatypeClique = G.clique (fmap Variable tus)
pure $ G.overlays $ [vDeps] ++ tvDeps ++ cstrDeps ++ [destrDeps] ++ [nonDatatypeClique]
let tyus = fmap (view PLC.theUnique) $ _tyVarDeclName d : fmap _tyVarDeclName tvs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what this does; worth some comment. There should also be some explanation or reference to the bug here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea either, that's Michael code and as you can see above Michael isn't particularly keen on dealing with it :)

let tus = fmap (view PLC.theUnique) $ destr : fmap _varDeclName constrs
let localDeps = G.clique (fmap Variable $ tyus ++ tus)
pure $ G.overlays $ [vDeps] ++ tvDeps ++ cstrDeps ++ [localDeps]

varDeclDeps ::
( DepGraph g
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
(nonrec)
(datatypebind
(datatype
$0$
$1$
(tyvardecl $4$ Maybe (fun (type) (type)))
(tyvardecl $2$ a (type))
match_Maybe
(vardecl $16$ Nothing [ Maybe a ]) (vardecl $6$ Just (fun a [ Maybe a ]))
(vardecl $17$ Nothing [ Maybe a ]) (vardecl $6$ Just (fun a [ Maybe a ]))
)
)
Nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
(nonrec)
(datatypebind
(datatype
$0$
(tyvardecl $4$ Maybe (fun (type) (type)))
(tyvardecl $0$ a (type))
$1$
(tyvardecl $17$ Maybe (fun (type) (type)))
(tyvardecl $2$ a (type))
match_Maybe
(vardecl $0$ Nothing [ Maybe a ]) (vardecl $0$ Just (fun a [ Maybe a ]))
(vardecl $4$ Nothing [ Maybe a ]) (vardecl $6$ Just (fun a [ Maybe a ]))
)
)
(error Maybe)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(let
(nonrec)
(typebind (tyvardecl $0$ unit (type)) (all a (type) (fun a a)))
(typebind (tyvardecl $7$ unit (type)) (all a (type) (fun a a)))
(let
(nonrec)
(datatypebind
(datatype
$0$
(tyvardecl $2$ SomeType (type))
$1$
(tyvardecl $14$ SomeType (type))

match_SomeType
(vardecl $0$ Constr (fun unit SomeType))
(vardecl $11$ Constr (fun unit SomeType))
)
)
(lam arg SomeType arg)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
let
Maybe :: * -> * = \a -> all a. a -> a
data (Maybe :: * -> *) a | match_Maybe where
Nothing : Maybe a
Just : a -> Maybe a
in
error {Maybe integer}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let
unit = all a. a -> a
in
let
SomeType = all a. a -> a
data SomeType | match_SomeType where
Constr : unit -> SomeType
in
\(arg : SomeType) -> error {unit}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
({cpu: 3040100 | mem: 19100})
({cpu: 4096100 | mem: 25700})
({cpu: 3232100 | mem: 20300})
({cpu: 4192100 | mem: 26300})
({cpu: 5673685 | mem: 34902})
({cpu: 6794067 | mem: 41104})
({cpu: 8083652 | mem: 48506})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
program
1.1.0
(let
data Credential | Credential_match where
PubKeyCredential : Credential
data StakingCredential | StakingCredential_match where
StakingHash : Credential -> StakingCredential
StakingPtr : StakingCredential
in
StakingPtr)
11 changes: 11 additions & 0 deletions plutus-tx-plugin/test/Plugin/Data/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ typeFamilies = testNested "families" [
, goldenPirReadable "associated" associated
, goldenPirReadable "associatedParam" associatedParam
, goldenPirReadable "basicData" basicData
, goldenPirReadable "stakingCredential" stakingCredential
, goldenUPlc "irreducible" irreducible
]

Expand Down Expand Up @@ -405,3 +406,13 @@ data instance BasicData Bool = Inst Integer

basicData :: CompiledCode (BasicData Bool -> Integer)
basicData = plc (Proxy @"basicData") (\(x :: BasicData Bool) -> let Inst i = x in i)

data Credential
= PubKeyCredential
data StakingCredential
= StakingHash Credential
| StakingPtr

-- | Check that a data type used in an unused construtor of a used data type doesn't get eliminated.
stakingCredential :: CompiledCode StakingCredential
stakingCredential = plc (Proxy @"StakingCredential") StakingPtr
Loading