Skip to content

[Refectoring] Remove Prism from type checking/compiler error handling #7111

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

Merged
merged 1 commit into from
May 30, 2025

Conversation

SeungheonOh
Copy link
Collaborator

@SeungheonOh SeungheonOh commented May 21, 2025

closes #6160

Removed all prisms from type checking and compiler error handling. All functions previously threw unrealized error types were given minimal error type that can cover all kinds of error the function throws. Function calls within a function that throws different error type now requires changing error type using modifyError manually.

hoist-error seems like a viable option at first, but all we need is Control.Monad.Except.modifyError since error-throwing function calls are always made within another MonadError. hoistError is just a more general version of modifyError, and in this case we don't need extra generality!

Changes made in this PR arguably increases verbosity as this requires manually lifting error types of each function calls.

@SeungheonOh
Copy link
Collaborator Author

@effectfully 0 conflicts with #7110 :D

@SeungheonOh SeungheonOh added the No Changelog Required Add this to skip the Changelog Check label May 23, 2025
@SeungheonOh SeungheonOh changed the title [Refectoring] Remove Prism entirely from error handling [Refectoring] Remove Prism from type checking/compiler error handling May 23, 2025
@SeungheonOh SeungheonOh force-pushed the seungeonoh/6160 branch 2 times, most recently from 2819978 to 65675c1 Compare May 23, 2025 09:13
@SeungheonOh SeungheonOh requested review from effectfully and Unisay May 27, 2025 01:33
tryError :: MonadError e m => m a -> m (Either e a)
tryError a = (Right <$> a) `catchError` (pure . Left)
{-# INLINE tryError #-}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This probably should've been a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a minor enough improvement, it's uncontroversial and even if it accidentally gets reverted who cares. I believe it's perfectly OK to lump such minor improvements into larger PRs.

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.

This looks like a step in the right direction. I think in future we should also get rid of MonadError constraints and just use Either/ExceptT directly and provide some automation for converting between different monad/error types, so that we don't keep writing all that modifyError blahblahblahblahblahblah boilerplate.

@@ -236,33 +226,36 @@ uplcOptimise =
UnsafeOptimise -> id
in fmap PLC.runQuoteT
. _Wrapped
-- . modifyError (PIR.PLCError . PLC.FreeVariableErrorE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code.

( MonadError err m -- Kind/type checking can fail
, AsTypeError err term uni fun ann -- with a 'TypeError'.
type MonadKindCheck error term uni fun ann m =
( MonadError error m -- Kind/type checking can fail
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point is there even benefit to keeping MonadError here? Can it be just Either? Can we simply move this functionality into TypeCheckT?

Anyway, that's probably is best to investigate separately, so feel free to ignore it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd be happy to kill MonadError as well. It's probably best in a separate PR however. I'll make an issue.

type MonadTypeCheckPir uni fun ann m =
( MonadTypeCheck (PIR.Error uni fun ann) (Term TyName Name uni fun ()) uni fun ann m
-- , AsTypeErrorExt err uni ann -- Plutus IR has additional type errors, see 'TypeErrorExt'.
-- TODO: TypeErrorExt should really be the actual extension of PLC.TypeError
Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, so this is where we can have different errors.

Commented out code btw.

tryError :: MonadError e m => m a -> m (Either e a)
tryError a = (Right <$> a) `catchError` (pure . Left)
{-# INLINE tryError #-}

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a minor enough improvement, it's uncontroversial and even if it accidentally gets reverted who cares. I believe it's perfectly OK to lump such minor improvements into larger PRs.

@SeungheonOh SeungheonOh merged commit de1b3ef into master May 30, 2025
9 checks passed
@SeungheonOh SeungheonOh deleted the seungeonoh/6160 branch May 30, 2025 02:36
@SeungheonOh SeungheonOh restored the seungeonoh/6160 branch May 30, 2025 04:47
kwxm pushed a commit that referenced this pull request Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
No Changelog Required Add this to skip the Changelog Check Refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get rid of prismatic error handling?
3 participants