From f867b78de193b1644ca46e33eea845b4aeb9ecf7 Mon Sep 17 00:00:00 2001 From: effectfully Date: Wed, 25 Sep 2024 03:43:10 +0200 Subject: [PATCH 1/2] [Test] [Bug] Trigger the overpruned dependency bug --- .../Data/9.6/families/stakingCredential.pir.golden | 0 plutus-tx-plugin/test/Plugin/Data/Spec.hs | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden diff --git a/plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden b/plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden new file mode 100644 index 00000000000..e69de29bb2d diff --git a/plutus-tx-plugin/test/Plugin/Data/Spec.hs b/plutus-tx-plugin/test/Plugin/Data/Spec.hs index 38af5ac7eb2..a473ce980b2 100644 --- a/plutus-tx-plugin/test/Plugin/Data/Spec.hs +++ b/plutus-tx-plugin/test/Plugin/Data/Spec.hs @@ -354,6 +354,7 @@ typeFamilies = testNested "families" [ , goldenPir "associated" associated , goldenPir "associatedParam" associatedParam , goldenPir "basicData" basicData + , goldenPir "stakingCredential" stakingCredential , goldenUPlc "irreducible" irreducible ] @@ -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 From 229b6903412086ed05b468a65e751fb59dd2fb08 Mon Sep 17 00:00:00 2001 From: effectfully Date: Tue, 1 Oct 2024 00:53:15 +0200 Subject: [PATCH 2/2] Try not pruning data types --- .../src/PlutusIR/Analysis/Dependencies.hs | 21 ++++--------------- .../9.6/families/stakingCredential.pir.golden | 10 +++++++++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/plutus-core/plutus-ir/src/PlutusIR/Analysis/Dependencies.hs b/plutus-core/plutus-ir/src/PlutusIR/Analysis/Dependencies.hs index 1dd33024c7f..4c37e202df5 100644 --- a/plutus-core/plutus-ir/src/PlutusIR/Analysis/Dependencies.hs +++ b/plutus-core/plutus-ir/src/PlutusIR/Analysis/Dependencies.hs @@ -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 + 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 diff --git a/plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden b/plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden index e69de29bb2d..07174201a4b 100644 --- a/plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden +++ b/plutus-tx-plugin/test/Plugin/Data/9.6/families/stakingCredential.pir.golden @@ -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) \ No newline at end of file