Skip to content

Commit

Permalink
Drop support for DAML-LF 1.3 from damlc (digital-asset#1445)
Browse files Browse the repository at this point in the history
* Drop support for DAML-LF 1.3 from damlc

This means `damlc` now only supports versions allowing arbitrary expressions
as contract keys. This is very helpful for the upcoming new template
de/re-sugaring underpinning generic templates.

* Unpin a few DAML-LF target versions in tests

* Fix golden tests

* Adapt changelog to rebase

* Rename DAML-LF scenario tests to 1.dev

* Update tests to --target 1.dev

* Fix release notes
  • Loading branch information
hurryabit authored Jun 3, 2019
1 parent 9f80f4c commit 5396f42
Show file tree
Hide file tree
Showing 28 changed files with 33 additions and 125 deletions.
9 changes: 1 addition & 8 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ data Version
data MinorVersion = PointStable Int | PointDev
deriving (Eq, Data, Generic, NFData, Ord, Show)

-- | DAML-LF version 1.3.
version1_3 :: Version
version1_3 = V1 $ PointStable 3

-- | DAML-LF version 1.4.
version1_4 :: Version
version1_4 = V1 $ PointStable 4
Expand All @@ -41,7 +37,7 @@ versionDev :: Version
versionDev = V1 PointDev

supportedInputVersions :: [Version]
supportedInputVersions = [version1_3, version1_4, version1_5, versionDev]
supportedInputVersions = [version1_4, version1_5, versionDev]

supportedOutputVersions :: [Version]
supportedOutputVersions = supportedInputVersions
Expand All @@ -52,9 +48,6 @@ data Feature = Feature
, featureMinVersion :: !Version
}

featureComplexContractKeys :: Feature
featureComplexContractKeys = Feature "Complex contract keys" version1_4

featureSerializablePolymorphicContractIds :: Feature
featureSerializablePolymorphicContractIds = Feature "Serializable polymorphic contract ids" version1_5

Expand Down
42 changes: 3 additions & 39 deletions compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/EncodeV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -428,54 +428,18 @@ encodeTemplate version Template{..} =
, P.defTemplateAgreement = encodeExpr version tplAgreement
, P.defTemplateChoices = encodeNameMap encodeTemplateChoice version tplChoices
, P.defTemplateLocation = encodeSourceLoc <$> tplLocation
, P.defTemplateKey = fmap (encodeTemplateKey version tplParam) tplKey
, P.defTemplateKey = fmap (encodeTemplateKey version) tplKey
}

encodeTemplateKey :: Version -> ExprVarName -> TemplateKey -> P.DefTemplate_DefKey
encodeTemplateKey version templateVar TemplateKey{..} = P.DefTemplate_DefKey
encodeTemplateKey :: Version -> TemplateKey -> P.DefTemplate_DefKey
encodeTemplateKey version TemplateKey{..} = P.DefTemplate_DefKey
{ P.defTemplate_DefKeyType = encodeType version tplKeyType
, P.defTemplate_DefKeyKeyExpr =
if version `supports` featureComplexContractKeys
then
Just $ P.DefTemplate_DefKeyKeyExprComplexKey $ encodeExpr' version tplKeyBody
else
case exprToKeyExpr templateVar tplKeyBody of
Left err -> error err
Right x -> Just $ P.DefTemplate_DefKeyKeyExprKey $ encodeKeyExpr version x
, P.defTemplate_DefKeyMaintainers = encodeExpr version tplKeyMaintainers
}


data KeyExpr =
KeyExprProjections ![(TypeConApp, FieldName)]
| KeyExprRecord !TypeConApp ![(FieldName, KeyExpr)]

encodeKeyExpr :: Version -> KeyExpr -> P.KeyExpr
encodeKeyExpr version = P.KeyExpr . Just . \case
KeyExprProjections projs -> P.KeyExprSumProjections $ P.KeyExpr_Projections $ V.fromList $ do
(tyCon, fld) <- projs
return (P.KeyExpr_Projection (encodeTypeConApp version tyCon) (encodeName unFieldName fld))
KeyExprRecord tyCon flds -> P.KeyExprSumRecord $ P.KeyExpr_Record (encodeTypeConApp version tyCon) $ V.fromList $ do
(fldName, ke) <- flds
return $ P.KeyExpr_RecordField (encodeName unFieldName fldName) $ Just $ encodeKeyExpr version ke

