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

Generate arbitrary constant for SomeConstant #4573

Closed
wants to merge 1 commit into from

Conversation

zliu41
Copy link
Member

@zliu41 zliu41 commented May 2, 2022

Previously only integer constants were generated.

Previously only integer constants were generated.
@zliu41 zliu41 requested review from michaelpj and effectfully May 2, 2022 16:02
Copy link
Contributor

@effectfully effectfully left a comment

Choose a reason for hiding this comment

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

But this is the exact opposite of what you convinced me would be the right thing to do? Why generate constants specifically when you can generate arbitrary terms and that would generate constants too? We'll need to amend the AST generators to generate constants of polymorphic built-in types though, but you could just copy your constant generation code there.

So with my version we had two functions:

genConstant :: forall a. TypeRep a -> Gen a

genArg
    :: term ~ Term TyName Name DefaultUni DefaultFun ()
    => MakeKnownIn DefaultUni term a => TypeRep a -> Gen term

The former is strictly for well-typed things and the latter is for any term (deferring to the former when we need to generate a constant). Crucially, when we have SomeConstant, we need to occasionally generate arbitrary terms, which doesn't fit into the TypeRep a -> Gen a interface, but fits perfectly well into the TypeRep a -> Gen term one.

And Opaque should be handled the same way as SomeConstant.

With the version from this PR genTypeable is not always for well-typed things (i.e. it's going to be hard to control the proportion of the happy path vs unhappy path tests) and we never generate arbitrary terms for SomeConstant arguments.

@zliu41
Copy link
Member Author

zliu41 commented May 2, 2022

@effectfully This is for the evaluation success case, i.e., the first bullet point in this comment. Generating arbitrary terms is for the evaluation failure case.

The reason I added a new genConstant instead of modifying PlutusCore.Generators.AST.genConstant is that doing so leads to some parser round-trip test failures. I should note this in a TODO.

@zliu41
Copy link
Member Author

zliu41 commented May 2, 2022

Oh, I think I see where the problem is .. previously it always instantiates TyVarRep to Integer, which was fine. But now it generates Integer for SomeConstant which is no good. So we are not testing the success case after all. Same with generating arbitrary constants for SomeConstant.

In other words, in the SomeConstant case we'd need to descend into the rep, similar as what the initial version of the previous PR did.

@zliu41 zliu41 marked this pull request as draft May 2, 2022 19:26
@zliu41 zliu41 closed this May 9, 2022
@zliu41 zliu41 deleted the arbitrary/constant branch October 5, 2022 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants