treeSitterManagedParserCoreAuditProbe function
Deterministic audit surface for managed-only parser value objects.
Native Tree-sitter stores these values in owned arrays, stack-version records, and parser-session structs. The Dart port uses immutable values and persistent frame links instead. This probe exercises those adaptation boundaries directly; it is not called by the parser or editor hot path.
Implementation
Map<String, Object?> treeSitterManagedParserCoreAuditProbe() {
const origin = TreeSitterTablePoint(0, 0);
const afterOne = TreeSitterTablePoint(0, 1);
const afterTwo = TreeSitterTablePoint(0, 2);
const action = TreeSitterParseAction(
type: TreeSitterParseActionType.shift,
state: 7,
symbol: 11,
childCount: 0,
dynamicPrecedence: 0,
productionId: 0,
extra: false,
extraChain: false,
repetition: false,
);
const token = TreeSitterTableToken(
symbol: 11,
startByte: 0,
endByte: 1,
startPoint: origin,
endPoint: afterOne,
text: 'x',
);
final leaf = GeneratedTreeSitterNode(
symbol: 11,
type: 'identifier',
startByte: 0,
endByte: 1,
startPoint: origin,
endPoint: afterOne,
named: true,
visible: true,
extra: false,
parseState: 3,
);
final suppliedChildren = <GeneratedTreeSitterNode>[leaf];
final suppliedFields = <GeneratedTreeSitterField>[
const GeneratedTreeSitterField('name', inherited: false),
];
final suppliedProductionFields = <GeneratedTreeSitterProductionField>[
const GeneratedTreeSitterProductionField(
name: 'name',
childIndex: 0,
inherited: false,
),
];
final parent = GeneratedTreeSitterNode(
symbol: 12,
structuralSymbol: 13,
type: 'declaration',
startByte: 0,
endByte: 1,
startPoint: origin,
endPoint: afterOne,
named: true,
visible: true,
extra: false,
children: suppliedChildren,
fields: suppliedFields,
productionFields: suppliedProductionFields,
);
suppliedChildren.clear();
suppliedFields.clear();
suppliedProductionFields.clear();
final changedRanges = <GeneratedTreeSitterChangedRange>[
const GeneratedTreeSitterChangedRange(
startByte: 1,
endByte: 2,
startPoint: afterOne,
endPoint: afterTwo,
),
];
final reuseRejections = <String, int>{'changed': 2};
final tree = GeneratedTreeSitterTree(
parent,
changedRanges: changedRanges,
reuseRejections: reuseRejections,
);
changedRanges.clear();
reuseRejections.clear();
final firstFrame = _Frame(
1,
leaf,
extra: false,
nativeOrder: 4,
scannerState: Uint8List.fromList(const <int>[1, 2]),
);
final secondFrame = _Frame(2, parent, extra: false, pending: true);
final frames = _FrameStack.of(<_Frame>[firstFrame, secondFrame]);
final sharedFrames = frames.share();
frames.add(_Frame(3, null, extra: false, errorRepeat: true));
final removedFrame = frames.removeLast();
final replacedFrames = frames.share()..[0] = secondFrame;
final truncatedFrames = frames.share()..removeRange(1, 2);
final stack = _ParseStack(
frames: frames,
position: 1,
point: afterOne,
dynamicPrecedence: 2,
errorCost: 3,
recoverySteps: 4,
recovering: true,
zeroWidthExternalTokens: <String>{'11:1'},
scannerState: Uint8List.fromList(const <int>[5, 6]),
nodeCountAtLastError: 7,
acceptedAtExplicitEnd: true,
summary: const <_StackSummaryEntry>[
_StackSummaryEntry(state: 2, position: 1, point: afterOne, depth: 0),
],
arenaHead: 9,
gssPartition: 10,
skipReuseOnce: true,
);
final stackCopy = stack.copy();
stackCopy
..scannerState[0] = 99
..frames.add(_Frame(8, null, extra: false));
final versionCopy = stack.copyVersion();
final payload = _GssHeadPayload.fromStack(stack, layer: 12, nodeCount: 13);
stack.scannerState[1] = 88;
final activeOne = stack.copy();
final activeTwo = stack.copy();
final pausedOne = stack.copy();
final pausedTwo = stack.copy();
final dispatch = _DispatchOutcome()
..emitActive(activeOne, _DispatchRole.replacement)
..emitActive(activeTwo, _DispatchRole.replacement)
..emitPaused(pausedOne, _DispatchRole.replacement)
..emitPaused(pausedTwo, _DispatchRole.appended)
..acceptedPosition = 21
..acceptedPoint = afterTwo;
final tokenCandidate = _TokenCandidate(
token,
Uint8List.fromList(const <int>[7, 8]),
lexParseState: 9,
isKeyword: true,
forcedExtra: leaf,
fallbackToken: token,
endOfNonTerminalExtra: true,
reusedNode: parent,
reusedPosition: const GeneratedTreeSitterNodePosition(
startByte: 0,
endByte: 1,
startPoint: origin,
endPoint: afterOne,
),
)..reuseConsumed = true;
final cachedCandidate = tokenCandidate.copyForCache();
tokenCandidate.scannerState[0] = 99;
final cache = _ParserTokenCache(
byteIndex: 1,
scannerStateBefore: Uint8List.fromList(const <int>[4]),
candidate: cachedCandidate,
);
final reductionProfile = _AnyTerminalReductionProfile(
reductions: const <TreeSitterParseAction>[action],
hasShiftAction: true,
);
const missingShift = _MissingShiftCandidate(symbol: 11, action: action);
const firstAncestor = _GssAncestor(1, null);
const secondAncestor = _GssAncestor(2, firstAncestor);
const reductionPath = _ReductionPath(
state: 1,
graphHead: 2,
graphRevision: 3,
symbol: 4,
childCount: 5,
productionId: 6,
previous: null,
);
final sExpressionFrame =
_GeneratedSExpressionFrame(
parent,
fieldName: 'value',
root: true,
includeAll: false,
)
..children.add('(identifier)')
..nextChild = 1
..structuralIndex = 1;
final balanceSession = _GeneratedBalanceSession(parent);
final slot = _VersionSlot(id: 17, stack: stack.copy());
final parseSession = _GeneratedParseSession(slots: <_VersionSlot>[slot])
..accepted.add(stack.copy())
..balanceSession = balanceSession;
final changedRange = tree.changedRanges.single;
final field = parent.fields.single;
final productionField = parent.productionFields.single;
final hashes = _nodeHashes(parent);
final sameParent = parent.withPositionAndChildren(
startByte: parent.startByte,
endByte: parent.endByte,
startPoint: parent.startPoint,
endPoint: parent.endPoint,
children: parent.children,
);
return Map<String, Object?>.unmodifiable(<String, Object?>{
'point.add.column': _addTablePoint(afterOne, afterTwo).column,
'point.add.newline': _addTablePoint(
afterTwo,
const TreeSitterTablePoint(1, 3),
).column,
'point.subtract.same': _subtractTablePoint(afterTwo, afterOne).column,
'point.subtract.row': _subtractTablePoint(
const TreeSitterTablePoint(2, 7),
const TreeSitterTablePoint(1, 9),
).column,
'node.collections_owned':
parent.children.length == 1 &&
parent.fields.length == 1 &&
parent.productionFields.length == 1,
'node.field': '${field.name}:${field.inherited}',
'node.production_field':
'${productionField.name}:${productionField.childIndex}:'
'${productionField.inherited}',
'node.structural_symbol': parent.structuralSymbol,
'node.walk': <String>[for (final node in parent.walk()) node.type],
'node.hashes': <int>[hashes.first, hashes.second],
'node.equivalent_copy': _nodesEquivalent(parent, sameParent),
'tree.collections_owned':
tree.changedRanges.length == 1 && tree.reuseRejections['changed'] == 2,
'range':
'${changedRange.startByte}:${changedRange.endByte}:'
'${changedRange.startPoint.column}:${changedRange.endPoint.column}',
'frame.copy_scanner': <int>[...firstFrame.scannerState],
'frame.removed_state': removedFrame.state,
'frames.shared_length': sharedFrames.length,
'frames.states': <int>[for (final frame in frames) frame.state],
'frames.replaced_states': <int>[
for (final frame in replacedFrames) frame.state,
],
'frames.truncated_states': <int>[
for (final frame in truncatedFrames) frame.state,
],
'frames.last_index_pending': frames.lastIndexWhere(
(frame) => frame.pending,
),
'frames.equivalent_shared': frames.equivalentTo(
sharedFrames,
compareShapes: true,
),
'stack.copy_scanner_isolated': stack.scannerState.first == 5,
'stack.copy_frames_isolated': stack.frames.length == 2,
'stack.copy_fields': <Object?>[
stack.position,
stack.point.column,
stack.dynamicPrecedence,
stack.errorCost,
stack.recoverySteps,
stack.recovering,
stack.nodeCountAtLastError,
stack.acceptedAtExplicitEnd,
stack.arenaHead,
stack.gssPartition,
stack.skipReuseOnce,
],
'stack.version_copy_summary_empty': versionCopy.summary.isEmpty,
'payload.snapshot': <Object?>[
payload.point.column,
payload.dynamicPrecedence,
payload.errorCost,
payload.nodeCount,
payload.recoverySteps,
payload.recovering,
payload.zeroWidthExternalTokens.single,
<int>[...payload.scannerState],
payload.layer,
],
'dispatch.active': <int>[
dispatch.replacement == activeTwo ? 1 : 0,
dispatch.appended.single == activeOne ? 1 : 0,
dispatch.activeEmissionOrder.length,
],
'dispatch.paused': <int>[
dispatch.pausedReplacement == pausedOne ? 1 : 0,
dispatch.pausedAppended.single == pausedTwo ? 1 : 0,
dispatch.pausedEmissionOrder.length,
],
'dispatch.accepted_location':
'${dispatch.acceptedPosition}:${dispatch.acceptedPoint?.column}',
'ancestor.contains': <bool>[
secondAncestor.contains(1),
secondAncestor.contains(2),
secondAncestor.contains(3),
],
'reduction_path.contains': <bool>[
reductionPath.contains(
state: 1,
graphHead: 2,
graphRevision: 3,
symbol: 4,
childCount: 5,
productionId: 6,
),
reductionPath.contains(
state: 1,
graphHead: 2,
graphRevision: 99,
symbol: 4,
childCount: 5,
productionId: 6,
),
],
'token_cache': <Object?>[
cache.byteIndex,
<int>[...cache.scannerStateBefore],
<int>[...cache.candidate.scannerState],
cache.candidate.token.symbol,
cache.candidate.lexParseState,
cache.candidate.isKeyword,
cache.candidate.forcedExtra?.symbol,
cache.candidate.fallbackToken?.symbol,
cache.candidate.endOfNonTerminalExtra,
cache.candidate.reusedNode == null,
cache.candidate.reusedPosition == null,
cache.candidate.reuseConsumed,
],
'reduction_profile': <Object?>[
reductionProfile.reductions.single.type.name,
reductionProfile.hasShiftAction,
],
'missing_shift': <Object?>[missingShift.symbol, missingShift.action.state],
's_expression_frame': <Object?>[
sExpressionFrame.node.type,
sExpressionFrame.fieldName,
sExpressionFrame.root,
sExpressionFrame.includeAll,
sExpressionFrame.children.single,
sExpressionFrame.nextChild,
sExpressionFrame.structuralIndex,
sExpressionFrame.isVisible,
],
'balance_session': <Object?>[
balanceSession.root.type,
balanceSession.pending.length,
balanceSession.transformed.length,
balanceSession.depths.length,
],
'parse_session': <Object?>[
parseSession.slots.single.id,
parseSession.accepted.length,
parseSession.balanceSession == balanceSession,
],
'parse_halted_type': const GeneratedTreeSitterParseHalted().runtimeType
.toString(),
'builtins': <int>[
_treeSitterBuiltinErrorSymbol,
_treeSitterBuiltinErrorRepeatSymbol,
],
'empty_scanner_state': _emptyScannerState.length,
'bytes_equal': <bool>[
_bytesExactlyEqual(
Uint8List.fromList(const <int>[1, 2]),
Uint8List.fromList(const <int>[1, 2]),
),
_bytesExactlyEqual(
Uint8List.fromList(const <int>[1]),
Uint8List.fromList(const <int>[2]),
),
],
'mix_hash': <int>[_mixHash(1, 2), _mixHash2(1, 2)],
});
}