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

[Builtins] Add detection of stuck 'ToHoles' #4345

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

effectfully
Copy link
Contributor

This adds another custom type error, the final one that I had in mind.

I've also polished the PlutusCore.Constant.Debug module a bit.

Comment on lines -57 to -61
inferDebug
:: forall a binds args res j.
( args ~ GetArgs a, a ~ FoldArgs args res, binds ~ Merge (ListToBinds args) (ToBinds res)
, KnownPolytype binds TermDebug args res a, SpecializeFromTo 0 j TermDebug a
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the last major refactoring of the builtins API elaboration needs KnownTypeAst instances and so there isn't much sense in having two debug functions anymore, hence I only left one. A single function makes for a better UX anyway.

@@ -306,8 +343,8 @@ type SpecializeFromTo i j term a = HandleHole i j term (TypeHole a)
-- 2. an uninstantiated costing function
makeBuiltinMeaning
:: forall a term cost binds args res j.
( args ~ GetArgs a, a ~ FoldArgs args res, binds ~ Merge (ListToBinds args) (ToBinds res)
, KnownPolytype binds term args res a, SpecializeFromTo 0 j term a
( binds ~ ToBinds a, args ~ GetArgs a, a ~ FoldArgs args res
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 realized I can now call ToBinds directly over a, no need to deconstruct a to get its bound variables.

@effectfully effectfully force-pushed the effectfully/builtins/detecting-stuck-ToHoles branch from 3868c17 to a7f4daa Compare January 23, 2022 04:23
type family ThrowOnStuckList err xs where
ThrowOnStuckList _ '[] = '[]
ThrowOnStuckList _ (x ': xs) = x ': xs
ThrowOnStuckList err _ = err
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kind of horrified that this works 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you read the linked blog post? The err does not actually get returned. ThrowOnStuckList is as stuck as the stuck list that it's applied to. And that stuckiness causes err to appear in the application and be triggered eventually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I understand that, it's just kind of bizarre.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not as bizarre as the fact that ThrowOnStuckList can actually return the first argument if the second one is neither stuck nor a constructor of [], but that's Haskell's type-level Python.

@effectfully effectfully merged commit 7a3e0a2 into master Jan 28, 2022
@effectfully effectfully deleted the effectfully/builtins/detecting-stuck-ToHoles branch January 28, 2022 16:54
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.

2 participants