Skip to content

Commit

Permalink
Merge commit '9641fd5f83f5954add9fc147c9bd43e5a1abd885' into 10334-de…
Browse files Browse the repository at this point in the history
…tect-contract-table-desync
  • Loading branch information
S11001001 committed Sep 28, 2021
2 parents 6f11c86 + 9641fd5 commit 5da2571
Show file tree
Hide file tree
Showing 69 changed files with 666 additions and 291 deletions.
1 change: 0 additions & 1 deletion ci/cron/daily-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ jobs:
--detect.tools=BAZEL \
--detect.bazel.target=//... \
--detect.bazel.dependency.type=${BAZEL_DEPENDENCY_TYPE} \
--detect.policy.check.fail.on.severities=MAJOR,CRITICAL,BLOCKER \
--detect.notices.report=true \
--detect.code.location.name=digital-asset_daml_${BAZEL_DEPENDENCY_TYPE} \
--detect.timeout=1500
Expand Down
6 changes: 3 additions & 3 deletions compiler/daml-extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ node-fetch@^2.6.1:
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

nth-check@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.0.0.tgz#1bb4f6dac70072fc313e8c9cd1417b5074c0a125"
integrity sha512-i4sc/Kj8htBrAiH1viZ0TgU8Y5XqCaV/FziYK6TBczxmeKm3AEFWqqF3195yKudrarqy7Zu80Ra5dobFjn9X/Q==
version "2.0.1"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.0.1.tgz#2efe162f5c3da06a28959fbd3db75dbeea9f0fc2"
integrity sha512-it1vE95zF6dTT9lBsYbxvqh0Soy4SPowchj0UBGj/V6cTPnXXtQOPUbhZ6CmGzAD/rW22LQK6E96pcdJXk4A4w==
dependencies:
boolbase "^1.0.0"

Expand Down
1 change: 1 addition & 0 deletions compiler/damlc/daml-lf-conversion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ da_haskell_test(
srcs = glob(["test/**/*.hs"]),
hackage_deps = [
"base",
"containers",
"either",
"ghc-lib-parser",
"ghc-lib",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE PatternSynonyms #-}

-- | Encoding/decoding of metadata (i.e. non-semantically-relevant bindings) in LF,
Expand All @@ -22,11 +23,15 @@ module DA.Daml.LFConversion.MetadataEncoding
, encodeOverlapMode
, decodeOverlapMode
, mkMetadataStub
, moduleImportsName
, encodeModuleImports
, decodeModuleImports
) where

import Safe (readMay)
import Control.Monad (guard, liftM2)
import Data.List (sortOn)
import qualified Data.Set as S
import qualified Data.Text as T

import qualified "ghc-lib-parser" BasicTypes as GHC
Expand Down Expand Up @@ -104,6 +109,10 @@ minimalName (LF.TypeSynName xs) = LF.ExprValName ("$$minimal" <> T.concat xs)
pattern TEncodedStr :: T.Text -> LF.Type
pattern TEncodedStr x = LF.TStruct [(LF.FieldName x, LF.TUnit)]

decodeText :: LF.Type -> Maybe T.Text
decodeText (TEncodedStr x) = Just x
decodeText _ = Nothing

pattern TEncodedCon :: T.Text -> LF.Type -> LF.Type
pattern TEncodedCon a b = LF.TStruct [(LF.FieldName a, b)]

Expand Down Expand Up @@ -153,6 +162,49 @@ decodeOverlapMode = \case
]
_ -> Nothing

--------------------------
-- INSTANCE PROPAGATION --
--------------------------
moduleImportsName :: LF.ExprValName
moduleImportsName = LF.ExprValName "$$imports"

encodeModuleImports :: S.Set (LF.Qualified ()) -> LF.Type
encodeModuleImports = encodeTypeList encodeModuleImport . S.toList

encodeModuleImport :: LF.Qualified () -> LF.Type
encodeModuleImport q =
encodeTypeList id
[ encodePackageRef (LF.qualPackage q)
, encodeModuleName (LF.qualModule q)
]

encodePackageRef :: LF.PackageRef -> LF.Type
encodePackageRef = \case
LF.PRSelf -> LF.TUnit
LF.PRImport (LF.PackageId packageId) -> TEncodedStr packageId

encodeModuleName :: LF.ModuleName -> LF.Type
encodeModuleName (LF.ModuleName components) =
encodeTypeList TEncodedStr components

decodeModuleImports :: LF.Type -> Maybe (S.Set (LF.Qualified ()))
decodeModuleImports = fmap S.fromList . decodeTypeList decodeModuleImport

