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

Engine: clean conversion builtin names #9726

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1708,34 +1708,34 @@ private[lf] object DecodeV1 {
maxVersion = Some(genComparison),
implicitParameters = List(TParty),
),
BuiltinFunctionInfo(INT64_TO_TEXT, BToTextInt64),
BuiltinFunctionInfo(INT64_TO_TEXT, BInt64ToText),
BuiltinFunctionInfo(
DECIMAL_TO_TEXT,
BToTextNumeric,
BNumericToText,
maxVersion = Some(numeric),
implicitParameters = List(TNat.Decimal),
),
BuiltinFunctionInfo(NUMERIC_TO_TEXT, BToTextNumeric, minVersion = numeric),
BuiltinFunctionInfo(TIMESTAMP_TO_TEXT, BToTextTimestamp),
BuiltinFunctionInfo(PARTY_TO_TEXT, BToTextParty),
BuiltinFunctionInfo(TEXT_TO_TEXT, BToTextText),
BuiltinFunctionInfo(NUMERIC_TO_TEXT, BNumericToText, minVersion = numeric),
BuiltinFunctionInfo(TIMESTAMP_TO_TEXT, BTimestampToText),
BuiltinFunctionInfo(PARTY_TO_TEXT, BPartyToText),
BuiltinFunctionInfo(TEXT_TO_TEXT, BTextToText),
BuiltinFunctionInfo(
CONTRACT_ID_TO_TEXT,
BToTextContractId,
BContractIdToText,
minVersion = contractIdTextConversions,
),
BuiltinFunctionInfo(PARTY_TO_QUOTED_TEXT, BToQuotedTextParty, maxVersion = Some(exceptions)),
BuiltinFunctionInfo(CODE_POINTS_TO_TEXT, BToTextCodePoints, minVersion = textPacking),
BuiltinFunctionInfo(TEXT_TO_PARTY, BFromTextParty),
BuiltinFunctionInfo(TEXT_TO_INT64, BFromTextInt64),
BuiltinFunctionInfo(PARTY_TO_QUOTED_TEXT, BPartyToQuotedText, maxVersion = Some(exceptions)),
BuiltinFunctionInfo(CODE_POINTS_TO_TEXT, BCodePointsToText, minVersion = textPacking),
BuiltinFunctionInfo(TEXT_TO_PARTY, BTextToParty),
BuiltinFunctionInfo(TEXT_TO_INT64, BTextToInt64),
BuiltinFunctionInfo(
TEXT_TO_DECIMAL,
BFromTextNumeric,
BTextToNumeric,
implicitParameters = List(TNat.Decimal),
maxVersion = Some(numeric),
),
BuiltinFunctionInfo(TEXT_TO_NUMERIC, BFromTextNumeric, minVersion = numeric),
BuiltinFunctionInfo(TEXT_POINTS_TO_CODE, BFromTextCodePoints, minVersion = textPacking),
BuiltinFunctionInfo(TEXT_TO_NUMERIC, BTextToNumeric, minVersion = numeric),
BuiltinFunctionInfo(TEXT_POINTS_TO_CODE, BTextToCodePoints, minVersion = textPacking),
BuiltinFunctionInfo(SHA256_TEXT, BSHA256Text),
BuiltinFunctionInfo(DATE_TO_UNIX_DAYS, BDateToUnixDays),
BuiltinFunctionInfo(EXPLODE_TEXT, BExplodeText),
Expand All @@ -1759,7 +1759,7 @@ private[lf] object DecodeV1 {
maxVersion = Some(genComparison),
),
BuiltinFunctionInfo(TIMESTAMP_TO_UNIX_MICROSECONDS, BTimestampToUnixMicroseconds),
BuiltinFunctionInfo(DATE_TO_TEXT, BToTextDate),
BuiltinFunctionInfo(DATE_TO_TEXT, BDateToText),
BuiltinFunctionInfo(UNIX_DAYS_TO_DATE, BUnixDaysToDate),
BuiltinFunctionInfo(UNIX_MICROSECONDS_TO_TIMESTAMP, BUnixMicrosecondsToTimestamp),
BuiltinFunctionInfo(
Expand Down Expand Up @@ -1839,9 +1839,9 @@ private[lf] object DecodeV1 {
BuiltinFunctionInfo(MUL_BIGNUMERIC, BMulBigNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(DIV_BIGNUMERIC, BDivBigNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(SHIFT_RIGHT_BIGNUMERIC, BShiftRightBigNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(BIGNUMERIC_TO_NUMERIC, BToNumericBigNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(NUMERIC_TO_BIGNUMERIC, BToBigNumericNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(BIGNUMERIC_TO_TEXT, BToTextBigNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(BIGNUMERIC_TO_NUMERIC, BBigNumericToNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(NUMERIC_TO_BIGNUMERIC, BNumericToBigNumeric, minVersion = bigNumeric),
BuiltinFunctionInfo(BIGNUMERIC_TO_TEXT, BBigNumericToText, minVersion = bigNumeric),
BuiltinFunctionInfo(ANY_EXCEPTION_MESSAGE, BAnyExceptionMessage, minVersion = exceptions),
BuiltinFunctionInfo(
ANY_EXCEPTION_IS_ARITHMETIC_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ class DecodeV1Spec
(
DamlLf1.BuiltinFunction.DECIMAL_TO_TEXT,
"6",
Ast.ETyApp(Ast.EBuiltin(Ast.BToTextNumeric), TDecimalScale),
Ast.ETyApp(Ast.EBuiltin(Ast.BNumericToText), TDecimalScale),
),
(
DamlLf1.BuiltinFunction.TEXT_TO_DECIMAL,
"6",
Ast.ETyApp(Ast.EBuiltin(Ast.BFromTextNumeric), TDecimalScale),
Ast.ETyApp(Ast.EBuiltin(Ast.BTextToNumeric), TDecimalScale),
),
(
DamlLf1.BuiltinFunction.INT64_TO_DECIMAL,
Expand All @@ -462,8 +462,8 @@ class DecodeV1Spec
DamlLf1.BuiltinFunction.MUL_NUMERIC -> Ast.EBuiltin(Ast.BMulNumeric),
DamlLf1.BuiltinFunction.DIV_NUMERIC -> Ast.EBuiltin(Ast.BDivNumeric),
DamlLf1.BuiltinFunction.ROUND_NUMERIC -> Ast.EBuiltin(Ast.BRoundNumeric),
DamlLf1.BuiltinFunction.NUMERIC_TO_TEXT -> Ast.EBuiltin(Ast.BToTextNumeric),
DamlLf1.BuiltinFunction.TEXT_TO_NUMERIC -> Ast.EBuiltin(Ast.BFromTextNumeric),
DamlLf1.BuiltinFunction.NUMERIC_TO_TEXT -> Ast.EBuiltin(Ast.BNumericToText),
DamlLf1.BuiltinFunction.TEXT_TO_NUMERIC -> Ast.EBuiltin(Ast.BTextToNumeric),
DamlLf1.BuiltinFunction.INT64_TO_NUMERIC -> Ast.EBuiltin(Ast.BInt64ToNumeric),
DamlLf1.BuiltinFunction.NUMERIC_TO_INT64 -> Ast.EBuiltin(Ast.BNumericToInt64),
)
Expand Down Expand Up @@ -525,7 +525,7 @@ class DecodeV1Spec

val contractIdTextConversionCases = Table(
"builtin" -> "expected output",
DamlLf1.BuiltinFunction.CONTRACT_ID_TO_TEXT -> Ast.EBuiltin(Ast.BToTextContractId),
DamlLf1.BuiltinFunction.CONTRACT_ID_TO_TEXT -> Ast.EBuiltin(Ast.BContractIdToText),
)

"translate non numeric/decimal builtin as is for any version" in {
Expand Down Expand Up @@ -788,11 +788,11 @@ class DecodeV1Spec
DamlLf1.BuiltinFunction.DIV_BIGNUMERIC ->
Ast.EBuiltin(Ast.BDivBigNumeric),
DamlLf1.BuiltinFunction.NUMERIC_TO_BIGNUMERIC ->
Ast.EBuiltin(Ast.BToBigNumericNumeric),
Ast.EBuiltin(Ast.BNumericToBigNumeric),
DamlLf1.BuiltinFunction.BIGNUMERIC_TO_NUMERIC ->
Ast.EBuiltin(Ast.BToNumericBigNumeric),
Ast.EBuiltin(Ast.BBigNumericToNumeric),
DamlLf1.BuiltinFunction.BIGNUMERIC_TO_TEXT ->
Ast.EBuiltin(Ast.BToTextBigNumeric),
Ast.EBuiltin(Ast.BBigNumericToText),
)

forEveryVersion { version =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private[lf] final class Compiler(
case BGreaterNumeric => SBGreaterNumeric
case BGreaterEqNumeric => SBGreaterEqNumeric
case BEqualNumeric => SBEqualNumeric
case BToTextNumeric => SBEToTextNumeric
case BNumericToText => SBEToTextNumeric

case BTextMapEmpty => SEValue.EmptyTextMap
case BGenMapEmpty => SEValue.EmptyGenMap
Expand Down Expand Up @@ -516,18 +516,18 @@ private[lf] final class Compiler(
case BImplodeText => SBImplodeText
case BAppendText => SBAppendText

case BToTextInt64 => SBToText
case BToTextText => SBToText
case BToTextTimestamp => SBToText
case BToTextParty => SBToText
case BToTextDate => SBToText
case BToTextContractId => SBToTextContractId
case BToQuotedTextParty => SBToQuotedTextParty
case BToTextCodePoints => SBToTextCodePoints
case BFromTextParty => SBFromTextParty
case BFromTextInt64 => SBFromTextInt64
case BFromTextNumeric => SBFromTextNumeric
case BFromTextCodePoints => SBFromTextCodePoints
case BInt64ToText => SBToText
case BTextToText => SBToText
case BTimestampToText => SBToText
case BPartyToText => SBToText
case BDateToText => SBToText
case BContractIdToText => SBContractIdToText
case BPartyToQuotedText => SBPartyToQuotedText
case BCodePointsToText => SBCodePointsToText
case BTextToParty => SBTextToParty
case BTextToInt64 => SBTextToInt64
case BTextToNumeric => SBTextToNumeric
case BTextToCodePoints => SBTextToCodePoints

case BSHA256Text => SBSHA256Text

Expand Down Expand Up @@ -570,9 +570,9 @@ private[lf] final class Compiler(
case BDivBigNumeric => SBDivBigNumeric
case BMulBigNumeric => SBMulBigNumeric
case BShiftRightBigNumeric => SBShiftRightBigNumeric
case BToBigNumericNumeric => SBToBigNumericNumeric
case BToNumericBigNumeric => SBToNumericBigNumeric
case BToTextBigNumeric => SBToText
case BNumericToBigNumeric => SBNumericToBigNumeric
case BBigNumericToNumeric => SBBigNumericToNumeric
case BBigNumericToText => SBToText

// Unstable Text Primitives
case BTextToUpper => SBTextToUpper
Expand All @@ -587,7 +587,7 @@ private[lf] final class Compiler(
// Implemented using normal SExpr
case BFoldl | BFoldr | BCoerceContractId | BEqual | BEqualList | BLessEq |
BLess | BGreaterEq | BGreater | BLessNumeric | BLessEqNumeric | BGreaterNumeric |
BGreaterEqNumeric | BEqualNumeric | BToTextNumeric | BTextMapEmpty | BGenMapEmpty =>
BGreaterEqNumeric | BEqualNumeric | BNumericToText | BTextMapEmpty | BGenMapEmpty =>
throw CompilationError(s"unexpected $bf")

case BAnyExceptionMessage => SBAnyExceptionMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private[lf] object SBuiltin {
SText(litToText(args.get(0)))
}

final case object SBToTextContractId extends SBuiltin(1) {
final case object SBContractIdToText extends SBuiltin(1) {
override private[speedy] final def execute(
args: util.ArrayList[SValue],
machine: Machine,
Expand All @@ -439,19 +439,19 @@ private[lf] object SBuiltin {
}
}

final case object SBToQuotedTextParty extends SBuiltinPure(1) {
final case object SBPartyToQuotedText extends SBuiltinPure(1) {
override private[speedy] final def executePure(args: util.ArrayList[SValue]): SValue =
SText(s"'${getSParty(args, 0): String}'")
}

final case object SBToTextCodePoints extends SBuiltinPure(1) {
final case object SBCodePointsToText extends SBuiltinPure(1) {
override private[speedy] final def executePure(args: util.ArrayList[SValue]): SValue = {
val codePoints = getSList(args, 0).map(_.asInstanceOf[SInt64].value)
SText(Utf8.pack(codePoints.toImmArray))
}
}

final case object SBFromTextParty extends SBuiltinPure(1) {
final case object SBTextToParty extends SBuiltinPure(1) {
override private[speedy] final def executePure(args: util.ArrayList[SValue]): SValue = {
Party.fromString(getSText(args, 0)) match {
case Left(_) => SV.None
Expand All @@ -460,7 +460,7 @@ private[lf] object SBuiltin {
}
}

final case object SBFromTextInt64 extends SBuiltinPure(1) {
final case object SBTextToInt64 extends SBuiltinPure(1) {
private val pattern = """[+-]?\d+""".r.pattern

override private[speedy] final def executePure(args: util.ArrayList[SValue]): SValue = {
Expand All @@ -481,7 +481,7 @@ private[lf] object SBuiltin {
// accept and convert. In particular it should convert any string with an arbitrary number of
// leading and trailing '0's as long as the corresponding number fits a Numeric without loss of
// precision. We should take care not calling String to BigDecimal conversion on huge strings.
final case object SBFromTextNumeric extends SBuiltinPure(2) {
final case object SBTextToNumeric extends SBuiltinPure(2) {
private val validFormat =
"""([+-]?)0*(\d+)(\.(\d*[1-9]|0)0*)?""".r

Expand Down Expand Up @@ -512,7 +512,7 @@ private[lf] object SBuiltin {
}
}

final case object SBFromTextCodePoints extends SBuiltinPure(1) {
final case object SBTextToCodePoints extends SBuiltinPure(1) {
override private[speedy] final def executePure(args: util.ArrayList[SValue]): SValue = {
val string = getSText(args, 0)
val codePoints = Utf8.unpack(string)
Expand Down Expand Up @@ -879,14 +879,14 @@ private[lf] object SBuiltin {
}
}

final object SBToBigNumericNumeric extends SBuiltinPure(2) {
final object SBNumericToBigNumeric extends SBuiltinPure(2) {
override private[speedy] def executePure(args: util.ArrayList[SValue]): SBigNumeric = {
val x = getSNumeric(args, 1)
SBigNumeric.fromNumeric(x)
}
}

final object SBToNumericBigNumeric extends SBBuiltinArithmetic("BIGNUMERIC_TO_NUMERIC", 2) {
final object SBBigNumericToNumeric extends SBBuiltinArithmetic("BIGNUMERIC_TO_NUMERIC", 2) {
override private[speedy] def compute(args: util.ArrayList[SValue]): Option[SNumeric] = {
val scale = getSTNat(args, 0)
val x = getSBigNumeric(args, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ class SBuiltinTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChe
"SHIFT_RIGHT_BIGNUMERIC",
),
(
SBToNumericBigNumeric,
SBBigNumericToNumeric,
List[SValue](TMinScale, VeryBigBigNumericA),
"BIGNUMERIC_TO_NUMERIC",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,20 @@ object Ast {
final case object BImplodeText extends BuiltinFunction // : List Text -> Text
final case object BAppendText extends BuiltinFunction // : Text → Text → Text

final case object BToTextInt64 extends BuiltinFunction // Int64 → Text
final case object BToTextNumeric extends BuiltinFunction // : ∀s. Numeric s → Text
final case object BToTextText extends BuiltinFunction // : Text → Text
final case object BToTextTimestamp extends BuiltinFunction // : Timestamp → Text
final case object BToTextParty extends BuiltinFunction // : Party → Text
final case object BToTextDate extends BuiltinFunction // : Date -> Text
final case object BToTextContractId
final case object BInt64ToText extends BuiltinFunction // Int64 → Text
final case object BNumericToText extends BuiltinFunction // : ∀s. Numeric s → Text
final case object BTextToText extends BuiltinFunction // : Text → Text
final case object BTimestampToText extends BuiltinFunction // : Timestamp → Text
final case object BPartyToText extends BuiltinFunction // : Party → Text
final case object BDateToText extends BuiltinFunction // : Date -> Text
final case object BContractIdToText
extends BuiltinFunction // : forall t. ContractId t -> Optional Text
final case object BToQuotedTextParty extends BuiltinFunction // : Party -> Text
final case object BToTextCodePoints extends BuiltinFunction // : [Int64] -> Text
final case object BFromTextParty extends BuiltinFunction // : Text -> Optional Party
final case object BFromTextInt64 extends BuiltinFunction // : Text -> Optional Int64
final case object BFromTextNumeric extends BuiltinFunction // : ∀s. Text -> Optional (Numeric s)
final case object BFromTextCodePoints extends BuiltinFunction // : Text -> List Int64
final case object BPartyToQuotedText extends BuiltinFunction // : Party -> Text
final case object BCodePointsToText extends BuiltinFunction // : [Int64] -> Text
final case object BTextToParty extends BuiltinFunction // : Text -> Optional Party
final case object BTextToInt64 extends BuiltinFunction // : Text -> Optional Int64
final case object BTextToNumeric extends BuiltinFunction // : ∀s. Text -> Optional (Numeric s)
final case object BTextToCodePoints extends BuiltinFunction // : Text -> List Int64

final case object BSHA256Text extends BuiltinFunction // : Text -> Text

Expand Down Expand Up @@ -455,9 +455,9 @@ object Ast {
extends BuiltinFunction // : Int64 -> RoundingMode → BigNumeric → BigNumeric → BigNumeric s
final case object BShiftRightBigNumeric
extends BuiltinFunction // : Int64 → BigNumeric → BigNumeric
final case object BToNumericBigNumeric extends BuiltinFunction // : ∀s. BigNumeric → Numeric s
final case object BToBigNumericNumeric extends BuiltinFunction // : ∀s. Numeric s → BigNumeric
final case object BToTextBigNumeric extends BuiltinFunction // : BigNumeric → Text
final case object BBigNumericToNumeric extends BuiltinFunction // : ∀s. BigNumeric → Numeric s
final case object BNumericToBigNumeric extends BuiltinFunction // : ∀s. Numeric s → BigNumeric
final case object BBigNumericToText extends BuiltinFunction // : BigNumeric → Text

// Unstable Text Primitives
final case object BTextToUpper extends BuiltinFunction // Text → Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,19 @@ private[parser] class ExprParser[P](parserParameters: ParserParameters[P]) {
"IMPLODE_TEXT" -> BImplodeText,
"APPEND_TEXT" -> BAppendText,
"SHA256_TEXT" -> BSHA256Text,
"INT64_TO_TEXT" -> BToTextInt64,
"NUMERIC_TO_TEXT" -> BToTextNumeric,
"TEXT_TO_TEXT" -> BToTextText,
"TIMESTAMP_TO_TEXT" -> BToTextTimestamp,
"PARTY_TO_TEXT" -> BToTextParty,
"DATE_TO_TEXT" -> BToTextDate,
"CONTRACT_ID_TO_TEXT" -> BToTextContractId,
"PARTY_TO_QUOTED_TEXT" -> BToQuotedTextParty,
"CODE_POINTS_TO_TEXT" -> BToTextCodePoints,
"TEXT_TO_PARTY" -> BFromTextParty,
"TEXT_TO_INT64" -> BFromTextInt64,
"TEXT_TO_NUMERIC" -> BFromTextNumeric,
"TEXT_POINTS_TO_CODE" -> BFromTextCodePoints,
"INT64_TO_TEXT" -> BInt64ToText,
"NUMERIC_TO_TEXT" -> BNumericToText,
"TEXT_TO_TEXT" -> BTextToText,
"TIMESTAMP_TO_TEXT" -> BTimestampToText,
"PARTY_TO_TEXT" -> BPartyToText,
"DATE_TO_TEXT" -> BDateToText,
"CONTRACT_ID_TO_TEXT" -> BContractIdToText,
"PARTY_TO_QUOTED_TEXT" -> BPartyToQuotedText,
"CODE_POINTS_TO_TEXT" -> BCodePointsToText,
"TEXT_TO_PARTY" -> BTextToParty,
"TEXT_TO_INT64" -> BTextToInt64,
"TEXT_TO_NUMERIC" -> BTextToNumeric,
"TEXT_POINTS_TO_CODE" -> BTextToCodePoints,
"ERROR" -> BError,
"LESS_NUMERIC" -> BLessNumeric,
"LESS_EQ_NUMERIC" -> BLessEqNumeric,
Expand All @@ -320,9 +320,9 @@ private[parser] class ExprParser[P](parserParameters: ParserParameters[P]) {
"MUL_BIGNUMERIC" -> BMulBigNumeric,
"DIV_BIGNUMERIC" -> BDivBigNumeric,
"SHIFT_RIGHT_BIGNUMERIC" -> BShiftRightBigNumeric,
"BIGNUMERIC_TO_NUMERIC" -> BToNumericBigNumeric,
"NUMERIC_TO_BIGNUMERIC" -> BToBigNumericNumeric,
"BIGNUMERIC_TO_TEXT" -> BToTextBigNumeric,
"BIGNUMERIC_TO_NUMERIC" -> BBigNumericToNumeric,
"NUMERIC_TO_BIGNUMERIC" -> BNumericToBigNumeric,
"BIGNUMERIC_TO_TEXT" -> BBigNumericToText,
)

private lazy val experimental: Parser[Expr] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ class ParsersSpec extends AnyWordSpec with ScalaCheckPropertyChecks with Matcher
"EXPLODE_TEXT" -> BExplodeText,
"IMPLODE_TEXT" -> BImplodeText,
"APPEND_TEXT" -> BAppendText,
"INT64_TO_TEXT" -> BToTextInt64,
"NUMERIC_TO_TEXT" -> BToTextNumeric,
"TEXT_TO_TEXT" -> BToTextText,
"TIMESTAMP_TO_TEXT" -> BToTextTimestamp,
"PARTY_TO_TEXT" -> BToTextParty,
"DATE_TO_TEXT" -> BToTextDate,
"INT64_TO_TEXT" -> BInt64ToText,
"NUMERIC_TO_TEXT" -> BNumericToText,
"TEXT_TO_TEXT" -> BTextToText,
"TIMESTAMP_TO_TEXT" -> BTimestampToText,
"PARTY_TO_TEXT" -> BPartyToText,
"DATE_TO_TEXT" -> BDateToText,
"ERROR" -> BError,
"LESS_NUMERIC" -> BLessNumeric,
"LESS_EQ_NUMERIC" -> BLessEqNumeric,
Expand Down
Loading