Skip to content

Commit 23c3c33

Browse files
scenario-service: run no validation, when called from ide (#3003)
1 parent 2ac81ce commit 23c3c33

File tree

12 files changed

+35
-61
lines changed

12 files changed

+35
-61
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ contextForFile file = do
286286
{ ctxModules = Map.fromList encodedModules
287287
, ctxPackages = [(dalfPackageId pkg, dalfPackageBytes pkg) | pkg <- Map.elems pkgMap]
288288
, ctxDamlLfVersion = lfVersion
289-
, ctxLightValidation = case envScenarioValidation of
290-
ScenarioValidationFull -> SS.LightValidation False
291-
ScenarioValidationLight -> SS.LightValidation True
289+
, ctxSkipValidation = SS.SkipValidation (getSkipScenarioValidation envSkipScenarioValidation)
292290
}
293291

294292
worldForFile :: NormalizedFilePath -> Action LF.World
@@ -328,9 +326,10 @@ createScenarioContextRule =
328326
dalfForScenario :: NormalizedFilePath -> Action LF.Module
329327
dalfForScenario file = do
330328
DamlEnv{..} <- getDamlServiceEnv
331-
case envScenarioValidation of
332-
ScenarioValidationLight -> use_ GenerateRawDalf file
333-
ScenarioValidationFull -> use_ GenerateDalf file
329+
if getSkipScenarioValidation envSkipScenarioValidation then
330+
use_ GenerateRawDalf file
331+
else
332+
use_ GenerateDalf file
334333

335334
runScenariosRule :: Rules ()
336335
runScenariosRule =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ data DamlEnv = DamlEnv
6666
-- ^ The scenario contexts we used as GC roots in the last iteration.
6767
-- This is used to avoid unnecessary GC calls.
6868
, envDamlLfVersion :: LF.Version
69-
, envScenarioValidation :: ScenarioValidation
69+
, envSkipScenarioValidation :: SkipScenarioValidation
7070
}
7171

7272
instance IsIdeGlobal DamlEnv
@@ -82,7 +82,7 @@ mkDamlEnv opts scenarioService = do
8282
, envScenarioContexts = scenarioContextsVar
8383
, envPreviousScenarioContexts = previousScenarioContextsVar
8484
, envDamlLfVersion = optDamlLfVersion opts
85-
, envScenarioValidation = optScenarioValidation opts
85+
, envSkipScenarioValidation = optSkipScenarioValidation opts
8686
}
8787

8888
getDamlServiceEnv :: Action DamlEnv

compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module DA.Daml.Options.Types
55
( Options(..)
66
, EnableScenarioService(..)
7-
, ScenarioValidation(..)
7+
, SkipScenarioValidation(..)
88
, DlintUsage(..)
99
, Haddock(..)
1010
, defaultOptionsIO
@@ -55,10 +55,9 @@ data Options = Options
5555
-- ^ custom options, parsed by GHC option parser, overriding DynFlags
5656
, optScenarioService :: EnableScenarioService
5757
-- ^ Controls whether the scenario service is started.
58-
, optScenarioValidation :: ScenarioValidation
59-
-- ^ Controls whether the scenario service server runs all checks
60-
-- or only a subset of them. This is mostly used to run additional
61-
-- checks on CI while keeping the IDE fast.
58+
, optSkipScenarioValidation :: SkipScenarioValidation
59+
-- ^ Controls whether the scenario service server run package validations.
60+
-- This is mostly used to run additional checks on CI while keeping the IDE fast.
6261
, optDlintUsage :: DlintUsage
6362
-- ^ Information about dlint usage.
6463
, optIsGenerated :: Bool
@@ -85,10 +84,8 @@ data DlintUsage
8584
| DlintDisabled
8685
deriving Show
8786

88-
data ScenarioValidation
89-
= ScenarioValidationLight
90-
| ScenarioValidationFull
91-
deriving Show
87+
newtype SkipScenarioValidation = SkipScenarioValidation { getSkipScenarioValidation :: Bool }
88+
deriving Show
9289

9390
newtype EnableScenarioService = EnableScenarioService { getEnableScenarioService :: Bool }
9491
deriving Show
@@ -161,7 +158,7 @@ defaultOptions mbVersion =
161158
, optDebug = False
162159
, optGhcCustomOpts = []
163160
, optScenarioService = EnableScenarioService True
164-
, optScenarioValidation = ScenarioValidationFull
161+
, optSkipScenarioValidation = SkipScenarioValidation False
165162
, optDlintUsage = DlintDisabled
166163
, optIsGenerated = False
167164
, optDflagCheck = True

compiler/damlc/lib/DA/Cli/Damlc.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ execIde telemetry (Debug debug) enableScenarioService ghcOpts mbProfileDir = Com
353353
opts <- defaultOptionsIO Nothing
354354
opts <- pure $ opts
355355
{ optScenarioService = enableScenarioService
356-
, optScenarioValidation = ScenarioValidationLight
356+
, optSkipScenarioValidation = SkipScenarioValidation True
357357
, optShakeProfiling = mbProfileDir
358358
, optThreads = 0
359359
, optDlintUsage = DlintEnabled dlintDataDir True

compiler/damlc/lib/DA/Cli/Options.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ optionsParser numProcessors enableScenarioService parsePkgName = Options
386386
<*> optDebugLog
387387
<*> optGhcCustomOptions
388388
<*> pure enableScenarioService
389-
<*> pure (optScenarioValidation $ defaultOptions Nothing)
389+
<*> pure (optSkipScenarioValidation $ defaultOptions Nothing)
390390
<*> dlintUsageOpt
391391
<*> pure False
392392
<*> optNoDflagCheck

compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ getIntegrationTests registerTODO scenarioService version = do
126126
opts <- defaultOptionsIO (Just version)
127127
opts <- pure $ opts
128128
{ optThreads = 0
129-
, optScenarioValidation = ScenarioValidationFull
129+
, optSkipScenarioValidation = SkipScenarioValidation False
130130
, optCoreLinting = True
131131
}
132132

compiler/scenario-service/client/src/DA/Daml/LF/ScenarioServiceClient.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module DA.Daml.LF.ScenarioServiceClient
1111
, Handle
1212
, withScenarioService
1313
, Context(..)
14-
, LowLevel.LightValidation(..)
14+
, LowLevel.SkipValidation(..)
1515
, LowLevel.ContextId
1616
, getNewCtx
1717
, deleteCtx
@@ -118,7 +118,7 @@ data Context = Context
118118
{ ctxModules :: MS.Map Hash (LF.ModuleName, BS.ByteString)
119119
, ctxPackages :: [(LF.PackageId, BS.ByteString)]
120120
, ctxDamlLfVersion :: LF.Version
121-
, ctxLightValidation :: LowLevel.LightValidation
121+
, ctxSkipValidation :: LowLevel.SkipValidation
122122
}
123123

124124
getNewCtx :: Handle -> Context -> IO (Either LowLevel.BackendError LowLevel.ContextId)
@@ -141,7 +141,7 @@ getNewCtx Handle{..} Context{..} = withLock hContextLock $ withSem hConcurrencyS
141141
loadPackages
142142
(S.toList unloadPackages)
143143
ctxDamlLfVersion
144-
ctxLightValidation
144+
ctxSkipValidation
145145
writeIORef hLoadedPackages newLoadedPackages
146146
writeIORef hLoadedModules ctxModules
147147
res <- LowLevel.updateCtx hLowLevelHandle hContextId ctxUpdate

compiler/scenario-service/client/src/DA/Daml/LF/ScenarioServiceClient/LowLevel.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module DA.Daml.LF.ScenarioServiceClient.LowLevel
1818
, deleteCtx
1919
, gcCtxs
2020
, ContextUpdate(..)
21-
, LightValidation(..)
21+
, SkipValidation(..)
2222
, updateCtx
2323
, runScenario
2424
, SS.ScenarioResult(..)
@@ -81,16 +81,17 @@ data Handle = Handle
8181
newtype ContextId = ContextId { getContextId :: Int64 }
8282
deriving (NFData, Eq, Show)
8383

84-
-- | If true, the scenario service server only runs a subset of validations.
85-
newtype LightValidation = LightValidation { getLightValidation :: Bool }
84+
-- | If true, the scenario service server do not run package validations.
85+
newtype SkipValidation = SkipValidation { getSkipValidation :: Bool }
86+
deriving Show
8687

8788
data ContextUpdate = ContextUpdate
8889
{ updLoadModules :: ![(LF.ModuleName, BS.ByteString)]
8990
, updUnloadModules :: ![LF.ModuleName]
9091
, updLoadPackages :: ![(LF.PackageId, BS.ByteString)]
9192
, updUnloadPackages :: ![LF.PackageId]
9293
, updDamlLfVersion :: LF.Version
93-
, updLightValidation :: LightValidation
94+
, updSkipValidation :: SkipValidation
9495
}
9596

9697
encodeModule :: LF.Version -> LF.Module -> BS.ByteString
@@ -293,7 +294,7 @@ updateCtx Handle{..} (ContextId ctxId) ContextUpdate{..} = do
293294
ctxId
294295
(Just updModules)
295296
(Just updPackages)
296-
(getLightValidation updLightValidation)
297+
(getSkipValidation updSkipValidation)
297298
pure (void res)
298299
where
299300
updModules =

compiler/scenario-service/protos/scenario_service.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ message UpdateContextRequest {
9898
int64 context_id = 1;
9999
UpdateModules update_modules = 2;
100100
UpdatePackages update_packages = 3;
101-
bool lightValidation = 4; // if true runs only a subset of the validations
101+
bool noValidation = 4; // if true, does not run the package validations
102102
}
103103

104104
message UpdateContextResponse {

compiler/scenario-service/server/src/main/scala/com/digitalasset/daml/lf/ScenarioServiceMain.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class ScenarioService extends ScenarioServiceGrpc.ScenarioServiceImplBase {
201201
loadModules,
202202
unloadPackages,
203203
loadPackages,
204-
req.getLightValidation
204+
req.getNoValidation
205205
)
206206

207207
resp.addAllLoadedModules(ctx.loadedModules().map(_.toString).asJava)

compiler/scenario-service/server/src/main/scala/com/digitalasset/daml/lf/scenario/Context.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import com.digitalasset.daml.lf.speedy.SValue
1717
import com.digitalasset.daml.lf.types.Ledger.Ledger
1818
import com.digitalasset.daml.lf.PureCompiledPackages
1919
import com.digitalasset.daml.lf.speedy.SExpr.{LfDefRef, SDefinitionRef}
20-
import com.digitalasset.daml.lf.validation.{Validation, ValidationError}
20+
import com.digitalasset.daml.lf.validation.Validation
2121
import com.google.protobuf.ByteString
2222
import com.digitalasset.daml.lf.transaction.VersionTimeline
2323

@@ -85,15 +85,10 @@ class Context(val contextId: Context.ContextId) {
8585
dop.decodeScenarioModule(homePackageId, lfMod)
8686
}
8787

88-
private def validate(pkgIds: Traversable[PackageId], forScenarioService: Boolean): Unit = {
89-
val validator: PackageId => Either[ValidationError, Unit] =
90-
if (forScenarioService)
91-
Validation.checkPackageForScenarioService(allPackages, _)
92-
else
93-
Validation.checkPackage(allPackages, _)
94-
95-
pkgIds.foreach(validator(_).left.foreach(e => throw ParseError(e.pretty)))
96-
}
88+
private def validate(pkgIds: Traversable[PackageId]): Unit =
89+
pkgIds.foreach(
90+
Validation.checkPackage(allPackages, _).left.foreach(e => throw ParseError(e.pretty))
91+
)
9792

9893
@throws[ParseError]
9994
def update(
@@ -137,7 +132,8 @@ class Context(val contextId: Context.ContextId) {
137132
})
138133
modules ++= lfModules.map(m => m.name -> m)
139134

140-
validate(newPackages.keys ++ Iterable(homePackageId), forScenarioService)
135+
if (!forScenarioService)
136+
validate(newPackages.keys ++ Iterable(homePackageId))
141137

142138
// At this point 'allPackages' is consistent and we can
143139
// compile the new modules.

daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/Validation.scala

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,4 @@ object Validation {
3535
Serializability.checkModule(world, pkgId, mod)
3636
PartyLiterals.checkModule(world, pkgId, mod)
3737
}
38-
39-
/*
40-
checkPackageForScenarioService runs a subset of the validation for the scenario service.
41-
42-
We do not want type check because it is slow and duplicated in Haskell side
43-
We do not want serializability check because the inference is not properly propagate to the engine (in case of scenario)
44-
We want collision check because it is not done on Haskell side.
45-
*/
46-
def checkPackageForScenarioService(
47-
pkgs: PartialFunction[PackageId, Package],
48-
pkgId: PackageId
49-
): Either[ValidationError, Unit] =
50-
try {
51-
val world = new World(pkgs)
52-
Right(Collision.checkPackage(pkgId, world.lookupPackage(NoContext, pkgId).modules))
53-
} catch {
54-
case e: ValidationError =>
55-
Left(e)
56-
}
5738
}

0 commit comments

Comments
 (0)