decodeModuleImport :: LF.Type -> Maybe (LF.Qualified ())
decodeModuleImport x = do
[p, m] <- decodeTypeList Just x
packageRef <- decodePackageRef p
moduleName <- decodeModuleName m
pure (LF.Qualified packageRef moduleName ())

decodePackageRef :: LF.Type -> Maybe LF.PackageRef
decodePackageRef = \case
LF.TUnit -> pure LF.PRSelf
TEncodedStr packageId -> pure (LF.PRImport (LF.PackageId packageId))
_ -> Nothing

decodeModuleName :: LF.Type -> Maybe LF.ModuleName
decodeModuleName = fmap LF.ModuleName . decodeTypeList decodeText

---------------------
-- STUB GENERATION --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Test.Tasty.HUnit
import Data.Either.Combinators (whenLeft, whenRight)
import Data.Maybe (isNothing)
import Data.Ratio
import qualified Data.Set as S
import qualified Data.Text as T

import DA.Daml.LFConversion
Expand Down Expand Up @@ -58,8 +59,33 @@ metadataEncodingTests = testGroup "MetadataEncoding"
, ("overlaps", GHC.Overlaps GHC.NoSourceText)
, ("incoherent", GHC.Incoherent GHC.NoSourceText)
]
, roundtripTests "module imports" encodeModuleImports decodeModuleImports
[ ("()", S.empty)
, ("(Foo.Bar)"
, S.fromList
[ mkImport Nothing ["Foo", "Bar"]])
, ("(\"foo\" Foo.Bar)"
, S.fromList
[ mkImport (Just "foo") ["Foo", "Bar"]])
, ("(Foo.Bar, Baz.Qux.Florp)"
, S.fromList
[ mkImport Nothing ["Foo", "Bar"]
, mkImport Nothing ["Baz", "Qux", "Florp"]])
, ("(\"foo\" Foo.Bar, \"baz\" Baz.Qux.Florp)"
, S.fromList
[ mkImport (Just "foo") ["Foo", "Bar"]
, mkImport (Just "baz") ["Baz", "Qux", "Florp"]])
]
]

mkImport :: Maybe T.Text -> [T.Text] -> LF.Qualified ()
mkImport mPackage moduleComponents =
LF.Qualified
{ qualPackage = maybe LF.PRSelf (LF.PRImport . LF.PackageId) mPackage
, qualModule = LF.ModuleName moduleComponents
, qualObject = ()
}

