-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace Builtin RoundingMode by stable packages
- Loading branch information
1 parent
5b63b00
commit c4a9318
Showing
19 changed files
with
290 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "generate_and_track_cabal") | ||
load( | ||
"//daml-lf/language:daml-lf.bzl", | ||
"LF_MAJOR_VERSIONS", | ||
) | ||
|
||
da_haskell_library( | ||
name = "stable-packages-lib", | ||
srcs = glob(["lib/**/*.hs"]), | ||
hackage_deps = [ | ||
"base", | ||
"bytestring", | ||
"containers", | ||
"text", | ||
], | ||
src_strip_prefix = "lib", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//compiler/daml-lf-ast", | ||
"//compiler/daml-lf-proto-encode", | ||
"//compiler/damlc/daml-lf-util", | ||
"//libs-haskell/da-hs-base", | ||
], | ||
) | ||
|
||
da_haskell_binary( | ||
name = "generate-stable-package", | ||
srcs = glob(["src/**/*.hs"]), | ||
hackage_deps = [ | ||
"base", | ||
"bytestring", | ||
"containers", | ||
"optparse-applicative", | ||
"text", | ||
], | ||
src_strip_prefix = "src", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"stable-packages-lib", | ||
"//compiler/daml-lf-ast", | ||
"//compiler/daml-lf-proto-encode", | ||
"//libs-haskell/da-hs-base", | ||
], | ||
) | ||
|
||
[ | ||
genrule( | ||
name = "gen-stable-packages-v{}".format(majorLfVersion), | ||
srcs = [], | ||
outs = [ | ||
"lf-v{}/daml-prim/GHC-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/GHC-Prim.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/GHC-Tuple.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Internal-Erased.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Internal-NatSyn.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Internal-PromotedText.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-GeneralError.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-ArithmeticError.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-AssertionFailed.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-PreconditionFailed.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Template.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Any.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Time-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-NonEmpty-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Date-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Semigroup-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Set-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Monoid-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Logic-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Validation-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Down.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Interface-AnyView-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Action-State-Type.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Random-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Stack-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Types-RoundingMode.dalf".format(majorLfVersion), | ||
], | ||
cmd = """ | ||
$(location :generate-stable-package) --major-version {major} --module GHC.Types -o $(location lf-v{major}/daml-prim/GHC-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module GHC.Prim -o $(location lf-v{major}/daml-prim/GHC-Prim.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module GHC.Tuple -o $(location lf-v{major}/daml-prim/GHC-Tuple.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.Erased -o $(location lf-v{major}/daml-prim/DA-Internal-Erased.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.NatSyn -o $(location lf-v{major}/daml-prim/DA-Internal-NatSyn.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.PromotedText -o $(location lf-v{major}/daml-prim/DA-Internal-PromotedText.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Exception.GeneralError -o $(location lf-v{major}/daml-prim/DA-Exception-GeneralError.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Exception.ArithmeticError -o $(location lf-v{major}/daml-prim/DA-Exception-ArithmeticError.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Exception.AssertionFailed -o $(location lf-v{major}/daml-prim/DA-Exception-AssertionFailed.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Exception.PreconditionFailed -o $(location lf-v{major}/daml-prim/DA-Exception-PreconditionFailed.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Types -o $(location lf-v{major}/daml-prim/DA-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Time.Types -o $(location lf-v{major}/daml-stdlib/DA-Time-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.NonEmpty.Types -o $(location lf-v{major}/daml-stdlib/DA-NonEmpty-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Date.Types -o $(location lf-v{major}/daml-stdlib/DA-Date-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Semigroup.Types -o $(location lf-v{major}/daml-stdlib/DA-Semigroup-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Set.Types -o $(location lf-v{major}/daml-stdlib/DA-Set-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Monoid.Types -o $(location lf-v{major}/daml-stdlib/DA-Monoid-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Logic.Types -o $(location lf-v{major}/daml-stdlib/DA-Logic-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Validation.Types -o $(location lf-v{major}/daml-stdlib/DA-Validation-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.Down -o $(location lf-v{major}/daml-stdlib/DA-Internal-Down.dalf) | ||
# These types are not serializable but they leak into typeclass methods so they need to be stable. | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.Any -o $(location lf-v{major}/daml-stdlib/DA-Internal-Any.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.Template -o $(location lf-v{major}/daml-stdlib/DA-Internal-Template.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Internal.Interface.AnyView.Types -o $(location lf-v{major}/daml-stdlib/DA-Internal-Interface-AnyView-Types.dalf) | ||
# These types are not serializable but they need to be stable so users can reuse functions from data-dependencies. | ||
$(location :generate-stable-package) --major-version {major} --module DA.Action.State.Type -o $(location lf-v{major}/daml-stdlib/DA-Action-State-Type.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Random.Types -o $(location lf-v{major}/daml-stdlib/DA-Random-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Stack.Types -o $(location lf-v{major}/daml-stdlib/DA-Stack-Types.dalf) | ||
$(location :generate-stable-package) --major-version {major} --module DA.Types.RoundingMode -o $(location lf-v{major}/daml-stdlib/DA-Types-RoundingMode.dalf) | ||
""".format(major = majorLfVersion), | ||
tools = [":generate-stable-package"], | ||
visibility = ["//visibility:public"], | ||
) | ||
for majorLfVersion in LF_MAJOR_VERSIONS | ||
] | ||
|
||
# If you change this you also need to update generateStablePackages in Development.IDE.Core.Rules.Daml | ||
filegroup( | ||
name = "stable-packages", | ||
srcs = [ | ||
dalf | ||
for dalfs in [ | ||
[ | ||
"lf-v{}/daml-prim/DA-Exception-ArithmeticError.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-AssertionFailed.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-GeneralError.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Exception-PreconditionFailed.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Internal-Erased.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Internal-NatSyn.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Internal-PromotedText.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/DA-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/GHC-Prim.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/GHC-Tuple.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-prim/GHC-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Action-State-Type.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Date-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Any.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Down.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Interface-AnyView-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Internal-Template.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Logic-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Monoid-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-NonEmpty-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Random-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Semigroup-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Set-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Stack-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Types-RoundingMode.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Time-Types.dalf".format(majorLfVersion), | ||
"lf-v{}/daml-stdlib/DA-Validation-Types.dalf".format(majorLfVersion), | ||
] | ||
for majorLfVersion in LF_MAJOR_VERSIONS | ||
] | ||
for dalf in dalfs | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
genrule( | ||
name = "stable-packages-list-srcs", | ||
outs = ["DA/Daml/StablePackagesList.hs"], | ||
cmd = """ | ||
$(location :generate-stable-package) gen-package-list -o $(location DA/Daml/StablePackagesList.hs) | ||
""", | ||
tools = [":generate-stable-package"], | ||
) | ||
|
||
# We generate this as a library rather than depending on :stable-packages-lib | ||
# to avoid a cyclical dependency between the daml-lf-proto and :stable-packages-lib | ||
# and to avoid having to encode the packages at runtime to get their package id. | ||
da_haskell_library( | ||
name = "stable-packages-list", | ||
srcs = ["DA/Daml/StablePackagesList.hs"], | ||
hackage_deps = [ | ||
"base", | ||
"containers", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//compiler/daml-lf-ast", | ||
], | ||
) | ||
|
||
generate_and_track_cabal("stable-packages-lib", "generate-stable-package") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
sdk/compiler/damlc/daml-stdlib-src/DA/Types/RoundingMode.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
module DA.Types.RoundingMode (RoundingMode (..)) where | ||
|
||
-- | Rounding modes for `BigNumeric` operations like `div` and `round` from `DA.BigNumeric`. | ||
data RoundingMode | ||
= RoundingUp -- ^ Round away from zero. | ||
| RoundingDown -- ^ Round towards zero. | ||
| RoundingCeiling -- ^ Round towards positive infinity. | ||
| RoundingFloor -- ^ Round towards negative infinity. | ||
| RoundingHalfUp | ||
-- ^ Round towards the nearest neighbor unless both neighbors | ||
-- are equidistant, in which case round away from zero. | ||
| RoundingHalfDown | ||
-- ^ Round towards the nearest neighbor unless both neighbors | ||
-- are equidistant, in which case round towards zero. | ||
| RoundingHalfEven | ||
-- ^ Round towards the nearest neighbor unless both neighbors | ||
-- are equidistant, in which case round towards the even neighbor. | ||
| RoundingUnnecessary | ||
-- ^ Do not round. Raises an error if the result cannot | ||
-- be represented without rounding at the targeted scale. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.