Skip to content

Commit

Permalink
ensure effect_internal_* function names are preserved with esm (#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored May 21, 2024
1 parent 02c87ec commit dfc87e2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions packages/effect/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
8 changes: 4 additions & 4 deletions packages/effect/src/internal/core-effect.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -772,15 +772,15 @@ 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<any> | IteratorReturnResult<any>
): Effect.Effect<any, any, any> => {
return (state.done
? 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)
Expand Down Expand Up @@ -2185,7 +2185,7 @@ export const functionWithSpan = <Args extends Array<any>, 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,
Expand Down
14 changes: 7 additions & 7 deletions packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -534,9 +534,9 @@ export const async = <A, E = never, R = never>(
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, (_) => {
Expand Down Expand Up @@ -1007,8 +1007,8 @@ export const interruptibleMask = <A, E, R>(
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
})

Expand Down Expand Up @@ -1323,8 +1323,8 @@ export const uninterruptibleMask = <A, E, R>(
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
})

Expand Down
22 changes: 11 additions & 11 deletions packages/effect/src/internal/fiberRuntime.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<any, any>,
Expand All @@ -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<any, any>,
Expand All @@ -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
}
Expand Down Expand Up @@ -1074,7 +1074,7 @@ export class FiberRuntime<in out A, in out E = never> 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)) {
Expand Down Expand Up @@ -1113,7 +1113,7 @@ export class FiberRuntime<in out A, in out E = never> 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))
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ export class FiberRuntime<in out A, in out E = never> 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<unknown, unknown>,
FiberStatus.running(this._runtimeFlags) as FiberStatus.Running
Expand Down Expand Up @@ -1210,7 +1210,7 @@ export class FiberRuntime<in out A, in out E = never> 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
}
Expand Down Expand Up @@ -1262,7 +1262,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
}

[OpCodes.OP_COMMIT](op: core.Primitive & { _op: OpCodes.OP_COMMIT }) {
return internalCall(() => op.commit())
return effect_internal_function(() => op.commit())
}

/**
Expand Down
24 changes: 13 additions & 11 deletions packages/effect/src/internal/stm/core.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -505,16 +505,18 @@ export class STMDriver<in out R, out E, out A> {
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
Expand All @@ -524,7 +526,7 @@ export class STMDriver<in out R, out E, out A> {
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
}
Expand All @@ -533,7 +535,7 @@ export class STMDriver<in out R, out E, out A> {
break
}
case OpCodes.OP_WITH_STM_RUNTIME: {
curr = internalCall(() =>
curr = effect_internal_function(() =>
current.effect_instruction_i1(this as STMDriver<unknown, unknown, unknown>) as Primitive
)
break
Expand All @@ -547,7 +549,7 @@ export class STMDriver<in out R, out E, out A> {
}
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)))
Expand All @@ -560,17 +562,17 @@ export class STMDriver<in out R, out E, out A> {
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
}
Expand Down

0 comments on commit dfc87e2

Please sign in to comment.