[compiler] Collapse CompilerError.{invariant,simpleInvariant} (#35614)
`invariant()` was a pain to use - we always record a single location, but the API required passing a compiler detail. This PR replaces `invariant()` (keeping the name) with `simpleInvariant()`s signature, and updates call sites accordingly. I've noticed that agents consistently get invariant() wrong, which aligns with it being tedious to call when you're writing code by hand. The simplified API should help a bit.
Joseph Savona committed
Jan 23, 2026 at 11:07 UTC
006ae379727ebceb82d03929222a71104d01135f
72 files changed
+316
-2183
compiler/packages/babel-plugin-react-compiler/src/CompilerError.ts
+3
-18
@@ -304,11 +304,12 @@ export class CompilerError extends Error {
304
disabledDetails: Array<CompilerErrorDetail | CompilerDiagnostic> = [];
305
printedMessage: string | null = null;
306
307
- static simpleInvariant(
307
+ static invariant(
308
condition: unknown,
309
options: {
310
reason: CompilerDiagnosticOptions['reason'];
311
description?: CompilerDiagnosticOptions['description'];
312
+ message?: string | null;
313
loc: SourceLocation;
314
},
315
): asserts condition {
@@ -322,28 +323,12 @@ export class CompilerError extends Error {
323
}).withDetails({
324
kind: 'error',
325
loc: options.loc,
325
- message: options.reason,
326
+ message: options.message ?? options.reason,
327
}),
328
);
329
throw errors;
330
}
331
}
331
- static invariant(
332
- condition: unknown,
333
- options: Omit<CompilerDiagnosticOptions, 'category'>,
334
- ): asserts condition {
335
- if (!condition) {
336
- const errors = new CompilerError();
337
- errors.pushDiagnostic(
338
- CompilerDiagnostic.create({
339
- reason: options.reason,
340
- description: options.description,
341
- category: ErrorCategory.Invariant,
342
- }).withDetails(...options.details),
343
- );
344
- throw errors;
345
- }
346
- }
332
333
static throwDiagnostic(options: CompilerDiagnosticOptions): never {
334
const errors = new CompilerError();
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Gating.ts
+4
-23
@@ -8,6 +8,7 @@
8
import {NodePath} from '@babel/core';
9
import * as t from '@babel/types';
10
import {CompilerError} from '../CompilerError';
11
+import {GeneratedSource} from '../HIR';
12
import {ProgramContext} from './Imports';
13
import {ExternalFunction} from '..';
14
@@ -51,26 +52,12 @@ function insertAdditionalFunctionDeclaration(
52
CompilerError.invariant(originalFnName != null && compiled.id != null, {
53
reason:
54
'Expected function declarations that are referenced elsewhere to have a named identifier',
54
- description: null,
55
- details: [
56
- {
57
- kind: 'error',
58
- loc: fnPath.node.loc ?? null,
59
- message: null,
60
- },
61
- ],
55
+ loc: fnPath.node.loc ?? GeneratedSource,
56
});
57
CompilerError.invariant(originalFnParams.length === compiledParams.length, {
58
reason:
59
'Expected React Compiler optimized function declarations to have the same number of parameters as source',
66
- description: null,
67
- details: [
68
- {
69
- kind: 'error',
70
- loc: fnPath.node.loc ?? null,
71
- message: null,
72
- },
73
- ],
60
+ loc: fnPath.node.loc ?? GeneratedSource,
61
});
62
63
const gatingCondition = t.identifier(
@@ -154,13 +141,7 @@ export function insertGatedFunctionDeclaration(
141
CompilerError.invariant(compiled.type === 'FunctionDeclaration', {
142
reason: 'Expected compiled node type to match input type',
143
description: `Got ${compiled.type} but expected FunctionDeclaration`,
157
- details: [
158
- {
159
- kind: 'error',
160
- loc: fnPath.node.loc ?? null,
161
- message: null,
162
- },
163
- ],
144
+ loc: fnPath.node.loc ?? GeneratedSource,
145
});
146
insertAdditionalFunctionDeclaration(
147
fnPath,
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Imports.ts
+2
-15
@@ -257,14 +257,7 @@ export function addImportsToProgram(
257
reason:
258
'Encountered conflicting import specifiers in generated program',
259
description: `Conflict from import ${loweredImport.module}:(${loweredImport.imported} as ${loweredImport.name})`,
260
- details: [
261
- {
262
- kind: 'error',
263
- loc: GeneratedSource,
264
- message: null,
265
- },
266
- ],
267
- suggestions: null,
260
+ loc: GeneratedSource,
261
},
262
);
263
CompilerError.invariant(
@@ -274,13 +267,7 @@ export function addImportsToProgram(
267
reason:
268
'Found inconsistent import specifier. This is an internal bug.',
269
description: `Expected import ${moduleName}:${specifierName} but found ${loweredImport.module}:${loweredImport.imported}`,
277
- details: [
278
- {
279
- kind: 'error',
280
- loc: GeneratedSource,
281
- message: null,
282
- },
283
- ],
270
+ loc: GeneratedSource,
271
},
272
);
273
}
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts
+3
-24
@@ -315,13 +315,7 @@ function insertNewOutlinedFunctionNode(
315
CompilerError.invariant(insertedFuncDecl.isFunctionDeclaration(), {
316
reason: 'Expected inserted function declaration',
317
description: `Got: ${insertedFuncDecl}`,
318
- details: [
319
- {
320
- kind: 'error',
321
- loc: insertedFuncDecl.node?.loc ?? null,
322
- message: null,
323
- },
324
- ],
318
+ loc: insertedFuncDecl.node?.loc ?? GeneratedSource,
319
});
320
return insertedFuncDecl;
321
}
@@ -446,14 +440,7 @@ export function compileProgram(
440
for (const outlined of compiled.outlined) {
441
CompilerError.invariant(outlined.fn.outlined.length === 0, {
442
reason: 'Unexpected nested outlined functions',
449
- description: null,
450
- details: [
451
- {
452
- kind: 'error',
453
- loc: outlined.fn.loc,
454
- message: null,
455
- },
456
- ],
443
+ loc: outlined.fn.loc,
444
});
445
const fn = insertNewOutlinedFunctionNode(
446
program,
@@ -1451,15 +1438,7 @@ export function getReactCompilerRuntimeModule(
1438
typeof target.runtimeModule === 'string',
1439
{
1440
reason: 'Expected target to already be validated',
1454
- description: null,
1455
- details: [
1456
- {
1457
- kind: 'error',
1458
- loc: null,
1459
- message: null,
1460
- },
1461
- ],
1462
- suggestions: null,
1441
+ loc: GeneratedSource,
1442
},
1443
);
1444
return target.runtimeModule;
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Suppression.ts
+1
-8
@@ -163,14 +163,7 @@ export function suppressionsToCompilerError(
163
): CompilerError {
164
CompilerError.invariant(suppressionRanges.length !== 0, {
165
reason: `Expected at least suppression comment source range`,
166
- description: null,
167
- details: [
168
- {
169
- kind: 'error',
170
- loc: GeneratedSource,
171
- message: null,
172
- },
173
- ],
166
+ loc: GeneratedSource,
167
});
168
const error = new CompilerError();
169
for (const suppressionRange of suppressionRanges) {
compiler/packages/babel-plugin-react-compiler/src/Entrypoint/ValidateNoUntransformedReferences.ts
+2
-16
@@ -215,14 +215,7 @@ function validateImportSpecifier(
215
const binding = local.scope.getBinding(local.node.name);
216
CompilerError.invariant(binding != null, {
217
reason: 'Expected binding to be found for import specifier',
218
- description: null,
219
- details: [
220
- {
221
- kind: 'error',
222
- loc: local.node.loc ?? null,
223
- message: null,
224
- },
225
- ],
218
+ loc: local.node.loc ?? GeneratedSource,
219
});
220
checkFn(binding.referencePaths, state);
221
}
@@ -242,14 +235,7 @@ function validateNamespacedImport(
235
236
CompilerError.invariant(binding != null, {
237
reason: 'Expected binding to be found for import specifier',
245
- description: null,
246
- details: [
247
- {
248
- kind: 'error',
249
- loc: local.node.loc ?? null,
250
- message: null,
251
- },
252
- ],
238
+ loc: local.node.loc ?? GeneratedSource,
239
});
240
const filteredReferences = new Map<
241
CheckInvalidReferenceFn,
compiler/packages/babel-plugin-react-compiler/src/Flood/TypeErrors.ts
+1
-8
@@ -46,14 +46,7 @@ export function raiseUnificationErrors(
46
if (errs.length === 0) {
47
CompilerError.invariant(false, {
48
reason: 'Should not have array of zero errors',
49
- description: null,
50
- details: [
51
- {
52
- kind: 'error',
53
- loc,
54
- message: null,
55
- },
56
- ],
49
+ loc,
50
});
51
} else if (errs.length === 1) {
52
CompilerError.throwInvalidJS({
compiler/packages/babel-plugin-react-compiler/src/Flood/Types.ts
+9
-75
@@ -151,15 +151,7 @@ export type LinearId = number & {
151
export function makeLinearId(id: number): LinearId {
152
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
153
reason: 'Expected LinearId id to be a non-negative integer',
154
- description: null,
155
- details: [
156
- {
157
- kind: 'error',
158
- loc: null,
159
- message: null,
160
- },
161
- ],
162
- suggestions: null,
154
+ loc: GeneratedSource,
155
});
156
return id as LinearId;
157
}
@@ -172,15 +164,7 @@ export type TypeParameterId = number & {
164
export function makeTypeParameterId(id: number): TypeParameterId {
165
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
166
reason: 'Expected TypeParameterId to be a non-negative integer',
175
- description: null,
176
- details: [
177
- {
178
- kind: 'error',
179
- loc: null,
180
- message: null,
181
- },
182
- ],
183
- suggestions: null,
167
+ loc: GeneratedSource,
168
});
169
return id as TypeParameterId;
170
}
@@ -202,15 +186,7 @@ export type VariableId = number & {
186
export function makeVariableId(id: number): VariableId {
187
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
188
reason: 'Expected VariableId id to be a non-negative integer',
205
- description: null,
206
- details: [
207
- {
208
- kind: 'error',
209
- loc: null,
210
- message: null,
211
- },
212
- ],
213
- suggestions: null,
189
+ loc: GeneratedSource,
190
});
191
return id as VariableId;
192
}
@@ -417,14 +393,7 @@ function convertFlowType(flowType: FlowType, loc: string): ResolvedType {
393
} else {
394
CompilerError.invariant(false, {
395
reason: `Unsupported property kind ${prop.kind}`,
420
- description: null,
421
- details: [
422
- {
423
- kind: 'error',
424
- loc: GeneratedSource,
425
- message: null,
426
- },
427
- ],
396
+ loc: GeneratedSource,
397
});
398
}
399
}
@@ -493,14 +462,7 @@ function convertFlowType(flowType: FlowType, loc: string): ResolvedType {
462
} else {
463
CompilerError.invariant(false, {
464
reason: `Unsupported property kind ${prop.kind}`,
496
- description: null,
497
- details: [
498
- {
499
- kind: 'error',
500
- loc: GeneratedSource,
501
- message: null,
502
- },
503
- ],
465
+ loc: GeneratedSource,
466
});
467
}
468
}
@@ -519,14 +481,7 @@ function convertFlowType(flowType: FlowType, loc: string): ResolvedType {
481
} else {
482
CompilerError.invariant(false, {
483
reason: `Unsupported property kind ${prop.kind}`,
522
- description: null,
523
- details: [
524
- {
525
- kind: 'error',
526
- loc: GeneratedSource,
527
- message: null,
528
- },
529
- ],
484
+ loc: GeneratedSource,
485
});
486
}
487
}
@@ -539,14 +494,7 @@ function convertFlowType(flowType: FlowType, loc: string): ResolvedType {
494
}
495
CompilerError.invariant(false, {
496
reason: `Unsupported class instance type ${flowType.def.type.kind}`,
542
- description: null,
543
- details: [
544
- {
545
- kind: 'error',
546
- loc: GeneratedSource,
547
- message: null,
548
- },
549
- ],
497
+ loc: GeneratedSource,
498
});
499
}
500
case 'Fun':
@@ -605,14 +553,7 @@ function convertFlowType(flowType: FlowType, loc: string): ResolvedType {
553
} else {
554
CompilerError.invariant(false, {
555
reason: `Unsupported component props type ${propsType.type.kind}`,
608
- description: null,
609
- details: [
610
- {
611
- kind: 'error',
612
- loc: GeneratedSource,
613
- message: null,
614
- },
615
- ],
556
+ loc: GeneratedSource,
557
});
558
}
559
@@ -765,14 +706,7 @@ export class FlowTypeEnv implements ITypeEnv {
706
// TODO: use flow-js only for web environments (e.g. playground)
707
CompilerError.invariant(env.config.flowTypeProvider != null, {
708
reason: 'Expected flowDumpTypes to be defined in environment config',
768
- description: null,
769
- details: [
770
- {
771
- kind: 'error',
772
- loc: GeneratedSource,
773
- message: null,
774
- },
775
- ],
709
+ loc: GeneratedSource,
710
});
711
let stdout: any;
712
if (source === lastFlowSource) {
compiler/packages/babel-plugin-react-compiler/src/HIR/AssertConsistentIdentifiers.ts
+3
-24
@@ -38,28 +38,14 @@ export function assertConsistentIdentifiers(fn: HIRFunction): void {
38
CompilerError.invariant(instr.lvalue.identifier.name === null, {
39
reason: `Expected all lvalues to be temporaries`,
40
description: `Found named lvalue \`${instr.lvalue.identifier.name}\``,
41
- details: [
42
- {
43
- kind: 'error',
44
- loc: instr.lvalue.loc,
45
- message: null,
46
- },
47
- ],
48
- suggestions: null,
41
+ loc: instr.lvalue.loc,
42
});
43
CompilerError.invariant(!assignments.has(instr.lvalue.identifier.id), {
44
reason: `Expected lvalues to be assigned exactly once`,
45
description: `Found duplicate assignment of '${printPlace(
46
instr.lvalue,
47
)}'`,
55
- details: [
56
- {
57
- kind: 'error',
58
- loc: instr.lvalue.loc,
59
- message: null,
60
- },
61
- ],
62
- suggestions: null,
48
+ loc: instr.lvalue.loc,
49
});
50
assignments.add(instr.lvalue.identifier.id);
51
for (const operand of eachInstructionLValue(instr)) {
@@ -89,14 +75,7 @@ function validate(
75
CompilerError.invariant(identifier === previous, {
76
reason: `Duplicate identifier object`,
77
description: `Found duplicate identifier object for id ${identifier.id}`,
92
- details: [
93
- {
94
- kind: 'error',
95
- loc: loc ?? GeneratedSource,
96
- message: null,
97
- },
98
- ],
99
- suggestions: null,
78
+ loc: loc ?? GeneratedSource,
79
});
80
}
81
}
compiler/packages/babel-plugin-react-compiler/src/HIR/AssertTerminalBlocksExist.ts
+3
-22
@@ -18,14 +18,7 @@ export function assertTerminalSuccessorsExist(fn: HIRFunction): void {
18
description: `Block bb${successor} does not exist for terminal '${printTerminal(
19
block.terminal,
20
)}'`,
21
- details: [
22
- {
23
- kind: 'error',
24
- loc: (block.terminal as any).loc ?? GeneratedSource,
25
- message: null,
26
- },
27
- ],
28
- suggestions: null,
21
+ loc: (block.terminal as any).loc ?? GeneratedSource,
22
});
23
return successor;
24
});
@@ -39,26 +32,14 @@ export function assertTerminalPredsExist(fn: HIRFunction): void {
32
CompilerError.invariant(predBlock != null, {
33
reason: 'Expected predecessor block to exist',
34
description: `Block ${block.id} references non-existent ${pred}`,
42
- details: [
43
- {
44
- kind: 'error',
45
- loc: GeneratedSource,
46
- message: null,
47
- },
48
- ],
35
+ loc: GeneratedSource,
36
});
37
CompilerError.invariant(
38
[...eachTerminalSuccessor(predBlock.terminal)].includes(block.id),
39
{
40
reason: 'Terminal successor does not reference correct predecessor',
41
description: `Block bb${block.id} has bb${predBlock.id} as a predecessor, but bb${predBlock.id}'s successors do not include bb${block.id}`,
55
- details: [
56
- {
57
- kind: 'error',
58
- loc: GeneratedSource,
59
- message: null,
60
- },
61
- ],
42
+ loc: GeneratedSource,
43
},
44
);
45
}
compiler/packages/babel-plugin-react-compiler/src/HIR/AssertValidBlockNesting.ts
+1
-7
@@ -131,13 +131,7 @@ export function recursivelyTraverseItems<T, TContext>(
131
CompilerError.invariant(disjoint || nested, {
132
reason: 'Invalid nesting in program blocks or scopes',
133
description: `Items overlap but are not nested: ${maybeParentRange.start}:${maybeParentRange.end}(${currRange.start}:${currRange.end})`,
134
- details: [
135
- {
136
- kind: 'error',
137
- loc: GeneratedSource,
138
- message: null,
139
- },
140
- ],
134
+ loc: GeneratedSource,
135
});
136
if (disjoint) {
137
exit(maybeParent, context);
compiler/packages/babel-plugin-react-compiler/src/HIR/AssertValidMutableRanges.ts
+1
-7
@@ -57,13 +57,7 @@ function validateMutableRange(
57
{
58
reason: `Invalid mutable range: [${range.start}:${range.end}]`,
59
description: `${printPlace(place)} in ${description}`,
60
- details: [
61
- {
62
- kind: 'error',
63
- loc: place.loc,
64
- message: null,
65
- },
66
- ],
60
+ loc: place.loc,
61
},
62
);
63
}
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
+14
-122
@@ -450,14 +450,7 @@ function lowerStatement(
450
CompilerError.invariant(binding != null, {
451
reason: 'Expected to find binding for hoisted identifier',
452
description: `Could not find a binding for ${id.node.name}`,
453
- suggestions: null,
454
- details: [
455
- {
456
- kind: 'error',
457
- loc: id.node.loc ?? GeneratedSource,
458
- message: null,
459
- },
460
- ],
453
+ loc: id.node.loc ?? GeneratedSource,
454
});
455
if (builder.environment.isHoistedIdentifier(binding.identifier)) {
456
// Already hoisted
@@ -499,14 +492,7 @@ function lowerStatement(
492
CompilerError.invariant(identifier.kind === 'Identifier', {
493
reason:
494
'Expected hoisted binding to be a local identifier, not a global',
502
- description: null,
503
- details: [
504
- {
505
- kind: 'error',
506
- loc: id.node.loc ?? GeneratedSource,
507
- message: null,
508
- },
509
- ],
495
+ loc: id.node.loc ?? GeneratedSource,
496
});
497
const place: Place = {
498
effect: Effect.Unknown,
@@ -1038,15 +1024,7 @@ function lowerStatement(
1024
stmt.skip();
1025
CompilerError.invariant(stmt.get('id').type === 'Identifier', {
1026
reason: 'function declarations must have a name',
1041
- description: null,
1042
- details: [
1043
- {
1044
- kind: 'error',
1045
- loc: stmt.node.loc ?? null,
1046
- message: null,
1047
- },
1048
- ],
1049
- suggestions: null,
1027
+ loc: stmt.node.loc ?? GeneratedSource,
1028
});
1029
const id = stmt.get('id') as NodePath<t.Identifier>;
1030
@@ -1144,15 +1122,7 @@ function lowerStatement(
1122
const declarations = left.get('declarations');
1123
CompilerError.invariant(declarations.length === 1, {
1124
reason: `Expected only one declaration in the init of a ForOfStatement, got ${declarations.length}`,
1147
- description: null,
1148
- details: [
1149
- {
1150
- kind: 'error',
1151
- loc: left.node.loc ?? null,
1152
- message: null,
1153
- },
1154
- ],
1155
- suggestions: null,
1125
+ loc: left.node.loc ?? GeneratedSource,
1126
});
1127
const id = declarations[0].get('id');
1128
const assign = lowerAssignment(
@@ -1167,14 +1137,7 @@ function lowerStatement(
1137
} else {
1138
CompilerError.invariant(left.isLVal(), {
1139
reason: 'Expected ForOf init to be a variable declaration or lval',
1170
- description: null,
1171
- details: [
1172
- {
1173
- kind: 'error',
1174
- loc: leftLoc,
1175
- message: null,
1176
- },
1177
- ],
1140
+ loc: leftLoc,
1141
});
1142
const assign = lowerAssignment(
1143
builder,
@@ -1250,15 +1213,7 @@ function lowerStatement(
1213
const declarations = left.get('declarations');
1214
CompilerError.invariant(declarations.length === 1, {
1215
reason: `Expected only one declaration in the init of a ForInStatement, got ${declarations.length}`,
1253
- description: null,
1254
- details: [
1255
- {
1256
- kind: 'error',
1257
- loc: left.node.loc ?? null,
1258
- message: null,
1259
- },
1260
- ],
1261
- suggestions: null,
1216
+ loc: left.node.loc ?? GeneratedSource,
1217
});
1218
const id = declarations[0].get('id');
1219
const assign = lowerAssignment(
@@ -1273,14 +1228,7 @@ function lowerStatement(
1228
} else {
1229
CompilerError.invariant(left.isLVal(), {
1230
reason: 'Expected ForIn init to be a variable declaration or lval',
1276
- description: null,
1277
- details: [
1278
- {
1279
- kind: 'error',
1280
- loc: leftLoc,
1281
- message: null,
1282
- },
1283
- ],
1231
+ loc: leftLoc,
1232
});
1233
const assign = lowerAssignment(
1234
builder,
@@ -2244,15 +2192,7 @@ function lowerExpression(
2192
} else {
2193
CompilerError.invariant(namePath.isJSXNamespacedName(), {
2194
reason: 'Refinement',
2247
- description: null,
2248
- details: [
2249
- {
2250
- kind: 'error',
2251
- loc: namePath.node.loc ?? null,
2252
- message: null,
2253
- },
2254
- ],
2255
- suggestions: null,
2195
+ loc: namePath.node.loc ?? GeneratedSource,
2196
});
2197
const namespace = namePath.node.namespace.name;
2198
const name = namePath.node.name.name;
@@ -2305,15 +2245,7 @@ function lowerExpression(
2245
// This is already checked in builder.resolveIdentifier
2246
CompilerError.invariant(tagIdentifier.kind !== 'Identifier', {
2247
reason: `<${tagName}> tags should be module-level imports`,
2308
- description: null,
2309
- details: [
2310
- {
2311
- kind: 'error',
2312
- loc: openingIdentifier.node.loc ?? GeneratedSource,
2313
- message: null,
2314
- },
2315
- ],
2316
- suggestions: null,
2248
+ loc: openingIdentifier.node.loc ?? GeneratedSource,
2249
});
2250
}
2251
// see `error.todo-multiple-fbt-plural` fixture for explanation
@@ -2415,15 +2347,7 @@ function lowerExpression(
2347
CompilerError.invariant(expr.get('quasi').get('quasis').length == 1, {
2348
reason:
2349
"there should be only one quasi as we don't support interpolations yet",
2418
- description: null,
2419
- details: [
2420
- {
2421
- kind: 'error',
2422
- loc: expr.node.loc ?? null,
2423
- message: null,
2424
- },
2425
- ],
2426
- suggestions: null,
2350
+ loc: expr.node.loc ?? GeneratedSource,
2351
});
2352
const value = expr.get('quasi').get('quasis').at(0)!.node.value;
2353
if (value.raw !== value.cooked) {
@@ -2819,15 +2743,7 @@ function lowerOptionalMemberExpression(
2743
});
2744
CompilerError.invariant(object !== null, {
2745
reason: 'Satisfy type checker',
2822
- description: null,
2823
- details: [
2824
- {
2825
- kind: 'error',
2826
- loc: null,
2827
- message: null,
2828
- },
2829
- ],
2830
- suggestions: null,
2746
+ loc: GeneratedSource,
2747
});
2748
2749
/*
@@ -3399,15 +3315,7 @@ function lowerJsxMemberExpression(
3315
} else {
3316
CompilerError.invariant(object.isJSXIdentifier(), {
3317
reason: `TypeScript refinement fail: expected 'JsxIdentifier', got \`${object.node.type}\``,
3402
- description: null,
3403
- details: [
3404
- {
3405
- kind: 'error',
3406
- loc: object.node.loc ?? null,
3407
- message: null,
3408
- },
3409
- ],
3410
- suggestions: null,
3318
+ loc: object.node.loc ?? GeneratedSource,
3319
});
3320
3321
const kind = getLoadKind(builder, object);
@@ -3447,15 +3355,7 @@ function lowerJsxElement(
3355
} else {
3356
CompilerError.invariant(expression.isExpression(), {
3357
reason: `(BuildHIR::lowerJsxElement) Expected Expression but found ${expression.type}!`,
3450
- description: null,
3451
- details: [
3452
- {
3453
- kind: 'error',
3454
- loc: expression.node.loc ?? null,
3455
- message: null,
3456
- },
3457
- ],
3458
- suggestions: null,
3358
+ loc: expression.node.loc ?? GeneratedSource,
3359
});
3360
return lowerExpressionToTemporary(builder, expression);
3361
}
@@ -3851,15 +3751,7 @@ function lowerAssignment(
3751
// This can only occur because of a coding error, parsers enforce this condition
3752
CompilerError.invariant(kind === InstructionKind.Reassign, {
3753
reason: 'MemberExpression may only appear in an assignment expression',
3854
- description: null,
3855
- details: [
3856
- {
3857
- kind: 'error',
3858
- loc: lvaluePath.node.loc ?? null,
3859
- message: null,
3860
- },
3861
- ],
3862
- suggestions: null,
3754
+ loc: lvaluePath.node.loc ?? GeneratedSource,
3755
});
3756
const lvalue = lvaluePath as NodePath<t.MemberExpression>;
3757
const property = lvalue.get('property');
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts
+1
-8
@@ -234,14 +234,7 @@ function pushEndScopeTerminal(
234
const fallthroughId = context.fallthroughs.get(scope.id);
235
CompilerError.invariant(fallthroughId != null, {
236
reason: 'Expected scope to exist',
237
- description: null,
238
- details: [
239
- {
240
- kind: 'error',
241
- loc: GeneratedSource,
242
- message: null,
243
- },
244
- ],
237
+ loc: GeneratedSource,
238
});
239
context.rewrites.push({
240
kind: 'EndScope',
compiler/packages/babel-plugin-react-compiler/src/HIR/CollectHoistablePropertyLoads.ts
+4
-31
@@ -269,14 +269,7 @@ class PropertyPathRegistry {
269
CompilerError.invariant(reactive === rootNode.fullPath.reactive, {
270
reason:
271
'[HoistablePropertyLoads] Found inconsistencies in `reactive` flag when deduping identifier reads within the same scope',
272
- description: null,
273
- details: [
274
- {
275
- kind: 'error',
276
- loc: identifier.loc,
277
- message: null,
278
- },
279
- ],
272
+ loc: identifier.loc,
273
});
274
}
275
return rootNode;
@@ -531,14 +524,7 @@ function propagateNonNull(
524
if (node == null) {
525
CompilerError.invariant(false, {
526
reason: `Bad node ${nodeId}, kind: ${direction}`,
534
- description: null,
535
- details: [
536
- {
537
- kind: 'error',
538
- loc: GeneratedSource,
539
- message: null,
540
- },
541
- ],
527
+ loc: GeneratedSource,
528
});
529
}
530
const neighbors = Array.from(
@@ -610,14 +596,7 @@ function propagateNonNull(
596
CompilerError.invariant(i++ < 100, {
597
reason:
598
'[CollectHoistablePropertyLoads] fixed point iteration did not terminate after 100 loops',
613
- description: null,
614
- details: [
615
- {
616
- kind: 'error',
617
- loc: GeneratedSource,
618
- message: null,
619
- },
620
- ],
599
+ loc: GeneratedSource,
600
});
601
602
changed = false;
@@ -649,13 +628,7 @@ export function assertNonNull<T extends NonNullable<U>, U>(
628
CompilerError.invariant(value != null, {
629
reason: 'Unexpected null',
630
description: source != null ? `(from ${source})` : null,
652
- details: [
653
- {
654
- kind: 'error',
655
- loc: GeneratedSource,
656
- message: null,
657
- },
658
- ],
631
+ loc: GeneratedSource,
632
});
633
return value;
634
}
compiler/packages/babel-plugin-react-compiler/src/HIR/CollectOptionalChainDependencies.ts
+7
-54
@@ -186,13 +186,7 @@ function matchOptionalTestBlock(
186
reason:
187
'[OptionalChainDeps] Inconsistent optional chaining property load',
188
description: `Test=${printIdentifier(terminal.test.identifier)} PropertyLoad base=${printIdentifier(propertyLoad.value.object.identifier)}`,
189
- details: [
190
- {
191
- kind: 'error',
192
- loc: propertyLoad.loc,
193
- message: null,
194
- },
195
- ],
189
+ loc: propertyLoad.loc,
190
},
191
);
192
@@ -200,14 +194,7 @@ function matchOptionalTestBlock(
194
storeLocal.value.identifier.id === propertyLoad.lvalue.identifier.id,
195
{
196
reason: '[OptionalChainDeps] Unexpected storeLocal',
203
- description: null,
204
- details: [
205
- {
206
- kind: 'error',
207
- loc: propertyLoad.loc,
208
- message: null,
209
- },
210
- ],
197
+ loc: propertyLoad.loc,
198
},
199
);
200
if (
@@ -224,14 +211,7 @@ function matchOptionalTestBlock(
211
alternate.instructions[1].value.kind === 'StoreLocal',
212
{
213
reason: 'Unexpected alternate structure',
227
- description: null,
228
- details: [
229
- {
230
- kind: 'error',
231
- loc: terminal.loc,
232
- message: null,
233
- },
234
- ],
214
+ loc: terminal.loc,
215
},
216
);
217
@@ -267,14 +247,7 @@ function traverseOptionalBlock(
247
if (maybeTest.terminal.kind === 'branch') {
248
CompilerError.invariant(optional.terminal.optional, {
249
reason: '[OptionalChainDeps] Expect base case to be always optional',
270
- description: null,
271
- details: [
272
- {
273
- kind: 'error',
274
- loc: optional.terminal.loc,
275
- message: null,
276
- },
277
- ],
250
+ loc: optional.terminal.loc,
251
});
252
/**
253
* Optional base expressions are currently within value blocks which cannot
@@ -312,14 +285,7 @@ function traverseOptionalBlock(
285
maybeTest.instructions.at(-1)!.lvalue.identifier.id,
286
{
287
reason: '[OptionalChainDeps] Unexpected test expression',
315
- description: null,
316
- details: [
317
- {
318
- kind: 'error',
319
- loc: maybeTest.terminal.loc,
320
- message: null,
321
- },
322
- ],
288
+ loc: maybeTest.terminal.loc,
289
},
290
);
291
baseObject = {
@@ -408,14 +374,7 @@ function traverseOptionalBlock(
374
reason:
375
'[OptionalChainDeps] Unexpected instructions an inner optional block. ' +
376
'This indicates that the compiler may be incorrectly concatenating two unrelated optional chains',
411
- description: null,
412
- details: [
413
- {
414
- kind: 'error',
415
- loc: optional.terminal.loc,
416
- message: null,
417
- },
418
- ],
377
+ loc: optional.terminal.loc,
378
});
379
}
380
const matchConsequentResult = matchOptionalTestBlock(test, context.blocks);
@@ -428,13 +387,7 @@ function traverseOptionalBlock(
387
{
388
reason: '[OptionalChainDeps] Unexpected optional goto-fallthrough',
389
description: `${matchConsequentResult.consequentGoto} != ${optional.terminal.fallthrough}`,
431
- details: [
432
- {
433
- kind: 'error',
434
- loc: optional.terminal.loc,
435
- message: null,
436
- },
437
- ],
390
+ loc: optional.terminal.loc,
391
},
392
);
393
const load = {
compiler/packages/babel-plugin-react-compiler/src/HIR/ComputeUnconditionalBlocks.ts
+7
-10
@@ -5,7 +5,12 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
-import {BlockId, HIRFunction, computePostDominatorTree} from '.';
8
+import {
9
+ BlockId,
10
+ GeneratedSource,
11
+ HIRFunction,
12
+ computePostDominatorTree,
13
+} from '.';
14
import {CompilerError} from '..';
15
16
export function computeUnconditionalBlocks(fn: HIRFunction): Set<BlockId> {
@@ -24,15 +29,7 @@ export function computeUnconditionalBlocks(fn: HIRFunction): Set<BlockId> {
29
CompilerError.invariant(!unconditionalBlocks.has(current), {
30
reason:
31
'Internal error: non-terminating loop in ComputeUnconditionalBlocks',
27
- description: null,
28
- details: [
29
- {
30
- kind: 'error',
31
- loc: null,
32
- message: null,
33
- },
34
- ],
35
- suggestions: null,
32
+ loc: GeneratedSource,
33
});
34
unconditionalBlocks.add(current);
35
current = dominators.get(current);
compiler/packages/babel-plugin-react-compiler/src/HIR/DeriveMinimalDependenciesHIR.ts
+2
-15
@@ -54,14 +54,7 @@ export class ReactiveScopeDependencyTreeHIR {
54
prevAccessType == null || prevAccessType === accessType,
55
{
56
reason: 'Conflicting access types',
57
- description: null,
58
- details: [
59
- {
60
- kind: 'error',
61
- loc: GeneratedSource,
62
- message: null,
63
- },
64
- ],
57
+ loc: GeneratedSource,
58
},
59
);
60
let nextNode = currNode.properties.get(path[i].property);
@@ -97,13 +90,7 @@ export class ReactiveScopeDependencyTreeHIR {
90
CompilerError.invariant(reactive === rootNode.reactive, {
91
reason: '[DeriveMinimalDependenciesHIR] Conflicting reactive root flag',
92
description: `Identifier ${printIdentifier(identifier)}`,
100
- details: [
101
- {
102
- kind: 'error',
103
- loc: GeneratedSource,
104
- message: null,
105
- },
106
- ],
93
+ loc: GeneratedSource,
94
});
95
}
96
return rootNode;
compiler/packages/babel-plugin-react-compiler/src/HIR/Dominator.ts
+4
-28
@@ -7,7 +7,7 @@
7
8
import prettyFormat from 'pretty-format';
9
import {CompilerError} from '../CompilerError';
10
-import {BlockId, HIRFunction} from './HIR';
10
+import {BlockId, GeneratedSource, HIRFunction} from './HIR';
11
import {eachTerminalSuccessor} from './visitors';
12
13
/*
@@ -88,15 +88,7 @@ export class Dominator<T> {
88
const dominator = this.#nodes.get(id);
89
CompilerError.invariant(dominator !== undefined, {
90
reason: 'Unknown node',
91
- description: null,
92
- details: [
93
- {
94
- kind: 'error',
95
- loc: null,
96
- message: null,
97
- },
98
- ],
99
- suggestions: null,
91
+ loc: GeneratedSource,
92
});
93
return dominator === id ? null : dominator;
94
}
@@ -135,15 +127,7 @@ export class PostDominator<T> {
127
const dominator = this.#nodes.get(id);
128
CompilerError.invariant(dominator !== undefined, {
129
reason: 'Unknown node',
138
- description: null,
139
- details: [
140
- {
141
- kind: 'error',
142
- loc: null,
143
- message: null,
144
- },
145
- ],
146
- suggestions: null,
130
+ loc: GeneratedSource,
131
});
132
return dominator === id ? null : dominator;
133
}
@@ -186,15 +170,7 @@ function computeImmediateDominators<T>(graph: Graph<T>): Map<T, T> {
170
}
171
CompilerError.invariant(newIdom !== null, {
172
reason: `At least one predecessor must have been visited for block ${id}`,
189
- description: null,
190
- details: [
191
- {
192
- kind: 'error',
193
- loc: null,
194
- message: null,
195
- },
196
- ],
197
- suggestions: null,
173
+ loc: GeneratedSource,
174
});
175
176
for (const pred of node.preds) {
compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
+7
-52
@@ -24,6 +24,7 @@ import {
24
BuiltInType,
25
Effect,
26
FunctionType,
27
+ GeneratedSource,
28
HIRFunction,
29
IdentifierId,
30
NonLocalBinding,
@@ -816,15 +817,7 @@ export class Environment {
817
for (const [hookName, hook] of this.config.customHooks) {
818
CompilerError.invariant(!this.#globals.has(hookName), {
819
reason: `[Globals] Found existing definition in global registry for custom hook ${hookName}`,
819
- description: null,
820
- details: [
821
- {
822
- kind: 'error',
823
- loc: null,
824
- message: null,
825
- },
826
- ],
827
- suggestions: null,
820
+ loc: GeneratedSource,
821
});
822
this.#globals.set(
823
hookName,
@@ -856,14 +849,7 @@ export class Environment {
849
CompilerError.invariant(code != null, {
850
reason:
851
'Expected Environment to be initialized with source code when a Flow type provider is specified',
859
- description: null,
860
- details: [
861
- {
862
- kind: 'error',
863
- loc: null,
864
- message: null,
865
- },
866
- ],
852
+ loc: GeneratedSource,
853
});
854
this.#flowTypeEnvironment.init(this, code);
855
} else {
@@ -874,14 +860,7 @@ export class Environment {
860
get typeContext(): FlowTypeEnv {
861
CompilerError.invariant(this.#flowTypeEnvironment != null, {
862
reason: 'Flow type environment not initialized',
877
- description: null,
878
- details: [
879
- {
880
- kind: 'error',
881
- loc: null,
882
- message: null,
883
- },
884
- ],
863
+ loc: GeneratedSource,
864
});
865
return this.#flowTypeEnvironment;
866
}
@@ -1193,15 +1172,7 @@ export class Environment {
1172
1173
CompilerError.invariant(shape !== undefined, {
1174
reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`,
1196
- description: null,
1197
- details: [
1198
- {
1199
- kind: 'error',
1200
- loc: null,
1201
- message: null,
1202
- },
1203
- ],
1204
- suggestions: null,
1175
+ loc: GeneratedSource,
1176
});
1177
return shape.properties.get('*') ?? null;
1178
}
@@ -1224,15 +1195,7 @@ export class Environment {
1195
const shape = this.#shapes.get(shapeId);
1196
CompilerError.invariant(shape !== undefined, {
1197
reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`,
1227
- description: null,
1228
- details: [
1229
- {
1230
- kind: 'error',
1231
- loc: null,
1232
- message: null,
1233
- },
1234
- ],
1235
- suggestions: null,
1198
+ loc: GeneratedSource,
1199
});
1200
if (typeof property === 'string') {
1201
return (
@@ -1255,15 +1218,7 @@ export class Environment {
1218
const shape = this.#shapes.get(shapeId);
1219
CompilerError.invariant(shape !== undefined, {
1220
reason: `[HIR] Forget internal error: cannot resolve shape ${shapeId}`,
1258
- description: null,
1259
- details: [
1260
- {
1261
- kind: 'error',
1262
- loc: null,
1263
- message: null,
1264
- },
1265
- ],
1266
- suggestions: null,
1221
+ loc: GeneratedSource,
1222
});
1223
return shape.functionType;
1224
}
compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts
+2
-18
@@ -183,29 +183,13 @@ function handleAssignment(
183
const valuePath = property.get('value');
184
CompilerError.invariant(valuePath.isLVal(), {
185
reason: `[FindContextIdentifiers] Expected object property value to be an LVal, got: ${valuePath.type}`,
186
- description: null,
187
- details: [
188
- {
189
- kind: 'error',
190
- loc: valuePath.node.loc ?? GeneratedSource,
191
- message: null,
192
- },
193
- ],
194
- suggestions: null,
186
+ loc: valuePath.node.loc ?? GeneratedSource,
187
});
188
handleAssignment(currentFn, identifiers, valuePath);
189
} else {
190
CompilerError.invariant(property.isRestElement(), {
191
reason: `[FindContextIdentifiers] Invalid assumptions for babel types.`,
200
- description: null,
201
- details: [
202
- {
203
- kind: 'error',
204
- loc: property.node.loc ?? GeneratedSource,
205
- message: null,
206
- },
207
- ],
208
- suggestions: null,
192
+ loc: property.node.loc ?? GeneratedSource,
193
});
194
handleAssignment(currentFn, identifiers, property);
195
}
compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
+8
-70
@@ -1373,14 +1373,7 @@ export function promoteTemporary(identifier: Identifier): void {
1373
CompilerError.invariant(identifier.name === null, {
1374
reason: `Expected a temporary (unnamed) identifier`,
1375
description: `Identifier already has a name, \`${identifier.name}\``,
1376
- details: [
1377
- {
1378
- kind: 'error',
1379
- loc: GeneratedSource,
1380
- message: null,
1381
- },
1382
- ],
1383
- suggestions: null,
1376
+ loc: GeneratedSource,
1377
});
1378
identifier.name = {
1379
kind: 'promoted',
@@ -1403,14 +1396,7 @@ export function promoteTemporaryJsxTag(identifier: Identifier): void {
1396
CompilerError.invariant(identifier.name === null, {
1397
reason: `Expected a temporary (unnamed) identifier`,
1398
description: `Identifier already has a name, \`${identifier.name}\``,
1406
- details: [
1407
- {
1408
- kind: 'error',
1409
- loc: GeneratedSource,
1410
- message: null,
1411
- },
1412
- ],
1413
- suggestions: null,
1399
+ loc: GeneratedSource,
1400
});
1401
identifier.name = {
1402
kind: 'promoted',
@@ -1576,15 +1562,7 @@ export function isMutableEffect(
1562
case Effect.Unknown: {
1563
CompilerError.invariant(false, {
1564
reason: 'Unexpected unknown effect',
1579
- description: null,
1580
- details: [
1581
- {
1582
- kind: 'error',
1583
- loc: location,
1584
- message: null,
1585
- },
1586
- ],
1587
- suggestions: null,
1565
+ loc: location,
1566
});
1567
}
1568
case Effect.Read:
@@ -1737,15 +1715,7 @@ export type BlockId = number & {[opaqueBlockId]: 'BlockId'};
1715
export function makeBlockId(id: number): BlockId {
1716
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
1717
reason: 'Expected block id to be a non-negative integer',
1740
- description: null,
1741
- details: [
1742
- {
1743
- kind: 'error',
1744
- loc: null,
1745
- message: null,
1746
- },
1747
- ],
1748
- suggestions: null,
1718
+ loc: GeneratedSource,
1719
});
1720
return id as BlockId;
1721
}
@@ -1760,15 +1730,7 @@ export type ScopeId = number & {[opaqueScopeId]: 'ScopeId'};
1730
export function makeScopeId(id: number): ScopeId {
1731
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
1732
reason: 'Expected block id to be a non-negative integer',
1763
- description: null,
1764
- details: [
1765
- {
1766
- kind: 'error',
1767
- loc: null,
1768
- message: null,
1769
- },
1770
- ],
1771
- suggestions: null,
1733
+ loc: GeneratedSource,
1734
});
1735
return id as ScopeId;
1736
}
@@ -1783,15 +1745,7 @@ export type IdentifierId = number & {[opaqueIdentifierId]: 'IdentifierId'};
1745
export function makeIdentifierId(id: number): IdentifierId {
1746
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
1747
reason: 'Expected identifier id to be a non-negative integer',
1786
- description: null,
1787
- details: [
1788
- {
1789
- kind: 'error',
1790
- loc: null,
1791
- message: null,
1792
- },
1793
- ],
1794
- suggestions: null,
1748
+ loc: GeneratedSource,
1749
});
1750
return id as IdentifierId;
1751
}
@@ -1806,15 +1760,7 @@ export type DeclarationId = number & {[opageDeclarationId]: 'DeclarationId'};
1760
export function makeDeclarationId(id: number): DeclarationId {
1761
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
1762
reason: 'Expected declaration id to be a non-negative integer',
1809
- description: null,
1810
- details: [
1811
- {
1812
- kind: 'error',
1813
- loc: null,
1814
- message: null,
1815
- },
1816
- ],
1817
- suggestions: null,
1763
+ loc: GeneratedSource,
1764
});
1765
return id as DeclarationId;
1766
}
@@ -1829,15 +1775,7 @@ export type InstructionId = number & {[opaqueInstructionId]: 'IdentifierId'};
1775
export function makeInstructionId(id: number): InstructionId {
1776
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
1777
reason: 'Expected instruction id to be a non-negative integer',
1832
- description: null,
1833
- details: [
1834
- {
1835
- kind: 'error',
1836
- loc: null,
1837
- message: null,
1838
- },
1839
- ],
1840
- suggestions: null,
1778
+ loc: GeneratedSource,
1779
});
1780
return id as InstructionId;
1781
}
compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts
+10
-86
@@ -506,15 +506,7 @@ export default class HIRBuilder {
506
last.breakBlock === breakBlock,
507
{
508
reason: 'Mismatched label',
509
- description: null,
510
- details: [
511
- {
512
- kind: 'error',
513
- loc: null,
514
- message: null,
515
- },
516
- ],
517
- suggestions: null,
509
+ loc: GeneratedSource,
510
},
511
);
512
return value;
@@ -535,15 +527,7 @@ export default class HIRBuilder {
527
last.breakBlock === breakBlock,
528
{
529
reason: 'Mismatched label',
538
- description: null,
539
- details: [
540
- {
541
- kind: 'error',
542
- loc: null,
543
- message: null,
544
- },
545
- ],
546
- suggestions: null,
530
+ loc: GeneratedSource,
531
},
532
);
533
return value;
@@ -577,15 +561,7 @@ export default class HIRBuilder {
561
last.breakBlock === breakBlock,
562
{
563
reason: 'Mismatched loops',
580
- description: null,
581
- details: [
582
- {
583
- kind: 'error',
584
- loc: null,
585
- message: null,
586
- },
587
- ],
588
- suggestions: null,
564
+ loc: GeneratedSource,
565
},
566
);
567
return value;
@@ -608,15 +584,7 @@ export default class HIRBuilder {
584
}
585
CompilerError.invariant(false, {
586
reason: 'Expected a loop or switch to be in scope',
611
- description: null,
612
- details: [
613
- {
614
- kind: 'error',
615
- loc: null,
616
- message: null,
617
- },
618
- ],
619
- suggestions: null,
587
+ loc: GeneratedSource,
588
});
589
}
590
@@ -635,29 +603,13 @@ export default class HIRBuilder {
603
} else if (label !== null && scope.label === label) {
604
CompilerError.invariant(false, {
605
reason: 'Continue may only refer to a labeled loop',
638
- description: null,
639
- details: [
640
- {
641
- kind: 'error',
642
- loc: null,
643
- message: null,
644
- },
645
- ],
646
- suggestions: null,
606
+ loc: GeneratedSource,
607
});
608
}
609
}
610
CompilerError.invariant(false, {
611
reason: 'Expected a loop to be in scope',
652
- description: null,
653
- details: [
654
- {
655
- kind: 'error',
656
- loc: null,
657
- message: null,
658
- },
659
- ],
660
- suggestions: null,
612
+ loc: GeneratedSource,
613
});
614
}
615
}
@@ -678,15 +630,7 @@ function _shrink(func: HIR): void {
630
const block = func.blocks.get(blockId);
631
CompilerError.invariant(block != null, {
632
reason: `expected block ${blockId} to exist`,
681
- description: null,
682
- details: [
683
- {
684
- kind: 'error',
685
- loc: null,
686
- message: null,
687
- },
688
- ],
689
- suggestions: null,
633
+ loc: GeneratedSource,
634
});
635
target = getTargetIfIndirection(block);
636
if (target !== null) {
@@ -817,13 +761,7 @@ function getReversePostorderedBlocks(func: HIR): HIR['blocks'] {
761
CompilerError.invariant(block != null, {
762
reason: '[HIRBuilder] Unexpected null block',
763
description: `expected block ${blockId} to exist`,
820
- details: [
821
- {
822
- kind: 'error',
823
- loc: GeneratedSource,
824
- message: null,
825
- },
826
- ],
764
+ loc: GeneratedSource,
765
});
766
const successors = [...eachTerminalSuccessor(block.terminal)].reverse();
767
const fallthrough = terminalFallthrough(block.terminal);
@@ -878,15 +816,7 @@ export function markInstructionIds(func: HIR): void {
816
for (const instr of block.instructions) {
817
CompilerError.invariant(!visited.has(instr), {
818
reason: `${printInstruction(instr)} already visited!`,
881
- description: null,
882
- details: [
883
- {
884
- kind: 'error',
885
- loc: instr.loc,
886
- message: null,
887
- },
888
- ],
889
- suggestions: null,
819
+ loc: instr.loc,
820
});
821
visited.add(instr);
822
instr.id = makeInstructionId(++id);
@@ -908,13 +838,7 @@ export function markPredecessors(func: HIR): void {
838
CompilerError.invariant(block != null, {
839
reason: 'unexpected missing block',
840
description: `block ${blockId}`,
911
- details: [
912
- {
913
- kind: 'error',
914
- loc: GeneratedSource,
915
- message: null,
916
- },
917
- ],
841
+ loc: GeneratedSource,
842
});
843
if (prevBlock) {
844
block.preds.add(prevBlock.id);
compiler/packages/babel-plugin-react-compiler/src/HIR/MergeConsecutiveBlocks.ts
+2
-18
@@ -60,15 +60,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
60
const predecessor = fn.body.blocks.get(predecessorId);
61
CompilerError.invariant(predecessor !== undefined, {
62
reason: `Expected predecessor ${predecessorId} to exist`,
63
- description: null,
64
- details: [
65
- {
66
- kind: 'error',
67
- loc: null,
68
- message: null,
69
- },
70
- ],
71
- suggestions: null,
63
+ loc: GeneratedSource,
64
});
65
if (predecessor.terminal.kind !== 'goto' || predecessor.kind !== 'block') {
66
/*
@@ -82,15 +74,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
74
for (const phi of block.phis) {
75
CompilerError.invariant(phi.operands.size === 1, {
76
reason: `Found a block with a single predecessor but where a phi has multiple (${phi.operands.size}) operands`,
85
- description: null,
86
- details: [
87
- {
88
- kind: 'error',
89
- loc: null,
90
- message: null,
91
- },
92
- ],
93
- suggestions: null,
77
+ loc: GeneratedSource,
78
});
79
const operand = Array.from(phi.operands.values())[0]!;
80
const lvalue: Place = {
compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts
+3
-23
@@ -119,13 +119,7 @@ function parseAliasingSignatureConfig(
119
CompilerError.invariant(!lifetimes.has(temp), {
120
reason: `Invalid type configuration for module`,
121
description: `Expected aliasing signature to have unique names for receiver, params, rest, returns, and temporaries in module '${moduleName}'`,
122
- details: [
123
- {
124
- kind: 'error',
125
- loc,
126
- message: null,
127
- },
128
- ],
122
+ loc,
123
});
124
const place = signatureArgument(lifetimes.size);
125
lifetimes.set(temp, place);
@@ -136,13 +130,7 @@ function parseAliasingSignatureConfig(
130
CompilerError.invariant(place != null, {
131
reason: `Invalid type configuration for module`,
132
description: `Expected aliasing signature effects to reference known names from receiver/params/rest/returns/temporaries, but '${temp}' is not a known name in '${moduleName}'`,
139
- details: [
140
- {
141
- kind: 'error',
142
- loc,
143
- message: null,
144
- },
145
- ],
133
+ loc,
134
});
135
return place;
136
}
@@ -276,15 +264,7 @@ function addShape(
264
265
CompilerError.invariant(!registry.has(id), {
266
reason: `[ObjectShape] Could not add shape to registry: name ${id} already exists.`,
279
- description: null,
280
- details: [
281
- {
282
- kind: 'error',
283
- loc: null,
284
- message: null,
285
- },
286
- ],
287
- suggestions: null,
267
+ loc: GeneratedSource,
268
});
269
registry.set(id, shape);
270
return shape;
compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts
+2
-18
@@ -598,15 +598,7 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
598
instrValue.subexprs.length === instrValue.quasis.length - 1,
599
{
600
reason: 'Bad assumption about quasi length.',
601
- description: null,
602
- details: [
603
- {
604
- kind: 'error',
605
- loc: instrValue.loc,
606
- message: null,
607
- },
608
- ],
609
- suggestions: null,
601
+ loc: instrValue.loc,
602
},
603
);
604
for (let i = 0; i < instrValue.subexprs.length; i++) {
@@ -874,15 +866,7 @@ export function printManualMemoDependency(
866
} else {
867
CompilerError.invariant(val.root.value.identifier.name?.kind === 'named', {
868
reason: 'DepsValidation: expected named local variable in depslist',
877
- description: null,
878
- suggestions: null,
879
- details: [
880
- {
881
- kind: 'error',
882
- loc: val.root.value.loc,
883
- message: null,
884
- },
885
- ],
869
+ loc: val.root.value.loc,
870
});
871
rootStr = nameOnly
872
? val.root.value.identifier.name.value
compiler/packages/babel-plugin-react-compiler/src/HIR/PropagateScopeDependenciesHIR.ts
+2
-16
@@ -86,14 +86,7 @@ export function propagateScopeDependenciesHIR(fn: HIRFunction): void {
86
const hoistables = hoistablePropertyLoads.get(scope.id);
87
CompilerError.invariant(hoistables != null, {
88
reason: '[PropagateScopeDependencies] Scope not found in tracked blocks',
89
- description: null,
90
- details: [
91
- {
92
- kind: 'error',
93
- loc: GeneratedSource,
94
- message: null,
95
- },
96
- ],
89
+ loc: GeneratedSource,
90
});
91
/**
92
* Step 2: Calculate hoistable dependencies.
@@ -435,14 +428,7 @@ export class DependencyCollectionContext {
428
const scopedDependencies = this.#dependencies.value;
429
CompilerError.invariant(scopedDependencies != null, {
430
reason: '[PropagateScopeDeps]: Unexpected scope mismatch',
438
- description: null,
439
- details: [
440
- {
441
- kind: 'error',
442
- loc: scope.loc,
443
- message: null,
444
- },
445
- ],
431
+ loc: scope.loc,
432
});
433
434
// Restore context of previous scope
compiler/packages/babel-plugin-react-compiler/src/HIR/PruneUnusedLabelsHIR.ts
+2
-16
@@ -53,14 +53,7 @@ export function pruneUnusedLabelsHIR(fn: HIRFunction): void {
53
next.phis.size === 0 && fallthrough.phis.size === 0,
54
{
55
reason: 'Unexpected phis when merging label blocks',
56
- description: null,
57
- details: [
58
- {
59
- kind: 'error',
60
- loc: label.terminal.loc,
61
- message: null,
62
- },
63
- ],
56
+ loc: label.terminal.loc,
57
},
58
);
59
@@ -71,14 +64,7 @@ export function pruneUnusedLabelsHIR(fn: HIRFunction): void {
64
fallthrough.preds.has(nextId),
65
{
66
reason: 'Unexpected block predecessors when merging label blocks',
74
- description: null,
75
- details: [
76
- {
77
- kind: 'error',
78
- loc: label.terminal.loc,
79
- message: null,
80
- },
81
- ],
67
+ loc: label.terminal.loc,
68
},
69
);
70
compiler/packages/babel-plugin-react-compiler/src/HIR/ScopeDependencyUtils.ts
+2
-18
@@ -202,15 +202,7 @@ function writeOptionalDependency(
202
CompilerError.invariant(firstOptional !== -1, {
203
reason:
204
'[ScopeDependencyUtils] Internal invariant broken: expected optional path',
205
- description: null,
206
- details: [
207
- {
208
- kind: 'error',
209
- loc: dep.identifier.loc,
210
- message: null,
211
- },
212
- ],
213
- suggestions: null,
205
+ loc: dep.identifier.loc,
206
});
207
if (firstOptional === dep.path.length - 1) {
208
// Base case: the test block is simple
@@ -244,15 +236,7 @@ function writeOptionalDependency(
236
builder.enterReserved(consequent, () => {
237
CompilerError.invariant(testIdentifier !== null, {
238
reason: 'Satisfy type checker',
247
- description: null,
248
- details: [
249
- {
250
- kind: 'error',
251
- loc: null,
252
- message: null,
253
- },
254
- ],
255
- suggestions: null,
239
+ loc: GeneratedSource,
240
});
241
242
lowerValueToTemporary(builder, {
compiler/packages/babel-plugin-react-compiler/src/HIR/Types.ts
+2
-10
@@ -6,7 +6,7 @@
6
*/
7
8
import {CompilerError} from '../CompilerError';
9
-import {PropertyLiteral} from './HIR';
9
+import {GeneratedSource, PropertyLiteral} from './HIR';
10
11
export type BuiltInType = PrimitiveType | FunctionType | ObjectType;
12
@@ -86,15 +86,7 @@ export type TypeId = number & {[opaqueTypeId]: 'IdentifierId'};
86
export function makeTypeId(id: number): TypeId {
87
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
88
reason: 'Expected instruction id to be a non-negative integer',
89
- description: null,
90
- details: [
91
- {
92
- kind: 'error',
93
- loc: null,
94
- message: null,
95
- },
96
- ],
97
- suggestions: null,
89
+ loc: GeneratedSource,
90
});
91
return id as TypeId;
92
}
compiler/packages/babel-plugin-react-compiler/src/HIR/visitors.ts
+2
-16
@@ -1260,14 +1260,7 @@ export class ScopeBlockTraversal {
1260
CompilerError.invariant(blockInfo.scope.id === top, {
1261
reason:
1262
'Expected traversed block fallthrough to match top-most active scope',
1263
- description: null,
1264
- details: [
1265
- {
1266
- kind: 'error',
1267
- loc: block.instructions[0]?.loc ?? block.terminal.id,
1268
- message: null,
1269
- },
1270
- ],
1263
+ loc: block.instructions[0]?.loc ?? block.terminal.loc,
1264
});
1265
this.#activeScopes.pop();
1266
}
@@ -1281,14 +1274,7 @@ export class ScopeBlockTraversal {
1274
!this.blockInfos.has(block.terminal.fallthrough),
1275
{
1276
reason: 'Expected unique scope blocks and fallthroughs',
1284
- description: null,
1285
- details: [
1286
- {
1287
- kind: 'error',
1288
- loc: block.terminal.loc,
1289
- message: null,
1290
- },
1291
- ],
1277
+ loc: block.terminal.loc,
1278
},
1279
);
1280
this.blockInfos.set(block.terminal.block, {
compiler/packages/babel-plugin-react-compiler/src/Inference/AnalyseFunctions.ts
+1
-8
@@ -78,14 +78,7 @@ function lowerWithMutationAliasing(fn: HIRFunction): void {
78
case 'Apply': {
79
CompilerError.invariant(false, {
80
reason: `[AnalyzeFunctions] Expected Apply effects to be replaced with more precise effects`,
81
- description: null,
82
- details: [
83
- {
84
- kind: 'error',
85
- loc: effect.function.loc,
86
- message: null,
87
- },
88
- ],
81
+ loc: effect.function.loc,
82
});
83
}
84
case 'Mutate':
compiler/packages/babel-plugin-react-compiler/src/Inference/DropManualMemoization.ts
+2
-8
@@ -586,14 +586,8 @@ function findOptionalPlaces(fn: HIRFunction): Set<IdentifierId> {
586
default: {
587
CompilerError.invariant(false, {
588
reason: `Unexpected terminal in optional`,
589
- description: null,
590
- details: [
591
- {
592
- kind: 'error',
593
- loc: terminal.loc,
594
- message: `Unexpected ${terminal.kind} in optional`,
595
- },
596
- ],
589
+ message: `Unexpected ${terminal.kind} in optional`,
590
+ loc: terminal.loc,
591
});
592
}
593
}
compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts
+5
-40
@@ -438,14 +438,7 @@ function rewriteSplices(
438
{
439
reason:
440
'[InferEffectDependencies] Internal invariant broken: expected block instructions to be sorted',
441
- description: null,
442
- details: [
443
- {
444
- kind: 'error',
445
- loc: originalInstrs[cursor].loc,
446
- message: null,
447
- },
448
- ],
441
+ loc: originalInstrs[cursor].loc,
442
},
443
);
444
currBlock.instructions.push(originalInstrs[cursor]);
@@ -454,14 +447,7 @@ function rewriteSplices(
447
CompilerError.invariant(originalInstrs[cursor].id === rewrite.location, {
448
reason:
449
'[InferEffectDependencies] Internal invariant broken: splice location not found',
457
- description: null,
458
- details: [
459
- {
460
- kind: 'error',
461
- loc: originalInstrs[cursor].loc,
462
- message: null,
463
- },
464
- ],
450
+ loc: originalInstrs[cursor].loc,
451
});
452
453
if (rewrite.kind === 'instr') {
@@ -481,14 +467,7 @@ function rewriteSplices(
467
{
468
reason:
469
'[InferEffectDependencies] Internal invariant broken: expected entry block to have a fallthrough',
484
- description: null,
485
- details: [
486
- {
487
- kind: 'error',
488
- loc: entryBlock.terminal.loc,
489
- message: null,
490
- },
491
- ],
470
+ loc: entryBlock.terminal.loc,
471
},
472
);
473
const originalTerminal = currBlock.terminal;
@@ -587,14 +566,7 @@ function inferMinimalDependencies(
566
CompilerError.invariant(hoistableToFnEntry != null, {
567
reason:
568
'[InferEffectDependencies] Internal invariant broken: missing entry block',
590
- description: null,
591
- details: [
592
- {
593
- kind: 'error',
594
- loc: fnInstr.loc,
595
- message: null,
596
- },
597
- ],
569
+ loc: fnInstr.loc,
570
});
571
572
const dependencies = inferDependencies(
@@ -650,14 +622,7 @@ function inferDependencies(
622
CompilerError.invariant(resultUnfiltered != null, {
623
reason:
624
'[InferEffectDependencies] Internal invariant broken: missing scope dependencies',
653
- description: null,
654
- details: [
655
- {
656
- kind: 'error',
657
- loc: fn.loc,
658
- message: null,
659
- },
660
- ],
625
+ loc: fn.loc,
626
});
627
628
const fnContext = new Set(fn.context.map(dep => dep.identifier.id));
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts
+22
-140
@@ -134,15 +134,7 @@ export function inferMutationAliasingEffects(
134
CompilerError.invariant(fn.params.length <= 2, {
135
reason:
136
'Expected React component to have not more than two parameters: one for props and for ref',
137
- description: null,
138
- details: [
139
- {
140
- kind: 'error',
141
- loc: fn.loc,
142
- message: null,
143
- },
144
- ],
145
- suggestions: null,
137
+ loc: fn.loc,
138
});
139
const [props, ref] = fn.params;
140
if (props != null) {
@@ -209,13 +201,7 @@ export function inferMutationAliasingEffects(
201
CompilerError.invariant(false, {
202
reason: `[InferMutationAliasingEffects] Potential infinite loop`,
203
description: `A value, temporary place, or effect was not cached properly`,
212
- details: [
213
- {
214
- kind: 'error',
215
- loc: fn.loc,
216
- message: null,
217
- },
218
- ],
204
+ loc: fn.loc,
205
});
206
}
207
for (const [blockId, block] of fn.body.blocks) {
@@ -528,14 +514,7 @@ function inferBlock(
514
CompilerError.invariant(state.kind(handlerParam) != null, {
515
reason:
516
'Expected catch binding to be intialized with a DeclareLocal Catch instruction',
531
- description: null,
532
- details: [
533
- {
534
- kind: 'error',
535
- loc: terminal.loc,
536
- message: null,
537
- },
538
- ],
517
+ loc: terminal.loc,
518
});
519
const effects: Array<AliasingEffect> = [];
520
for (const instr of block.instructions) {
@@ -685,14 +664,7 @@ function applySignature(
664
) {
665
CompilerError.invariant(false, {
666
reason: `Expected instruction lvalue to be initialized`,
688
- description: null,
689
- details: [
690
- {
691
- kind: 'error',
692
- loc: instruction.loc,
693
- message: null,
694
- },
695
- ],
667
+ loc: instruction.loc,
668
});
669
}
670
return effects.length !== 0 ? effects : null;
@@ -721,13 +693,7 @@ function applyEffect(
693
CompilerError.invariant(!initialized.has(effect.into.identifier.id), {
694
reason: `Cannot re-initialize variable within an instruction`,
695
description: `Re-initialized ${printPlace(effect.into)} in ${printAliasingEffect(effect)}`,
724
- details: [
725
- {
726
- kind: 'error',
727
- loc: effect.into.loc,
728
- message: null,
729
- },
730
- ],
696
+ loc: effect.into.loc,
697
});
698
initialized.add(effect.into.identifier.id);
699
@@ -766,13 +732,7 @@ function applyEffect(
732
CompilerError.invariant(!initialized.has(effect.into.identifier.id), {
733
reason: `Cannot re-initialize variable within an instruction`,
734
description: `Re-initialized ${printPlace(effect.into)} in ${printAliasingEffect(effect)}`,
769
- details: [
770
- {
771
- kind: 'error',
772
- loc: effect.into.loc,
773
- message: null,
774
- },
775
- ],
735
+ loc: effect.into.loc,
736
});
737
initialized.add(effect.into.identifier.id);
738
@@ -832,13 +792,7 @@ function applyEffect(
792
CompilerError.invariant(!initialized.has(effect.into.identifier.id), {
793
reason: `Cannot re-initialize variable within an instruction`,
794
description: `Re-initialized ${printPlace(effect.into)} in ${printAliasingEffect(effect)}`,
835
- details: [
836
- {
837
- kind: 'error',
838
- loc: effect.into.loc,
839
- message: null,
840
- },
841
- ],
795
+ loc: effect.into.loc,
796
});
797
initialized.add(effect.into.identifier.id);
798
@@ -916,13 +870,7 @@ function applyEffect(
870
description:
871
`Destination ${printPlace(effect.into)} is not initialized in this ` +
872
`instruction for effect ${printAliasingEffect(effect)}`,
919
- details: [
920
- {
921
- kind: 'error',
922
- loc: effect.into.loc,
923
- message: null,
924
- },
925
- ],
873
+ loc: effect.into.loc,
874
},
875
);
876
/*
@@ -1000,13 +948,7 @@ function applyEffect(
948
CompilerError.invariant(!initialized.has(effect.into.identifier.id), {
949
reason: `Cannot re-initialize variable within an instruction`,
950
description: `Re-initialized ${printPlace(effect.into)} in ${printAliasingEffect(effect)}`,
1003
- details: [
1004
- {
1005
- kind: 'error',
1006
- loc: effect.into.loc,
1007
- message: null,
1008
- },
1009
- ],
951
+ loc: effect.into.loc,
952
});
953
initialized.add(effect.into.identifier.id);
954
@@ -1406,15 +1348,7 @@ class InferenceState {
1348
CompilerError.invariant(value.kind !== 'LoadLocal', {
1349
reason:
1350
'[InferMutationAliasingEffects] Expected all top-level identifiers to be defined as variables, not values',
1409
- description: null,
1410
- details: [
1411
- {
1412
- kind: 'error',
1413
- loc: value.loc,
1414
- message: null,
1415
- },
1416
- ],
1417
- suggestions: null,
1351
+ loc: value.loc,
1352
});
1353
this.#values.set(value, kind);
1354
}
@@ -1424,14 +1358,8 @@ class InferenceState {
1358
CompilerError.invariant(values != null, {
1359
reason: `[InferMutationAliasingEffects] Expected value kind to be initialized`,
1360
description: `${printPlace(place)}`,
1427
- details: [
1428
- {
1429
- kind: 'error',
1430
- loc: place.loc,
1431
- message: 'this is uninitialized',
1432
- },
1433
- ],
1434
- suggestions: null,
1361
+ message: 'this is uninitialized',
1362
+ loc: place.loc,
1363
});
1364
return Array.from(values);
1365
}
@@ -1442,14 +1370,8 @@ class InferenceState {
1370
CompilerError.invariant(values != null, {
1371
reason: `[InferMutationAliasingEffects] Expected value kind to be initialized`,
1372
description: `${printPlace(place)}`,
1445
- details: [
1446
- {
1447
- kind: 'error',
1448
- loc: place.loc,
1449
- message: 'this is uninitialized',
1450
- },
1451
- ],
1452
- suggestions: null,
1373
+ message: 'this is uninitialized',
1374
+ loc: place.loc,
1375
});
1376
let mergedKind: AbstractValue | null = null;
1377
for (const value of values) {
@@ -1460,14 +1382,7 @@ class InferenceState {
1382
CompilerError.invariant(mergedKind !== null, {
1383
reason: `[InferMutationAliasingEffects] Expected at least one value`,
1384
description: `No value found at \`${printPlace(place)}\``,
1463
- details: [
1464
- {
1465
- kind: 'error',
1466
- loc: place.loc,
1467
- message: null,
1468
- },
1469
- ],
1470
- suggestions: null,
1385
+ loc: place.loc,
1386
});
1387
return mergedKind;
1388
}
@@ -1478,14 +1393,8 @@ class InferenceState {
1393
CompilerError.invariant(values != null, {
1394
reason: `[InferMutationAliasingEffects] Expected value for identifier to be initialized`,
1395
description: `${printIdentifier(value.identifier)}`,
1481
- details: [
1482
- {
1483
- kind: 'error',
1484
- loc: value.loc,
1485
- message: 'Expected value for identifier to be initialized',
1486
- },
1487
- ],
1488
- suggestions: null,
1396
+ message: 'Expected value for identifier to be initialized',
1397
+ loc: value.loc,
1398
});
1399
this.#variables.set(place.identifier.id, new Set(values));
1400
}
@@ -1495,14 +1404,8 @@ class InferenceState {
1404
CompilerError.invariant(values != null, {
1405
reason: `[InferMutationAliasingEffects] Expected value for identifier to be initialized`,
1406
description: `${printIdentifier(value.identifier)}`,
1498
- details: [
1499
- {
1500
- kind: 'error',
1501
- loc: value.loc,
1502
- message: 'Expected value for identifier to be initialized',
1503
- },
1504
- ],
1505
- suggestions: null,
1407
+ message: 'Expected value for identifier to be initialized',
1408
+ loc: value.loc,
1409
});
1410
const prevValues = this.values(place);
1411
this.#variables.set(
@@ -1516,14 +1419,7 @@ class InferenceState {
1419
CompilerError.invariant(this.#values.has(value), {
1420
reason: `[InferMutationAliasingEffects] Expected value to be initialized`,
1421
description: printInstructionValue(value),
1519
- details: [
1520
- {
1521
- kind: 'error',
1522
- loc: value.loc,
1523
- message: 'Expected value for identifier to be initialized',
1524
- },
1525
- ],
1526
- suggestions: null,
1422
+ loc: value.loc,
1423
});
1424
this.#variables.set(place.identifier.id, new Set([value]));
1425
}
@@ -2963,15 +2859,7 @@ export function isKnownMutableEffect(effect: Effect): boolean {
2859
case Effect.Unknown: {
2860
CompilerError.invariant(false, {
2861
reason: 'Unexpected unknown effect',
2966
- description: null,
2967
- details: [
2968
- {
2969
- kind: 'error',
2970
- loc: GeneratedSource,
2971
- message: null,
2972
- },
2973
- ],
2974
- suggestions: null,
2862
+ loc: GeneratedSource,
2863
});
2864
}
2865
case Effect.Read:
@@ -3079,13 +2967,7 @@ function mergeValueKinds(a: ValueKind, b: ValueKind): ValueKind {
2967
{
2968
reason: `Unexpected value kind in mergeValues()`,
2969
description: `Found kinds ${a} and ${b}`,
3082
- details: [
3083
- {
3084
- kind: 'error',
3085
- loc: GeneratedSource,
3086
- message: null,
3087
- },
3088
- ],
2970
+ loc: GeneratedSource,
2971
},
2972
);
2973
return ValueKind.Primitive;
compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingRanges.ts
+3
-24
@@ -229,14 +229,7 @@ export function inferMutationAliasingRanges(
229
} else {
230
CompilerError.invariant(effect.kind === 'Freeze', {
231
reason: `Unexpected '${effect.kind}' effect for MaybeThrow terminal`,
232
- description: null,
233
- details: [
234
- {
235
- kind: 'error',
236
- loc: block.terminal.loc,
237
- message: null,
238
- },
239
- ],
232
+ loc: block.terminal.loc,
233
});
234
}
235
}
@@ -385,14 +378,7 @@ export function inferMutationAliasingRanges(
378
case 'Apply': {
379
CompilerError.invariant(false, {
380
reason: `[AnalyzeFunctions] Expected Apply effects to be replaced with more precise effects`,
388
- description: null,
389
- details: [
390
- {
391
- kind: 'error',
392
- loc: effect.function.loc,
393
- message: null,
394
- },
395
- ],
381
+ loc: effect.function.loc,
382
});
383
}
384
case 'MutateTransitive':
@@ -539,14 +525,7 @@ export function inferMutationAliasingRanges(
525
const fromNode = state.nodes.get(from.identifier);
526
CompilerError.invariant(fromNode != null, {
527
reason: `Expected a node to exist for all parameters and context variables`,
542
- description: null,
543
- details: [
544
- {
545
- kind: 'error',
546
- loc: into.loc,
547
- message: null,
548
- },
549
- ],
528
+ loc: into.loc,
529
});
530
if (fromNode.lastMutated === mutationIndex) {
531
if (into.identifier.id === fn.returns.identifier.id) {
compiler/packages/babel-plugin-react-compiler/src/Inference/InferReactivePlaces.ts
+1
-9
@@ -310,15 +310,7 @@ export function inferReactivePlaces(fn: HIRFunction): void {
310
case Effect.Unknown: {
311
CompilerError.invariant(false, {
312
reason: 'Unexpected unknown effect',
313
- description: null,
314
- details: [
315
- {
316
- kind: 'error',
317
- loc: operand.loc,
318
- message: null,
319
- },
320
- ],
321
- suggestions: null,
313
+ loc: operand.loc,
314
});
315
}
316
default: {
compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts
+3
-18
@@ -8,6 +8,7 @@
8
import {isValidIdentifier} from '@babel/types';
9
import {CompilerError} from '../CompilerError';
10
import {
11
+ GeneratedSource,
12
GotoVariant,
13
HIRFunction,
14
IdentifierId,
@@ -191,15 +192,7 @@ function evaluatePhi(phi: Phi, constants: Constants): Constant | null {
192
case 'Primitive': {
193
CompilerError.invariant(value.kind === 'Primitive', {
194
reason: 'value kind expected to be Primitive',
194
- description: null,
195
- details: [
196
- {
197
- kind: 'error',
198
- loc: null,
199
- message: null,
200
- },
201
- ],
202
- suggestions: null,
195
+ loc: GeneratedSource,
196
});
197
198
// different constant values, can't constant propogate
@@ -211,15 +204,7 @@ function evaluatePhi(phi: Phi, constants: Constants): Constant | null {
204
case 'LoadGlobal': {
205
CompilerError.invariant(value.kind === 'LoadGlobal', {
206
reason: 'value kind expected to be LoadGlobal',
214
- description: null,
215
- details: [
216
- {
217
- kind: 'error',
218
- loc: null,
219
- message: null,
220
- },
221
- ],
222
- suggestions: null,
207
+ loc: GeneratedSource,
208
});
209
210
// different global values, can't constant propogate
compiler/packages/babel-plugin-react-compiler/src/Optimization/InlineJsxTransform.ts
+1
-8
@@ -709,14 +709,7 @@ function createPropsProperties(
709
const spreadProp = jsxSpreadAttributes[0];
710
CompilerError.invariant(spreadProp.kind === 'JsxSpreadAttribute', {
711
reason: 'Spread prop attribute must be of kind JSXSpreadAttribute',
712
- description: null,
713
- details: [
714
- {
715
- kind: 'error',
716
- loc: instr.loc,
717
- message: null,
718
- },
719
- ],
712
+ loc: instr.loc,
713
});
714
propsProperty = {
715
kind: 'ObjectProperty',
compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts
+5
-18
@@ -78,17 +78,10 @@ export function instructionReordering(fn: HIRFunction): void {
78
}
79
CompilerError.invariant(shared.size === 0, {
80
reason: `InstructionReordering: expected all reorderable nodes to have been emitted`,
81
- description: null,
82
- details: [
83
- {
84
- kind: 'error',
85
- loc:
86
- [...shared.values()]
87
- .map(node => node.instruction?.loc)
88
- .filter(loc => loc != null)[0] ?? GeneratedSource,
89
- message: null,
90
- },
91
- ],
81
+ loc:
82
+ [...shared.values()]
83
+ .map(node => node.instruction?.loc)
84
+ .filter(loc => loc != null)[0] ?? GeneratedSource,
85
});
86
markInstructionIds(fn.body);
87
}
@@ -309,17 +302,11 @@ function reorderBlock(
302
node.reorderability === Reorderability.Reorderable,
303
{
304
reason: `Expected all remaining instructions to be reorderable`,
312
- details: [
313
- {
314
- kind: 'error',
315
- loc: node.instruction?.loc ?? block.terminal.loc,
316
- message: null,
317
- },
318
- ],
305
description:
306
node.instruction != null
307
? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable`
308
: `Lvalue $${id} was not emitted yet but is not reorderable`,
309
+ loc: node.instruction?.loc ?? block.terminal.loc,
310
},
311
);
312
compiler/packages/babel-plugin-react-compiler/src/Optimization/OptimizeForSSR.ts
+2
-8
@@ -178,14 +178,8 @@ export function optimizeForSSR(fn: HIRFunction): void {
178
{
179
reason:
180
'Expected a valid destructuring pattern for inlined state',
181
- description: null,
182
- details: [
183
- {
184
- kind: 'error',
185
- message: 'Expected a valid destructuring pattern',
186
- loc: value.loc,
187
- },
188
- ],
181
+ message: 'Expected a valid destructuring pattern',
182
+ loc: value.loc,
183
},
184
);
185
const store: StoreLocal = {
compiler/packages/babel-plugin-react-compiler/src/Optimization/PruneMaybeThrows.ts
+1
-8
@@ -52,17 +52,10 @@ export function pruneMaybeThrows(fn: HIRFunction): void {
52
const mappedTerminal = terminalMapping.get(predecessor);
53
CompilerError.invariant(mappedTerminal != null, {
54
reason: `Expected non-existing phi operand's predecessor to have been mapped to a new terminal`,
55
- details: [
56
- {
57
- kind: 'error',
58
- loc: GeneratedSource,
59
- message: null,
60
- },
61
- ],
55
description: `Could not find mapping for predecessor bb${predecessor} in block bb${
56
block.id
57
} for phi ${printPlace(phi.place)}`,
65
- suggestions: null,
58
+ loc: GeneratedSource,
59
});
60
phi.operands.delete(predecessor);
61
phi.operands.set(mappedTerminal, operand);
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignObjectMethodScopes.ts
+1
-9
@@ -41,15 +41,7 @@ function findScopesToMerge(fn: HIRFunction): DisjointSet<ReactiveScope> {
41
{
42
reason:
43
'Internal error: Expected all ObjectExpressions and ObjectMethods to have non-null scope.',
44
- description: null,
45
- suggestions: null,
46
- details: [
47
- {
48
- kind: 'error',
49
- loc: GeneratedSource,
50
- message: null,
51
- },
52
- ],
44
+ loc: GeneratedSource,
45
},
46
);
47
mergeScopesBuilder.union([operandScope, lvalueScope]);
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AlignReactiveScopesToBlockScopesHIR.ts
+2
-16
@@ -170,14 +170,7 @@ export function alignReactiveScopesToBlockScopesHIR(fn: HIRFunction): void {
170
171
CompilerError.invariant(!valueBlockNodes.has(fallthrough), {
172
reason: 'Expect hir blocks to have unique fallthroughs',
173
- description: null,
174
- details: [
175
- {
176
- kind: 'error',
177
- loc: terminal.loc,
178
- message: null,
179
- },
180
- ],
173
+ loc: terminal.loc,
174
});
175
if (node != null) {
176
valueBlockNodes.set(fallthrough, node);
@@ -259,14 +252,7 @@ export function alignReactiveScopesToBlockScopesHIR(fn: HIRFunction): void {
252
// Transition from block->value block, derive the outer block range
253
CompilerError.invariant(fallthrough !== null, {
254
reason: `Expected a fallthrough for value block`,
262
- description: null,
263
- details: [
264
- {
265
- kind: 'error',
266
- loc: terminal.loc,
267
- message: null,
268
- },
269
- ],
255
+ loc: terminal.loc,
256
});
257
const fallthroughBlock = fn.body.blocks.get(fallthrough)!;
258
const nextId =
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AssertScopeInstructionsWithinScope.ts
+1
-8
@@ -84,14 +84,7 @@ class CheckInstructionsAgainstScopesVisitor extends ReactiveFunctionVisitor<
84
reason:
85
'Encountered an instruction that should be part of a scope, but where that scope has already completed',
86
description: `Instruction [${id}] is part of scope @${scope.id}, but that scope has already completed`,
87
- details: [
88
- {
89
- kind: 'error',
90
- loc: place.loc,
91
- message: null,
92
- },
93
- ],
94
- suggestions: null,
87
+ loc: place.loc,
88
});
89
}
90
}
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/AssertWellFormedBreakTargets.ts
+1
-8
@@ -28,14 +28,7 @@ class Visitor extends ReactiveFunctionVisitor<Set<BlockId>> {
28
if (terminal.kind === 'break' || terminal.kind === 'continue') {
29
CompilerError.invariant(seenLabels.has(terminal.target), {
30
reason: 'Unexpected break to invalid label',
31
- description: null,
32
- details: [
33
- {
34
- kind: 'error',
35
- loc: stmt.terminal.loc,
36
- message: null,
37
- },
38
- ],
31
+ loc: stmt.terminal.loc,
32
});
33
}
34
}
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts
+23
-186
@@ -9,6 +9,7 @@ import {CompilerError} from '../CompilerError';
9
import {
10
BasicBlock,
11
BlockId,
12
+ GeneratedSource,
13
GotoVariant,
14
HIR,
15
InstructionId,
@@ -70,15 +71,7 @@ class Driver {
71
visitBlock(block: BasicBlock, blockValue: ReactiveBlock): void {
72
CompilerError.invariant(!this.cx.emitted.has(block.id), {
73
reason: `Cannot emit the same block twice: bb${block.id}`,
73
- description: null,
74
- details: [
75
- {
76
- kind: 'error',
77
- loc: null,
78
- message: null,
79
- },
80
- ],
81
- suggestions: null,
74
+ loc: GeneratedSource,
75
});
76
this.cx.emitted.add(block.id);
77
for (const instruction of block.instructions) {
@@ -137,14 +130,7 @@ class Driver {
130
if (this.cx.isScheduled(terminal.consequent)) {
131
CompilerError.invariant(false, {
132
reason: `Unexpected 'if' where the consequent is already scheduled`,
140
- description: null,
141
- details: [
142
- {
143
- kind: 'error',
144
- loc: terminal.loc,
145
- message: null,
146
- },
147
- ],
133
+ loc: terminal.loc,
134
});
135
} else {
136
consequent = this.traverseBlock(
@@ -157,14 +143,7 @@ class Driver {
143
if (this.cx.isScheduled(alternateId)) {
144
CompilerError.invariant(false, {
145
reason: `Unexpected 'if' where the alternate is already scheduled`,
160
- description: null,
161
- details: [
162
- {
163
- kind: 'error',
164
- loc: terminal.loc,
165
- message: null,
166
- },
167
- ],
146
+ loc: terminal.loc,
147
});
148
} else {
149
alternate = this.traverseBlock(this.cx.ir.blocks.get(alternateId)!);
@@ -217,14 +196,7 @@ class Driver {
196
if (this.cx.isScheduled(case_.block)) {
197
CompilerError.invariant(case_.block === terminal.fallthrough, {
198
reason: `Unexpected 'switch' where a case is already scheduled and block is not the fallthrough`,
220
- description: null,
221
- details: [
222
- {
223
- kind: 'error',
224
- loc: terminal.loc,
225
- message: null,
226
- },
227
- ],
199
+ loc: terminal.loc,
200
});
201
return;
202
} else {
@@ -283,14 +255,7 @@ class Driver {
255
} else {
256
CompilerError.invariant(false, {
257
reason: `Unexpected 'do-while' where the loop is already scheduled`,
286
- description: null,
287
- details: [
288
- {
289
- kind: 'error',
290
- loc: terminal.loc,
291
- message: null,
292
- },
293
- ],
258
+ loc: terminal.loc,
259
});
260
}
261
@@ -351,14 +316,7 @@ class Driver {
316
} else {
317
CompilerError.invariant(false, {
318
reason: `Unexpected 'while' where the loop is already scheduled`,
354
- description: null,
355
- details: [
356
- {
357
- kind: 'error',
358
- loc: terminal.loc,
359
- message: null,
360
- },
361
- ],
319
+ loc: terminal.loc,
320
});
321
}
322
@@ -444,14 +402,7 @@ class Driver {
402
} else {
403
CompilerError.invariant(false, {
404
reason: `Unexpected 'for' where the loop is already scheduled`,
447
- description: null,
448
- details: [
449
- {
450
- kind: 'error',
451
- loc: terminal.loc,
452
- message: null,
453
- },
454
- ],
405
+ loc: terminal.loc,
406
});
407
}
408
@@ -549,14 +500,7 @@ class Driver {
500
} else {
501
CompilerError.invariant(false, {
502
reason: `Unexpected 'for-of' where the loop is already scheduled`,
552
- description: null,
553
- details: [
554
- {
555
- kind: 'error',
556
- loc: terminal.loc,
557
- message: null,
558
- },
559
- ],
503
+ loc: terminal.loc,
504
});
505
}
506
@@ -628,14 +572,7 @@ class Driver {
572
} else {
573
CompilerError.invariant(false, {
574
reason: `Unexpected 'for-in' where the loop is already scheduled`,
631
- description: null,
632
- details: [
633
- {
634
- kind: 'error',
635
- loc: terminal.loc,
636
- message: null,
637
- },
638
- ],
575
+ loc: terminal.loc,
576
});
577
}
578
@@ -678,14 +615,7 @@ class Driver {
615
if (this.cx.isScheduled(terminal.alternate)) {
616
CompilerError.invariant(false, {
617
reason: `Unexpected 'branch' where the alternate is already scheduled`,
681
- description: null,
682
- details: [
683
- {
684
- kind: 'error',
685
- loc: terminal.loc,
686
- message: null,
687
- },
688
- ],
618
+ loc: terminal.loc,
619
});
620
} else {
621
alternate = this.traverseBlock(
@@ -723,14 +653,7 @@ class Driver {
653
if (this.cx.isScheduled(terminal.block)) {
654
CompilerError.invariant(false, {
655
reason: `Unexpected 'label' where the block is already scheduled`,
726
- description: null,
727
- details: [
728
- {
729
- kind: 'error',
730
- loc: terminal.loc,
731
- message: null,
732
- },
733
- ],
656
+ loc: terminal.loc,
657
});
658
} else {
659
block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)!);
@@ -888,14 +811,7 @@ class Driver {
811
if (this.cx.isScheduled(terminal.block)) {
812
CompilerError.invariant(false, {
813
reason: `Unexpected 'scope' where the block is already scheduled`,
891
- description: null,
892
- details: [
893
- {
894
- kind: 'error',
895
- loc: terminal.loc,
896
- message: null,
897
- },
898
- ],
814
+ loc: terminal.loc,
815
});
816
} else {
817
block = this.traverseBlock(this.cx.ir.blocks.get(terminal.block)!);
@@ -920,15 +836,7 @@ class Driver {
836
case 'unsupported': {
837
CompilerError.invariant(false, {
838
reason: 'Unexpected unsupported terminal',
923
- description: null,
924
- details: [
925
- {
926
- kind: 'error',
927
- loc: terminal.loc,
928
- message: null,
929
- },
930
- ],
931
- suggestions: null,
839
+ loc: terminal.loc,
840
});
841
}
842
default: {
@@ -963,15 +871,7 @@ class Driver {
871
{
872
reason:
873
'Expected branch block to end in an instruction that sets the test value',
966
- description: null,
967
- details: [
968
- {
969
- kind: 'error',
970
- loc: instr.lvalue.loc,
971
- message: null,
972
- },
973
- ],
974
- suggestions: null,
874
+ loc: instr.lvalue.loc,
875
},
876
);
877
return {
@@ -1001,15 +901,7 @@ class Driver {
901
if (instructions.length === 0) {
902
CompilerError.invariant(false, {
903
reason: 'Expected goto value block to have at least one instruction',
1004
- description: null,
1005
- details: [
1006
- {
1007
- kind: 'error',
1008
- loc: null,
1009
- message: null,
1010
- },
1011
- ],
1012
- suggestions: null,
904
+ loc: GeneratedSource,
905
});
906
} else if (defaultBlock.instructions.length === 1) {
907
const instr = defaultBlock.instructions[0]!;
@@ -1292,28 +1184,13 @@ class Driver {
1184
if (target === null) {
1185
CompilerError.invariant(false, {
1186
reason: 'Expected a break target',
1295
- description: null,
1296
- details: [
1297
- {
1298
- kind: 'error',
1299
- loc: null,
1300
- message: null,
1301
- },
1302
- ],
1303
- suggestions: null,
1187
+ loc: GeneratedSource,
1188
});
1189
}
1190
if (this.cx.scopeFallthroughs.has(target.block)) {
1191
CompilerError.invariant(target.type === 'implicit', {
1192
reason: 'Expected reactive scope to implicitly break to fallthrough',
1309
- description: null,
1310
- details: [
1311
- {
1312
- kind: 'error',
1313
- loc,
1314
- message: null,
1315
- },
1316
- ],
1193
+ loc,
1194
});
1195
return null;
1196
}
@@ -1338,15 +1215,7 @@ class Driver {
1215
const target = this.cx.getContinueTarget(block);
1216
CompilerError.invariant(target !== null, {
1217
reason: `Expected continue target to be scheduled for bb${block}`,
1341
- description: null,
1342
- details: [
1343
- {
1344
- kind: 'error',
1345
- loc: null,
1346
- message: null,
1347
- },
1348
- ],
1349
- suggestions: null,
1218
+ loc: GeneratedSource,
1219
});
1220
1221
return {
@@ -1419,15 +1288,7 @@ class Context {
1288
const id = this.#nextScheduleId++;
1289
CompilerError.invariant(!this.#scheduled.has(block), {
1290
reason: `Break block is already scheduled: bb${block}`,
1422
- description: null,
1423
- details: [
1424
- {
1425
- kind: 'error',
1426
- loc: null,
1427
- message: null,
1428
- },
1429
- ],
1430
- suggestions: null,
1291
+ loc: GeneratedSource,
1292
});
1293
this.#scheduled.add(block);
1294
this.#controlFlowStack.push({block, id, type});
@@ -1444,15 +1305,7 @@ class Context {
1305
this.#scheduled.add(fallthroughBlock);
1306
CompilerError.invariant(!this.#scheduled.has(continueBlock), {
1307
reason: `Continue block is already scheduled: bb${continueBlock}`,
1447
- description: null,
1448
- details: [
1449
- {
1450
- kind: 'error',
1451
- loc: null,
1452
- message: null,
1453
- },
1454
- ],
1455
- suggestions: null,
1308
+ loc: GeneratedSource,
1309
});
1310
this.#scheduled.add(continueBlock);
1311
let ownsLoop = false;
@@ -1478,15 +1331,7 @@ class Context {
1331
const last = this.#controlFlowStack.pop();
1332
CompilerError.invariant(last !== undefined && last.id === scheduleId, {
1333
reason: 'Can only unschedule the last target',
1481
- description: null,
1482
- details: [
1483
- {
1484
- kind: 'error',
1485
- loc: null,
1486
- message: null,
1487
- },
1488
- ],
1489
- suggestions: null,
1334
+ loc: GeneratedSource,
1335
});
1336
if (last.type !== 'loop' || last.ownsBlock !== null) {
1337
this.#scheduled.delete(last.block);
@@ -1559,15 +1404,7 @@ class Context {
1404
1405
CompilerError.invariant(false, {
1406
reason: 'Expected a break target',
1562
- description: null,
1563
- details: [
1564
- {
1565
- kind: 'error',
1566
- loc: null,
1567
- message: null,
1568
- },
1569
- ],
1570
- suggestions: null,
1407
+ loc: GeneratedSource,
1408
});
1409
}
1410
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts
+44
-353
@@ -297,15 +297,7 @@ export function codegenFunction(
297
CompilerError.invariant(globalGating != null, {
298
reason:
299
'Bad config not caught! Expected at least one of gating or globalGating',
300
- description: null,
301
- details: [
302
- {
303
- kind: 'error',
304
- loc: null,
305
- message: null,
306
- },
307
- ],
308
- suggestions: null,
300
+ loc: GeneratedSource,
301
});
302
ifTest = globalGating;
303
}
@@ -509,15 +501,7 @@ function codegenBlock(cx: Context, block: ReactiveBlock): t.BlockStatement {
501
}
502
CompilerError.invariant(temp.get(key)! === value, {
503
reason: 'Expected temporary value to be unchanged',
512
- description: null,
513
- suggestions: null,
514
- details: [
515
- {
516
- kind: 'error',
517
- loc: null,
518
- message: null,
519
- },
520
- ],
504
+ loc: GeneratedSource,
505
});
506
}
507
cx.temp = temp;
@@ -688,14 +672,7 @@ function codegenReactiveScope(
672
description: `Declaration \`${printIdentifier(
673
identifier,
674
)}\` is unnamed in scope @${scope.id}`,
691
- details: [
692
- {
693
- kind: 'error',
694
- loc: null,
695
- message: null,
696
- },
697
- ],
698
- suggestions: null,
675
+ loc: GeneratedSource,
676
});
677
678
const name = convertIdentifier(identifier);
@@ -731,14 +708,7 @@ function codegenReactiveScope(
708
CompilerError.invariant(firstOutputIndex !== null, {
709
reason: `Expected scope to have at least one declaration`,
710
description: `Scope '@${scope.id}' has no declarations`,
734
- details: [
735
- {
736
- kind: 'error',
737
- loc: null,
738
- message: null,
739
- },
740
- ],
741
- suggestions: null,
711
+ loc: GeneratedSource,
712
});
713
testCondition = t.binaryExpression(
714
'===',
@@ -760,13 +730,7 @@ function codegenReactiveScope(
730
{
731
reason: `Expected to not have both change detection enabled and memoization disabled`,
732
description: `Incompatible config options`,
763
- details: [
764
- {
765
- kind: 'error',
766
- loc: null,
767
- message: null,
768
- },
769
- ],
733
+ loc: GeneratedSource,
734
},
735
);
736
testCondition = t.logicalExpression(
@@ -950,15 +914,7 @@ function codegenReactiveScope(
914
earlyReturnValue.value.name.kind === 'named',
915
{
916
reason: `Expected early return value to be promoted to a named variable`,
953
- description: null,
954
- details: [
955
- {
956
- kind: 'error',
957
- loc: earlyReturnValue.loc,
958
- message: null,
959
- },
960
- ],
961
- suggestions: null,
917
+ loc: earlyReturnValue.loc,
918
},
919
);
920
const name: ValidIdentifierName = earlyReturnValue.value.name.value;
@@ -1020,14 +976,7 @@ function codegenTerminal(
976
CompilerError.invariant(terminal.init.kind === 'SequenceExpression', {
977
reason: `Expected a sequence expression init for for..in`,
978
description: `Got \`${terminal.init.kind}\` expression instead`,
1023
- details: [
1024
- {
1025
- kind: 'error',
1026
- loc: terminal.init.loc,
1027
- message: null,
1028
- },
1029
- ],
1030
- suggestions: null,
979
+ loc: terminal.init.loc,
980
});
981
if (terminal.init.instructions.length !== 2) {
982
CompilerError.throwTodo({
@@ -1061,14 +1010,7 @@ function codegenTerminal(
1010
CompilerError.invariant(false, {
1011
reason: `Expected a StoreLocal or Destructure to be assigned to the collection`,
1012
description: `Found ${iterableItem.value.kind}`,
1064
- details: [
1065
- {
1066
- kind: 'error',
1067
- loc: iterableItem.value.loc,
1068
- message: null,
1069
- },
1070
- ],
1071
- suggestions: null,
1013
+ loc: iterableItem.value.loc,
1014
});
1015
}
1016
let varDeclKind: 'const' | 'let';
@@ -1083,15 +1025,7 @@ function codegenTerminal(
1025
CompilerError.invariant(false, {
1026
reason:
1027
'Destructure should never be Reassign as it would be an Object/ArrayPattern',
1086
- description: null,
1087
- details: [
1088
- {
1089
- kind: 'error',
1090
- loc: iterableItem.loc,
1091
- message: null,
1092
- },
1093
- ],
1094
- suggestions: null,
1028
+ loc: iterableItem.loc,
1029
});
1030
case InstructionKind.Catch:
1031
case InstructionKind.HoistedConst:
@@ -1100,15 +1034,7 @@ function codegenTerminal(
1034
case InstructionKind.Function:
1035
CompilerError.invariant(false, {
1036
reason: `Unexpected ${iterableItem.value.lvalue.kind} variable in for..in collection`,
1103
- description: null,
1104
- details: [
1105
- {
1106
- kind: 'error',
1107
- loc: iterableItem.loc,
1108
- message: null,
1109
- },
1110
- ],
1111
- suggestions: null,
1037
+ loc: iterableItem.loc,
1038
});
1039
default:
1040
assertExhaustive(
@@ -1137,14 +1063,7 @@ function codegenTerminal(
1063
{
1064
reason: `Expected a single-expression sequence expression init for for..of`,
1065
description: `Got \`${terminal.init.kind}\` expression instead`,
1140
- details: [
1141
- {
1142
- kind: 'error',
1143
- loc: terminal.init.loc,
1144
- message: null,
1145
- },
1146
- ],
1147
- suggestions: null,
1066
+ loc: terminal.init.loc,
1067
},
1068
);
1069
const iterableCollection = terminal.init.instructions[0].value;
@@ -1152,14 +1071,7 @@ function codegenTerminal(
1071
CompilerError.invariant(terminal.test.kind === 'SequenceExpression', {
1072
reason: `Expected a sequence expression test for for..of`,
1073
description: `Got \`${terminal.init.kind}\` expression instead`,
1155
- details: [
1156
- {
1157
- kind: 'error',
1158
- loc: terminal.test.loc,
1159
- message: null,
1160
- },
1161
- ],
1162
- suggestions: null,
1074
+ loc: terminal.test.loc,
1075
});
1076
if (terminal.test.instructions.length !== 2) {
1077
CompilerError.throwTodo({
@@ -1192,14 +1104,7 @@ function codegenTerminal(
1104
CompilerError.invariant(false, {
1105
reason: `Expected a StoreLocal or Destructure to be assigned to the collection`,
1106
description: `Found ${iterableItem.value.kind}`,
1195
- details: [
1196
- {
1197
- kind: 'error',
1198
- loc: iterableItem.value.loc,
1199
- message: null,
1200
- },
1201
- ],
1202
- suggestions: null,
1107
+ loc: iterableItem.value.loc,
1108
});
1109
}
1110
let varDeclKind: 'const' | 'let';
@@ -1218,15 +1123,7 @@ function codegenTerminal(
1123
case InstructionKind.Function:
1124
CompilerError.invariant(false, {
1125
reason: `Unexpected ${iterableItem.value.lvalue.kind} variable in for..of collection`,
1221
- description: null,
1222
- details: [
1223
- {
1224
- kind: 'error',
1225
- loc: iterableItem.loc,
1226
- message: null,
1227
- },
1228
- ],
1229
- suggestions: null,
1126
+ loc: iterableItem.loc,
1127
});
1128
default:
1129
assertExhaustive(
@@ -1376,15 +1273,8 @@ function codegenInstructionNullable(
1273
case InstructionKind.Const: {
1274
CompilerError.invariant(instr.lvalue === null, {
1275
reason: `Const declaration cannot be referenced as an expression`,
1379
- description: null,
1380
- details: [
1381
- {
1382
- kind: 'error',
1383
- loc: instr.value.loc,
1384
- message: `this is ${kind}`,
1385
- },
1386
- ],
1387
- suggestions: null,
1276
+ message: `this is ${kind}`,
1277
+ loc: instr.value.loc,
1278
});
1279
return createVariableDeclaration(instr.loc, 'const', [
1280
createVariableDeclarator(codegenLValue(cx, lvalue), value),
@@ -1393,40 +1283,17 @@ function codegenInstructionNullable(
1283
case InstructionKind.Function: {
1284
CompilerError.invariant(instr.lvalue === null, {
1285
reason: `Function declaration cannot be referenced as an expression`,
1396
- description: null,
1397
- details: [
1398
- {
1399
- kind: 'error',
1400
- loc: instr.value.loc,
1401
- message: `this is ${kind}`,
1402
- },
1403
- ],
1404
- suggestions: null,
1286
+ loc: instr.value.loc,
1287
});
1288
const genLvalue = codegenLValue(cx, lvalue);
1289
CompilerError.invariant(genLvalue.type === 'Identifier', {
1290
reason: 'Expected an identifier as a function declaration lvalue',
1409
- description: null,
1410
- details: [
1411
- {
1412
- kind: 'error',
1413
- loc: instr.value.loc,
1414
- message: null,
1415
- },
1416
- ],
1417
- suggestions: null,
1291
+ loc: instr.value.loc,
1292
});
1293
CompilerError.invariant(value?.type === 'FunctionExpression', {
1294
reason: 'Expected a function as a function declaration value',
1295
description: `Got ${value == null ? String(value) : value.type} at ${printInstruction(instr)}`,
1422
- details: [
1423
- {
1424
- kind: 'error',
1425
- loc: instr.value.loc,
1426
- message: null,
1427
- },
1428
- ],
1429
- suggestions: null,
1296
+ loc: instr.value.loc,
1297
});
1298
return createFunctionDeclaration(
1299
instr.loc,
@@ -1440,15 +1307,8 @@ function codegenInstructionNullable(
1307
case InstructionKind.Let: {
1308
CompilerError.invariant(instr.lvalue === null, {
1309
reason: `Const declaration cannot be referenced as an expression`,
1443
- description: null,
1444
- details: [
1445
- {
1446
- kind: 'error',
1447
- loc: instr.value.loc,
1448
- message: 'this is const',
1449
- },
1450
- ],
1451
- suggestions: null,
1310
+ message: `this is ${kind}`,
1311
+ loc: instr.value.loc,
1312
});
1313
return createVariableDeclaration(instr.loc, 'let', [
1314
createVariableDeclarator(codegenLValue(cx, lvalue), value),
@@ -1457,15 +1317,7 @@ function codegenInstructionNullable(
1317
case InstructionKind.Reassign: {
1318
CompilerError.invariant(value !== null, {
1319
reason: 'Expected a value for reassignment',
1460
- description: null,
1461
- details: [
1462
- {
1463
- kind: 'error',
1464
- loc: instr.value.loc,
1465
- message: null,
1466
- },
1467
- ],
1468
- suggestions: null,
1320
+ loc: instr.value.loc,
1321
});
1322
const expr = t.assignmentExpression(
1323
'=',
@@ -1496,15 +1348,7 @@ function codegenInstructionNullable(
1348
case InstructionKind.HoistedFunction: {
1349
CompilerError.invariant(false, {
1350
reason: `Expected ${kind} to have been pruned in PruneHoistedContexts`,
1499
- description: null,
1500
- details: [
1501
- {
1502
- kind: 'error',
1503
- loc: instr.loc,
1504
- message: null,
1505
- },
1506
- ],
1507
- suggestions: null,
1351
+ loc: instr.loc,
1352
});
1353
}
1354
default: {
@@ -1521,15 +1365,7 @@ function codegenInstructionNullable(
1365
} else if (instr.value.kind === 'ObjectMethod') {
1366
CompilerError.invariant(instr.lvalue, {
1367
reason: 'Expected object methods to have a temp lvalue',
1524
- description: null,
1525
- details: [
1526
- {
1527
- kind: 'error',
1528
- loc: null,
1529
- message: null,
1530
- },
1531
- ],
1532
- suggestions: null,
1368
+ loc: GeneratedSource,
1369
});
1370
cx.objectMethods.set(instr.lvalue.identifier.id, instr.value);
1371
return null;
@@ -1575,15 +1411,8 @@ function codegenForInit(
1411
(instr.kind === 'let' || instr.kind === 'const'),
1412
{
1413
reason: 'Expected a variable declaration',
1578
- details: [
1579
- {
1580
- kind: 'error',
1581
- loc: init.loc,
1582
- message: null,
1583
- },
1584
- ],
1414
description: `Got ${instr.type}`,
1586
- suggestions: null,
1415
+ loc: init.loc,
1416
},
1417
);
1418
if (instr.kind === 'let') {
@@ -1594,15 +1423,7 @@ function codegenForInit(
1423
});
1424
CompilerError.invariant(declarators.length > 0, {
1425
reason: 'Expected a variable declaration',
1597
- details: [
1598
- {
1599
- kind: 'error',
1600
- loc: init.loc,
1601
- message: null,
1602
- },
1603
- ],
1604
- description: null,
1605
- suggestions: null,
1426
+ loc: init.loc,
1427
});
1428
return t.variableDeclaration(kind, declarators);
1429
} else {
@@ -1958,15 +1779,7 @@ function codegenInstructionValue(
1779
case 'CallExpression': {
1780
CompilerError.invariant(t.isExpression(optionalValue.callee), {
1781
reason: 'v8 intrinsics are validated during lowering',
1961
- description: null,
1962
- details: [
1963
- {
1964
- kind: 'error',
1965
- loc: optionalValue.callee.loc ?? null,
1966
- message: null,
1967
- },
1968
- ],
1969
- suggestions: null,
1782
+ loc: optionalValue.callee.loc ?? GeneratedSource,
1783
});
1784
value = t.optionalCallExpression(
1785
optionalValue.callee,
@@ -1980,15 +1793,7 @@ function codegenInstructionValue(
1793
const property = optionalValue.property;
1794
CompilerError.invariant(t.isExpression(property), {
1795
reason: 'Private names are validated during lowering',
1983
- description: null,
1984
- details: [
1985
- {
1986
- kind: 'error',
1987
- loc: property.loc ?? null,
1988
- message: null,
1989
- },
1990
- ],
1991
- suggestions: null,
1796
+ loc: property.loc ?? GeneratedSource,
1797
});
1798
value = t.optionalMemberExpression(
1799
optionalValue.object,
@@ -2003,14 +1808,7 @@ function codegenInstructionValue(
1808
reason:
1809
'Expected an optional value to resolve to a call expression or member expression',
1810
description: `Got a \`${optionalValue.type}\``,
2006
- details: [
2007
- {
2008
- kind: 'error',
2009
- loc: instrValue.loc,
2010
- message: null,
2011
- },
2012
- ],
2013
- suggestions: null,
1811
+ loc: instrValue.loc,
1812
});
1813
}
1814
}
@@ -2026,15 +1824,8 @@ function codegenInstructionValue(
1824
{
1825
reason:
1826
'[Codegen] Internal error: MethodCall::property must be an unpromoted + unmemoized MemberExpression',
2029
- description: null,
2030
- details: [
2031
- {
2032
- kind: 'error',
2033
- loc: memberExpr.loc ?? null,
2034
- message: `Got: '${memberExpr.type}'`,
2035
- },
2036
- ],
2037
- suggestions: null,
1827
+ message: `Got: '${memberExpr.type}'`,
1828
+ loc: memberExpr.loc ?? GeneratedSource,
1829
},
1830
);
1831
CompilerError.invariant(
@@ -2046,15 +1837,7 @@ function codegenInstructionValue(
1837
reason:
1838
'[Codegen] Internal error: Forget should always generate MethodCall::property ' +
1839
'as a MemberExpression of MethodCall::receiver',
2049
- description: null,
2050
- details: [
2051
- {
2052
- kind: 'error',
2053
- loc: memberExpr.loc ?? null,
2054
- message: null,
2055
- },
2056
- ],
2057
- suggestions: null,
1840
+ loc: memberExpr.loc ?? GeneratedSource,
1841
},
1842
);
1843
const args = instrValue.args.map(arg => codegenArgument(cx, arg));
@@ -2098,15 +1881,7 @@ function codegenInstructionValue(
1881
const method = cx.objectMethods.get(property.place.identifier.id);
1882
CompilerError.invariant(method, {
1883
reason: 'Expected ObjectMethod instruction',
2101
- description: null,
2102
- details: [
2103
- {
2104
- kind: 'error',
2105
- loc: null,
2106
- message: null,
2107
- },
2108
- ],
2109
- suggestions: null,
1884
+ loc: GeneratedSource,
1885
});
1886
const loweredFunc = method.loweredFunc;
1887
const reactiveFunction = buildReactiveFunction(loweredFunc.func);
@@ -2175,15 +1950,7 @@ function codegenInstructionValue(
1950
} else {
1951
CompilerError.invariant(tagValue.type === 'StringLiteral', {
1952
reason: `Expected JSX tag to be an identifier or string, got \`${tagValue.type}\``,
2178
- description: null,
2179
- details: [
2180
- {
2181
- kind: 'error',
2182
- loc: tagValue.loc ?? null,
2183
- message: null,
2184
- },
2185
- ],
2186
- suggestions: null,
1953
+ loc: tagValue.loc ?? GeneratedSource,
1954
});
1955
if (tagValue.value.indexOf(':') >= 0) {
1956
const [namespace, name] = tagValue.value.split(':', 2);
@@ -2202,16 +1969,8 @@ function codegenInstructionValue(
1969
SINGLE_CHILD_FBT_TAGS.has(tagValue.value)
1970
) {
1971
CompilerError.invariant(instrValue.children != null, {
2205
- details: [
2206
- {
2207
- kind: 'error',
2208
- loc: instrValue.loc,
2209
- message: null,
2210
- },
2211
- ],
1972
reason: 'Expected fbt element to have children',
2213
- suggestions: null,
2214
- description: null,
1973
+ loc: instrValue.loc,
1974
});
1975
children = instrValue.children.map(child =>
1976
codegenJsxFbtChildElement(cx, child),
@@ -2522,15 +2281,7 @@ function codegenInstructionValue(
2281
instrValue.lvalue.kind === InstructionKind.Reassign,
2282
{
2283
reason: `Unexpected StoreLocal in codegenInstructionValue`,
2525
- description: null,
2526
- details: [
2527
- {
2528
- kind: 'error',
2529
- loc: instrValue.loc,
2530
- message: null,
2531
- },
2532
- ],
2533
- suggestions: null,
2284
+ loc: instrValue.loc,
2285
},
2286
);
2287
value = t.assignmentExpression(
@@ -2558,15 +2309,7 @@ function codegenInstructionValue(
2309
case 'StoreContext': {
2310
CompilerError.invariant(false, {
2311
reason: `Unexpected ${instrValue.kind} in codegenInstructionValue`,
2561
- description: null,
2562
- details: [
2563
- {
2564
- kind: 'error',
2565
- loc: instrValue.loc,
2566
- message: null,
2567
- },
2568
- ],
2569
- suggestions: null,
2312
+ loc: instrValue.loc,
2313
});
2314
}
2315
default: {
@@ -2713,15 +2456,7 @@ function convertMemberExpressionToJsx(
2456
): t.JSXMemberExpression {
2457
CompilerError.invariant(expr.property.type === 'Identifier', {
2458
reason: 'Expected JSX member expression property to be a string',
2716
- description: null,
2717
- details: [
2718
- {
2719
- kind: 'error',
2720
- loc: expr.loc ?? null,
2721
- message: null,
2722
- },
2723
- ],
2724
- suggestions: null,
2459
+ loc: expr.loc ?? GeneratedSource,
2460
});
2461
const property = t.jsxIdentifier(expr.property.name);
2462
if (expr.object.type === 'Identifier') {
@@ -2730,15 +2465,7 @@ function convertMemberExpressionToJsx(
2465
CompilerError.invariant(expr.object.type === 'MemberExpression', {
2466
reason:
2467
'Expected JSX member expression to be an identifier or nested member expression',
2733
- description: null,
2734
- details: [
2735
- {
2736
- kind: 'error',
2737
- loc: expr.object.loc ?? null,
2738
- message: null,
2739
- },
2740
- ],
2741
- suggestions: null,
2468
+ loc: expr.object.loc ?? GeneratedSource,
2469
});
2470
const object = convertMemberExpressionToJsx(expr.object);
2471
return t.jsxMemberExpression(object, property);
@@ -2760,15 +2487,7 @@ function codegenObjectPropertyKey(
2487
const expr = codegenPlace(cx, key.name);
2488
CompilerError.invariant(t.isExpression(expr), {
2489
reason: 'Expected object property key to be an expression',
2763
- description: null,
2764
- details: [
2765
- {
2766
- kind: 'error',
2767
- loc: key.name.loc,
2768
- message: null,
2769
- },
2770
- ],
2771
- suggestions: null,
2490
+ loc: key.name.loc,
2491
});
2492
return expr;
2493
}
@@ -2916,14 +2635,7 @@ function codegenPlace(cx: Context, place: Place): t.Expression | t.JSXText {
2635
description: `Value for '${printPlace(
2636
place,
2637
)}' was not set in the codegen context`,
2919
- details: [
2920
- {
2921
- kind: 'error',
2922
- loc: place.loc,
2923
- message: null,
2924
- },
2925
- ],
2926
- suggestions: null,
2638
+ loc: place.loc,
2639
});
2640
const identifier = convertIdentifier(place.identifier);
2641
identifier.loc = place.loc as any;
@@ -2935,15 +2647,8 @@ function convertIdentifier(identifier: Identifier): t.Identifier {
2647
identifier.name !== null && identifier.name.kind === 'named',
2648
{
2649
reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`,
2938
- details: [
2939
- {
2940
- kind: 'error',
2941
- loc: GeneratedSource,
2942
- message: null,
2943
- },
2944
- ],
2650
description: `identifier ${identifier.id} is unnamed`,
2946
- suggestions: null,
2651
+ loc: GeneratedSource,
2652
},
2653
);
2654
return createIdentifier(identifier.loc, identifier.name.value);
@@ -2957,14 +2662,7 @@ function compareScopeDependency(
2662
a.identifier.name?.kind === 'named' && b.identifier.name?.kind === 'named',
2663
{
2664
reason: '[Codegen] Expected named identifier for dependency',
2960
- description: null,
2961
- details: [
2962
- {
2963
- kind: 'error',
2964
- loc: a.identifier.loc,
2965
- message: null,
2966
- },
2967
- ],
2665
+ loc: a.identifier.loc,
2666
},
2667
);
2668
const aName = [
@@ -2988,14 +2686,7 @@ function compareScopeDeclaration(
2686
a.identifier.name?.kind === 'named' && b.identifier.name?.kind === 'named',
2687
{
2688
reason: '[Codegen] Expected named identifier for declaration',
2991
- description: null,
2992
- details: [
2993
- {
2994
- kind: 'error',
2995
- loc: a.identifier.loc,
2996
- message: null,
2997
- },
2998
- ],
2689
+ loc: a.identifier.loc,
2690
},
2691
);
2692
const aName = a.identifier.name.value;
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/FlattenScopesWithHooksOrUseHIR.ts
+1
-7
@@ -75,13 +75,7 @@ export function flattenScopesWithHooksOrUseHIR(fn: HIRFunction): void {
75
CompilerError.invariant(terminal.kind === 'scope', {
76
reason: `Expected block to have a scope terminal`,
77
description: `Expected block bb${block.id} to end in a scope terminal`,
78
- details: [
79
- {
80
- kind: 'error',
81
- loc: terminal.loc,
82
- message: null,
83
- },
84
- ],
78
+ loc: terminal.loc,
79
});
80
const body = fn.body.blocks.get(terminal.block)!;
81
if (
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/InferReactiveScopeVariables.ts
+1
-7
@@ -162,16 +162,10 @@ export function inferReactiveScopeVariables(fn: HIRFunction): void {
162
});
163
CompilerError.invariant(false, {
164
reason: `Invalid mutable range for scope`,
165
- details: [
166
- {
167
- kind: 'error',
168
- loc: GeneratedSource,
169
- message: null,
170
- },
171
- ],
165
description: `Scope @${scope.id} has range [${scope.range.start}:${
166
scope.range.end
167
}] but the valid range is [1:${maxInstruction + 1}]`,
168
+ loc: GeneratedSource,
169
});
170
}
171
}
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/MergeReactiveScopesThatInvalidateTogether.ts
+3
-18
@@ -8,6 +8,7 @@
8
import {CompilerError} from '..';
9
import {
10
DeclarationId,
11
+ GeneratedSource,
12
InstructionId,
13
InstructionKind,
14
Place,
@@ -161,15 +162,7 @@ class Transform extends ReactiveFunctionTransform<ReactiveScopeDependencies | nu
162
CompilerError.invariant(current !== null, {
163
reason:
164
'MergeConsecutiveScopes: expected current scope to be non-null if reset()',
164
- description: null,
165
- details: [
166
- {
167
- kind: 'error',
168
- loc: null,
169
- message: null,
170
- },
171
- ],
172
- suggestions: null,
165
+ loc: GeneratedSource,
166
});
167
if (current.to > current.from + 1) {
168
merged.push(current);
@@ -383,15 +376,7 @@ class Transform extends ReactiveFunctionTransform<ReactiveScopeDependencies | nu
376
CompilerError.invariant(mergedScope.kind === 'scope', {
377
reason:
378
'MergeConsecutiveScopes: Expected scope starting index to be a scope',
386
- description: null,
387
- details: [
388
- {
389
- kind: 'error',
390
- loc: null,
391
- message: null,
392
- },
393
- ],
394
- suggestions: null,
379
+ loc: GeneratedSource,
380
});
381
nextInstructions.push(mergedScope);
382
index++;
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PrintReactiveFunction.ts
+2
-9
@@ -7,6 +7,7 @@
7
8
import {CompilerError} from '../CompilerError';
9
import {
10
+ GeneratedSource,
11
PrunedReactiveScopeBlock,
12
ReactiveFunction,
13
ReactiveScope,
@@ -322,15 +323,7 @@ function writeTerminal(writer: Writer, terminal: ReactiveTerminal): void {
323
const block = case_.block;
324
CompilerError.invariant(block != null, {
325
reason: 'Expected case to have a block',
325
- description: null,
326
- details: [
327
- {
328
- kind: 'error',
329
- loc: case_.test?.loc ?? null,
330
- message: null,
331
- },
332
- ],
333
- suggestions: null,
326
+ loc: case_.test?.loc ?? GeneratedSource,
327
});
328
writeReactiveInstructions(writer, block);
329
});
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PromoteUsedTemporaries.ts
+2
-17
@@ -290,14 +290,7 @@ class PromoteInterposedTemporaries extends ReactiveFunctionVisitor<InterState> {
290
CompilerError.invariant(lval.identifier.name != null, {
291
reason:
292
'PromoteInterposedTemporaries: Assignment targets not expected to be temporaries',
293
- description: null,
294
- details: [
295
- {
296
- kind: 'error',
297
- loc: instruction.loc,
298
- message: null,
299
- },
300
- ],
293
+ loc: instruction.loc,
294
});
295
}
296
@@ -460,15 +453,7 @@ function promoteIdentifier(identifier: Identifier, state: State): void {
453
CompilerError.invariant(identifier.name === null, {
454
reason:
455
'promoteTemporary: Expected to be called only for temporary variables',
463
- description: null,
464
- details: [
465
- {
466
- kind: 'error',
467
- loc: GeneratedSource,
468
- message: null,
469
- },
470
- ],
471
- suggestions: null,
456
+ loc: GeneratedSource,
457
});
458
if (state.tags.has(identifier.declarationId)) {
459
promoteTemporaryJsxTag(identifier);
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneHoistedContexts.ts
+1
-8
@@ -145,14 +145,7 @@ class Visitor extends ReactiveFunctionTransform<VisitorState> {
145
if (maybeHoistedFn != null) {
146
CompilerError.invariant(maybeHoistedFn.kind === 'func', {
147
reason: '[PruneHoistedContexts] Unexpected hoisted function',
148
- description: null,
149
- details: [
150
- {
151
- kind: 'error',
152
- loc: instruction.loc,
153
- message: null,
154
- },
155
- ],
148
+ loc: instruction.loc,
149
});
150
maybeHoistedFn.definition = instruction.value.lvalue.place;
151
/**
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneInitializationDependencies.ts
+1
-8
@@ -196,14 +196,7 @@ class Visitor extends ReactiveFunctionVisitor<CreateUpdate> {
196
): void {
197
CompilerError.invariant(state !== 'Create', {
198
reason: "Visiting a terminal statement with state 'Create'",
199
- description: null,
200
- details: [
201
- {
202
- kind: 'error',
203
- loc: stmt.terminal.loc,
204
- message: null,
205
- },
206
- ],
199
+ loc: stmt.terminal.loc,
200
});
201
super.visitTerminal(stmt, state);
202
}
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts
+6
-44
@@ -9,6 +9,7 @@ import {CompilerError} from '../CompilerError';
9
import {
10
DeclarationId,
11
Environment,
12
+ GeneratedSource,
13
Identifier,
14
InstructionId,
15
Pattern,
@@ -264,14 +265,7 @@ class State {
265
CompilerError.invariant(identifierNode !== undefined, {
266
reason: 'Expected identifier to be initialized',
267
description: `[${id}] operand=${printPlace(place)} for identifier declaration ${identifier}`,
267
- details: [
268
- {
269
- kind: 'error',
270
- loc: place.loc,
271
- message: null,
272
- },
273
- ],
274
- suggestions: null,
268
+ loc: place.loc,
269
});
270
identifierNode.scopes.add(scope.id);
271
}
@@ -291,15 +285,7 @@ function computeMemoizedIdentifiers(state: State): Set<DeclarationId> {
285
const node = state.identifiers.get(id);
286
CompilerError.invariant(node !== undefined, {
287
reason: `Expected a node for all identifiers, none found for \`${id}\``,
294
- description: null,
295
- details: [
296
- {
297
- kind: 'error',
298
- loc: null,
299
- message: null,
300
- },
301
- ],
302
- suggestions: null,
288
+ loc: GeneratedSource,
289
});
290
if (node.seen) {
291
return node.memoized;
@@ -339,15 +325,7 @@ function computeMemoizedIdentifiers(state: State): Set<DeclarationId> {
325
const node = state.scopes.get(id);
326
CompilerError.invariant(node !== undefined, {
327
reason: 'Expected a node for all scopes',
342
- description: null,
343
- details: [
344
- {
345
- kind: 'error',
346
- loc: null,
347
- message: null,
348
- },
349
- ],
350
- suggestions: null,
328
+ loc: GeneratedSource,
329
});
330
if (node.seen) {
331
return;
@@ -994,15 +972,7 @@ class CollectDependenciesVisitor extends ReactiveFunctionVisitor<
972
);
973
CompilerError.invariant(identifierNode !== undefined, {
974
reason: 'Expected identifier to be initialized',
997
- description: null,
998
- details: [
999
- {
1000
- kind: 'error',
1001
- loc: stmt.terminal.loc,
1002
- message: null,
1003
- },
1004
- ],
1005
- suggestions: null,
975
+ loc: stmt.terminal.loc,
976
});
977
for (const scope of scopes) {
978
identifierNode.scopes.add(scope.id);
@@ -1025,15 +995,7 @@ class CollectDependenciesVisitor extends ReactiveFunctionVisitor<
995
);
996
CompilerError.invariant(identifierNode !== undefined, {
997
reason: 'Expected identifier to be initialized',
1028
- description: null,
1029
- details: [
1030
- {
1031
- kind: 'error',
1032
- loc: reassignment.loc,
1033
- message: null,
1034
- },
1035
- ],
1036
- suggestions: null,
998
+ loc: reassignment.loc,
999
});
1000
for (const scope of scopes) {
1001
identifierNode.scopes.add(scope.id);
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/RenameVariables.ts
+2
-9
@@ -9,6 +9,7 @@ import {ProgramContext} from '..';
9
import {CompilerError} from '../CompilerError';
10
import {
11
DeclarationId,
12
+ GeneratedSource,
13
Identifier,
14
IdentifierName,
15
InstructionId,
@@ -185,15 +186,7 @@ class Scopes {
186
const last = this.#stack.pop();
187
CompilerError.invariant(last === next, {
188
reason: 'Mismatch push/pop calls',
188
- description: null,
189
- details: [
190
- {
191
- kind: 'error',
192
- loc: null,
193
- message: null,
194
- },
195
- ],
196
- suggestions: null,
189
+ loc: GeneratedSource,
190
});
191
}
192
}
compiler/packages/babel-plugin-react-compiler/src/SSA/EliminateRedundantPhi.ts
+10
-26
@@ -6,7 +6,13 @@
6
*/
7
8
import {CompilerError} from '../CompilerError';
9
-import {BlockId, HIRFunction, Identifier, Place} from '../HIR/HIR';
9
+import {
10
+ BlockId,
11
+ GeneratedSource,
12
+ HIRFunction,
13
+ Identifier,
14
+ Place,
15
+} from '../HIR/HIR';
16
import {
17
eachInstructionLValue,
18
eachInstructionOperand,
@@ -96,15 +102,7 @@ export function eliminateRedundantPhi(
102
}
103
CompilerError.invariant(same !== null, {
104
reason: 'Expected phis to be non-empty',
99
- description: null,
100
- details: [
101
- {
102
- kind: 'error',
103
- loc: null,
104
- message: null,
105
- },
106
- ],
107
- suggestions: null,
105
+ loc: GeneratedSource,
106
});
107
rewrites.set(phi.place.identifier, same);
108
block.phis.delete(phi);
@@ -155,26 +153,12 @@ export function eliminateRedundantPhi(
153
for (const phi of block.phis) {
154
CompilerError.invariant(!rewrites.has(phi.place.identifier), {
155
reason: '[EliminateRedundantPhis]: rewrite not complete',
158
- description: null,
159
- details: [
160
- {
161
- kind: 'error',
162
- loc: phi.place.loc,
163
- message: null,
164
- },
165
- ],
156
+ loc: phi.place.loc,
157
});
158
for (const [, operand] of phi.operands) {
159
CompilerError.invariant(!rewrites.has(operand.identifier), {
160
reason: '[EliminateRedundantPhis]: rewrite not complete',
170
- description: null,
171
- details: [
172
- {
173
- kind: 'error',
174
- loc: phi.place.loc,
175
- message: null,
176
- },
177
- ],
161
+ loc: phi.place.loc,
162
});
163
}
164
}
compiler/packages/babel-plugin-react-compiler/src/SSA/EnterSSA.ts
+5
-36
@@ -10,6 +10,7 @@ import {Environment} from '../HIR/Environment';
10
import {
11
BasicBlock,
12
BlockId,
13
+ GeneratedSource,
14
HIRFunction,
15
Identifier,
16
IdentifierId,
@@ -69,15 +70,7 @@ class SSABuilder {
70
state(): State {
71
CompilerError.invariant(this.#current !== null, {
72
reason: 'we need to be in a block to access state!',
72
- description: null,
73
- details: [
74
- {
75
- kind: 'error',
76
- loc: null,
77
- message: null,
78
- },
79
- ],
80
- suggestions: null,
73
+ loc: GeneratedSource,
74
});
75
return this.#states.get(this.#current)!;
76
}
@@ -258,15 +251,7 @@ function enterSSAImpl(
251
for (const [blockId, block] of func.body.blocks) {
252
CompilerError.invariant(!visitedBlocks.has(block), {
253
reason: `found a cycle! visiting bb${block.id} again`,
261
- description: null,
262
- details: [
263
- {
264
- kind: 'error',
265
- loc: null,
266
- message: null,
267
- },
268
- ],
269
- suggestions: null,
254
+ loc: GeneratedSource,
255
});
256
257
visitedBlocks.add(block);
@@ -277,15 +262,7 @@ function enterSSAImpl(
262
// NOTE: func.context should be empty for the root function
263
CompilerError.invariant(func.context.length === 0, {
264
reason: `Expected function context to be empty for outer function declarations`,
280
- description: null,
281
- details: [
282
- {
283
- kind: 'error',
284
- loc: func.loc,
285
- message: null,
286
- },
287
- ],
288
- suggestions: null,
265
+ loc: func.loc,
266
});
267
func.params = func.params.map(param => {
268
if (param.kind === 'Identifier') {
@@ -312,15 +289,7 @@ function enterSSAImpl(
289
CompilerError.invariant(entry.preds.size === 0, {
290
reason:
291
'Expected function expression entry block to have zero predecessors',
315
- description: null,
316
- details: [
317
- {
318
- kind: 'error',
319
- loc: null,
320
- message: null,
321
- },
322
- ],
323
- suggestions: null,
292
+ loc: GeneratedSource,
293
});
294
entry.preds.add(blockId);
295
builder.defineFunction(loweredFunc);
compiler/packages/babel-plugin-react-compiler/src/SSA/RewriteInstructionKindsBasedOnReassignment.ts
+9
-63
@@ -8,6 +8,7 @@
8
import {CompilerError} from '../CompilerError';
9
import {
10
DeclarationId,
11
+ GeneratedSource,
12
HIRFunction,
13
InstructionKind,
14
LValue,
@@ -59,13 +60,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
60
{
61
reason: `Expected variable not to be defined prior to declaration`,
62
description: `${printPlace(lvalue.place)} was already defined`,
62
- details: [
63
- {
64
- kind: 'error',
65
- loc: lvalue.place.loc,
66
- message: null,
67
- },
68
- ],
63
+ loc: lvalue.place.loc,
64
},
65
);
66
declarations.set(lvalue.place.identifier.declarationId, lvalue);
@@ -83,13 +78,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
78
{
79
reason: `Expected variable not to be defined prior to declaration`,
80
description: `${printPlace(lvalue.place)} was already defined`,
86
- details: [
87
- {
88
- kind: 'error',
89
- loc: lvalue.place.loc,
90
- message: null,
91
- },
92
- ],
81
+ loc: lvalue.place.loc,
82
},
83
);
84
declarations.set(lvalue.place.identifier.declarationId, lvalue);
@@ -113,14 +102,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
102
description: `other places were \`${kind}\` but '${printPlace(
103
place,
104
)}' is const`,
116
- details: [
117
- {
118
- kind: 'error',
119
- loc: place.loc,
120
- message: 'Expected consistent kind for destructuring',
121
- },
122
- ],
123
- suggestions: null,
105
+ loc: place.loc,
106
},
107
);
108
kind = InstructionKind.Const;
@@ -131,15 +113,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
113
if (declaration === undefined) {
114
CompilerError.invariant(block.kind !== 'value', {
115
reason: `TODO: Handle reassignment in a value block where the original declaration was removed by dead code elimination (DCE)`,
134
- description: null,
135
- details: [
136
- {
137
- kind: 'error',
138
- loc: place.loc,
139
- message: null,
140
- },
141
- ],
142
- suggestions: null,
116
+ loc: place.loc,
117
});
118
declarations.set(place.identifier.declarationId, lvalue);
119
CompilerError.invariant(
@@ -149,14 +123,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
123
description: `Other places were \`${kind}\` but '${printPlace(
124
place,
125
)}' is const`,
152
- details: [
153
- {
154
- kind: 'error',
155
- loc: place.loc,
156
- message: 'Expected consistent kind for destructuring',
157
- },
158
- ],
159
- suggestions: null,
126
+ loc: place.loc,
127
},
128
);
129
kind = InstructionKind.Const;
@@ -168,14 +135,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
135
description: `Other places were \`${kind}\` but '${printPlace(
136
place,
137
)}' is reassigned`,
171
- details: [
172
- {
173
- kind: 'error',
174
- loc: place.loc,
175
- message: 'Expected consistent kind for destructuring',
176
- },
177
- ],
178
- suggestions: null,
138
+ loc: place.loc,
139
},
140
);
141
kind = InstructionKind.Reassign;
@@ -185,15 +145,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
145
}
146
CompilerError.invariant(kind !== null, {
147
reason: 'Expected at least one operand',
188
- description: null,
189
- details: [
190
- {
191
- kind: 'error',
192
- loc: null,
193
- message: null,
194
- },
195
- ],
196
- suggestions: null,
148
+ loc: GeneratedSource,
149
});
150
lvalue.kind = kind;
151
break;
@@ -205,13 +157,7 @@ export function rewriteInstructionKindsBasedOnReassignment(
157
CompilerError.invariant(declaration !== undefined, {
158
reason: `Expected variable to have been defined`,
159
description: `No declaration for ${printPlace(lvalue)}`,
208
- details: [
209
- {
210
- kind: 'error',
211
- loc: lvalue.loc,
212
- message: null,
213
- },
214
- ],
160
+ loc: lvalue.loc,
161
});
162
declaration.kind = InstructionKind.Let;
163
break;
compiler/packages/babel-plugin-react-compiler/src/TypeInference/InferTypes.ts
+2
-9
@@ -10,6 +10,7 @@ import {CompilerError} from '../CompilerError';
10
import {Environment} from '../HIR';
11
import {lowerType} from '../HIR/BuildHIR';
12
import {
13
+ GeneratedSource,
14
HIRFunction,
15
Identifier,
16
IdentifierId,
@@ -659,15 +660,7 @@ class Unifier {
660
if (type.kind === 'Phi') {
661
CompilerError.invariant(type.operands.length > 0, {
662
reason: 'there should be at least one operand',
662
- description: null,
663
- details: [
664
- {
665
- kind: 'error',
666
- loc: null,
667
- message: null,
668
- },
669
- ],
670
- suggestions: null,
663
+ loc: GeneratedSource,
664
});
665
666
let candidateType: Type | null = null;
compiler/packages/babel-plugin-react-compiler/src/Utils/DisjointSet.ts
+2
-9
@@ -6,6 +6,7 @@
6
*/
7
8
import {CompilerError} from '../CompilerError';
9
+import {GeneratedSource} from '../HIR/HIR';
10
11
// Represents items which form disjoint sets.
12
export default class DisjointSet<T> {
@@ -20,15 +21,7 @@ export default class DisjointSet<T> {
21
const first = items.shift();
22
CompilerError.invariant(first != null, {
23
reason: 'Expected set to be non-empty',
23
- description: null,
24
- details: [
25
- {
26
- kind: 'error',
27
- loc: null,
28
- message: null,
29
- },
30
- ],
31
- suggestions: null,
24
+ loc: GeneratedSource,
25
});
26
/*
27
* determine an arbitrary "root" for this set: if the first
compiler/packages/babel-plugin-react-compiler/src/Utils/TestUtils.ts
+2
-8
@@ -14,6 +14,7 @@ import {
14
PluginOptions,
15
} from '../Entrypoint';
16
import {EnvironmentConfig} from '..';
17
+import {GeneratedSource} from '../HIR/HIR';
18
import {
19
EnvironmentConfigSchema,
20
PartialEnvironmentConfig,
@@ -155,14 +156,7 @@ function parseConfigPragmaEnvironmentForTest(
156
CompilerError.invariant(false, {
157
reason: 'Internal error, could not parse config from pragma string',
158
description: `${fromZodError(config.error)}`,
158
- details: [
159
- {
160
- kind: 'error',
161
- loc: null,
162
- message: null,
163
- },
164
- ],
165
- suggestions: null,
159
+ loc: GeneratedSource,
160
});
161
}
162
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateContextVariableLValues.ts
+3
-11
@@ -108,17 +108,9 @@ function visit(
108
CompilerError.invariant(false, {
109
reason:
110
'Expected all references to a variable to be consistently local or context references',
111
- description: `Identifier ${printPlace(
112
- place,
113
- )} is referenced as a ${kind} variable, but was previously referenced as a ${prev.kind} variable`,
114
- suggestions: null,
115
- details: [
116
- {
117
- kind: 'error',
118
- loc: place.loc,
119
- message: `this is ${prev.kind}`,
120
- },
121
- ],
111
+ description: `Identifier ${printPlace(place)} is referenced as a ${kind} variable, but was previously referenced as a ${prev.kind} variable`,
112
+ message: `this is ${prev.kind}`,
113
+ loc: place.loc,
114
});
115
}
116
}
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateExhaustiveDependencies.ts
+12
-11
@@ -111,7 +111,7 @@ export function validateExhaustiveDependencies(
111
dependencies: Set<InferredDependency>,
112
locals: Set<IdentifierId>,
113
): void {
114
- CompilerError.simpleInvariant(startMemo == null, {
114
+ CompilerError.invariant(startMemo == null, {
115
reason: 'Unexpected nested memo calls',
116
loc: value.loc,
117
});
@@ -124,7 +124,7 @@ export function validateExhaustiveDependencies(
124
dependencies: Set<InferredDependency>,
125
locals: Set<IdentifierId>,
126
): void {
127
- CompilerError.simpleInvariant(
127
+ CompilerError.invariant(
128
startMemo != null && startMemo.manualMemoId === value.manualMemoId,
129
{
130
reason: 'Found FinishMemoize without corresponding StartMemoize',
@@ -233,7 +233,7 @@ function validateDependencies(
233
if (a.kind === 'Global' && b.kind == 'Global') {
234
return a.binding.name.localeCompare(b.binding.name);
235
} else if (a.kind == 'Local' && b.kind == 'Local') {
236
- CompilerError.simpleInvariant(
236
+ CompilerError.invariant(
237
a.identifier.name != null &&
238
a.identifier.name.kind === 'named' &&
239
b.identifier.name != null &&
@@ -320,7 +320,7 @@ function validateDependencies(
320
}
321
continue;
322
}
323
- CompilerError.simpleInvariant(inferredDependency.kind === 'Local', {
323
+ CompilerError.invariant(inferredDependency.kind === 'Local', {
324
reason: 'Unexpected function dependency',
325
loc: inferredDependency.loc,
326
});
@@ -361,7 +361,7 @@ function validateDependencies(
361
continue;
362
}
363
if (dep.root.kind === 'NamedLocal' && dep.root.constant) {
364
- CompilerError.simpleInvariant(
364
+ CompilerError.invariant(
365
!dep.root.value.reactive && isPrimitiveType(dep.root.value.identifier),
366
{
367
reason: 'Expected constant-folded dependency to be non-reactive',
@@ -871,7 +871,7 @@ function printInferredDependency(dep: InferredDependency): string {
871
return dep.binding.name;
872
}
873
case 'Local': {
874
- CompilerError.simpleInvariant(
874
+ CompilerError.invariant(
875
dep.identifier.name != null && dep.identifier.name.kind === 'named',
876
{
877
reason: 'Expected dependencies to be named variables',
@@ -889,7 +889,7 @@ function printManualMemoDependency(dep: ManualMemoDependency): string {
889
identifierName = dep.root.identifierName;
890
} else {
891
const name = dep.root.value.identifier.name;
892
- CompilerError.simpleInvariant(name != null && name.kind === 'named', {
892
+ CompilerError.invariant(name != null && name.kind === 'named', {
893
reason: 'Expected manual dependencies to be named variables',
894
loc: dep.root.value.loc,
895
});
@@ -976,7 +976,7 @@ export function findOptionalPlaces(
976
switch (terminal.kind) {
977
case 'branch': {
978
const isOptional = queue.pop();
979
- CompilerError.simpleInvariant(isOptional !== undefined, {
979
+ CompilerError.invariant(isOptional !== undefined, {
980
reason:
981
'Expected an optional value for each optional test condition',
982
loc: terminal.test.loc,
@@ -1017,14 +1017,15 @@ export function findOptionalPlaces(
1017
break;
1018
}
1019
default: {
1020
- CompilerError.simpleInvariant(false, {
1020
+ CompilerError.invariant(false, {
1021
reason: `Unexpected terminal in optional`,
1022
+ message: `Unexpected ${terminal.kind} in optional`,
1023
loc: terminal.loc,
1024
});
1025
}
1026
}
1027
}
1027
- CompilerError.simpleInvariant(queue.length === 0, {
1028
+ CompilerError.invariant(queue.length === 0, {
1029
reason:
1030
'Expected a matching number of conditional blocks and branch points',
1031
loc: block.terminal.loc,
@@ -1091,7 +1092,7 @@ function createDiagnostic(
1092
break;
1093
}
1094
default: {
1094
- CompilerError.simpleInvariant(false, {
1095
+ CompilerError.invariant(false, {
1096
reason: `Unexpected error category: ${category}`,
1097
loc: GeneratedSource,
1098
});
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateLocalsNotReassignedAfterRender.ts
+1
-8
@@ -191,14 +191,7 @@ function getContextReassignment(
191
for (const operand of operands) {
192
CompilerError.invariant(operand.effect !== Effect.Unknown, {
193
reason: `Expected effects to be inferred prior to ValidateLocalsNotReassignedAfterRender`,
194
- description: null,
195
- details: [
196
- {
197
- kind: 'error',
198
- loc: operand.loc,
199
- message: '',
200
- },
201
- ],
194
+ loc: operand.loc,
195
});
196
const reassignment = reassigningFunctions.get(
197
operand.identifier.id,
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects.ts
+1
-8
@@ -83,14 +83,7 @@ export function validateNoDerivedComputationsInEffects(fn: HIRFunction): void {
83
const dependencies: Array<IdentifierId> = deps.elements.map(dep => {
84
CompilerError.invariant(dep.kind === 'Identifier', {
85
reason: `Dependency is checked as a place above`,
86
- description: null,
87
- details: [
88
- {
89
- kind: 'error',
90
- loc: value.loc,
91
- message: 'this is checked as a place above',
92
- },
93
- ],
86
+ loc: value.loc,
87
});
88
return locals.get(dep.identifier.id) ?? dep.identifier.id;
89
});
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts
+3
-23
@@ -244,13 +244,7 @@ export function validateNoDerivedComputationsInEffects_exp(
244
reason:
245
'[ValidateNoDerivedComputationsInEffects] Fixpoint iteration failed to converge.',
246
description: `Fixpoint iteration exceeded ${MAX_FIXPOINT_ITERATIONS} iterations while tracking derivations. This suggests a cyclic dependency in the derivation cache.`,
247
- details: [
248
- {
249
- kind: 'error',
250
- loc: fn.loc,
251
- message: `Exceeded ${MAX_FIXPOINT_ITERATIONS} iterations in ValidateNoDerivedComputationsInEffects`,
252
- },
253
- ],
247
+ loc: fn.loc,
248
});
249
} while (context.derivationCache.snapshot());
250
@@ -484,14 +478,7 @@ function recordInstructionDerivations(
478
case Effect.Unknown: {
479
CompilerError.invariant(false, {
480
reason: 'Unexpected unknown effect',
487
- description: null,
488
- details: [
489
- {
490
- kind: 'error',
491
- loc: operand.loc,
492
- message: 'Unexpected unknown effect',
493
- },
494
- ],
481
+ loc: operand.loc,
482
});
483
}
484
default: {
@@ -539,14 +526,7 @@ function buildTreeNode(
526
CompilerError.invariant(childId !== sourceId, {
527
reason:
528
'Unexpected self-reference: a value should not have itself as a source',
542
- description: null,
543
- details: [
544
- {
545
- kind: 'error',
546
- loc: sourceMetadata.place.loc,
547
- message: null,
548
- },
549
- ],
529
+ loc: sourceMetadata.place.loc,
530
});
531
532
const childNodes = buildTreeNode(
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoRefAccessInRender.ts
+7
-49
@@ -12,6 +12,7 @@ import {
12
} from '../CompilerError';
13
import {
14
BlockId,
15
+ GeneratedSource,
16
HIRFunction,
17
IdentifierId,
18
Identifier,
@@ -58,15 +59,7 @@ type RefId = number & {[opaqueRefId]: 'RefId'};
59
function makeRefId(id: number): RefId {
60
CompilerError.invariant(id >= 0 && Number.isInteger(id), {
61
reason: 'Expected identifier id to be a non-negative integer',
61
- description: null,
62
- suggestions: null,
63
- details: [
64
- {
65
- kind: 'error',
66
- loc: null,
67
- message: null,
68
- },
69
- ],
62
+ loc: GeneratedSource,
63
});
64
return id as RefId;
65
}
@@ -204,40 +197,19 @@ function tyEqual(a: RefAccessType, b: RefAccessType): boolean {
197
case 'Guard':
198
CompilerError.invariant(b.kind === 'Guard', {
199
reason: 'Expected ref value',
207
- description: null,
208
- details: [
209
- {
210
- kind: 'error',
211
- loc: null,
212
- message: null,
213
- },
214
- ],
200
+ loc: GeneratedSource,
201
});
202
return a.refId === b.refId;
203
case 'RefValue':
204
CompilerError.invariant(b.kind === 'RefValue', {
205
reason: 'Expected ref value',
220
- description: null,
221
- details: [
222
- {
223
- kind: 'error',
224
- loc: null,
225
- message: null,
226
- },
227
- ],
206
+ loc: GeneratedSource,
207
});
208
return a.loc == b.loc;
209
case 'Structure': {
210
CompilerError.invariant(b.kind === 'Structure', {
211
reason: 'Expected structure',
233
- description: null,
234
- details: [
235
- {
236
- kind: 'error',
237
- loc: null,
238
- message: null,
239
- },
240
- ],
212
+ loc: GeneratedSource,
213
});
214
const fnTypesEqual =
215
(a.fn === null && b.fn === null) ||
@@ -276,14 +248,7 @@ function joinRefAccessTypes(...types: Array<RefAccessType>): RefAccessType {
248
a.kind === 'Structure' && b.kind === 'Structure',
249
{
250
reason: 'Expected structure',
279
- description: null,
280
- details: [
281
- {
282
- kind: 'error',
283
- loc: null,
284
- message: null,
285
- },
286
- ],
251
+ loc: GeneratedSource,
252
},
253
);
254
const fn =
@@ -782,14 +747,7 @@ function validateNoRefAccessInRenderImpl(
747
748
CompilerError.invariant(!env.hasChanged(), {
749
reason: 'Ref type environment did not converge',
785
- description: null,
786
- details: [
787
- {
788
- kind: 'error',
789
- loc: null,
790
- message: null,
791
- },
792
- ],
750
+ loc: GeneratedSource,
751
});
752
753
return Ok(
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts
+1
-9
@@ -264,15 +264,7 @@ function getSetStateCall(
264
case Effect.Unknown: {
265
CompilerError.invariant(false, {
266
reason: 'Unexpected unknown effect',
267
- description: null,
268
- details: [
269
- {
270
- kind: 'error',
271
- loc: operand.loc,
272
- message: null,
273
- },
274
- ],
275
- suggestions: null,
267
+ loc: operand.loc,
268
});
269
}
270
default: {
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInRender.ts
+2
-16
@@ -102,14 +102,7 @@ function validateNoSetStateInRenderImpl(
102
case 'StartMemoize': {
103
CompilerError.invariant(activeManualMemoId === null, {
104
reason: 'Unexpected nested StartMemoize instructions',
105
- description: null,
106
- details: [
107
- {
108
- kind: 'error',
109
- loc: instr.value.loc,
110
- message: null,
111
- },
112
- ],
105
+ loc: instr.value.loc,
106
});
107
activeManualMemoId = instr.value.manualMemoId;
108
break;
@@ -120,14 +113,7 @@ function validateNoSetStateInRenderImpl(
113
{
114
reason:
115
'Expected FinishMemoize to align with previous StartMemoize instruction',
123
- description: null,
124
- details: [
125
- {
126
- kind: 'error',
127
- loc: instr.value.loc,
128
- message: null,
129
- },
130
- ],
116
+ loc: instr.value.loc,
117
},
118
);
119
activeManualMemoId = null;
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts
+3
-25
@@ -248,15 +248,7 @@ function validateInferredDep(
248
CompilerError.invariant(dep.identifier.name?.kind === 'named', {
249
reason:
250
'ValidatePreservedManualMemoization: expected scope dependency to be named',
251
- description: null,
252
- details: [
253
- {
254
- kind: 'error',
255
- loc: GeneratedSource,
256
- message: null,
257
- },
258
- ],
259
- suggestions: null,
251
+ loc: GeneratedSource,
252
});
253
normalizedDep = {
254
root: {
@@ -504,14 +496,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
496
CompilerError.invariant(state.manualMemoState == null, {
497
reason: 'Unexpected nested StartMemoize instructions',
498
description: `Bad manual memoization ids: ${state.manualMemoState?.manualMemoId}, ${value.manualMemoId}`,
507
- details: [
508
- {
509
- kind: 'error',
510
- loc: value.loc,
511
- message: null,
512
- },
513
- ],
514
- suggestions: null,
499
+ loc: value.loc,
500
});
501
502
state.manualMemoState = {
@@ -571,14 +556,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
556
{
557
reason: 'Unexpected mismatch between StartMemoize and FinishMemoize',
558
description: `Encountered StartMemoize id=${state.manualMemoState?.manualMemoId} followed by FinishMemoize id=${value.manualMemoId}`,
574
- details: [
575
- {
576
- kind: 'error',
577
- loc: value.loc,
578
- message: null,
579
- },
580
- ],
581
- suggestions: null,
559
+ loc: value.loc,
560
},
561
);
562
const reassignments = state.manualMemoState.reassignments;