Skip to content

Commit ecbf550

Browse files
[WIP] Initial implementation
1 parent c8a0078 commit ecbf550

File tree

22 files changed

+215
-124
lines changed

22 files changed

+215
-124
lines changed

sdk/compatibility/versions/UpdateVersions.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ renderVersionsFile versions =
5151
, "# Update versions/UpdateVersions.hs instead."
5252
]
5353
, [ "sdk_versions = [" ]
54-
, map renderVersion (Map.keys versions <> [headVersion])
54+
, map renderTodoVersion (Map.keys versions <> [headVersion])
5555
, [ "]"]
5656
, [ "platform_versions = [" ]
57-
, map renderVersion (Map.keys versions <> [headVersion])
57+
, map renderTodoVersion (Map.keys versions <> [headVersion])
5858
, [ "]" ]
5959
, [ "stable_versions = [" ]
60-
, map renderVersion (Map.keys stableVersions <> [headVersion])
60+
, map renderTodoVersion (Map.keys stableVersions <> [headVersion])
6161
, [ "]" ]
6262
, [ "latest_stable_version = \"" <> SemVer.toText latestVersion <> "\"" ]
6363
, [ "version_sha256s = {"]
@@ -79,7 +79,7 @@ renderVersionsFile versions =
7979
, [ " }," ]
8080
]
8181
renderDigest digest = T.pack $ show (convertToBase Base16 digest :: ByteString)
82-
renderVersion ver = " \"" <> SemVer.toText ver <> "\","
82+
renderTodoVersion ver = " \"" <> SemVer.toText ver <> "\","
8383
stableVersions = Map.filterWithKey (const . null . view SemVer.release) versions
8484
firstVersion = SemVer.version 3 3 0 [fromJust $ SemVer.textual "snapshot", SemVer.numeric 20250930, SemVer.numeric 0] []
8585
latestVersion = if Map.null versions then firstVersion else fst $ Map.findMax versions

sdk/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version/VersionType.hs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ import GHC.Generics
2121
import qualified DA.Daml.LF.Ast.Range as R
2222
import DA.Pretty
2323

24+
type Patch = Int
25+
2426
-- | Daml-LF version of an archive payload.
25-
data Version = Version
27+
data Version = VersionP
2628
{ versionMajor :: MajorVersion
2729
, versionMinor :: MinorVersion
30+
, patch :: Patch
2831
}
2932
deriving (Eq, Data, Generic, NFData, Show, Ord, Aeson.FromJSON, Aeson.ToJSON)
3033

@@ -81,16 +84,28 @@ renderMinorVersion = \case
8184
PointStaging minor -> show minor
8285
PointDev -> "dev"
8386

84-
renderVersion :: Version -> String
85-
renderVersion (Version major minor) =
87+
renderPatch :: Patch -> String
88+
renderPatch = show
89+
90+
renderVersionWithPatch :: Version -> String
91+
renderVersionWithPatch (VersionP major minor patch) =
92+
renderMajorVersion major <> "." <> renderMinorVersion minor <> "." <> renderPatch patch
93+
94+
--TODO: convert usages of toBeDecidedRenderVersion to renderVersion
95+
--wherever we can, or (back to) renderTodoVersion everywhere else
96+
renderVersionWithoutPatch :: Version -> String
97+
renderVersionWithoutPatch (VersionP major minor _) =
8698
renderMajorVersion major <> "." <> renderMinorVersion minor
8799

100+
renderTodoVersion :: Version -> String
101+
renderTodoVersion = renderVersionWithoutPatch
102+
88103
-- | A datatype describing a set of language versions. Used in the definition of
89104
-- 'Feature' below.
90105
type VersionReq = R.Range Version
91106

92107
instance Pretty Version where
93-
pPrint = string . renderVersion
108+
pPrint = string . renderTodoVersion
94109

