Skip to content

Commit

Permalink
#1968: private bindings PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
pshirshov committed Aug 8, 2024
1 parent ab3c908 commit 5e87bfb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import izumi.distage.model.definition.errors.ProvisionerIssue.IncompatibleEffect
import izumi.distage.model.definition.errors.ProvisionerIssue.ProvisionerExceptionIssue.{IntegrationCheckFailure, UnexpectedIntegrationCheck}
import izumi.distage.model.exceptions.runtime.IntegrationCheckException
import izumi.distage.model.plan.ExecutableOp.*
import izumi.distage.model.plan.operations.OperationOrigin
import izumi.distage.model.plan.{ExecutableOp, Plan, Roots}
import izumi.distage.model.provisioning.*
import izumi.distage.model.provisioning.PlanInterpreter.{FailedProvision, FailedProvisionInternal, FinalizerFilter}
Expand Down Expand Up @@ -62,7 +63,18 @@ class PlanInterpreterNonSequentialRuntimeImpl(
): F[Either[FailedProvisionInternal[F], LocatorDefaultImpl[F]]] = {
val integrationCheckFType = SafeType.get[IntegrationCheck[F]]

val privateBindings = plan.input.bindings.bindings.filter(b => b.tags.contains(BindingTag.Confined)).map(_.key)
val privateBindings = plan.stepsUnordered
.filter {
op =>
op.origin.value match {
case OperationOrigin.UserBinding(binding) =>
binding.tags.contains(BindingTag.Confined)
case OperationOrigin.SyntheticBinding(binding) =>
binding.tags.contains(BindingTag.Confined)
case OperationOrigin.Unknown =>
false // TODO: true if everyting is private
}
}.map(_.target).toSet

val ctx: ProvisionMutable[F] = new ProvisionMutable[F](plan, parentContext, privateBindings)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@ import distage.{Injector, ModuleDef}
import izumi.distage.fixtures.BasicCases.BasicCase1
import izumi.distage.model.PlannerInput
import org.scalatest.wordspec.AnyWordSpec
import BasicCase1.*

class PrivateBindingsTest extends AnyWordSpec with MkInjector {
"Support private bindings" in {
import BasicCase1.*
val loc2 = prepareInheritedLocator(new ModuleDef {
make[TestDependency0].from[TestImpl0].confined
})

val injector = mkInjector()
assert(loc2.find[JustTrait].nonEmpty)
assert(loc2.find[TestDependency0].isEmpty)
}

val def1 = PlannerInput.everything(new ModuleDef {
make[TestDependency0].from[TestImpl0].confined
"Support public bindings" in {
val loc2 = prepareInheritedLocator(new ModuleDef {
make[TestDependency0].from[TestImpl0]
})

assert(loc2.find[JustTrait].nonEmpty)
assert(loc2.find[TestDependency0].nonEmpty)
}

private def prepareInheritedLocator(m: ModuleDef) = {
val injector = mkInjector()

val def1 = PlannerInput.everything(m)
val plan1 = injector.planUnsafe(def1)
val loc = injector.produce(plan1).unsafeGet()
assert(loc.find[TestDependency0].nonEmpty)
Expand All @@ -25,9 +40,7 @@ class PrivateBindingsTest extends AnyWordSpec with MkInjector {
})
val plan2 = injector2.planUnsafe(def2)
val loc2 = injector2.produce(plan2).unsafeGet()

assert(loc2.find[JustTrait].nonEmpty)
assert(loc2.find[TestDependency0].isEmpty)
loc2
}

}

0 comments on commit 5e87bfb

Please sign in to comment.