mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +00:00
fix(javascript): move reader effect reads into the effect log and order require and process rebinding by activation (#11356)
* refactor(javascript): move the last reader effect reads into the effect log * refactor(javascript): skip escapes when a reader asks only about member writes * fix(javascript): order require and process rebinding by activation timing (#11479) * refactor(javascript): ask one ordering whether require was rebound before a call * refactor(javascript): order process replacement by activation, like require * fix(javascript): keep instance field values out of literal-loop source ordering * fix(javascript): stop effect ordering at instance field values inside the effect semanticEffectFollowsReference proved that an assignment follows a read written inside its own right-hand side, even when the read sits in an instance field value, which runs on construction after the assignment. process = class { value = process.env.MODE; }; new process() therefore kept the original process identity, and require = class { fs = require('fs') } kept a Node module origin. The first walk now stops at instance field values like it stops at function bodies. * fix(javascript): attribute process effects that may reach the original object (#11521) * fix(javascript): attribute process effects that may reach the original object A write or escape through the global process object was attributed to node:process only when no replacement of process may precede it. Effects need the opposite question: they reach the original unless a replacement with a fresh object is proven to run before them. The effect log gains ambientReplacementPrecedes (the must counterpart of the may-observe queries), RequireOrigin owns the effect question, and member mutation asks it for direct, qualified and ambient process effects. Refs #11488 * fix(javascript): prove a process replacement with the global path reader ambientReplacementPrecedes accepted any earlier fresh assignment of the process path, even when a later write might restore the original or when the assignment went through a possible alias of the global object. The global path reader already owns definite replacement at a site (it checks the written namespace and every competing write), so the effect question asks it and keeps only the freshness check. ambientReplacementPrecedes is removed.
This commit is contained in:
1 parent
1f24b3fa57
commit
0a7d288ed8
14 files changed
+770
-261
No files matched your search
@@ -292,7 +292,10 @@ export const semanticEffectFollowsReference = (
|
||||
let current: t.Node | undefined = reference;
|
||||
let child: t.Node | undefined;
|
||||
while (current !== undefined && current !== effect) {
|
||||
if (t.isFunction(current)) break;
|
||||
// A function body or instance field value runs later, on its own
|
||||
// activation, even when it is written inside the effect.
|
||||
if (t.isFunction(current) || delayedInstanceFieldValue(current, child))
|
||||
break;
|
||||
child = current;
|
||||
current = parents.get(current);
|
||||
}
|
||||
@@ -358,17 +361,9 @@ export const semanticEffectTiming = (
|
||||
if (cardinality === "empty") return "after";
|
||||
if (cardinality === "nonempty") {
|
||||
const loopParent = state.parentsByNode.get(loop);
|
||||
const crossesFunction = (node: t.Node): boolean => {
|
||||
let current: t.Node | undefined = node;
|
||||
while (current !== undefined) {
|
||||
if (t.isFunction(current)) return true;
|
||||
current = state.parentsByNode.get(current);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (
|
||||
loopParent === state.program &&
|
||||
!crossesFunction(site) &&
|
||||
runsInProgramActivation(site, state.program, state.parentsByNode) &&
|
||||
typeof loop.start === "number" &&
|
||||
typeof loop.end === "number" &&
|
||||
typeof site.start === "number"
|
||||
@@ -385,16 +380,45 @@ export const semanticEffectTiming = (
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether `node` runs when the program body itself runs: no function body or
|
||||
* instance field value, which run later, on a call or a construction, lies
|
||||
* between it and the program.
|
||||
*/
|
||||
const runsInProgramActivation = (
|
||||
node: t.Node,
|
||||
program: t.Node,
|
||||
parents: WeakMap<t.Node, t.Node>,
|
||||
): boolean => {
|
||||
let child: t.Node | undefined;
|
||||
for (
|
||||
let current: t.Node | undefined = node;
|
||||
current !== undefined && current !== program;
|
||||
current = parents.get(current)
|
||||
) {
|
||||
if (t.isFunction(current) || delayedInstanceFieldValue(current, child))
|
||||
return false;
|
||||
child = current;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/** The for-in/of loop whose body runs `node` in the same activation. */
|
||||
const semanticEnclosingIteration = (
|
||||
node: t.Node,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): t.ForInStatement | t.ForOfStatement | undefined => {
|
||||
let current: t.Node | undefined = node;
|
||||
while (current !== undefined) {
|
||||
let child: t.Node | undefined;
|
||||
for (
|
||||
let current: t.Node | undefined = node;
|
||||
current !== undefined;
|
||||
current = state.parentsByNode.get(current)
|
||||
) {
|
||||
if (t.isForInStatement(current) || t.isForOfStatement(current))
|
||||
return current;
|
||||
if (t.isFunction(current)) return undefined;
|
||||
current = state.parentsByNode.get(current);
|
||||
if (t.isFunction(current) || delayedInstanceFieldValue(current, child))
|
||||
return undefined;
|
||||
child = current;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user