From 85c430c47d70ce1ef47a9b89a9f9ba0f3d498fbb Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 22 May 2024 11:48:40 +1200 Subject: [PATCH] ensure effect_internal_* function names are preserved with esm --- packages/effect/src/Utils.ts | 4 ++-- packages/effect/src/internal/core-effect.ts | 8 +++---- packages/effect/src/internal/core.ts | 14 ++++++------ packages/effect/src/internal/fiberRuntime.ts | 22 +++++++++--------- packages/effect/src/internal/stm/core.ts | 24 +++++++++++--------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/effect/src/Utils.ts b/packages/effect/src/Utils.ts index 5c61961f5b..c134b79d9c 100644 --- a/packages/effect/src/Utils.ts +++ b/packages/effect/src/Utils.ts @@ -796,11 +796,11 @@ const tracingFunction = (name: string) => { * @status experimental * @category tracing */ -export const internalCall = tracingFunction("effect_internal_function") +export const effect_internal_function = tracingFunction("effect_internal_function") /** * @since 3.2.2 * @status experimental * @category tracing */ -export const internalGeneratorCall = tracingFunction("effect_internal_generator") +export const effect_internal_generator = tracingFunction("effect_internal_generator") diff --git a/packages/effect/src/internal/core-effect.ts b/packages/effect/src/internal/core-effect.ts index 0604bfcdf8..ca05fc4485 100644 --- a/packages/effect/src/internal/core-effect.ts +++ b/packages/effect/src/internal/core-effect.ts @@ -1,4 +1,4 @@ -import { internalCall, internalGeneratorCall } from "effect/Utils" +import { effect_internal_function, effect_internal_generator } from "effect/Utils" import * as Arr from "../Array.js" import type * as Cause from "../Cause.js" import * as Chunk from "../Chunk.js" @@ -772,7 +772,7 @@ export const gen: typeof Effect.gen = function() { } return core.suspend(() => { const iterator = f(pipe) - const state = internalGeneratorCall(() => iterator.next()) + const state = effect_internal_generator(() => iterator.next()) const run = ( state: IteratorYieldResult | IteratorReturnResult ): Effect.Effect => { @@ -780,7 +780,7 @@ export const gen: typeof Effect.gen = function() { ? core.succeed(state.value) : core.flatMap( yieldWrapGet(state.value) as any, - (val: any) => run(internalGeneratorCall(() => iterator.next(val))) + (val: any) => run(effect_internal_generator(() => iterator.next(val))) )) } return run(state) @@ -2185,7 +2185,7 @@ export const functionWithSpan = , Ret extends Effect.Eff ? options.options.apply(null, arguments as any) : options.options return withSpan( - core.suspend(() => internalCall(() => options.body.apply(this, arguments as any))), + core.suspend(() => effect_internal_function(() => options.body.apply(this, arguments as any))), opts.name, { ...opts, diff --git a/packages/effect/src/internal/core.ts b/packages/effect/src/internal/core.ts index 639df94431..b623e7c94f 100644 --- a/packages/effect/src/internal/core.ts +++ b/packages/effect/src/internal/core.ts @@ -1,4 +1,4 @@ -import { internalCall } from "effect/Utils" +import { effect_internal_function } from "effect/Utils" import * as Arr from "../Array.js" import type * as Cause from "../Cause.js" import * as Chunk from "../Chunk.js" @@ -534,9 +534,9 @@ export const async = ( let controllerRef: AbortController | void = undefined if (this.effect_instruction_i0.length !== 1) { controllerRef = new AbortController() - cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal)) + cancelerRef = effect_internal_function(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal)) } else { - cancelerRef = internalCall(() => (this.effect_instruction_i0 as any)(proxyResume)) + cancelerRef = effect_internal_function(() => (this.effect_instruction_i0 as any)(proxyResume)) } return (cancelerRef || controllerRef) ? onInterrupt(effect, (_) => { @@ -1007,8 +1007,8 @@ export const interruptibleMask = ( effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(_runtimeFlags.Interruption) effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) => _runtimeFlags.interruption(oldFlags) - ? internalCall(() => this.effect_instruction_i0(interruptible)) - : internalCall(() => this.effect_instruction_i0(uninterruptible)) + ? effect_internal_function(() => this.effect_instruction_i0(interruptible)) + : effect_internal_function(() => this.effect_instruction_i0(uninterruptible)) return effect }) @@ -1323,8 +1323,8 @@ export const uninterruptibleMask = ( effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(_runtimeFlags.Interruption) effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) => _runtimeFlags.interruption(oldFlags) - ? internalCall(() => this.effect_instruction_i0(interruptible)) - : internalCall(() => this.effect_instruction_i0(uninterruptible)) + ? effect_internal_function(() => this.effect_instruction_i0(interruptible)) + : effect_internal_function(() => this.effect_instruction_i0(uninterruptible)) return effect }) diff --git a/packages/effect/src/internal/fiberRuntime.ts b/packages/effect/src/internal/fiberRuntime.ts index 96d204ae60..c73521e30b 100644 --- a/packages/effect/src/internal/fiberRuntime.ts +++ b/packages/effect/src/internal/fiberRuntime.ts @@ -1,4 +1,4 @@ -import { internalCall } from "effect/Utils" +import { effect_internal_function } from "effect/Utils" import * as RA from "../Array.js" import * as Boolean from "../Boolean.js" import type * as Cause from "../Cause.js" @@ -147,7 +147,7 @@ const contOpSuccess = { cont: core.OnSuccess, value: unknown ) => { - return internalCall(() => cont.effect_instruction_i1(value)) + return effect_internal_function(() => cont.effect_instruction_i1(value)) }, ["OnStep"]: ( _: FiberRuntime, @@ -161,7 +161,7 @@ const contOpSuccess = { cont: core.OnSuccessAndFailure, value: unknown ) => { - return internalCall(() => cont.effect_instruction_i2(value)) + return effect_internal_function(() => cont.effect_instruction_i2(value)) }, [OpCodes.OP_REVERT_FLAGS]: ( self: FiberRuntime, @@ -180,10 +180,10 @@ const contOpSuccess = { cont: core.While, value: unknown ) => { - internalCall(() => cont.effect_instruction_i2(value)) - if (internalCall(() => cont.effect_instruction_i0())) { + effect_internal_function(() => cont.effect_instruction_i2(value)) + if (effect_internal_function(() => cont.effect_instruction_i0())) { self.pushStack(cont) - return internalCall(() => cont.effect_instruction_i1()) + return effect_internal_function(() => cont.effect_instruction_i1()) } else { return core.void } @@ -1074,7 +1074,7 @@ export class FiberRuntime implements Fiber.RuntimeFi } [OpCodes.OP_SYNC](op: core.Primitive & { _op: OpCodes.OP_SYNC }) { - const value = internalCall(() => op.effect_instruction_i0()) + const value = effect_internal_function(() => op.effect_instruction_i0()) const cont = this.getNextSuccessCont() if (cont !== undefined) { if (!(cont._op in contOpSuccess)) { @@ -1113,7 +1113,7 @@ export class FiberRuntime implements Fiber.RuntimeFi case OpCodes.OP_ON_FAILURE: case OpCodes.OP_ON_SUCCESS_AND_FAILURE: { if (!(_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted())) { - return internalCall(() => cont.effect_instruction_i1(cause)) + return effect_internal_function(() => cont.effect_instruction_i1(cause)) } else { return core.exitFailCause(internalCause.stripFailures(cause)) } @@ -1144,7 +1144,7 @@ export class FiberRuntime implements Fiber.RuntimeFi } [OpCodes.OP_WITH_RUNTIME](op: core.Primitive & { _op: OpCodes.OP_WITH_RUNTIME }) { - return internalCall(() => + return effect_internal_function(() => op.effect_instruction_i0( this as FiberRuntime, FiberStatus.running(this._runtimeFlags) as FiberStatus.Running @@ -1210,7 +1210,7 @@ export class FiberRuntime implements Fiber.RuntimeFi // Since we updated the flags, we need to revert them const revertFlags = _runtimeFlags.diff(newRuntimeFlags, oldRuntimeFlags) this.pushStack(new core.RevertFlags(revertFlags, op)) - return internalCall(() => op.effect_instruction_i1!(oldRuntimeFlags)) + return effect_internal_function(() => op.effect_instruction_i1!(oldRuntimeFlags)) } else { return core.exitVoid } @@ -1262,7 +1262,7 @@ export class FiberRuntime implements Fiber.RuntimeFi } [OpCodes.OP_COMMIT](op: core.Primitive & { _op: OpCodes.OP_COMMIT }) { - return internalCall(() => op.commit()) + return effect_internal_function(() => op.commit()) } /** diff --git a/packages/effect/src/internal/stm/core.ts b/packages/effect/src/internal/stm/core.ts index f89369bad0..6dc76056ca 100644 --- a/packages/effect/src/internal/stm/core.ts +++ b/packages/effect/src/internal/stm/core.ts @@ -1,4 +1,4 @@ -import { internalCall } from "effect/Utils" +import { effect_internal_function } from "effect/Utils" import * as Cause from "../../Cause.js" import * as Context from "../../Context.js" import * as Effect from "../../Effect.js" @@ -505,16 +505,18 @@ export class STMDriver { case "Commit": { switch (current.effect_instruction_i0) { case OpCodes.OP_DIE: { - exit = TExit.die(internalCall(() => current.effect_instruction_i1())) + exit = TExit.die(effect_internal_function(() => current.effect_instruction_i1())) break } case OpCodes.OP_FAIL: { const cont = this.nextFailure() if (cont === undefined) { - exit = TExit.fail(internalCall(() => current.effect_instruction_i1())) + exit = TExit.fail(effect_internal_function(() => current.effect_instruction_i1())) } else { - curr = internalCall(() => - cont.effect_instruction_i2(internalCall(() => current.effect_instruction_i1())) as Primitive + curr = effect_internal_function(() => + cont.effect_instruction_i2( + effect_internal_function(() => current.effect_instruction_i1()) + ) as Primitive ) } break @@ -524,7 +526,7 @@ export class STMDriver { if (cont === undefined) { exit = TExit.retry } else { - curr = internalCall(() => cont.effect_instruction_i2() as Primitive) + curr = effect_internal_function(() => cont.effect_instruction_i2() as Primitive) } break } @@ -533,7 +535,7 @@ export class STMDriver { break } case OpCodes.OP_WITH_STM_RUNTIME: { - curr = internalCall(() => + curr = effect_internal_function(() => current.effect_instruction_i1(this as STMDriver) as Primitive ) break @@ -547,7 +549,7 @@ export class STMDriver { } case OpCodes.OP_PROVIDE: { const env = this.env - this.env = internalCall(() => current.effect_instruction_i2(env)) + this.env = effect_internal_function(() => current.effect_instruction_i2(env)) curr = pipe( current.effect_instruction_i1, ensuring(sync(() => (this.env = env))) @@ -560,17 +562,17 @@ export class STMDriver { if (cont === undefined) { exit = TExit.succeed(value) } else { - curr = internalCall(() => cont.effect_instruction_i2(value) as Primitive) + curr = effect_internal_function(() => cont.effect_instruction_i2(value) as Primitive) } break } case OpCodes.OP_SYNC: { - const value = internalCall(() => current.effect_instruction_i1()) + const value = effect_internal_function(() => current.effect_instruction_i1()) const cont = this.nextSuccess() if (cont === undefined) { exit = TExit.succeed(value) } else { - curr = internalCall(() => cont.effect_instruction_i2(value) as Primitive) + curr = effect_internal_function(() => cont.effect_instruction_i2(value) as Primitive) } break }