Skip to content

Commit

Permalink
Revert "Delete LanePriority type (facebook#21090)"
Browse files Browse the repository at this point in the history
This reverts commit 26ddc63.

No longer using LanePriority anywhere, so this deletes the
remaining references.
  • Loading branch information
acdlite authored and koto committed Jun 15, 2021
1 parent d03ed9d commit 1225c42
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
76 changes: 76 additions & 0 deletions packages/react-reconciler/src/ReactFiberLane.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ import type {FiberRoot} from './ReactInternalTypes';

// TODO: Ideally these types would be opaque but that doesn't work well with
// our reconciler fork infra, since these leak into non-reconciler packages.
export type LanePriority =
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17;

export type Lanes = number;
export type Lane = number;
Expand All @@ -24,6 +43,28 @@ import {
} from 'shared/ReactFeatureFlags';
import {isDevToolsPresent} from './ReactFiberDevToolsHook.new';

export const SyncLanePriority: LanePriority = 12;

const InputContinuousHydrationLanePriority: LanePriority = 11;
export const InputContinuousLanePriority: LanePriority = 10;

const DefaultHydrationLanePriority: LanePriority = 9;
export const DefaultLanePriority: LanePriority = 8;

const TransitionHydrationPriority: LanePriority = 7;
export const TransitionPriority: LanePriority = 6;

const RetryLanePriority: LanePriority = 5;

const SelectiveHydrationLanePriority: LanePriority = 4;

const IdleHydrationLanePriority: LanePriority = 3;
export const IdleLanePriority: LanePriority = 2;

const OffscreenLanePriority: LanePriority = 1;

export const NoLanePriority: LanePriority = 0;

// Lane values below should be kept in sync with getLabelsForLanes(), used by react-devtools-scheduling-profiler.
// If those values are changed that package should be rebuilt and redeployed.

Expand Down Expand Up @@ -127,19 +168,29 @@ export const NoTimestamp = -1;
let nextTransitionLane: Lane = TransitionLane1;
let nextRetryLane: Lane = RetryLane1;

// "Registers" used to "return" multiple values
// Used by getHighestPriorityLanes and getNextLanes:
let return_highestLanePriority: LanePriority = DefaultLanePriority;

function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
switch (getHighestPriorityLane(lanes)) {
case SyncLane:
return_highestLanePriority = SyncLanePriority;
return SyncLane;
case InputContinuousHydrationLane:
return_highestLanePriority = InputContinuousHydrationLanePriority;
return InputContinuousHydrationLane;
case InputContinuousLane:
return_highestLanePriority = InputContinuousLanePriority;
return InputContinuousLane;
case DefaultHydrationLane:
return_highestLanePriority = DefaultHydrationLanePriority;
return DefaultHydrationLane;
case DefaultLane:
return_highestLanePriority = DefaultLanePriority;
return DefaultLane;
case TransitionHydrationLane:
return_highestLanePriority = TransitionHydrationPriority;
return TransitionHydrationLane;
case TransitionLane1:
case TransitionLane2:
Expand All @@ -157,20 +208,26 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
case TransitionLane14:
case TransitionLane15:
case TransitionLane16:
return_highestLanePriority = TransitionPriority;
return lanes & TransitionLanes;
case RetryLane1:
case RetryLane2:
case RetryLane3:
case RetryLane4:
case RetryLane5:
return_highestLanePriority = RetryLanePriority;
return lanes & RetryLanes;
case SelectiveHydrationLane:
return_highestLanePriority = SelectiveHydrationLanePriority;
return SelectiveHydrationLane;
case IdleHydrationLane:
return_highestLanePriority = IdleHydrationLanePriority;
return IdleHydrationLane;
case IdleLane:
return_highestLanePriority = IdleLanePriority;
return IdleLane;
case OffscreenLane:
return_highestLanePriority = OffscreenLanePriority;
return OffscreenLane;
default:
if (__DEV__) {
Expand All @@ -179,6 +236,7 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
);
}
// This shouldn't be reachable, but as a fallback, return the entire bitmask.
return_highestLanePriority = DefaultLanePriority;
return lanes;
}
}
Expand All @@ -187,10 +245,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
// Early bailout if there's no pending work left.
const pendingLanes = root.pendingLanes;
if (pendingLanes === NoLanes) {
return_highestLanePriority = NoLanePriority;
return NoLanes;
}

