@samitouri / QOS-React-2 / commits / 9d97015236

[globals] Remove global shape for Array.from

Type inference currently assumes that a `FunctionSignature`'s effects have no false positives. If a `mutate` effect is observed on a read-only place, Forget currently assumes this is an user error and [throws](https://github.com/facebook/react-forget/blob/207595e04e2be08b8f62bf21dac9d846b9651e43/forget/src/Inference/InferReferenceEffects.ts#L275-L281). Array.from is polymorphic -- its effects are dependent on the type of its parameters

mofeiZ committed Apr 5, 2023 at 12:53 UTC 9d97015236b8f19bbf313e98065aaeb4d0322cbc
1 file changed +9 -10
compiler/forget/src/HIR/Globals.ts
+9 -10
@@ -87,16 +87,15 @@ const TYPED_GLOBALS: Array<[string, BuiltInType]> = [
87 calleeEffect: Effect.Read,
88 }),
89 ],
90 - [
91 - "from",
92 - // Array.from(arrayLike, optionalFn, optionalThis)
93 - addFunction(DEFAULT_SHAPES, [], {
94 - positionalParams: [Effect.Mutate],
95 - restParam: Effect.Read,
96 - returnType: { kind: "Object", shapeId: BuiltInArrayId },
97 - calleeEffect: Effect.Read,
98 - }),
99 - ],
90 + // https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.from
91 + // Array.from(arrayLike, optionalFn, optionalThis) not added because
92 + // the Effect of `arrayLike` is polymorphic i.e.
93 + // - Effect.read if
94 + // - it does not have an @iterator property and is array-like
95 + // (i.e. has a length property)
96 + /// - it is an iterable object whose iterator does not mutate itself
97 + // - Effect.mutate if it is a self-mutative iterator (e.g. a generator
98 + // function)
99 [
100 "of",
101 // Array.of(element0, ..., elementN)