95110
data Feature = Feature
96111
{ featureName :: !T.Text

sdk/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version/VersionUtil.hs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@ import Data.Char (isDigit)
1111
import qualified DA.Daml.LF.Ast.Range as R
1212
import qualified Data.Text as T
1313
import Safe (headMay)
14-
import Text.ParserCombinators.ReadP (ReadP, pfail, readP_to_S, (+++), munch1)
14+
import Text.ParserCombinators.ReadP (ReadP, pfail, readP_to_S, (+++), (<++), eof, munch1)
1515
import qualified Text.ParserCombinators.ReadP as ReadP
1616
import qualified Data.Map.Strict as MS
17+
import qualified Data.Map as M
1718

1819
import Control.Lens (Getting, view)
1920
import Control.Monad.Reader.Class
2021

2122
import DA.Daml.LF.Ast.Version.VersionType
23+
import DA.Daml.LF.Ast.Version.GeneratedVersions
2224
import DA.Daml.LF.Ast.Version.GeneratedFeatures
2325

26+
validatePatch :: Version -> Bool
27+
validatePatch (VersionP _ PointDev _) = True
28+
validatePatch (VersionP _ minor patch) =
29+
maybe False (\patches -> patch `elem` patches) (M.lookup minor allowedPatchMap)
30+
2431
-- | x `canDependOn` y if dars compiled to version x can depend on dars compiled
2532
-- to version y.
2633
canDependOn :: Version -> Version -> Bool
27-
canDependOn (Version major1 minor1) (Version major2 minor2) =
34+
canDependOn (VersionP major1 minor1 _) (VersionP major2 minor2 _) =
2835
major1 == major2 && minor1 >= minor2
2936

3037
isDevVersion :: Version -> Bool
@@ -107,6 +114,9 @@ readMinorVersion = readStable +++ readDev
107114
readStable = PointStable <$> readSimpleInt
108115
readDev = PointDev <$ ReadP.string "dev"
109116

117+
readPatch :: ReadP Patch
118+
readPatch = readSimpleInt
119+
110120
-- >>> parseMinorVersion "14"
111121
-- Just (PointStable 14)
112122
-- >>> parseMinorVersion "dev"
@@ -117,20 +127,32 @@ parseMinorVersion :: String -> Maybe MinorVersion
117127
parseMinorVersion = headMay . map fst . readP_to_S readMinorVersion
118128

119129
readVersion :: ReadP Version
120-
readVersion = do
121-
major <- readMajorVersion
122-
_ <- ReadP.char '.'
123-
minor <- readMinorVersion
124-
pure (Version major minor)
130+
readVersion = readPatchfull <++ readPatchless
131+
where
132+
readPatchfull = do
133+
major <- readMajorVersion
134+
_ <- ReadP.char '.'
135+
minor <- readMinorVersion
136+
_ <- ReadP.char '.'
137+
patch <- readPatch
138+
pure (VersionP major minor patch)
139+
140+
readPatchless = do
141+
major <- readMajorVersion
142+
_ <- ReadP.char '.'
143+
minor <- readMinorVersion
144+
pure (Version major minor)
125145

126146
-- >>> parseVersion "2.dev"
127-
-- Just (Version {versionMajor = V2, versionMinor = PointDev})
147+
-- Just (VersionP {versionMajor = V2, versionMinor = PointDev, patch = 0})
128148
-- >>> parseVersion "2.15"
129-
-- Just (Version {versionMajor = V2, versionMinor = PointStable 15})
149+
-- Just (VersionP {versionMajor = V2, versionMinor = PointStable 15, patch = 0})
150+
-- >>> parseVersion "2.2.0"
151+
-- Just (VersionP {versionMajor = V2, versionMinor = PointStable 2, patch = 0})
130152
-- >>> parseVersion "2.garbage"
131153
-- Nothing
132154
parseVersion :: String -> Maybe Version
133-
parseVersion = headMay . map fst . readP_to_S readVersion
155+
parseVersion = headMay . map fst . readP_to_S (readVersion <* eof)
134156

135157
-- The extended implementation
136158
ifVersionWith :: MonadReader r m

sdk/compiler/daml-lf-ast/test/DA/Daml/LF/Ast/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ substitutionTests = testGroup "substitution"
296296
typeSynTests :: TestTree
297297
typeSynTests =
298298
testGroup "type synonyms" $
299-
[ testGroup (renderVersion version)
299+
[ testGroup (renderTodoVersion version)
300300
[ testGroup "happy" (map (mkHappyTestcase version) happyExamples)
301301
, testGroup "sad" (map (mkSadTestcase version) sadExamples)
302302
, testGroup "bad" (map (mkBadTestcase version) badDefSets)

sdk/compiler/daml-lf-proto-decode/src/DA/Daml/LF/Proto3/Decode.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import qualified DA.Daml.LF.Proto3.DecodeV2 as DecodeV2
2020
import qualified DA.Daml.LF.Ast as LF
2121
import DA.Daml.StablePackages (allStablePackageIds)
2222

23+
import Control.Monad (when)
2324
import Control.Monad.Except (throwError)
2425
import Control.Lens (over, _Left)
2526
import Data.Int (Int32)
@@ -35,8 +36,8 @@ decodeLfVersion major pkgId minorText patchInt = do
3536
minor <- if
3637
| Just minor <- LF.parseMinorVersion (T.unpack minorText) -> pure minor
3738
| otherwise -> unsupportedMinor
38-
_ <- if patchInt == 0 then pure () else unsupportedPatch minor patchInt
39-
let version = LF.Version major minor
39+
let version = LF.VersionP major minor (fromIntegral patchInt)
40+
when (not $ LF.validatePatch version) $ unsupportedPatch minor patchInt
4041
if pkgId `elem` allStablePackageIds || version `elem` LF.compilerInputLfVersions
4142
then pure version
4243
else unsupportedMinor

sdk/compiler/daml-lf-proto-encode/src/DA/Daml/LF/Proto3/Encode.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ import qualified Data.ByteString.Lazy as BSL
1616

1717
encodePayload :: Package -> ArchivePayload
1818
encodePayload package = case packageLfVersion package of
19-
(Version V2 minor) ->
19+
(VersionP V2 minor patch) ->
2020
let payload = ArchivePayloadSumDamlLf2 $ BSL.toStrict $ Proto.toLazyByteString (EncodeV2.encodePackage package)
21-
in ArchivePayload (TL.pack $ renderMinorVersion minor) 0 (Just payload)
21+
in ArchivePayload (TL.pack $ renderMinorVersion minor) (fromIntegral patch) (Just payload)

sdk/compiler/daml-lf-tools/tests/DA/Daml/LF/Simplifier/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ main = defaultMain $ testGroup "DA.Daml.LF.Simplifier"
2525
-- flags. The simplifier may thus behave differently based on the version of LF
2626
-- and thus we may need to test different LF versions as they diverge over time.
2727
constantLiftingTests :: Version -> TestTree
28-
constantLiftingTests version = testGroup ("Constant Lifting " <> renderVersion version)
28+
constantLiftingTests version = testGroup ("Constant Lifting " <> renderTodoVersion version)
2929
[ mkTestCase "empty module" [] []
3030
, mkTestCase "closed value"
3131
[ dval "foo" TInt64 (EBuiltinFun (BEInt64 10)) ]

sdk/compiler/damlc/daml-ide-core/src/Development/IDE/Core/Rules/Daml.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,18 +546,18 @@ getUpgradedPackageErrs opts file mainPkg
546546
Just $
547547
ideErrorPretty file $ mconcat
548548
[ mainPackage <> " LF Version ("
549-
, T.pack $ LF.renderVersion $ LF.packageLfVersion mainPkg
549+
, T.pack $ LF.renderTodoVersion $ LF.packageLfVersion mainPkg
550550
, ") must have the same major LF version as " <> upgradedPackage <> " LF Version ("
551-
, T.pack $ LF.renderVersion $ optDamlLfVersion opts
551+
, T.pack $ LF.renderTodoVersion $ optDamlLfVersion opts
552552
, ")"
553553
]
554554
else
555555
justIf (optDamlLfVersion opts `lfVersionMinorLt` LF.packageLfVersion mainPkg) $
556556
ideErrorPretty file $ mconcat
557557
[ mainPackage <> " LF Version ("
558-
, T.pack $ LF.renderVersion $ optDamlLfVersion opts
558+
, T.pack $ LF.renderTodoVersion $ optDamlLfVersion opts
559559
, ") cannot be lower than the " <> upgradedPackage <> " LF Version ("
560-
, T.pack $ LF.renderVersion $ LF.packageLfVersion mainPkg
560+
, T.pack $ LF.renderTodoVersion $ LF.packageLfVersion mainPkg
561561
, ")"
562562
]
563563
, justIf (optMbPackageName opts /= Just (LF.packageName $ LF.packageMetadata mainPkg)) $

sdk/compiler/damlc/daml-opts/daml-opts/DA/Daml/Options.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ expandSdkPackages logger lfVersion dars = do
560560
mapM (expand mbSdkPath) (nubOrd dars)
561561
where
562562
isSdkPackage fp = takeExtension fp `notElem` [".dar", ".dalf"]
563-
sdkSuffix = "-" <> LF.renderVersion lfVersion
563+
sdkSuffix = "-" <> LF.renderTodoVersion lfVersion
564564
expand mbSdkPath fp
565565
| fp `elem` basePackages = pure fp
566566
| isSdkPackage fp = case mbSdkPath of

sdk/compiler/damlc/daml-resolution-config/src/DA/Daml/Resolution/Config.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ instance ToJSON DalfInfoCacheEntry where
5656
toJSON DalfInfoCacheEntry{..} = object
5757
[ "package_name" .= diPackageName
5858
, "package_version" .= diPackageVersion
59-
, "lf_version" .= LF.renderVersion diLfVersion
59+
, "lf_version" .= LF.renderTodoVersion diLfVersion
6060
, "timestamp" .= diTimestamp
6161
]
6262
instance FromJSON DalfInfoCacheEntry where
@@ -174,8 +174,11 @@ findDarInDarInfos darInfos rawName lfVersion = do
174174
case availableVersions of
175175
[] -> do
176176
let allPackageNames = T.intercalate "," . nubOrd $ LF.unPackageName . diPackageName <$> Map.elems darInfos
177+
let allPackageVersions = T.intercalate "," $ T.pack . show . diLfVersion <$> Map.elems darInfos
177178
Left $ "Package " <> rawName <> " could not be found, available packages are:\n"
178179
<> allPackageNames <> "\nIf your package is shown, it may not be compatible with your LF version."
180+
<> "\nThis Lf version: " <> (T.pack . show) lfVersion
181+
<> "\nAllPackageVersion: " <> (T.pack . show) allPackageVersions
179182
[_] ->
180183
-- Major LF versions aren't cross compatible, so all will be same major here due to canDependOn check above
181184
-- as such, we take maximum by minor version

0 commit comments

Comments
 (0)