let nextLanes = NoLanes;
let nextLanePriority = NoLanePriority;

const suspendedLanes = root.suspendedLanes;
const pingedLanes = root.pingedLanes;
Expand All @@ -202,20 +262,24 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
const nonIdleUnblockedLanes = nonIdlePendingLanes & ~suspendedLanes;
if (nonIdleUnblockedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(nonIdleUnblockedLanes);
nextLanePriority = return_highestLanePriority;
} else {
const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes;
if (nonIdlePingedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(nonIdlePingedLanes);
nextLanePriority = return_highestLanePriority;
}
}
} else {
// The only remaining work is Idle.
const unblockedLanes = pendingLanes & ~suspendedLanes;
if (unblockedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(unblockedLanes);
nextLanePriority = return_highestLanePriority;
} else {
if (pingedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(pingedLanes);
nextLanePriority = return_highestLanePriority;
}
}
}
Expand Down Expand Up @@ -249,6 +313,8 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
) {
// Keep working on the existing in-progress tree. Do not interrupt.
return wipLanes;
} else {
return_highestLanePriority = nextLanePriority;
}
}

Expand Down Expand Up @@ -443,6 +509,9 @@ export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {
return NoLanes;
}

export function returnNextLanesPriority() {
return return_highestLanePriority;
}
export function includesNonIdleWork(lanes: Lanes) {
return (lanes & NonIdleLanes) !== NoLanes;
}
Expand Down Expand Up @@ -548,6 +617,13 @@ export function higherPriorityLane(a: Lane, b: Lane) {
return a !== NoLane && a < b ? a : b;
}

export function higherLanePriority(
a: LanePriority,
b: LanePriority,
): LanePriority {
return a !== NoLanePriority && a > b ? a : b;
}

export function createLaneMap<T>(initial: T): LaneMap<T> {
// Intentionally pushing one by one.
// https://v8.dev/blog/elements-kinds#avoid-creating-holes
Expand Down
76 changes: 76 additions & 0 deletions packages/react-reconciler/src/ReactFiberLane.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ import type {FiberRoot} from './ReactInternalTypes';

// TODO: Ideally these types would be opaque but that doesn't work well with
// our reconciler fork infra, since these leak into non-reconciler packages.
export type LanePriority =
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17;

export type Lanes = number;
export type Lane = number;
Expand All @@ -24,6 +43,28 @@ import {
} from 'shared/ReactFeatureFlags';
import {isDevToolsPresent} from './ReactFiberDevToolsHook.old';

export const SyncLanePriority: LanePriority = 12;

const InputContinuousHydrationLanePriority: LanePriority = 11;
export const InputContinuousLanePriority: LanePriority = 10;

const DefaultHydrationLanePriority: LanePriority = 9;
export const DefaultLanePriority: LanePriority = 8;

const TransitionHydrationPriority: LanePriority = 7;
export const TransitionPriority: LanePriority = 6;

const RetryLanePriority: LanePriority = 5;

const SelectiveHydrationLanePriority: LanePriority = 4;

const IdleHydrationLanePriority: LanePriority = 3;
export const IdleLanePriority: LanePriority = 2;

const OffscreenLanePriority: LanePriority = 1;

export const NoLanePriority: LanePriority = 0;

// Lane values below should be kept in sync with getLabelsForLanes(), used by react-devtools-scheduling-profiler.
// If those values are changed that package should be rebuilt and redeployed.

Expand Down Expand Up @@ -127,19 +168,29 @@ export const NoTimestamp = -1;
let nextTransitionLane: Lane = TransitionLane1;
let nextRetryLane: Lane = RetryLane1;

// "Registers" used to "return" multiple values
// Used by getHighestPriorityLanes and getNextLanes:
let return_highestLanePriority: LanePriority = DefaultLanePriority;

function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
switch (getHighestPriorityLane(lanes)) {
case SyncLane:
return_highestLanePriority = SyncLanePriority;
return SyncLane;
case InputContinuousHydrationLane:
return_highestLanePriority = InputContinuousHydrationLanePriority;
return InputContinuousHydrationLane;
case InputContinuousLane:
return_highestLanePriority = InputContinuousLanePriority;
return InputContinuousLane;
case DefaultHydrationLane:
return_highestLanePriority = DefaultHydrationLanePriority;
return DefaultHydrationLane;
case DefaultLane:
return_highestLanePriority = DefaultLanePriority;
return DefaultLane;
case TransitionHydrationLane:
return_highestLanePriority = TransitionHydrationPriority;
return TransitionHydrationLane;
case TransitionLane1:
case TransitionLane2:
Expand All @@ -157,20 +208,26 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
case TransitionLane14:
case TransitionLane15:
case TransitionLane16:
return_highestLanePriority = TransitionPriority;
return lanes & TransitionLanes;
case RetryLane1:
case RetryLane2:
case RetryLane3:
case RetryLane4:
case RetryLane5:
return_highestLanePriority = RetryLanePriority;
return lanes & RetryLanes;
case SelectiveHydrationLane:
return_highestLanePriority = SelectiveHydrationLanePriority;
return SelectiveHydrationLane;
case IdleHydrationLane:
return_highestLanePriority = IdleHydrationLanePriority;
return IdleHydrationLane;
case IdleLane:
return_highestLanePriority = IdleLanePriority;
return IdleLane;
case OffscreenLane:
return_highestLanePriority = OffscreenLanePriority;
return OffscreenLane;
default:
if (__DEV__) {
Expand All @@ -179,6 +236,7 @@ function getHighestPriorityLanes(lanes: Lanes | Lane): Lanes {
);
}
// This shouldn't be reachable, but as a fallback, return the entire bitmask.
return_highestLanePriority = DefaultLanePriority;
return lanes;
}
}
Expand All @@ -187,10 +245,12 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
// Early bailout if there's no pending work left.
const pendingLanes = root.pendingLanes;
if (pendingLanes === NoLanes) {
return_highestLanePriority = NoLanePriority;
return NoLanes;
}

