Skip to content

Commit

Permalink
LF: Rename builtins that would need a witness to allow nat type erasu…
Browse files Browse the repository at this point in the history
…re (#16743)

part of #11679
  • Loading branch information
remyhaemmerle-da authored Apr 24, 2023
1 parent 7a4ea18 commit 7a17c19
Show file tree
Hide file tree
Showing 25 changed files with 214 additions and 210 deletions.
24 changes: 12 additions & 12 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ data BuiltinExpr
| BENumericToText -- :: ∀(s:nat). Numeric s -> Text
| BEAddNumeric -- :: ∀(s:nat). Numeric s -> Numeric s -> Numeric s, crashes on overflow
| BESubNumeric -- :: ∀(s:nat). Numeric s -> Numeric s -> Numeric s, crashes on overflow
| BEMulNumeric -- :: ∀(s1:nat). ∀(s2:nat). ∀(s3:nat). Numeric s1 -> Numeric s2 -> Numeric s3, crashes on overflow and underflow, automatically rounds to even (see <https://en.wikipedia.org/wiki/Rounding#Round_half_to_even>)
| BEDivNumeric -- :: ∀(s1:nat). ∀(s2:nat). ∀(s3:nat). Numeric s1 -> Numeric s2 -> Numeric s3, automatically rounds to even, crashes on divisor = 0 and on overflow
| BEMulNumericLegacy -- :: ∀(s1:nat). ∀(s2:nat). ∀(s3:nat). Numeric s1 -> Numeric s2 -> Numeric s3, crashes on overflow and underflow, automatically rounds to even (see <https://en.wikipedia.org/wiki/Rounding#Round_half_to_even>)
| BEDivNumericLegacy -- :: ∀(s1:nat). ∀(s2:nat). ∀(s3:nat). Numeric s1 -> Numeric s2 -> Numeric s3, automatically rounds to even, crashes on divisor = 0 and on overflow
| BERoundNumeric -- :: ∀(s:nat). Int64 -> Numeric s -> Numeric s, the Int64 is the required scale. Note that this doesn't modify the scale of the type itself, it just zeroes things outside that scale out. Can be negative. Crashes if the scale is > 10 or < -27.
| BECastNumeric -- :: ∀(s1:nat). ∀(s2:nat). Numeric s1 -> Numeric s2
| BEShiftNumeric -- :: ∀(s1:nat). ∀(s2:nat). Numeric s1 -> Numeric s2
| BECastNumericLegacy -- :: ∀(s1:nat). ∀(s2:nat). Numeric s1 -> Numeric s2
| BEShiftNumericLegacy -- :: ∀(s1:nat). ∀(s2:nat). Numeric s1 -> Numeric s2

-- Integer arithmetic
| BEAddInt64 -- :: Int64 -> Int64 -> Int64, crashes on overflow
Expand All @@ -287,7 +287,7 @@ data BuiltinExpr
| BEExpInt64 -- :: Int64 -> Int64 -> Int64, crashes on overflow

-- Numerical conversion
| BEInt64ToNumeric -- :: ∀(s:nat). Int64 -> Numeric s, crashes if it doesn't fit (TODO: verify?)
| BEInt64ToNumericLegacy -- :: ∀(s:nat). Int64 -> Numeric s, crashes if it doesn't fit (TODO: verify?)
| BENumericToInt64 -- :: ∀(s:nat). Numeric s -> Int64, only converts the whole part, crashes if it doesn't fit

-- Time conversion
Expand Down Expand Up @@ -323,11 +323,11 @@ data BuiltinExpr
| BEAppendText -- :: Text -> Text -> Text
| BEImplodeText -- :: List Text -> Text
| BESha256Text -- :: Text -> Text
| BETextToParty -- :: Text -> Optional Party
| BETextToInt64 -- :: Text -> Optional Int64
| BETextToNumeric -- :: ∀(s:nat). Text -> Optional (Numeric s)
| BETextToParty -- :: Text -> Optional Party
| BETextToInt64 -- :: Text -> Optional Int64
| BETextToNumericLegacy -- :: ∀(s:nat). Text -> Optional (Numeric s)
| BETextToCodePoints -- :: Text -> List Int64
| BECodePointsToText -- :: List Int64 -> Text
| BECodePointsToText -- :: List Int64 -> Text
| BEPartyToQuotedText -- :: Party -> Text

-- BigNumeric operations
Expand All @@ -337,9 +337,9 @@ data BuiltinExpr
| BESubBigNumeric -- :: BigNumeric -> BigNumeric -> BigNumeric
| BEMulBigNumeric -- :: BigNumeric -> BigNumeric -> BigNumeric
| BEDivBigNumeric -- :: Int64 -> RoundingMode -> BigNumeric -> BigNumeric -> BigNumeric
| BEShiftRightBigNumeric -- :: Int64 -> BigNumeric -> BigNumeric
| BEBigNumericToNumeric -- :: ∀(s:nat). BigNumeric -> Numeric s
| BENumericToBigNumeric -- :: ∀(s:nat). Numeric s -> BigNumeric
| BEShiftRightBigNumeric -- :: Int64 -> BigNumeric -> BigNumeric
| BEBigNumericToNumericLegacy -- :: ∀(s:nat). BigNumeric -> Numeric s
| BENumericToBigNumeric -- :: ∀(s:nat). Numeric s -> BigNumeric

| BETrace -- :: forall a. Text -> a -> a
| BEEqualContractId -- :: forall a. ContractId a -> ContractId a -> Bool
Expand Down
14 changes: 7 additions & 7 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,19 @@ instance Pretty BuiltinExpr where
BEContractIdToText -> "CONTRACT_ID_TO_TEXT"
BEAddNumeric -> "ADD_NUMERIC"
BESubNumeric -> "SUB_NUMERIC"
BEMulNumeric -> "MUL_NUMERIC"
BEDivNumeric -> "DIV_NUMERIC"
BEMulNumericLegacy -> "MUL_NUMERIC_LEGACY"
BEDivNumericLegacy -> "DIV_NUMERIC_LEGACY"
BERoundNumeric -> "ROUND_NUMERIC"
BECastNumeric -> "CAST_NUMERIC"
BEShiftNumeric -> "SHIFT_NUMERIC"
BEInt64ToNumeric -> "INT64_TO_NUMERIC"
BECastNumericLegacy -> "CAST_NUMERIC_LEGACY"
BEShiftNumericLegacy -> "SHIFT_NUMERIC_LEGACY"
BEInt64ToNumericLegacy -> "INT64_TO_NUMERIC_LEGACY"
BENumericToInt64 -> "NUMERIC_TO_INT64"
BEEqualNumeric -> "EQUAL_NUMERIC"
BELessEqNumeric -> "LEQ_NUMERIC"
BELessNumeric -> "LESS_NUMERIC"
BEGreaterEqNumeric -> "GEQ_NUMERIC"
BEGreaterNumeric -> "GREATER_NUMERIC"
BETextToNumeric -> "TEXT_TO_NUMERIC"
BETextToNumericLegacy -> "TEXT_TO_NUMERIC_LEGACY"
BENumericToText -> "NUMERIC_TO_TEXT"
BEScaleBigNumeric -> "SCALE_BIGNUMERIC"
BEPrecisionBigNumeric -> "PRECISION_BIGNUMERIC"
Expand All @@ -257,7 +257,7 @@ instance Pretty BuiltinExpr where
BEMulBigNumeric -> "MUl_BIGNUMERIC"
BEDivBigNumeric -> "DIV_BIGNUMERIC"
BEShiftRightBigNumeric -> "SHIFT_RIGHT_BIGNUMERIC"
BEBigNumericToNumeric -> "BIGNUMERIC_TO_NUMERIC"
BEBigNumericToNumericLegacy -> "BIGNUMERIC_TO_NUMERIC_LEGACY"
BENumericToBigNumeric -> "NUMERIC_TO_BIGNUMERIC"
BEAddInt64 -> "ADD_INT64"
BESubInt64 -> "SUB_INT64"
Expand Down
14 changes: 7 additions & 7 deletions compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ decodeBuiltinFunction = \case
LF1.BuiltinFunctionCODE_POINTS_TO_TEXT -> pure BECodePointsToText
LF1.BuiltinFunctionTEXT_TO_PARTY -> pure BETextToParty
LF1.BuiltinFunctionTEXT_TO_INT64 -> pure BETextToInt64
LF1.BuiltinFunctionTEXT_TO_NUMERIC -> pure BETextToNumeric
LF1.BuiltinFunctionTEXT_TO_NUMERIC_LEGACY -> pure BETextToNumericLegacy
LF1.BuiltinFunctionTEXT_TO_CODE_POINTS -> pure BETextToCodePoints
LF1.BuiltinFunctionPARTY_TO_QUOTED_TEXT -> pure BEPartyToQuotedText

LF1.BuiltinFunctionADD_NUMERIC -> pure BEAddNumeric
LF1.BuiltinFunctionSUB_NUMERIC -> pure BESubNumeric
LF1.BuiltinFunctionMUL_NUMERIC -> pure BEMulNumeric
LF1.BuiltinFunctionDIV_NUMERIC -> pure BEDivNumeric
LF1.BuiltinFunctionMUL_NUMERIC_LEGACY -> pure BEMulNumericLegacy
LF1.BuiltinFunctionDIV_NUMERIC_LEGACY -> pure BEDivNumericLegacy
LF1.BuiltinFunctionROUND_NUMERIC -> pure BERoundNumeric
LF1.BuiltinFunctionCAST_NUMERIC -> pure BECastNumeric
LF1.BuiltinFunctionSHIFT_NUMERIC -> pure BEShiftNumeric
LF1.BuiltinFunctionCAST_NUMERIC_LEGACY -> pure BECastNumericLegacy
LF1.BuiltinFunctionSHIFT_NUMERIC_LEGACY -> pure BEShiftNumericLegacy

LF1.BuiltinFunctionADD_INT64 -> pure BEAddInt64
LF1.BuiltinFunctionSUB_INT64 -> pure BESubInt64
Expand Down Expand Up @@ -506,7 +506,7 @@ decodeBuiltinFunction = \case
LF1.BuiltinFunctionTIMESTAMP_TO_UNIX_MICROSECONDS -> pure BETimestampToUnixMicroseconds
LF1.BuiltinFunctionUNIX_MICROSECONDS_TO_TIMESTAMP -> pure BEUnixMicrosecondsToTimestamp

LF1.BuiltinFunctionINT64_TO_NUMERIC -> pure BEInt64ToNumeric
LF1.BuiltinFunctionINT64_TO_NUMERIC_LEGACY -> pure BEInt64ToNumericLegacy
LF1.BuiltinFunctionNUMERIC_TO_INT64 -> pure BENumericToInt64

LF1.BuiltinFunctionTRACE -> pure BETrace
Expand All @@ -531,7 +531,7 @@ decodeBuiltinFunction = \case
LF1.BuiltinFunctionMUL_BIGNUMERIC -> pure BEMulBigNumeric
LF1.BuiltinFunctionDIV_BIGNUMERIC -> pure BEDivBigNumeric
LF1.BuiltinFunctionSHIFT_RIGHT_BIGNUMERIC -> pure BEShiftRightBigNumeric
LF1.BuiltinFunctionBIGNUMERIC_TO_NUMERIC -> pure BEBigNumericToNumeric
LF1.BuiltinFunctionBIGNUMERIC_TO_NUMERIC_LEGACY -> pure BEBigNumericToNumericLegacy
LF1.BuiltinFunctionNUMERIC_TO_BIGNUMERIC -> pure BENumericToBigNumeric

LF1.BuiltinFunctionADD_DECIMAL -> unsupportedDecimal
Expand Down
14 changes: 7 additions & 7 deletions compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/EncodeV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -482,17 +482,17 @@ encodeBuiltinExpr = \case
BECodePointsToText -> builtin P.BuiltinFunctionCODE_POINTS_TO_TEXT
BETextToParty -> builtin P.BuiltinFunctionTEXT_TO_PARTY
BETextToInt64 -> builtin P.BuiltinFunctionTEXT_TO_INT64
BETextToNumeric-> builtin P.BuiltinFunctionTEXT_TO_NUMERIC
BETextToNumericLegacy-> builtin P.BuiltinFunctionTEXT_TO_NUMERIC_LEGACY
BETextToCodePoints -> builtin P.BuiltinFunctionTEXT_TO_CODE_POINTS
BEPartyToQuotedText -> builtin P.BuiltinFunctionPARTY_TO_QUOTED_TEXT

BEAddNumeric -> builtin P.BuiltinFunctionADD_NUMERIC
BESubNumeric -> builtin P.BuiltinFunctionSUB_NUMERIC
BEMulNumeric -> builtin P.BuiltinFunctionMUL_NUMERIC
BEDivNumeric -> builtin P.BuiltinFunctionDIV_NUMERIC
BEMulNumericLegacy -> builtin P.BuiltinFunctionMUL_NUMERIC_LEGACY
BEDivNumericLegacy -> builtin P.BuiltinFunctionDIV_NUMERIC_LEGACY
BERoundNumeric -> builtin P.BuiltinFunctionROUND_NUMERIC
BECastNumeric -> builtin P.BuiltinFunctionCAST_NUMERIC
BEShiftNumeric -> builtin P.BuiltinFunctionSHIFT_NUMERIC
BECastNumericLegacy -> builtin P.BuiltinFunctionCAST_NUMERIC_LEGACY
BEShiftNumericLegacy -> builtin P.BuiltinFunctionSHIFT_NUMERIC_LEGACY

BEScaleBigNumeric -> builtin P.BuiltinFunctionSCALE_BIGNUMERIC
BEPrecisionBigNumeric -> builtin P.BuiltinFunctionPRECISION_BIGNUMERIC
Expand All @@ -501,7 +501,7 @@ encodeBuiltinExpr = \case
BEMulBigNumeric -> builtin P.BuiltinFunctionMUL_BIGNUMERIC
BEDivBigNumeric -> builtin P.BuiltinFunctionDIV_BIGNUMERIC
BEShiftRightBigNumeric -> builtin P.BuiltinFunctionSHIFT_RIGHT_BIGNUMERIC
BEBigNumericToNumeric -> builtin P.BuiltinFunctionBIGNUMERIC_TO_NUMERIC
BEBigNumericToNumericLegacy -> builtin P.BuiltinFunctionBIGNUMERIC_TO_NUMERIC_LEGACY
BENumericToBigNumeric -> builtin P.BuiltinFunctionNUMERIC_TO_BIGNUMERIC

BEAddInt64 -> builtin P.BuiltinFunctionADD_INT64
Expand All @@ -511,7 +511,7 @@ encodeBuiltinExpr = \case
BEModInt64 -> builtin P.BuiltinFunctionMOD_INT64
BEExpInt64 -> builtin P.BuiltinFunctionEXP_INT64

BEInt64ToNumeric -> builtin P.BuiltinFunctionINT64_TO_NUMERIC
BEInt64ToNumericLegacy -> builtin P.BuiltinFunctionINT64_TO_NUMERIC_LEGACY
BENumericToInt64 -> builtin P.BuiltinFunctionNUMERIC_TO_INT64

BEFoldl -> builtin P.BuiltinFunctionFOLDL
Expand Down
24 changes: 12 additions & 12 deletions compiler/daml-lf-tools/src/DA/Daml/LF/Simplifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,25 @@ safetyStep = \case
BELessEqNumeric -> Safe 2
BEGreaterNumeric -> Safe 2
BEGreaterEqNumeric -> Safe 2
BEAddNumeric -> Safe 1
BESubNumeric -> Safe 1
BEMulNumeric -> Safe 1
BEDivNumeric -> Safe 1
BEInt64ToNumeric -> Safe 0
BENumericToInt64 -> Safe 0
BETextToNumeric -> Safe 1
BENumericToText -> Safe 1
BERoundNumeric -> Safe 1
BECastNumeric -> Safe 0
BEShiftNumeric -> Safe 1
BEAddNumeric -> Safe 1
BESubNumeric -> Safe 1
BEMulNumericLegacy -> Safe 1
BEDivNumericLegacy -> Safe 1
BEInt64ToNumericLegacy -> Safe 0
BENumericToInt64 -> Safe 0
BETextToNumericLegacy -> Safe 1
BENumericToText -> Safe 1
BERoundNumeric -> Safe 1
BECastNumericLegacy -> Safe 0
BEShiftNumericLegacy -> Safe 1
BEScaleBigNumeric -> Safe 1 -- doesn't fail
BEPrecisionBigNumeric -> Safe 1 -- doesn't fail
BEAddBigNumeric -> Safe 1 -- fails on overflow
BESubBigNumeric -> Safe 1 -- fails on overflow
BEMulBigNumeric -> Safe 1 -- fails on overflow
BEDivBigNumeric -> Safe 3 -- takes 4 arguments, fails on division by 0 and on rounding ("rounding unnecessary" mode)
BEShiftRightBigNumeric -> Safe 1 -- fails on overflow (shift too large)
BEBigNumericToNumeric -> Safe 0 -- fails on overflow (numeric doesn't fit)
BEBigNumericToNumericLegacy -> Safe 0 -- fails on overflow (numeric doesn't fit)
BENumericToBigNumeric -> Safe 1 -- doesn't fail
BEAddInt64 -> Safe 1
BESubInt64 -> Safe 1
Expand Down
14 changes: 7 additions & 7 deletions compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ typeOfBuiltin = \case
BEGreaterEqNumeric -> pure $ TForall (alpha, KNat) $ TNumeric tAlpha :-> TNumeric tAlpha :-> TBool
BEAddNumeric -> pure $ TForall (alpha, KNat) $ TNumeric tAlpha :-> TNumeric tAlpha :-> TNumeric tAlpha
BESubNumeric -> pure $ TForall (alpha, KNat) $ TNumeric tAlpha :-> TNumeric tAlpha :-> TNumeric tAlpha
BEMulNumeric -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TForall (gamma, KNat) $ TNumeric tAlpha :-> TNumeric tBeta :-> TNumeric tGamma
BEDivNumeric -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TForall (gamma, KNat) $ TNumeric tAlpha :-> TNumeric tBeta :-> TNumeric tGamma
BEMulNumericLegacy -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TForall (gamma, KNat) $ TNumeric tAlpha :-> TNumeric tBeta :-> TNumeric tGamma
BEDivNumericLegacy -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TForall (gamma, KNat) $ TNumeric tAlpha :-> TNumeric tBeta :-> TNumeric tGamma
BERoundNumeric -> pure $ TForall (alpha, KNat) $ TInt64 :-> TNumeric tAlpha :-> TNumeric tAlpha
BECastNumeric -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TNumeric tAlpha :-> TNumeric tBeta
BEShiftNumeric -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TNumeric tAlpha :-> TNumeric tBeta
BEInt64ToNumeric -> pure $ TForall (alpha, KNat) $ TInt64 :-> TNumeric tAlpha
BECastNumericLegacy -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TNumeric tAlpha :-> TNumeric tBeta
BEShiftNumericLegacy -> pure $ TForall (alpha, KNat) $ TForall (beta, KNat) $ TNumeric tAlpha :-> TNumeric tBeta
BEInt64ToNumericLegacy -> pure $ TForall (alpha, KNat) $ TInt64 :-> TNumeric tAlpha
BENumericToInt64 -> pure $ TForall (alpha, KNat) $ TNumeric tAlpha :-> TInt64
BENumericToText -> pure $ TForall (alpha, KNat) $ TNumeric tAlpha :-> TText
BETextToNumeric -> pure $ TForall (alpha, KNat) $ TText :-> TOptional (TNumeric tAlpha)
BETextToNumericLegacy -> pure $ TForall (alpha, KNat) $ TText :-> TOptional (TNumeric tAlpha)

BEScaleBigNumeric -> pure $ TBigNumeric :-> TInt64
BEPrecisionBigNumeric -> pure $ TBigNumeric :-> TInt64
Expand All @@ -260,7 +260,7 @@ typeOfBuiltin = \case
BEMulBigNumeric -> pure $ TBigNumeric :-> TBigNumeric :-> TBigNumeric
BEDivBigNumeric -> pure $ TInt64 :-> TRoundingMode :-> TBigNumeric :-> TBigNumeric :-> TBigNumeric
BEShiftRightBigNumeric -> pure $ TInt64 :-> TBigNumeric :-> TBigNumeric
BEBigNumericToNumeric -> pure $ TForall (alpha, KNat) $ TBigNumeric :-> TNumeric tAlpha
BEBigNumericToNumericLegacy -> pure $ TForall (alpha, KNat) $ TBigNumeric :-> TNumeric tAlpha
BENumericToBigNumeric -> pure $ TForall (alpha, KNat) $ TNumeric tAlpha :-> TBigNumeric

BEAddInt64 -> pure $ tBinop TInt64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,43 +159,43 @@ convertPrim _ "BEAddDecimal" (TNumeric10 :-> TNumeric10 :-> TNumeric10) =
convertPrim _ "BESubDecimal" (TNumeric10 :-> TNumeric10 :-> TNumeric10) =
pure $ ETyApp (EBuiltin BESubNumeric) TNat10
convertPrim _ "BEMulDecimal" (TNumeric10 :-> TNumeric10 :-> TNumeric10) =
pure $ EBuiltin BEMulNumeric `ETyApp` TNat10 `ETyApp` TNat10 `ETyApp` TNat10
pure $ EBuiltin BEMulNumericLegacy `ETyApp` TNat10 `ETyApp` TNat10 `ETyApp` TNat10
convertPrim _ "BEDivDecimal" (TNumeric10 :-> TNumeric10 :-> TNumeric10) =
pure $ EBuiltin BEDivNumeric `ETyApp` TNat10 `ETyApp` TNat10 `ETyApp` TNat10
pure $ EBuiltin BEDivNumericLegacy `ETyApp` TNat10 `ETyApp` TNat10 `ETyApp` TNat10
convertPrim _ "BERoundDecimal" (TInt64 :-> TNumeric10 :-> TNumeric10) =
pure $ ETyApp (EBuiltin BERoundNumeric) TNat10
convertPrim _ "BEInt64ToDecimal" (TInt64 :-> TNumeric10) =
pure $ ETyApp (EBuiltin BEInt64ToNumeric) TNat10
pure $ ETyApp (EBuiltin BEInt64ToNumericLegacy) TNat10
convertPrim _ "BEDecimalToInt64" (TNumeric10 :-> TInt64) =
pure $ ETyApp (EBuiltin BENumericToInt64) TNat10
convertPrim _ "BEToText" (TNumeric10 :-> TText) =
pure $ ETyApp (EBuiltin BENumericToText) TNat10
convertPrim _ "BETextToDecimal" (TText :-> TOptional TNumeric10) =
pure $ ETyApp (EBuiltin BETextToNumeric) TNat10
pure $ ETyApp (EBuiltin BETextToNumericLegacy) TNat10

-- Numeric primitives. These are polymorphic in the scale.
convertPrim _ "BEAddNumeric" (TNumeric n1 :-> TNumeric n2 :-> TNumeric n3) | n1 == n2, n1 == n3 =
pure $ ETyApp (EBuiltin BEAddNumeric) n1
convertPrim _ "BESubNumeric" (TNumeric n1 :-> TNumeric n2 :-> TNumeric n3) | n1 == n2, n1 == n3 =
pure $ ETyApp (EBuiltin BESubNumeric) n1
convertPrim _ "BEMulNumeric" (TNumeric n1 :-> TNumeric n2 :-> TNumeric n3) =
pure $ EBuiltin BEMulNumeric `ETyApp` n1 `ETyApp` n2 `ETyApp` n3
convertPrim _ "BEDivNumeric" (TNumeric n1 :-> TNumeric n2 :-> TNumeric n3) =
pure $ EBuiltin BEDivNumeric `ETyApp` n1 `ETyApp` n2 `ETyApp` n3
convertPrim _ "BEMulNumericLegacy" (TNumeric n1 :-> TNumeric n2 :-> TNumeric n3) =
pure $ EBuiltin BEMulNumericLegacy `ETyApp` n1 `ETyApp` n2 `ETyApp` n3
convertPrim _ "BEDivNumericLegacy" (TNumeric n1 :-> TNumeric n2 :-> TNumeric n3) =
pure $ EBuiltin BEDivNumericLegacy `ETyApp` n1 `ETyApp` n2 `ETyApp` n3
convertPrim _ "BERoundNumeric" (TInt64 :-> TNumeric n1 :-> TNumeric n2) | n1 == n2 =
pure $ ETyApp (EBuiltin BERoundNumeric) n1
convertPrim _ "BECastNumeric" (TNumeric n1 :-> TNumeric n2) =
pure $ EBuiltin BECastNumeric `ETyApp` n1 `ETyApp` n2
convertPrim _ "BEShiftNumeric" (TNumeric n1 :-> TNumeric n2) =
pure $ EBuiltin BEShiftNumeric `ETyApp` n1 `ETyApp` n2
convertPrim _ "BEInt64ToNumeric" (TInt64 :-> TNumeric n) =
pure $ ETyApp (EBuiltin BEInt64ToNumeric) n
convertPrim _ "BECastNumericLegacy" (TNumeric n1 :-> TNumeric n2) =
pure $ EBuiltin BECastNumericLegacy `ETyApp` n1 `ETyApp` n2
convertPrim _ "BEShiftNumericLegacy" (TNumeric n1 :-> TNumeric n2) =
pure $ EBuiltin BEShiftNumericLegacy `ETyApp` n1 `ETyApp` n2
convertPrim _ "BEInt64ToNumericLegacy" (TInt64 :-> TNumeric n) =
pure $ ETyApp (EBuiltin BEInt64ToNumericLegacy) n
convertPrim _ "BENumericToInt64" (TNumeric n :-> TInt64) =
pure $ ETyApp (EBuiltin BENumericToInt64) n
convertPrim _ "BENumericToText" (TNumeric n :-> TText) =
pure $ ETyApp (EBuiltin BENumericToText) n
convertPrim _ "BETextToNumeric" (TText :-> TOptional (TNumeric n)) =
pure $ ETyApp (EBuiltin BETextToNumeric) n
convertPrim _ "BETextToNumericLegacy" (TText :-> TOptional (TNumeric n)) =
pure $ ETyApp (EBuiltin BETextToNumericLegacy) n

convertPrim version "BEScaleBigNumeric" ty@(TBigNumeric :-> TInt64) =
pure $
Expand Down Expand Up @@ -229,10 +229,10 @@ convertPrim version "BENumericToBigNumeric" ty@(TNumeric n :-> TBigNumeric) =
pure $
whenRuntimeSupports version featureBigNumeric ty $
EBuiltin BENumericToBigNumeric `ETyApp` n
convertPrim version "BEBigNumericToNumeric" ty@(TBigNumeric :-> TNumeric n) =
convertPrim version "BEBigNumericToNumericLegacy" ty@(TBigNumeric :-> TNumeric n) =
pure $
whenRuntimeSupports version featureBigNumeric ty $
EBuiltin BEBigNumericToNumeric `ETyApp` n
EBuiltin BEBigNumericToNumericLegacy `ETyApp` n

-- Experimental text primitives.
convertPrim _ "BETextToUpper" (TText :-> TText) = pure $ EBuiltin BETextToUpper
Expand Down
4 changes: 2 additions & 2 deletions compiler/damlc/daml-prim-src/GHC/Classes.daml
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ class IsNumeric t where
fromBigNumeric : BigNumeric -> t

instance NumericScale n => IsNumeric (Numeric n) where
fromNumeric = primitive @"BECastNumeric"
fromBigNumeric = primitive @"BEBigNumericToNumeric"
fromNumeric = primitive @"BECastNumericLegacy"
fromBigNumeric = primitive @"BEBigNumericToNumericLegacy"

instance IsNumeric BigNumeric where
fromNumeric = primitive @"BENumericToBigNumeric"
Expand Down
Loading

0 comments on commit 7a17c19

Please sign in to comment.