8000 Fix bad owners for fail fast and partially for accumulating by arainko · Pull Request #127 · arainko/ducktape · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ object FalliblePlanInterpreter {
sourceValue: Expr[A],
mode: TransformationMode[F]
)(using Quotes): Expr[F[B]] =
recurse(plan, sourceValue, mode)(using sourceValue) match
case Value.Unwrapped(value) => '{ ${ mode.value }.pure[B](${ value.asExprOf[B] }) }
case Value.Wrapped(value) => value.asExprOf[F[B]]
recurse(plan, sourceValue, mode)(using sourceValue).wrapped(mode, Type.of[B])

private def recurse[F[+x]: Type, A: Type](
plan: Plan[Nothing, Fallible],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ private[ducktape] object ProductBinder {
generateLambda[[A] =>> A, destField, Dest](
field,
unwrappedValue =>
// TODO: Come back to this at some point, owners of the collected unwrapped defs need to be aligned to Symbol.spliceOwner
// so there are Exprs being constructed in a wrong way somewhere (this only occurts when falling back to the non-fallible PlanInterpreter)
val fields =
((field.name -> unwrappedValue) :: collectedUnwrappedFields.map(f => f.field.name -> f.value)).toMap
((field.name -> unwrappedValue) :: collectedUnwrappedFields.map(f =>
f.field.name -> alignOwner(f.value)
)).toMap
construct(fields).asExprOf[Dest]
)
}
Expand All @@ -50,8 +54,9 @@ private[ducktape] object ProductBinder {
${
generateLambda[F, destField, Dest](
field,
unwrappedValue =>
recurse(next, ProductZipper.Field.Unwrapped(field, unwrappedValue) :: collectedUnwrappedFields)
q ?=>
unwrappedValue =>
recurse(next, ProductZipper.Field.Unwrapped(field, unwrappedValue) :: collectedUnwrappedFields)(using q)
)
}
)
Expand All @@ -67,6 +72,11 @@ private[ducktape] object ProductBinder {
recurse(wrappedFields, unwrappedFields)
}

private def alignOwner(expr: Expr[Any])(using Quotes) = {
import quotes.reflect.*
expr.asTerm.changeOwner(Symbol.spliceOwner).asExpr
}

// this fixes a weird compiler crash where if I use the same name for each of the lambda args the compiler is not able to find a proxy for one of the invocations (?)
// this probably warrants a crash report?
@nowarn // todo: use @unchecked?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ object ProductZipper {

ProductZipper.unzip(nestedPairs, wrappedFields) match {
case (bind: Bind, unzippedFields) =>
val fields = (unzippedFields ::: unwrappedFields).map(field => field.field.name -> field.value).toMap
// TODO: Come back to this at some point, owners of the collected unwrapped defs need to be aligned to Symbol.spliceOwner
// so there are Exprs being constructed in a wrong way somewhere (this only occurts when falling back to the non-fallible PlanInterpreter)
val fields = (unzippedFields ::: unwrappedFields).map(field => field.field.name -> alignOwner(field.value)).toMap
Match(
nestedPairs.asTerm,
CaseDef(
Expand All @@ -75,7 +77,10 @@ object ProductZipper {
val wronglyMatchedReference = Ref(matchErrorBind).asExpr
val matchErrorCase =
CaseDef(Bind(matchErrorBind, Wildcard()), None, '{ throw new MatchError($wronglyMatchedReference) }.asTerm)
val fields = (unzippedFields ::: unwrappedFields).map(field => field.field.name -> field.value).toMap

// TODO: Come back to this at some point, owners of the collected unwrapped defs need to be aligned to Symbol.spliceOwner
// so there are Exprs being constructed in a wrong way somewhere (this only occurts when falling back to the non-fallible PlanInterpreter)
val fields = (unzippedFields ::: unwrappedFields).map(field => field.field.name -> alignOwner(field.value)).toMap

Match(
nestedPairs.asTerm,
Expand All @@ -88,6 +93,11 @@ object ProductZipper {
}
}

private def alignOwner(expr: Expr[Any])(using Quotes) = {
import quotes.reflect.*
expr.asTerm.changeOwner(Symbol.spliceOwner).asExpr
}

/**
* Imagine you have a value of type: Tuple2[Tuple2[Tuple2[Int, Double], Float], String], eg.
* val whatever: Tuple2[Tuple2[Tuple2[Int, Double], Float], String] = 1 -> 1d -> 1f -> "4"
Expand Down
0