|
| 1 | + |
| 2 | +## Input |
| 3 | + |
| 4 | +```javascript |
| 5 | +import { |
| 6 | + arrayPush, |
| 7 | + identity, |
| 8 | + makeArray, |
| 9 | + Stringify, |
| 10 | + useFragment, |
| 11 | +} from 'shared-runtime'; |
| 12 | + |
| 13 | +/** |
| 14 | + * Bug repro showing why it's invalid for function references to be annotated |
| 15 | + * with a `Read` effect when that reference might lead to the function being |
| 16 | + * invoked. |
| 17 | + * |
| 18 | + * Note that currently, `Array.map` is annotated to have `Read` effects on its |
| 19 | + * operands. This is incorrect as function effects must be replayed when `map` |
| 20 | + * is called |
| 21 | + * - Read: non-aliasing data dependency |
| 22 | + * - Capture: maybe-aliasing data dependency |
| 23 | + * - ConditionallyMutate: maybe-aliasing data dependency; maybe-write / invoke |
| 24 | + * but only if the value is mutable |
| 25 | + * |
| 26 | + * Invalid evaluator result: Found differences in evaluator results Non-forget |
| 27 | + * (expected): (kind: ok) |
| 28 | + * <div>{"x":[2,2,2],"count":3}</div><div>{"item":1}</div> |
| 29 | + * <div>{"x":[2,2,2],"count":4}</div><div>{"item":1}</div> |
| 30 | + * Forget: |
| 31 | + * (kind: ok) |
| 32 | + * <div>{"x":[2,2,2],"count":3}</div><div>{"item":1}</div> |
| 33 | + * <div>{"x":[2,2,2,2,2,2],"count":4}</div><div>{"item":1}</div> |
| 34 | + */ |
| 35 | + |
| 36 | +function Component({extraJsx}) { |
| 37 | + const x = makeArray(); |
| 38 | + const items = useFragment(); |
| 39 | + // This closure has the following effects that must be replayed: |
| 40 | + // - MaybeFreeze / Capture of `items` |
| 41 | + // - ConditionalMutate of x |
| 42 | + const jsx = items.a.map((item, i) => { |
| 43 | + arrayPush(x, 2); |
| 44 | + return <Stringify item={item} key={i} />; |
| 45 | + }); |
| 46 | + const offset = jsx.length; |
| 47 | + for (let i = 0; i < extraJsx; i++) { |
| 48 | + jsx.push(<Stringify item={0} key={i + offset} />); |
| 49 | + } |
| 50 | + const count = jsx.length; |
| 51 | + identity(count); |
| 52 | + return ( |
| 53 | + <> |
| 54 | + <Stringify x={x} count={count} /> |
| 55 | + {jsx[0]} |
| 56 | + </> |
| 57 | + ); |
| 58 | +} |
| 59 | +export const FIXTURE_ENTRYPOINT = { |
| 60 | + fn: Component, |
| 61 | + params: [{extraJsx: 0}], |
| 62 | + sequentialRenders: [{extraJsx: 0}, {extraJsx: 1}], |
| 63 | +}; |
| 64 | + |
| 65 | +``` |
| 66 | + |
| 67 | +## Code |
| 68 | + |
| 69 | +```javascript |
| 70 | +import { c as _c } from "react/compiler-runtime"; |
| 71 | +import { |
| 72 | + arrayPush, |
| 73 | + identity, |
| 74 | + makeArray, |
| 75 | + Stringify, |
| 76 | + useFragment, |
| 77 | +} from "shared-runtime"; |
| 78 | + |
| 79 | +/** |
| 80 | + * Bug repro showing why it's invalid for function references to be annotated |
| 81 | + * with a `Read` effect when that reference might lead to the function being |
| 82 | + * invoked. |
| 83 | + * |
| 84 | + * Note that currently, `Array.map` is annotated to have `Read` effects on its |
| 85 | + * operands. This is incorrect as function effects must be replayed when `map` |
| 86 | + * is called |
| 87 | + * - Read: non-aliasing data dependency |
| 88 | + * - Capture: maybe-aliasing data dependency |
| 89 | + * - ConditionallyMutate: maybe-aliasing data dependency; maybe-write / invoke |
| 90 | + * but only if the value is mutable |
| 91 | + * |
| 92 | + * Invalid evaluator result: Found differences in evaluator results Non-forget |
| 93 | + * (expected): (kind: ok) |
| 94 | + * <div>{"x":[2,2,2],"count":3}</div><div>{"item":1}</div> |
| 95 | + * <div>{"x":[2,2,2],"count":4}</div><div>{"item":1}</div> |
| 96 | + * Forget: |
| 97 | + * (kind: ok) |
| 98 | + * <div>{"x":[2,2,2],"count":3}</div><div>{"item":1}</div> |
| 99 | + * <div>{"x":[2,2,2,2,2,2],"count":4}</div><div>{"item":1}</div> |
| 100 | + */ |
| 101 | + |
| 102 | +function Component(t0) { |
| 103 | + const $ = _c(6); |
| 104 | + const { extraJsx } = t0; |
| 105 | + const x = makeArray(); |
| 106 | + const items = useFragment(); |
| 107 | + |
| 108 | + const jsx = items.a.map((item, i) => { |
| 109 | + arrayPush(x, 2); |
| 110 | + return <Stringify item={item} key={i} />; |
| 111 | + }); |
| 112 | + const offset = jsx.length; |
| 113 | + for (let i_0 = 0; i_0 < extraJsx; i_0++) { |
| 114 | + jsx.push(<Stringify item={0} key={i_0 + offset} />); |
| 115 | + } |
| 116 | + |
| 117 | + const count = jsx.length; |
| 118 | + identity(count); |
| 119 | + let t1; |
| 120 | + if ($[0] !== count || $[1] !== x) { |
| 121 | + t1 = <Stringify x={x} count={count} />; |
| 122 | + $[0] = count; |
| 123 | + $[1] = x; |
| 124 | + $[2] = t1; |
| 125 | + } else { |
| 126 | + t1 = $[2]; |
| 127 | + } |
| 128 | + const t2 = jsx[0]; |
| 129 | + let t3; |
| 130 | + if ($[3] !== t1 || $[4] !== t2) { |
| 131 | + t3 = ( |
| 132 | + <> |
| 133 | + {t1} |
| 134 | + {t2} |
| 135 | + </> |
| 136 | + ); |
| 137 | + $[3] = t1; |
| 138 | + $[4] = t2; |
| 139 | + $[5] = t3; |
| 140 | + } else { |
| 141 | + t3 = $[5]; |
| 142 | + } |
| 143 | + return t3; |
| 144 | +} |
| 145 | + |
| 146 | +export const FIXTURE_ENTRYPOINT = { |
| 147 | + fn: Component, |
| 148 | + params: [{ extraJsx: 0 }], |
| 149 | + sequentialRenders: [{ extraJsx: 0 }, { extraJsx: 1 }], |
| 150 | +}; |
| 151 | + |
| 152 | +``` |
| 153 | + |
| 154 | +### Eval output |
| 155 | +(kind: ok) <div>{"x":[2,2,2],"count":3}</div><div>{"item":1}</div> |
| 156 | +<div>{"x":[2,2,2],"count":4}</div><div>{"item":1}</div> |
0 commit comments