let nextLanes = NoLanes;
let nextLanePriority = NoLanePriority;

const suspendedLanes = root.suspendedLanes;
const pingedLanes = root.pingedLanes;
Expand All @@ -202,20 +262,24 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
const nonIdleUnblockedLanes = nonIdlePendingLanes & ~suspendedLanes;
if (nonIdleUnblockedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(nonIdleUnblockedLanes);
nextLanePriority = return_highestLanePriority;
} else {
const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes;
if (nonIdlePingedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(nonIdlePingedLanes);
nextLanePriority = return_highestLanePriority;
}
}
} else {
// The only remaining work is Idle.
const unblockedLanes = pendingLanes & ~suspendedLanes;
if (unblockedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(unblockedLanes);
nextLanePriority = return_highestLanePriority;
} else {
if (pingedLanes !== NoLanes) {
nextLanes = getHighestPriorityLanes(pingedLanes);
nextLanePriority = return_highestLanePriority;
}
}
}
Expand Down Expand Up @@ -249,6 +313,8 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
) {
// Keep working on the existing in-progress tree. Do not interrupt.
return wipLanes;
} else {
return_highestLanePriority = nextLanePriority;
}
}

Expand Down Expand Up @@ -443,6 +509,9 @@ export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {
return NoLanes;
}

export function returnNextLanesPriority() {
return return_highestLanePriority;
}
export function includesNonIdleWork(lanes: Lanes) {
return (lanes & NonIdleLanes) !== NoLanes;
}
Expand Down Expand Up @@ -548,6 +617,13 @@ export function higherPriorityLane(a: Lane, b: Lane) {
return a !== NoLane && a < b ? a : b;
}

export function higherLanePriority(
a: LanePriority,
b: LanePriority,
): LanePriority {
return a !== NoLanePriority && a > b ? a : b;
}

export function createLaneMap<T>(initial: T): LaneMap<T> {
// Intentionally pushing one by one.
// https://v8.dev/blog/elements-kinds#avoid-creating-holes
Expand Down

0 comments on commit 1225c42

Please sign in to comment.