[cfe][InternalNodes] Separate Variable from InternalVariable

This adds an InternalLegacyVariable the doesn't derive from LegacyVariable. This fully separates InternalVariable from Variable and assigned variable tracking and flow analysis is now changed to used InternalVariable instead.

TEST=existing

Change-Id: Ida9dc78d4f0e3fab3baf7a965273e1ddf68a80b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510341
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Johnni Winther
2026-06-11 02:43:16 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 680f6e24d7
commit c390eb0931
39 changed files with 1518 additions and 526 deletions
+2 -1
View File
@@ -147,7 +147,7 @@ type CanonicalName {
type ComponentFile {
UInt32 magic = 0x90ABCDEF;
UInt32 formatVersion = 131;
UInt32 formatVersion = 132;
Byte[10] shortSdkHash;
List<String> problemsAsJson; // Described in problems.md.
Library[] libraries;
@@ -1743,6 +1743,7 @@ type AssignedVariablePattern extends Pattern {
Byte tag = 129;
FileOffset fileOffset;
VariableReference variable;
Option<VariableReference> setter;
Option<DartType> matchedType;
Byte needsCast;
}
+7 -1
View File
@@ -2237,6 +2237,10 @@ class BinaryBuilder {
variableStack.addAll(variables);
}
Variable? readVariableReferenceOption() {
return readAndCheckOptionTag() ? readVariableReference() : null;
}
Variable readVariableReference() {
readUInt30(); // offset of the variable declaration in the binary.
return _readVariableReferenceInternal();
@@ -3311,12 +3315,14 @@ class BinaryBuilder {
AssignedVariablePattern _readAssignedVariablePattern() {
int fileOffset = readOffset();
Variable variable = readVariableReference();
Variable? setter = readVariableReferenceOption();
DartType? matchedType = readDartTypeOption();
bool needsCheck = readByte() == 1;
return AssignedVariablePattern(variable)
..fileOffset = fileOffset
..matchedValueType = matchedType
..needsCast = needsCheck;
..needsCast = needsCheck
..setter = setter;
}
CastPattern _readCastPattern() {
+10
View File
@@ -2864,6 +2864,15 @@ class BinaryPrinter
writeNode(node.receiver);
}
void _writeVariableReferenceOption(Variable? variable) {
if (variable == null) {
writeByte(Tag.Nothing);
} else {
writeByte(Tag.Something);
_writeVariableReference(variable);
}
}
void _writeVariableReference(Variable variable) {
int index = _getVariableIndex(variable);
writeUInt30(variable.binaryOffsetNoTag);
@@ -2883,6 +2892,7 @@ class BinaryPrinter
writeByte(Tag.AssignedVariablePattern);
writeOffset(node.fileOffset);
_writeVariableReference(node.variable);
_writeVariableReferenceOption(node.setter);
writeOptionalNode(node.matchedValueType);
writeByte(node.needsCast ? 1 : 0);
}
+1 -1
View File
@@ -237,7 +237,7 @@ class Tag {
/// Internal version of kernel binary format.
/// Bump it when making incompatible changes in kernel binaries.
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
static const int BinaryFormatVersion = 131;
static const int BinaryFormatVersion = 132;
}
abstract class ConstantTag {
+4
View File
@@ -871,6 +871,10 @@ class WildcardPattern extends Pattern {
class AssignedVariablePattern extends Pattern {
final Variable variable;
/// If [variable] is a lowered late variable, [setter] holds the variable of
/// the local function that should be used for assignment.
Variable? setter;
/// The type of the expression against which this pattern is matched.
///
/// This is set during inference.
+11
View File
@@ -4996,6 +4996,9 @@ class EquivalenceStrategy {
if (!checkAssignedVariablePattern_variable(visitor, node, other)) {
result = visitor.resultOnInequivalence;
}
if (!checkAssignedVariablePattern_setter(visitor, node, other)) {
result = visitor.resultOnInequivalence;
}
if (!checkAssignedVariablePattern_matchedValueType(visitor, node, other)) {
result = visitor.resultOnInequivalence;
}
@@ -11972,6 +11975,14 @@ class EquivalenceStrategy {
return visitor.checkNodes(node.variable, other.variable, 'variable');
}
bool checkAssignedVariablePattern_setter(
EquivalenceVisitor visitor,
AssignedVariablePattern node,
AssignedVariablePattern other,
) {
return visitor.checkNodes(node.setter, other.setter, 'setter');
}
bool checkAssignedVariablePattern_matchedValueType(
EquivalenceVisitor visitor,
AssignedVariablePattern node,