exprToKeyExpr :: ExprVarName -> Expr -> Either String KeyExpr
exprToKeyExpr tplParameter = \case
ELocation _loc expr ->
exprToKeyExpr tplParameter expr
EVar var -> if var == tplParameter
then Right (KeyExprProjections [])
else Left ("Expecting variable " ++ show tplParameter ++ " in key expression, got " ++ show var)
ERecProj tyCon fld e -> do
keyExpr <- exprToKeyExpr tplParameter e
case keyExpr of
KeyExprProjections projs -> return (KeyExprProjections (projs ++ [(tyCon, fld)]))
KeyExprRecord{} -> Left "Trying to project out of a record in key expression"
ERecCon tyCon flds -> do
keyFlds <- mapM (\(lbl, e) -> (lbl, ) <$> exprToKeyExpr tplParameter e) flds
return (KeyExprRecord tyCon keyFlds)
e -> Left ("Bad key expression " ++ show e)

encodeTemplateChoice :: Version -> TemplateChoice -> P.TemplateChoice
encodeTemplateChoice version TemplateChoice{..} =
P.TemplateChoice
Expand Down
23 changes: 0 additions & 23 deletions compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -529,26 +529,6 @@ checkTemplate m t@(Template _loc tpl param precond signatories observers text ch
where
withPart p = withContext (ContextTemplate m t p)

checkValidKeyExpr :: MonadGamma m => Expr -> m ()
checkValidKeyExpr = \case
ELocation _loc expr ->
checkValidKeyExpr expr
ERecCon _typ recordExpr -> do
traverse_ (checkValidKeyExpr . snd) recordExpr
expr ->
checkValidProjectionsKey expr

checkValidProjectionsKey :: MonadGamma m => Expr -> m ()
checkValidProjectionsKey = \case
ELocation _loc expr ->
checkValidProjectionsKey expr
EVar _var ->
pure ()
ERecProj _typ _field rec ->
checkValidProjectionsKey rec
expr ->
throwWithContext (EInvalidKeyExpression expr)

checkFeature :: MonadGamma m => Feature -> m ()
checkFeature feature = do
version <- getLfVersion
Expand All @@ -559,9 +539,6 @@ checkTemplateKey :: MonadGamma m => ExprVarName -> Qualified TypeConName -> Temp
checkTemplateKey param tcon TemplateKey{..} = do
introExprVar param (TCon tcon) $ do
checkType tplKeyType KStar
version <- getLfVersion
unless (version `supports` featureComplexContractKeys) $
checkValidKeyExpr tplKeyBody
checkExpr tplKeyBody tplKeyType
checkExpr tplKeyMaintainers (tplKeyType :-> TList TParty)

Expand Down
1 change: 0 additions & 1 deletion daml-foundations/daml-ghc/package-database/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ load(
)

DAML_LF_VERSIONS = [
"1.3",
"1.4",
"1.5",
"1.dev",
Expand Down
6 changes: 2 additions & 4 deletions daml-lf/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ TEST_FILES = \
daml_compile(
name = name,
main_src = "%s.daml" % name,
target = "1.3",
visibility = ["//daml-lf:__subpackages__"],
)
for name in TEST_FILES
Expand All @@ -28,7 +27,6 @@ TEST_FILES = \
daml_compile(
name = "Optional",
main_src = "Optional.daml",
target = "1.3",
visibility = ["//daml-lf:__subpackages__"],
)

Expand Down Expand Up @@ -56,7 +54,7 @@ daml_compile(

[
sh_test(
name = "test-scenario-1-3-" + file.split("/")[2],
name = "test-scenario-1-dev-" + file.split("/")[2],
size = "medium",
srcs = ["scenario/test.sh"],
args = [
Expand All @@ -74,5 +72,5 @@ daml_compile(
"@bazel_tools//tools/bash/runfiles",
],
)
for file in glob(["scenario/daml-1.3/*/Test.daml"])
for file in glob(["scenario/daml-1.dev/*/Test.daml"])
]
3 changes: 1 addition & 2 deletions daml-lf/tests/scenario/actualize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ TESTMAIN=$1
TESTDIR="$(dirname $TESTMAIN)"
TESTDAR="$TESTDIR/Main.dar"
BAZEL_BIN="$(bazel info bazel-bin)"
GHC_PRIM_DALF=${BAZEL_BIN}/daml-foundations/daml-ghc/package-database/deprecated/daml-prim-1.3.dalf
REGEX_HIDE_HASHES="s,@[a-z0-9]{8},@XXXXXXXX,g"

bazel build //daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app
../../../bazel-bin/daml-foundations/daml-tools/da-hs-damlc-app/da-hs-damlc-app package --debug --target 1.3 $TESTMAIN main -o $TESTDAR
../../../bazel-bin/daml-foundations/daml-tools/da-hs-damlc-app/da-hs-damlc-app package --debug --target 1.dev $TESTMAIN main -o $TESTDAR

bazel build //daml-lf/repl:repl
../../../bazel-bin/daml-lf/repl/repl test Test:run $TESTDAR | sed '1d' | sed -E "$REGEX_HIDE_HASHES" | tee ${TESTDIR}/EXPECTED.ledger.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
transactions:
TX #0 1970-01-01T00:00:00Z [Test:74]
#0:0
│ archived by #8:1
│ referenced by #4:0, #5:0, #8:0, #8:1
│ archived by #8:0
│ referenced by #4:0, #5:0, #8:0
│ known to (since): Alice (#0), Bob (#0)
└─> create Test:TextKey@XXXXXXXX
with: { p = 'Alice', k = "some-key", disclosedTo = ['Bob'] } value-version: 1
Expand Down Expand Up @@ -38,9 +38,6 @@ not found

TX #8 1970-01-01T00:00:00Z [Test:109]
#8:0
└─> ensure active #0:0

#8:1
│ known to (since): Alice (#8), Bob (#8)
└─> Alice exercises TextKeyChoice:Test:TextKey@XXXXXXXX on #0:0
with { } value-version: 1
Expand All @@ -54,24 +51,21 @@ not found

TX #10 1970-01-01T00:00:00Z [Test:118]
#10:0
│ archived by #11:1
│ referenced by #11:0, #11:1
│ archived by #11:0
│ referenced by #11:0
│ known to (since): Alice (#10), Bob (#10)
└─> create Test:TextKey@XXXXXXXX
with: { p = 'Alice', k = "some-key-2", disclosedTo = ['Bob'] } value-version: 1
key { _1 = 'Alice', _2 = "some-key-2" } value-version: 1

TX #11 1970-01-01T00:00:00Z [Test:123]
#11:0
└─> ensure active #10:0

#11:1
│ known to (since): Alice (#11), Bob (#11)
└─> Alice exercises TextKeyChoice:Test:TextKey@XXXXXXXX on #10:0
with { } value-version: 1


#11:2
#11:1
└─> lookup by key Test:TextKey@XXXXXXXX
key { _1 = 'Alice', _2 = "some-key-2" } value-version: 1
not found
Expand All @@ -91,57 +85,51 @@ found #12:0

TX #13 1970-01-01T00:00:00Z [Test:137]
#13:0
│ referenced by #14:0, #14:1
│ referenced by #14:0
│ known to (since): Alice (#13)
└─> create Test:CreateAndLookup@XXXXXXXX
with: { p = 'Alice', k = "same-choice-key" } value-version: 1

TX #14 1970-01-01T00:00:00Z [Test:141]
#14:0
└─> ensure active #13:0

#14:1
│ known to (since): Alice (#14)
└─> Alice exercises Good:Test:CreateAndLookup@XXXXXXXX on #13:0
with { } value-version: 1
children:
#14:2
│ referenced by #14:3
#14:1
│ referenced by #14:2
│ known to (since): Alice (#14)
└─> create Test:TextKey@XXXXXXXX
with: { p = 'Alice', k = "same-choice-key", disclosedTo = [] } value-version: 1
key { _1 = 'Alice', _2 = "same-choice-key" } value-version: 1
#14:3
#14:2
│ known to (since): Alice (#14)
└─> lookup by key Test:TextKey@XXXXXXXX
key { _1 = 'Alice', _2 = "same-choice-key" } value-version: 1
found #14:2
found #14:1

mustFailAt 'Alice' [Test:144]

TX #16 1970-01-01T00:00:00Z [Test:148]
#16:0
│ referenced by #16:1, #16:2, #16:3
│ referenced by #16:1, #16:2
│ known to (since): Alice (#16)
└─> create Test:TextKey@XXXXXXXX
with: { p = 'Alice', k = "non-consuming-choice", disclosedTo = [] } value-version: 1
key { _1 = 'Alice', _2 = "non-consuming-choice" } value-version: 1

#16:1
└─> ensure active #16:0

#16:2
│ known to (since): Alice (#16)
└─> Alice exercises TextKeyNonconsumingChoice:Test:TextKey@XXXXXXXX on #16:0
with { } value-version: 1


#16:3
#16:2
└─> lookup by key Test:TextKey@XXXXXXXX
key { _1 = 'Alice', _2 = "non-consuming-choice" } value-version: 1
found #16:0

mustFailAt 'Alice' [Test:158]

active contracts:
#12:0, #13:0, #14:2, #16:0
#12:0, #13:0, #14:1, #16:0
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
transactions:
TX #0 1970-01-01T00:00:00Z [Test:12]
#0:0
│ referenced by #2:2
│ referenced by #2:1
│ known to (since): Alice (#0), AlicesBank (#0), Bob (#2)
└─> create Test:Iou@XXXXXXXX
with: { payer = 'AlicesBank', owner = 'Alice', amount = Test:Amount@XXXXXXXX{ value = 1.0000000000, currency = "USD" } } value-version: 1

TX #1 1970-01-01T00:00:00Z [Test:17]
#1:0
│ referenced by #2:0, #2:1
│ referenced by #2:0
│ known to (since): AlicesBank (#1), Bob (#1)
└─> create Test:DivulgeIouByExercise@XXXXXXXX
with: { payer = 'AlicesBank', divulgee = 'Bob' } value-version: 1

TX #2 1970-01-01T00:00:00Z [Test:20]
#2:0
└─> ensure active #1:0

#2:1
│ known to (since): AlicesBank (#2), Bob (#2)
└─> AlicesBank exercises Divulge:Test:DivulgeIouByExercise@XXXXXXXX on #1:0
with { ref = #0:0 } value-version: 1
children:
#2:2
#2:1
│ known to (since): AlicesBank (#2), Bob (#2)
└─> ensure active #0:0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ mustFailAt 'Alice' [Test:123]

TX #10 1969-12-31T23:58:20Z [Test:128]
#10:0
│ archived by #11:1
│ referenced by #11:0, #11:1
│ archived by #11:0
│ referenced by #11:0
│ known to (since): Alice (#10), Bob (#10)
└─> create Test:ToTwoParties@XXXXXXXX
with: { p = 'Alice', p2 = 'Bob' } value-version: 1

TX #11 1969-12-31T23:58:20Z [Test:129]
#11:0
└─> ensure active #10:0

#11:1
│ known to (since): Alice (#11), Bob (#11)
└─> Bob exercises Convert:Test:ToTwoParties@XXXXXXXX on #10:0
with { } value-version: 1
children:
#11:2
#11:1
│ known to (since): Alice (#11), Bob (#11)
└─> create Test:TwoParties@XXXXXXXX
with: { p = 'Alice', p2 = 'Bob' } value-version: 1
Expand Down Expand Up @@ -88,4 +85,4 @@ TX #21 1969-12-31T23:58:20Z [Test:345]
mustFailAt 'Alice' [Test:346]

active contracts:
#4:0, #7:0, #11:2, #13:0, #16:0, #18:0, #21:0
#4:0, #7:0, #11:1, #13:0, #16:0, #18:0, #21:0
4 changes: 1 addition & 3 deletions daml-lf/tests/scenario/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ TESTMAIN=$(rlocation "$TEST_WORKSPACE/$3")
TESTDIR="$(dirname $TESTMAIN)"
TESTDAR="$TESTDIR/Main.dar"

TARGET="1.3"

REGEX_HIDE_HASHES="s,@[a-z0-9]{8},@XXXXXXXX,g"

$DAMLC package --debug --target $TARGET $TESTMAIN 'main' -o $TESTDAR
$DAMLC package --debug $TESTMAIN 'main' -o $TESTDAR

$REPL test Test:run $TESTDAR | sed '1d' | sed -E "$REGEX_HIDE_HASHES" > ${TESTDIR}/ACTUAL.ledger

Expand Down
5 changes: 5 additions & 0 deletions docs/source/support/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ This page contains release notes for the SDK.
HEAD — ongoing
--------------

DAML Compiler
~~~~~~~~~~~~~

- **BREAKING CHANGE**: Drop support for DAML-LF 1.3. Compiling to DAML-LF 1.4 should work without any code changes, although we highly recommend not specifying a target DAML-LF version at all. (The ledger server still supports DAML-LF 1.3.)

DAML Standard Library
~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion extractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ TEST_DARS = [
daml_compile(
name = darmod,
main_src = "src/test/resources/damls/%s.daml" % darmod,
target = "1.3",
)
for darmod in TEST_DARS
]
Expand Down
1 change: 0 additions & 1 deletion language-support/java/codegen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ da_scala_test(
daml_compile(
name = "test-daml",
main_src = "src/test/daml/test.daml",
target = "1.3",
)

jar_jar(
Expand Down
Loading

0 comments on commit 5396f42

Please sign in to comment.