roundtripTests :: (Eq a) => String -> (a -> b) -> (b -> Maybe a) -> [(String, a)] -> TestTree
roundtripTests groupName encode decode examples =
roundtripTestsPartial groupName (Just . encode) decode [] examples
Expand Down
37 changes: 4 additions & 33 deletions infra/es_cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ emit_build_events() {
jq -c \
--slurpfile job_md "$job/job-md.json" \
--arg cmd "$cmd" \
--arg index "$(index "$job" events)" \
--arg index "$(index "$job")" \
--arg job "$job" \
< "$file" \
'
Expand All @@ -748,20 +748,6 @@ emit_build_events() {
buildEvent: .
}
'
jq -c \
--slurpfile job_md "$job/job-md.json" \
--arg cmd "$cmd" \
--arg index "$(index "$job" jobs)" \
--arg job "$job" \
< "$file" \
--slurp \
'
{ index: { _index: $index, _id: ($job + "-" + $cmd + "-events") } },
{ job: $job_md[0],
command: { name: $cmd },
buildEvent: .
}
'
}
emit_trace_events() {
Expand All @@ -772,7 +758,7 @@ emit_trace_events() {
jq -c \
--slurpfile job_md "$job/job-md.json" \
--arg cmd "$cmd" \
--arg index "$(index "$job" events)" \
--arg index "$(index "$job")" \
--arg job "$job" \
< "$file" \
'
Expand All @@ -784,19 +770,6 @@ emit_trace_events() {
traceEvent: .value
}
'
jq -c \
--slurpfile job_md "$job/job-md.json" \
--arg cmd "$cmd" \
--arg index "$(index "$job" jobs)" \
--arg job "$job" \
< "$file" \
'
{ index: { _index: $index, _id: ($job + "-" + $cmd + "-profile") } },
{ job: $job_md[0],
command: { name: $cmd },
traceEvent: .traceEvents
}
'
}
bulk_upload() {
Expand Down Expand Up @@ -863,8 +836,7 @@ push() {
index() {
local job prefix
job="$1"
prefix="$2"
echo "$prefix-$(echo $job | cut -c1-10)"
echo "events-$(echo $job | cut -c1-10)"
}
pid=$$
Expand Down Expand Up @@ -895,8 +867,7 @@ for tar in $todo; do
job=$(basename $${tar%.tar.gz})
cd $(dirname $tar)
if ! [ -f $DONE/$job ]; then
ensure_index "$job" "$(index "$job" jobs)"
ensure_index "$job" "$(index "$job" events)"
ensure_index "$job" "$(index "$job")"
tar --force-local -x -z -f "$(basename "$tar")"
patch "$job"
push "$job"
Expand Down
3 changes: 2 additions & 1 deletion language-support/ts/packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"marked": "^2.0.0",
"**/y18n": "^4.0.1",
"**/@types/react-test-renderer": "^16.9.3",
"**/hosted-git-info": "^4.0.2"
"**/hosted-git-info": "^4.0.2",
"**/string-width": "^4.2.3"
}
}
44 changes: 21 additions & 23 deletions language-support/ts/packages/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,11 @@ ansi-regex@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==

ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==

ansi-styles@^3.2.0, ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
Expand Down Expand Up @@ -1509,11 +1514,6 @@ emittery@^0.8.1:
resolved "https://registry.yarnpkg.com/emittery/-/emittery-0.8.1.tgz#bb23cc86d03b30aa75a7f734819dee2e1ba70860"
integrity sha512-uDfvUjVrfGJJhymx/kz6prltenw1u7WrCg1oa94zYY8xxVpLLUu045LAT0dhDZdXG58/EpPL/5kA180fQ/qudg==

emoji-regex@^7.0.1:
version "7.0.3"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down Expand Up @@ -3294,25 +3294,16 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

string-width@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==
dependencies:
emoji-regex "^7.0.1"
is-fullwidth-code-point "^2.0.0"
strip-ansi "^5.1.0"

string-width@^4.1.0, string-width@^4.2.0:
version "4.2.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5"
integrity sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==
string-width@^3.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.0"
strip-ansi "^6.0.1"

strip-ansi@^5.1.0, strip-ansi@^5.2.0:
strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
Expand All @@ -3326,6 +3317,13 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"

strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-bom@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878"
Expand Down Expand Up @@ -3425,9 +3423,9 @@ tmp@^0.0.33:
os-tmpdir "~1.0.2"

tmpl@1.0.x:
version "1.0.4"
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
integrity sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=
version "1.0.5"
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"
integrity sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==

to-fast-properties@^2.0.0:
version "2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import com.daml.ledger.validator.{
LedgerStateOperations,
TimedLedgerStateOperations,
}
import com.daml.logging.LoggingContext
import com.daml.metrics.Metrics

import scala.concurrent.{ExecutionContext, Future}

final class InMemoryLedgerStateAccess(state: InMemoryState, metrics: Metrics)
extends LedgerStateAccess[Index] {
override def inTransaction[T](body: LedgerStateOperations[Index] => Future[T])(implicit
executionContext: ExecutionContext
override def inTransaction[T](
body: LedgerStateOperations[Index] => Future[T]
)(implicit
executionContext: ExecutionContext,
loggingContext: LoggingContext,
): Future[T] =
state.write { (log, state) =>
body(new TimedLedgerStateOperations(new InMemoryLedgerStateOperations(log, state), metrics))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.daml.ledger.on.memory.InMemoryState.MutableLog
import com.daml.ledger.participant.state.kvutils.api.LedgerRecord
import com.daml.ledger.participant.state.kvutils.{OffsetBuilder, Raw}
import com.daml.ledger.validator.BatchingLedgerStateOperations
import com.daml.logging.LoggingContext

import scala.concurrent.{ExecutionContext, Future}

Expand All @@ -19,20 +20,23 @@ final class InMemoryLedgerStateOperations(

override def readState(
keys: Iterable[Raw.StateKey]
)(implicit executionContext: ExecutionContext): Future[Seq[Option[Raw.Envelope]]] =
)(implicit
executionContext: ExecutionContext,
loggingContext: LoggingContext,
): Future[Seq[Option[Raw.Envelope]]] =
Future.successful(keys.view.map(state.get).toSeq)

override def writeState(
keyValuePairs: Iterable[Raw.StateEntry]
)(implicit executionContext: ExecutionContext): Future[Unit] = {
)(implicit executionContext: ExecutionContext, loggingContext: LoggingContext): Future[Unit] = {
state ++= keyValuePairs
Future.unit
}

override def appendToLog(
key: Raw.LogEntryId,
value: Raw.Envelope,
)(implicit executionContext: ExecutionContext): Future[Index] =
)(implicit executionContext: ExecutionContext, loggingContext: LoggingContext): Future[Index] =
Future.successful(appendEntry(log, LedgerRecord(_, key, value)))

}
Expand Down
Loading

0 comments on commit 5da2571

Please sign in to comment.