Skip to content

Commit ef697b4

Browse files
committed
WIP 37 - Target.persistent macro
1 parent f175357 commit ef697b4

File tree

1 file changed

+67
-60
lines changed

1 file changed

+67
-60
lines changed

main/define/src/mill/define/Task.scala

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,11 @@ object Target extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] {
225225
* that it computes the same result whether or not there is data in `T.dest`.
226226
* Violating that invariant can result in confusing mis-behaviors
227227
*/
228-
def persistent[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] =
229-
??? // macro Internal.persistentImpl[T]
228+
inline def persistent[T](inline t: Result[T])(implicit
229+
rw: RW[T],
230+
ctx: mill.define.Ctx
231+
): Target[T] =
232+
${ Internal.persistentImpl[T]('t)('rw, 'ctx, 'this) }
230233

231234
/**
232235
* A specialization of [[InputImpl]] defined via `T.sources`, [[SourcesImpl]]
@@ -422,23 +425,23 @@ object Target extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] {
422425
)
423426
}
424427

425-
def targetTaskImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[Task[T]])(
426-
rw: c.Expr[RW[T]],
427-
ctx: c.Expr[mill.define.Ctx]
428-
): c.Expr[Target[T]] = {
428+
def targetTaskImpl[T: Type](using Quotes)(t: Expr[Task[T]])(
429+
rw: Expr[RW[T]],
430+
ctx: Expr[mill.define.Ctx]
431+
): Expr[Target[T]] = {
429432
// import c.universe._
430433

431434
// val taskIsPrivate = isPrivateTargetOption(c)
432435

433436
// mill.moduledefs.Cacher.impl0[Target[T]](c)(
434-
// reify(
437+
// '{
435438
// new TargetImpl[T](
436439
// t.splice,
437440
// ctx.splice,
438441
// rw.splice,
439442
// taskIsPrivate.splice
440443
// )
441-
// )
444+
// }
442445
// )
443446
???
444447
}
@@ -491,43 +494,45 @@ object Target extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] {
491494
)
492495
}
493496

494-
def sourceImpl1(c: Context)(value: c.Expr[Result[os.Path]])(ctx: c.Expr[mill.define.Ctx])
495-
: c.Expr[Target[PathRef]] = {
497+
def sourceImpl1(using
498+
Quotes
499+
)(value: Expr[Result[os.Path]])(ctx: Expr[mill.define.Ctx]): Expr[Target[PathRef]] = {
496500
// import c.universe._
497501

498502
// val wrapped =
499503
// Applicative.impl0[Task, PathRef, mill.api.Ctx](c)(
500-
// reify(value.splice.map(PathRef(_))).tree
504+
// '{value.splice.map(PathRef(_))).tree
501505
// )
502506

503507
// val taskIsPrivate = isPrivateTargetOption(c)
504508

505509
// mill.moduledefs.Cacher.impl0[Target[PathRef]](c)(
506-
// reify(
510+
// '{
507511
// new SourceImpl(
508512
// wrapped.splice,
509513
// ctx.splice,
510514
// taskIsPrivate.splice
511515
// )
512-
// )
516+
// }
513517
// )
514518
???
515519
}
516520

517-
def sourceImpl2(c: Context)(value: c.Expr[Result[PathRef]])(ctx: c.Expr[mill.define.Ctx])
518-
: c.Expr[Target[PathRef]] = {
521+
def sourceImpl2(using
522+
Quotes
523+
)(value: Expr[Result[PathRef]])(ctx: Expr[mill.define.Ctx]): Expr[Target[PathRef]] = {
519524
// import c.universe._
520525

521526
// val taskIsPrivate = isPrivateTargetOption(c)
522527

523528
// mill.moduledefs.Cacher.impl0[Target[PathRef]](c)(
524-
// reify(
529+
// '{
525530
// new SourceImpl(
526531
// Applicative.impl0[Task, PathRef, mill.api.Ctx](c)(value.tree).splice,
527532
// ctx.splice,
528533
// taskIsPrivate.splice
529534
// )
530-
// )
535+
// }
531536
// )
532537
???
533538
}
@@ -553,99 +558,101 @@ object Target extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] {
553558
)
554559
}
555560

556-
def commandFromTask[T: c.WeakTypeTag](c: Context)(t: c.Expr[Task[T]])(
557-
ctx: c.Expr[mill.define.Ctx],
558-
w: c.Expr[W[T]],
559-
cls: c.Expr[EnclosingClass]
560-
): c.Expr[Command[T]] = {
561+
def commandFromTask[T: Type](using Quotes)(t: Expr[Task[T]])(
562+
ctx: Expr[mill.define.Ctx],
563+
w: Expr[W[T]],
564+
cls: Expr[EnclosingClass]
565+
): Expr[Command[T]] = {
561566
// import c.universe._
562567

563568
// val taskIsPrivate = isPrivateTargetOption(c)
564569

565-
// reify(
570+
// '{
566571
// new Command[T](
567572
// t.splice,
568573
// ctx.splice,
569574
// w.splice,
570575
// cls.splice.value,
571576
// taskIsPrivate.splice
572-
// )
577+
// }
573578
// )
574579
???
575580
}
576581

577-
def commandImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T])(
578-
w: c.Expr[W[T]],
579-
ctx: c.Expr[mill.define.Ctx],
580-
cls: c.Expr[EnclosingClass]
581-
): c.Expr[Command[T]] = {
582+
def commandImpl[T: Type](using Quotes)(t: Expr[T])(
583+
w: Expr[W[T]],
584+
ctx: Expr[mill.define.Ctx],
585+
cls: Expr[EnclosingClass]
586+
): Expr[Command[T]] = {
582587
// import c.universe._
583588

584589
// val taskIsPrivate = isPrivateTargetOption(c)
585590

586-
// reify(
591+
// '{
587592
// new Command[T](
588-
// Applicative.impl[Task, T, mill.api.Ctx](c)(t).splice,
593+
// Applicative.impl[Task, Task, Result, T, mill.api.Ctx](c)(t).splice,
589594
// ctx.splice,
590595
// w.splice,
591596
// cls.splice.value,
592597
// taskIsPrivate.splice
593-
// )
598+
// }
594599
// )
595600
???
596601
}
597602

598-
def workerImpl1[T: c.WeakTypeTag](c: Context)(t: c.Expr[Task[T]])(ctx: c.Expr[mill.define.Ctx])
599-
: c.Expr[Worker[T]] = {
603+
def workerImpl1[T: Type](using
604+
Quotes
605+
)(t: Expr[Task[T]])(ctx: Expr[mill.define.Ctx]): Expr[Worker[T]] = {
600606
// import c.universe._
601607

602608
// val taskIsPrivate = isPrivateTargetOption(c)
603609

604-
// mill.moduledefs.Cacher.impl0[Worker[T]](c)(
605-
// reify(
610+
// mill.moduledefs.Cacher.impl0[Worker[T]](
611+
// '{
606612
// new Worker[T](t.splice, ctx.splice, taskIsPrivate.splice)
607-
// )
613+
// }
608614
// )
609615
???
610616
}
611617

612-
def workerImpl2[T: c.WeakTypeTag](c: Context)(t: c.Expr[T])(ctx: c.Expr[mill.define.Ctx])
613-
: c.Expr[Worker[T]] = {
618+
def workerImpl2[T: Type](using
619+
Quotes
620+
)(t: Expr[T])(ctx: Expr[mill.define.Ctx]): Expr[Worker[T]] = {
614621
// import c.universe._
615622

616623
// val taskIsPrivate = isPrivateTargetOption(c)
617624

618-
// mill.moduledefs.Cacher.impl0[Worker[T]](c)(
619-
// reify(
625+
// mill.moduledefs.Cacher.impl0[Worker[T]](
626+
// '{
620627
// new Worker[T](
621-
// Applicative.impl[Task, T, mill.api.Ctx](c)(t).splice,
628+
// Applicative.impl[Task, Task, Result, T, mill.api.Ctx](c)(t).splice,
622629
// ctx.splice,
623630
// taskIsPrivate.splice
624631
// )
625-
// )
632+
// }
626633
// )
627634
???
628635
}
629636

630-
def persistentImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T])(
631-
rw: c.Expr[RW[T]],
632-
ctx: c.Expr[mill.define.Ctx]
633-
): c.Expr[PersistentImpl[T]] = {
634-
// import c.universe._
637+
def persistentImpl[T: Type](using Quotes)(t: Expr[Result[T]])(
638+
rw: Expr[RW[T]],
639+
ctx: Expr[mill.define.Ctx],
640+
caller: Expr[Applicative.Applyer[Task, Task, Result, mill.api.Ctx]]
641+
): Expr[PersistentImpl[T]] = {
642+
val taskIsPrivate = isPrivateTargetOption()
635643

636-
// val taskIsPrivate = isPrivateTargetOption(c)
644+
val lhs = Applicative.impl[Task, Task, Result, T, mill.api.Ctx](caller, t)
637645

638-
// mill.moduledefs.Cacher.impl0[PersistentImpl[T]](c)(
639-
// reify(
640-
// new PersistentImpl[T](
641-
// Applicative.impl[Task, T, mill.api.Ctx](c)(t).splice,
642-
// ctx.splice,
643-
// rw.splice,
644-
// taskIsPrivate.splice
645-
// )
646-
// )
647-
// )
648-
???
646+
mill.moduledefs.Cacher.impl0[PersistentImpl[T]](
647+
'{
648+
new PersistentImpl[T](
649+
$lhs,
650+
$ctx,
651+
$rw,
652+
$taskIsPrivate
653+
)
654+
}
655+
)
649656
}
650657
}
651658
}

0 commit comments

Comments
 (0)