@@ -84,7 +84,10 @@ class MillBuildBootstrap(
8484 upickle.write(logged, indent = 4 ),
8585 createFolders = true
8686 )
87- for (frame <- runnerLauncherState.frames) write(frame.depth, frame.logged)
87+ for (frame <- runnerLauncherState.metaFrames)
88+ write(frame.depth, RunnerLauncherState .Logged .fromMetaFrame(frame))
89+ for (frame <- runnerLauncherState.finalFrame)
90+ write(frame.depth, RunnerLauncherState .Logged .fromFinalFrame(frame))
8891
8992 runnerLauncherState
9093 }
@@ -98,7 +101,7 @@ class MillBuildBootstrap(
98101 if (containsBuildFile(currentRoot)) evaluateRec(depth + 1 )
99102 else makeBootstrapState(currentRoot, depth)
100103
101- val nestedDepths = nestedState.processedDepths
104+ val nestedDepths = nestedState.metaFrames.size + nestedState.finalFrame.size
102105 val requestedDepth = computeRequestedDepth(requestedMetaLevel, depth, nestedDepths)
103106
104107 // If an earlier frame errored out, just propagate the error to this frame.
@@ -110,9 +113,7 @@ class MillBuildBootstrap(
110113 // Final tasks already ran at a deeper level due to `--meta-level` or `@nonBootstrapped`.
111114 nestedState
112115 } else {
113- // At this point nestedState only contains Meta frames — Final frames
114- // would have triggered the early-return above.
115- val rootModuleRes = nestedState.frames.headOption match {
116+ val rootModuleRes = nestedState.metaFrames.headOption match {
116117 case None =>
117118 Result .Success (
118119 BuildFileApi .Bootstrap (sharedState.get().bootstrap.get.module)
@@ -177,15 +178,13 @@ class MillBuildBootstrap(
177178 else
178179 makeBootstrapModule(currentRoot, foundRootBuildFileName, useDummy) match {
179180 case Result .Success (bootstrapModule) =>
180- sharedState.updateAndGet(
181- _.withBootstrap(
182- RunnerSharedState .BootstrapCache (
183- bootstrapModule,
184- foundRootBuildFileName,
185- useDummy
186- )
181+ sharedState.updateAndGet(_.withBootstrap(
182+ RunnerSharedState .BootstrapCache (
183+ bootstrapModule,
184+ foundRootBuildFileName,
185+ useDummy
187186 )
188- )
187+ ))
189188 None
190189 case f : Result .Failure => Some (Util .formatError(f, logger.prompt.errorColor))
191190 }
@@ -194,7 +193,7 @@ class MillBuildBootstrap(
194193 RunnerLauncherState (
195194 errorOpt = error,
196195 buildFile = Some (foundRootBuildFileName),
197- bootstrapEvalWatched = Some (bootstrapEvalWatched)
196+ buildFileWatch = Some (bootstrapEvalWatched)
198197 )
199198 }
200199
@@ -207,9 +206,9 @@ class MillBuildBootstrap(
207206 val staticBuildOverrides0 = tryReadParent(currentRoot, " build.mill.yaml" )
208207 .orElse(tryReadParent(currentRoot, " build.mill" ))
209208
210- // At this point nestedState only contains Meta frames; the most recent is
211- // the just-published nested level we want to read shared metadata for.
212- val nestedMetaBuildFrame = nestedState.frames .headOption
209+ // The most recent meta-build frame is the just-published nested level we
210+ // want to read shared metadata for.
211+ val nestedMetaBuildFrame = nestedState.metaFrames .headOption
213212 val nestedSharedFrame = nestedMetaBuildFrame.flatMap(frame =>
214213 sharedState.get().reusableFrameAt(frame.depth)
215214 )
@@ -240,10 +239,7 @@ class MillBuildBootstrap(
240239 runArtifacts = runArtifacts,
241240 workerCache = workerCache,
242241 codeSignatures = nestedSharedFrame.map(_.codeSignatures).getOrElse(Map .empty),
243- spanningInvalidationTree = nestedMetaBuildFrame.flatMap(_.role match {
244- case m : RunnerLauncherState .Role .Meta => m.spanningInvalidationTree
245- case _ => None
246- }),
242+ spanningInvalidationTree = nestedMetaBuildFrame.flatMap(_.spanningInvalidationTree),
247243 rootModule = rootModule,
248244 // Use the current frame's runClasspath (includes mvnDeps and Mill jars) but filter out
249245 // compile.dest and generatedScriptSources.dest since build code changes are handled
@@ -303,7 +299,7 @@ class MillBuildBootstrap(
303299 ): RunnerLauncherState = {
304300 val taskSelector = Seq (" millBuildRootModuleResult" )
305301 val collectSelectiveMetadata = tasksAndParams.nonEmpty
306- type SharedFrame = RunnerSharedState .Frame . Reusable
302+ type SharedFrame = RunnerSharedState .Frame
307303 case class ReuseProbe (frameOpt : Option [SharedFrame ], reusableFrameOpt : Option [SharedFrame ])
308304
309305 // Module watching is one level offset: the watches produced by depth - 1 determine
@@ -319,9 +315,11 @@ class MillBuildBootstrap(
319315 def reusable (frameOpt : Option [SharedFrame ]): Result [ReuseProbe ] =
320316 frameOpt match {
321317 case None => Result .Success (ReuseProbe (None , None ))
318+ case Some (frame) if frame.reusable.isEmpty =>
319+ Result .Success (ReuseProbe (frameOpt, None ))
322320 case Some (_) if watchedParentInputsChanged() => Result .Success (ReuseProbe (frameOpt, None ))
323321 case Some (frame) =>
324- frame.selectiveMetadata match {
322+ frame.reusable.flatMap(_. selectiveMetadata) match {
325323 case None => Result .Success (ReuseProbe (frameOpt, None ))
326324 case Some (previousMetadata) =>
327325 evaluator
@@ -347,45 +345,46 @@ class MillBuildBootstrap(
347345 nestedState.withError(mill.internal.Util .formatError(f, logger.prompt.errorColor))
348346
349347 def reuseFrame (
350- frame : SharedFrame ,
348+ sharedFrame : RunnerSharedState . Frame ,
351349 lease : LauncherLocking .Lease
352350 ): RunnerLauncherState =
353- nestedState.withFrame (
354- RunnerLauncherState .metaFrame (
355- depth,
356- evaluator,
357- frame ,
358- lease,
351+ nestedState.withMetaFrame (
352+ RunnerLauncherState .MetaFrame (
353+ depth = depth ,
354+ evaluator = evaluator ,
355+ sharedFrame = sharedFrame ,
356+ readLease = Some ( lease) ,
359357 spanningInvalidationTree = None
360358 )
361359 )
362360
363- def closePriorAndPreviousClassloaders (previousShared : RunnerSharedState ): Unit =
361+ def closePriorAndPreviousClassloaders (
362+ displacedReusable : Option [RunnerSharedState .Frame .Reusable ]
363+ ): Unit =
364364 // Make sure we close old classloaders every time we publish a replacement, to avoid
365365 // leaking classloaders and workers that may depend on them.
366366 Seq (
367- prevCommandState.frameAt (depth).flatMap(_.classLoaderOpt),
368- previousShared.reusableFrameAt(depth) .map(_.classLoader)
367+ prevCommandState.metaFrameAt (depth).flatMap(_.classLoaderOpt),
368+ displacedReusable .map(_.classLoader)
369369 ).flatten.distinct.foreach(_.close())
370370
371371 def publishFailedFrame (
372372 f : Result .Failure ,
373373 evalWatches : Seq [Watchable ],
374374 moduleWatches : Seq [Watchable ]
375375 ): RunnerLauncherState = {
376- val failedShared = RunnerSharedState .Frame .Failed (
377- evalWatched = evalWatches,
378- moduleWatched = moduleWatches
379- )
380- val previous = sharedState.getAndUpdate(_.withFrame(depth, failedShared))
381- closePriorAndPreviousClassloaders(previous)
376+ val failedShared = RunnerSharedState .Frame (evalWatches, moduleWatches, None )
377+ val displaced =
378+ sharedState.getAndUpdate(_.withFrame(depth, failedShared)).reusableFrameAt(depth)
379+ closePriorAndPreviousClassloaders(displaced)
382380 nestedState
383- .withFrame(
384- RunnerLauncherState .failedMetaFrame(
385- depth,
386- evaluator,
387- evalWatches,
388- moduleWatches
381+ .withMetaFrame(
382+ RunnerLauncherState .MetaFrame (
383+ depth = depth,
384+ evaluator = evaluator,
385+ sharedFrame = failedShared,
386+ readLease = None ,
387+ spanningInvalidationTree = None
389388 )
390389 )
391390 .withError(mill.internal.Util .formatError(f, logger.prompt.errorColor))
@@ -423,25 +422,28 @@ class MillBuildBootstrap(
423422 Seq (" java." , " javax." , " scala." , " mill.api.daemon" , " sbt.testing." )
424423 )
425424 }
426- val fresh : SharedFrame = RunnerSharedState .Frame . Reusable (
425+ val fresh = RunnerSharedState .Frame (
427426 evalWatched = evalWatches,
428427 moduleWatched = moduleWatches,
429- classLoader = createClassLoader(),
430- runClasspath = runClasspath,
431- compileOutput = compileClasses,
432- codeSignatures = codeSignatures,
433- buildOverrideFiles = buildOverrideFiles,
434- selectiveMetadata =
435- Option .when(collectSelectiveMetadata)(readSelectiveMetadataFile()).flatten
428+ reusable = Some (RunnerSharedState .Frame .Reusable (
429+ classLoader = createClassLoader(),
430+ runClasspath = runClasspath,
431+ compileOutput = compileClasses,
432+ codeSignatures = codeSignatures,
433+ buildOverrideFiles = buildOverrideFiles,
434+ selectiveMetadata =
435+ Option .when(collectSelectiveMetadata)(readSelectiveMetadataFile()).flatten
436+ ))
436437 )
437- val previous = sharedState.getAndUpdate(_.withFrame(depth, fresh))
438- closePriorAndPreviousClassloaders(previous)
439- nestedState.withFrame(
440- RunnerLauncherState .metaFrame(
441- depth,
442- evaluator,
443- fresh,
444- retainedLease,
438+ val displaced =
439+ sharedState.getAndUpdate(_.withFrame(depth, fresh)).reusableFrameAt(depth)
440+ closePriorAndPreviousClassloaders(displaced)
441+ nestedState.withMetaFrame(
442+ RunnerLauncherState .MetaFrame (
443+ depth = depth,
444+ evaluator = evaluator,
445+ sharedFrame = fresh,
446+ readLease = Some (retainedLease),
445447 spanningInvalidationTree = Some (spanningInvalidationTree)
446448 )
447449 )
@@ -489,7 +491,7 @@ class MillBuildBootstrap(
489491 acquireRead = workspaceLocking.metaBuildLock(depth, LauncherLocking .LockKind .Read ),
490492 acquireWrite = workspaceLocking.metaBuildLock(depth, LauncherLocking .LockKind .Write )
491493 ) { scope =>
492- reusable(sharedState.get().reusableFrameAt (depth)) match {
494+ reusable(sharedState.get().frameAt (depth)) match {
493495 case f : Result .Failure =>
494496 LockUpgrade .Decision .Complete (errorState(f))
495497 case Result .Success (probe) =>
@@ -501,7 +503,7 @@ class MillBuildBootstrap(
501503 }
502504 }
503505 } { scope =>
504- val currentFrame = sharedState.get().reusableFrameAt (depth)
506+ val currentFrame = sharedState.get().frameAt (depth)
505507 val reuseResult = readProbeOpt.filter(_.frameOpt == currentFrame) match {
506508 case Some (probe) => Result .Success (probe)
507509 case None => reusable(currentFrame)
@@ -536,26 +538,21 @@ class MillBuildBootstrap(
536538 if (skipSelectiveExecution) None
537539 else
538540 prevCommandState.finalFrame
539- .filter(f =>
540- f.depth == depth && (f.role match {
541- case RunnerLauncherState .Role .Final (prevTasks) => prevTasks == tasksAndParams
542- case _ => false
543- })
544- )
541+ .filter(f => f.depth == depth && f.tasksAndParams == tasksAndParams)
545542 .map(f => (f.evalWatched, f.moduleWatched))
546543 .filter { case (ev, mw) =>
547544 ev.forall(Watching .haveNotChanged) && mw.forall(Watching .haveNotChanged)
548545 }
549546
550547 shortCircuitSource match {
551548 case Some ((evalWatched, moduleWatched)) =>
552- return nestedState.withFrame (
553- RunnerLauncherState .LauncherFrame (
549+ return nestedState.withFinalFrame (
550+ RunnerLauncherState .FinalFrame (
554551 depth = depth,
555552 evaluator = evaluator,
556553 evalWatched = evalWatched,
557554 moduleWatched = moduleWatched,
558- role = RunnerLauncherState . Role . Final ( tasksAndParams)
555+ tasksAndParams = tasksAndParams
559556 )
560557 )
561558 case None => ()
@@ -569,13 +566,13 @@ class MillBuildBootstrap(
569566 reporter = reporter(evaluator)
570567 )
571568
572- val withFinal = nestedState.withFrame (
573- RunnerLauncherState .LauncherFrame (
569+ val withFinal = nestedState.withFinalFrame (
570+ RunnerLauncherState .FinalFrame (
574571 depth = depth,
575572 evaluator = evaluator,
576573 evalWatched = evalWatched,
577574 moduleWatched = moduleWatched,
578- role = RunnerLauncherState . Role . Final ( tasksAndParams)
575+ tasksAndParams = tasksAndParams
579576 )
580577 )
581578 evaled match {
0 commit comments