Skip to content

Commit

Permalink
More renames and Soundness exports
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Sep 15, 2024
1 parent 26ef71c commit cefcba8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/core/contingency-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ infix type raises [SuccessType, ErrorType <: Exception] = Tactic[ErrorType] ?=>
infix type mitigates [ErrorType <: Exception, ErrorType2 <: Exception] =
ErrorType2 is Mitigable into ErrorType

infix type traces [ResultType, FocusType] = Tracing[FocusType] ?=> ResultType
infix type traces [ResultType, FocusType] = Foci[FocusType] ?=> ResultType

inline def focus[FocusType, ResultType](using inline trace: Tracing[FocusType])
inline def focus[FocusType, ResultType](using inline trace: Foci[FocusType])
(transform: Optional[FocusType] => FocusType)
(block: => ResultType)
: ResultType =
Expand Down Expand Up @@ -156,7 +156,7 @@ extension [AccrualType <: Exception, LambdaType[_]]

extension [AccrualType <: Exception, LambdaType[_], FocusType]
(inline trace: Trace[AccrualType, LambdaType, FocusType])
inline def within[ResultType](inline lambda: Tracing[FocusType] ?=> LambdaType[ResultType])
inline def within[ResultType](inline lambda: Foci[FocusType] ?=> LambdaType[ResultType])
(using tactic: Tactic[AccrualType])
: ResultType =
${ Contingency.traceWithin[AccrualType, LambdaType, ResultType, FocusType]('trace, 'lambda, 'tactic) }
12 changes: 6 additions & 6 deletions src/core/contingency.Contingency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ object Contingency:

def traceWithin[AccrualType <: Exception: Type, ContextType[_]: Type, ResultType: Type, FocusType: Type]
(trace: Expr[Trace[AccrualType, ContextType, FocusType]],
lambda: Expr[Tracing[FocusType] ?=> ContextType[ResultType]],
lambda: Expr[Foci[FocusType] ?=> ContextType[ResultType]],
tactic: Expr[Tactic[AccrualType]])
(using Quotes)
: Expr[ResultType] =

'{ val tracing: Tracing[FocusType] = Tracing()
'{ val foci: Foci[FocusType] = Foci()
val result = boundary[Option[ResultType]]: label ?=>
${ import quotes.reflect.*

Expand All @@ -299,19 +299,19 @@ object Contingency:
m"argument to `trace` should be a partial function implemented as match cases"

val tactics = cases.map: (_, _) =>
'{SupplementTactic(label, $trace.initial, tracing)}.asTerm
'{TraceTactic(label, $trace.initial, foci)}.asTerm

val contextTypeRepr = TypeRepr.of[ContextType[ResultType]]
val method = contextTypeRepr.typeSymbol.declaredMethod("apply").head
val term = '{$lambda(using tracing)}.asTerm.select(method).appliedToArgs(tactics.to(List))
val term = '{$lambda(using foci)}.asTerm.select(method).appliedToArgs(tactics.to(List))
val expr = term.asExprOf[ResultType]

'{Some($expr)} }

result match
case None => $tactic.abort($trace.initial)
case Some(value) =>
if tracing.success then value
else $tactic.abort(tracing.fold[AccrualType]($trace.initial)($trace.lambda(using _, _)))
if foci.success then value
else $tactic.abort(foci.fold[AccrualType]($trace.initial)($trace.lambda(using _, _)))

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import vacuous.*

import scala.collection.mutable as scm

class Tracing[FocusType]():
class Foci[FocusType]():
private val errors: scm.ArrayBuffer[Exception] = scm.ArrayBuffer()
private val focuses: scm.ArrayBuffer[Optional[FocusType]] = scm.ArrayBuffer()

Expand Down
8 changes: 4 additions & 4 deletions src/core/contingency.SupplementTactic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import language.experimental.pureFunctions
import rudiments.*

@capability
class SupplementTactic
class TraceTactic
[ErrorType <: Exception, AccrualType, ResultType, SupplementType]
(label: boundary.Label[Option[ResultType]],
initial: AccrualType,
trace: Tracing[SupplementType])
foci: Foci[SupplementType])
extends Tactic[ErrorType]:
def record(error: ErrorType): Unit = trace.register(error)
def record(error: ErrorType): Unit = foci.register(error)
def finish(): Unit = ()

def abort(error: ErrorType): Nothing =
trace.register(error)
foci.register(error)
boundary.break(None)(using label)
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/soundness+contingency-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package soundness

export contingency.{Tactic, Fatal, Recoverable, raise, abort, safely, unsafely, throwErrors,
capture, attempt, abandonment, ExpectationError, raises, Attempt, tend, mend, Unchecked, accrue,
within}
within, Trace, Foci, trace, focus}

package strategies:
export contingency.strategies.{throwUnsafely, throwSafely}

0 comments on commit cefcba8

Please sign in to comment.