@@ -45289,7 +45289,7 @@ function makeOrMergeProperty(node, property, accessType) {
45289
45289
var _DependencyCollectionContext_instances, _DependencyCollectionContext_declarations, _DependencyCollectionContext_reassignments, _DependencyCollectionContext_scopes, _DependencyCollectionContext_dependencies, _DependencyCollectionContext_temporaries, _DependencyCollectionContext_temporariesUsedOutsideScope, _DependencyCollectionContext_processedInstrsInOptional, _DependencyCollectionContext_innerFnContext, _DependencyCollectionContext_checkValidDependency, _DependencyCollectionContext_isScopeActive;
45290
45290
function propagateScopeDependenciesHIR(fn) {
45291
45291
const usedOutsideDeclaringScope = findTemporariesUsedOutsideDeclaringScope(fn);
45292
- const temporaries = collectTemporariesSidemap(fn, usedOutsideDeclaringScope);
45292
+ const temporaries = collectTemporariesSidemap$1 (fn, usedOutsideDeclaringScope);
45293
45293
const { temporariesReadInOptional, processedInstrsInOptional, hoistableObjects, } = collectOptionalChainSidemap(fn);
45294
45294
const hoistablePropertyLoads = keyByScopeId(fn, collectHoistablePropertyLoads(fn, temporaries, hoistableObjects));
45295
45295
const scopeDeps = collectDependencies(fn, usedOutsideDeclaringScope, new Map([...temporaries, ...temporariesReadInOptional]), processedInstrsInOptional);
@@ -45360,7 +45360,7 @@ function findTemporariesUsedOutsideDeclaringScope(fn) {
45360
45360
}
45361
45361
return usedOutsideDeclaringScope;
45362
45362
}
45363
- function collectTemporariesSidemap(fn, usedOutsideDeclaringScope) {
45363
+ function collectTemporariesSidemap$1 (fn, usedOutsideDeclaringScope) {
45364
45364
const temporaries = new Map();
45365
45365
collectTemporariesSidemapImpl(fn, usedOutsideDeclaringScope, temporaries, null);
45366
45366
return temporaries;
@@ -46185,7 +46185,7 @@ function collectDepUsages(deps, fnExpr) {
46185
46185
}
46186
46186
function inferMinimalDependencies(fnInstr) {
46187
46187
const fn = fnInstr.value.loweredFunc.func;
46188
- const temporaries = collectTemporariesSidemap(fn, new Set());
46188
+ const temporaries = collectTemporariesSidemap$1 (fn, new Set());
46189
46189
const { hoistableObjects, processedInstrsInOptional, temporariesReadInOptional, } = collectOptionalChainSidemap(fn);
46190
46190
const hoistablePropertyLoads = collectHoistablePropertyLoadsInInnerFn(fnInstr, temporaries, hoistableObjects);
46191
46191
const hoistableToFnEntry = hoistablePropertyLoads.get(fn.body.entry);
@@ -48151,7 +48151,7 @@ function validateNoCapitalizedCalls(fn) {
48151
48151
return errors.asResult();
48152
48152
}
48153
48153
48154
- var _Env_changed;
48154
+ var _Env_changed, _Env_data, _Env_temporaries ;
48155
48155
function makeRefId(id) {
48156
48156
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
48157
48157
reason: 'Expected identifier id to be a non-negative integer',
@@ -48165,32 +48165,84 @@ let _refId = 0;
48165
48165
function nextRefId() {
48166
48166
return makeRefId(_refId++);
48167
48167
}
48168
- class Env extends Map {
48168
+ class Env {
48169
48169
constructor() {
48170
- super(...arguments);
48171
48170
_Env_changed.set(this, false);
48171
+ _Env_data.set(this, new Map());
48172
+ _Env_temporaries.set(this, new Map());
48173
+ }
48174
+ lookup(place) {
48175
+ var _a;
48176
+ return (_a = __classPrivateFieldGet(this, _Env_temporaries, "f").get(place.identifier.id)) !== null && _a !== void 0 ? _a : place;
48177
+ }
48178
+ define(place, value) {
48179
+ __classPrivateFieldGet(this, _Env_temporaries, "f").set(place.identifier.id, value);
48172
48180
}
48173
48181
resetChanged() {
48174
48182
__classPrivateFieldSet(this, _Env_changed, false, "f");
48175
48183
}
48176
48184
hasChanged() {
48177
48185
return __classPrivateFieldGet(this, _Env_changed, "f");
48178
48186
}
48187
+ get(key) {
48188
+ var _a, _b;
48189
+ const operandId = (_b = (_a = __classPrivateFieldGet(this, _Env_temporaries, "f").get(key)) === null || _a === void 0 ? void 0 : _a.identifier.id) !== null && _b !== void 0 ? _b : key;
48190
+ return __classPrivateFieldGet(this, _Env_data, "f").get(operandId);
48191
+ }
48179
48192
set(key, value) {
48180
- const cur = this.get(key);
48193
+ var _a, _b;
48194
+ const operandId = (_b = (_a = __classPrivateFieldGet(this, _Env_temporaries, "f").get(key)) === null || _a === void 0 ? void 0 : _a.identifier.id) !== null && _b !== void 0 ? _b : key;
48195
+ const cur = __classPrivateFieldGet(this, _Env_data, "f").get(operandId);
48181
48196
const widenedValue = joinRefAccessTypes(value, cur !== null && cur !== void 0 ? cur : { kind: 'None' });
48182
48197
if (!(cur == null && widenedValue.kind === 'None') &&
48183
48198
(cur == null || !tyEqual(cur, widenedValue))) {
48184
48199
__classPrivateFieldSet(this, _Env_changed, true, "f");
48185
48200
}
48186
- return super.set(key, widenedValue);
48201
+ __classPrivateFieldGet(this, _Env_data, "f").set(operandId, widenedValue);
48202
+ return this;
48187
48203
}
48188
48204
}
48189
- _Env_changed = new WeakMap();
48205
+ _Env_changed = new WeakMap(), _Env_data = new WeakMap(), _Env_temporaries = new WeakMap() ;
48190
48206
function validateNoRefAccessInRender(fn) {
48191
48207
const env = new Env();
48208
+ collectTemporariesSidemap(fn, env);
48192
48209
return validateNoRefAccessInRenderImpl(fn, env).map(_ => undefined);
48193
48210
}
48211
+ function collectTemporariesSidemap(fn, env) {
48212
+ for (const block of fn.body.blocks.values()) {
48213
+ for (const instr of block.instructions) {
48214
+ const { lvalue, value } = instr;
48215
+ switch (value.kind) {
48216
+ case 'LoadLocal': {
48217
+ const temp = env.lookup(value.place);
48218
+ if (temp != null) {
48219
+ env.define(lvalue, temp);
48220
+ }
48221
+ break;
48222
+ }
48223
+ case 'StoreLocal': {
48224
+ const temp = env.lookup(value.value);
48225
+ if (temp != null) {
48226
+ env.define(lvalue, temp);
48227
+ env.define(value.lvalue.place, temp);
48228
+ }
48229
+ break;
48230
+ }
48231
+ case 'PropertyLoad': {
48232
+ if (isUseRefType(value.object.identifier) &&
48233
+ value.property === 'current') {
48234
+ continue;
48235
+ }
48236
+ const temp = env.lookup(value.object);
48237
+ if (temp != null) {
48238
+ env.define(lvalue, temp);
48239
+ }
48240
+ break;
48241
+ }
48242
+ }
48243
+ }
48244
+ }
48245
+ }
48194
48246
function refTypeOfType(place) {
48195
48247
if (isRefValueType(place.identifier)) {
48196
48248
return { kind: 'RefValue' };
@@ -48517,11 +48569,21 @@ function validateNoRefAccessInRenderImpl(fn, env) {
48517
48569
else {
48518
48570
validateNoRefUpdate(errors, env, instr.value.object, instr.loc);
48519
48571
}
48520
- for (const operand of eachInstructionValueOperand(instr.value)) {
48521
- if (operand === instr.value.object) {
48522
- continue;
48572
+ if (instr.value.kind === 'ComputedDelete' ||
48573
+ instr.value.kind === 'ComputedStore') {
48574
+ validateNoRefValueAccess(errors, env, instr.value.property);
48575
+ }
48576
+ if (instr.value.kind === 'ComputedStore' ||
48577
+ instr.value.kind === 'PropertyStore') {
48578
+ validateNoDirectRefValueAccess(errors, instr.value.value, env);
48579
+ const type = env.get(instr.value.value.identifier.id);
48580
+ if (type != null && type.kind === 'Structure') {
48581
+ let objectType = type;
48582
+ if (target != null) {
48583
+ objectType = joinRefAccessTypes(objectType, target);
48584
+ }
48585
+ env.set(instr.value.object.identifier.id, objectType);
48523
48586
}
48524
- validateNoRefValueAccess(errors, env, operand);
48525
48587
}
48526
48588
break;
48527
48589
}
@@ -48665,11 +48727,8 @@ function validateNoRefPassedToFunction(errors, env, operand, loc) {
48665
48727
}
48666
48728
}
48667
48729
function validateNoRefUpdate(errors, env, operand, loc) {
48668
- var _a;
48669
48730
const type = destructure(env.get(operand.identifier.id));
48670
- if ((type === null || type === void 0 ? void 0 : type.kind) === 'Ref' ||
48671
- (type === null || type === void 0 ? void 0 : type.kind) === 'RefValue' ||
48672
- ((type === null || type === void 0 ? void 0 : type.kind) === 'Structure' && ((_a = type.fn) === null || _a === void 0 ? void 0 : _a.readRefEffect))) {
48731
+ if ((type === null || type === void 0 ? void 0 : type.kind) === 'Ref' || (type === null || type === void 0 ? void 0 : type.kind) === 'RefValue') {
48673
48732
errors.pushDiagnostic(CompilerDiagnostic.create({
48674
48733
severity: ErrorSeverity.InvalidReact,
48675
48734
category: 'Cannot access refs during render',
0 commit comments