-
Notifications
You must be signed in to change notification settings - Fork 479
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
Change CMTooFewParamsError to a warning #5912
Changes from 1 commit
6074a58
691b1e1
6cbaac4
c16796d
1b00328
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ import PlutusCore.Evaluation.Machine.CostModelInterface | |||||||||||
import Control.Monad.Except | ||||||||||||
import Control.Monad.Writer.Strict | ||||||||||||
import Data.Char (toLower) | ||||||||||||
import Data.Int (Int64) | ||||||||||||
import Data.List as List (lookup) | ||||||||||||
import Data.Map qualified as Map | ||||||||||||
import Data.Text qualified as Text | ||||||||||||
|
@@ -99,9 +100,11 @@ tagWithParamNames ledgerParams = | |||||||||||
tell [CMTooManyParamsWarn {cmTooManyExpected = lenExpected, cmTooManyActual = lenActual}] | ||||||||||||
-- zip will truncate/ignore any extraneous parameter values | ||||||||||||
pure $ zip paramNames ledgerParams | ||||||||||||
GT -> | ||||||||||||
GT -> do | ||||||||||||
-- Too few parameters - substitute a large number for the missing parameters | ||||||||||||
-- See Note [Cost model parameters from the ledger's point of view] | ||||||||||||
throwError $ CMTooFewParamsError {cmTooFewExpected = lenExpected, cmTooFewActual = lenActual } | ||||||||||||
tell [CMTooFewParamsWarn {cmTooFewExpected = lenExpected, cmTooFewActual = lenActual}] | ||||||||||||
pure $ zip paramNames (ledgerParams ++ repeat (toInteger (maxBound :: Int64))) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we switch the type of
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
How so? Where does it fail? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll fail here: plutus/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/CostModelInterface.hs Lines 220 to 222 in 9d0a9cf
With something like this:
To be honest with you I am really surprised to see JSON and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a horrible hack, but nobody has been able to come up with a better solution yet 🙈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've already done it on the ledger side as soon as I found out that Plutus uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Jesus Christ, what a horrible mess, yes please, let's make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #5920 |
||||||||||||
|
||||||||||||
-- | Untags the plutus version from the typed cost model parameters and returns their raw textual form | ||||||||||||
-- (internally used by CostModelInterface). | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It think it is a terrible practice to have record fields for sum types, when they have inconsistent names, because those are essentially partial functions.
In this case we could alleviate it by giving them the same names, but that is not very forward compatible if you plan to add more warnings in the future:
IMHO it is better to avoid record syntax for sum types altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point on the renaming. Regarding record fields for sum types, it is handy for construction, but certainly not great for field access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also good for pattern matching. Ideally you just use
NoFieldSelectors
in this case, but we can't do that until we drop 8.10.