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

Conversation

effectfully
Copy link
Contributor

@effectfully effectfully commented Sep 25, 2024

The added test fails with

test
  Plugin
    Data
      9.6
        families
          stakingCredential: FAIL
            Exception: Error: Error from the PIR compiler:
                   Error from the PLC compiler:
                   Free type variable at  Ann {annInline = MayInline, annSrcSpans = { no-src-span }} :  Credential

The bug is in the dead code eliminator. To be precise, it's this part that it doesn't handle correctly despite promising to in PlutusIR.Analysis.Dependencies:

{- Note [Dependencies for datatype bindings, and pruning them]
At face value, all the names introduced by datatype bindings should depend on each other.
Given our meaning of "A depends on B", since we cannot remove any part of the datatype
binding without removing the whole thing, they all depend on each other

However, there are some circumstances in which we *can* prune datatype bindings.

In particular, if the datatype is only used at the type-level (i.e. all the term-level parts
(constructors and destructor) are dead), then we are free to completely replace the binding
with one for a trivial type with the same kind.

This is because there are *no* term-level effects, and types are erased in the end, so
in this case rest of the datatype binding really is superfluous.

But how do we represent this in the dependency graph? We still need to have proper dependencies
so that we don't make the wrong decisions wrt transitively used values, e.g.

let U :: * = ...
let datatype T = T1 | T2 U
in T1

Here we need to not delete U, even though T2 is "dead"!

The solution is to focus on the meaning of "dependency": with the pruning that we can do, we *can*
remove all the term level bits en masse, but only en-mass. So we need to make *them* into a clique,
so that this is visible to the dependency analysis.
-}

I don't know what went wrong there.

@effectfully
Copy link
Contributor Author

@michaelpj any idea?

@michaelpj
Copy link
Contributor

What happens if you get rid of the bit where it tries to prune dead constructors?

@effectfully
Copy link
Contributor Author

What happens if you get rid of the bit where it tries to prune dead constructors?

The test becomes green, see 229b690.

@michaelpj
Copy link
Contributor

Since you have a small test case I would dump the output from just after the bad dead code pass and see what's wrong. It looks like a simple case we should handle properly...

@michaelpj
Copy link
Contributor

From the error it seems like we get rid of Credential entirely, which seems odd.

@effectfully
Copy link
Contributor Author

Since you have a small test case I would dump the output from just after the bad dead code pass and see what's wrong. It looks like a simple case we should handle properly...

Yes, I've done exactly that when investigating and you're right that this is what's happening:

From the error it seems like we get rid of Credential entirely, which seems odd.

@michaelpj
Copy link
Contributor

I don't see why from just looking at it, some debugging is going to be required I think!

@effectfully
Copy link
Contributor Author

I don't see why from just looking at it, some debugging is going to be required I think!

Wanna do some debugging on a weekend? 🙂

…to effectfully/test/bug/overpruned-dependency
Comment on lines 0 to 2
({cpu: 34304100
| mem: 214500}) No newline at end of file
({cpu: 37152100
| mem: 232300})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zliu41 is this large enough difference to keep the bug in the dead code eliminator that causes necessary constructors to get eliminated?

Copy link
Member

Choose a reason for hiding this comment

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

10% is bad but only a small number of golden files are affected - I'm fine either way. What's your preference?

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 guess let's keep the bug in then, I think it's quite low priority compared to other things and I don't feel like studying the DCE algo at the moment (or ever haha). I'll reflect this problem in an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

-- 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 :)

Comment on lines 0 to 2
({cpu: 34304100
| mem: 214500}) No newline at end of file
({cpu: 37152100
| mem: 232300})
Copy link
Member

Choose a reason for hiding this comment

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

10% is bad but only a small number of golden files are affected - I'm fine either way. What's your preference?

@effectfully
Copy link
Contributor Author

I've added an entry to #5967, so that we don't forget about this bug, and let's close this PR for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants