Files
sdk/pkg/kernel/test/binary/can_read_platform_test.dart
T
Jens Johansen ed64348f68 [kernel] Calculate scopes for expression evaluation differently
This CL introduces an alternative way to calculate scopes for
expression evaluations. Currently the previous method is kept as well.

What this does is that it:

* Finds all nodes that match the offset and uri. (Ideally there's only
  one, but that's not always the case --- it's the case for less than
  60% of cases in the test added actually).
* Calculate the scope along the way.
* Return the scopes of all the found nodes that offset.

A test that asks for ~all file offsets in the dill files in the sdk and
compares the result with the scope the binary serialization computes is
added.
A single point can't always be found (for all dills in the sdk
only ~58.93% returns a single result), but for each query the wanted
scope is among the results returned.
For the non-outline dills in the sdk, between ~87.93% and ~94.52% of
the results are either a single result or multiple results with the
same actual scope in all of them.

Note that the test asks for ~all offsets, not just "debuggable" or
"stopable" offsets (which will likely vary depending on the vm/web
backend etc) --- likely the percentage will be higher for those points
though.

When this returns multiple results one can likely be picked by the
client based on information it has about names of variables in scope
etc.

Note that the test is rather slow, on my machine with the platforms
available there it makes 3,908,181 queries in ~3.5 minutes.
(Which corresponds to roughly 18,610 per second or under 0.06 ms per
query on average though, so it doesn't seem like a concert for actually
using it.)

Change-Id: I40b5360fcd935c70629543737e89a787de36ca16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332204
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2023-11-06 09:38:40 +00:00

67 lines
1.7 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:kernel/binary/ast_from_binary.dart';
import 'package:kernel/kernel.dart';
import 'find_sdk_dills.dart';
void main() {
List<File> dills = findSdkDills();
print("Found ${dills.length} dills!");
List<File> errors = [];
for (File dill in dills) {
if (!canRead(dill)) {
errors.add(dill);
}
}
if (errors.isEmpty) {
print("Read all OK.");
} else {
print("Errors when reading:");
for (File error in errors) {
print(error);
}
exitCode = 1;
}
}
bool canRead(File dill) {
print("Reading $dill");
List<int> bytes = dill.readAsBytesSync();
try {
Component component = new Component();
new BinaryBuilderWithMetadata(bytes).readComponent(component);
int libs = component.libraries.length;
component = new Component();
new BinaryBuilderWithMetadata(bytes).readComponentSource(component);
component = new Component();
new BinaryBuilder(bytes).readComponent(component);
if (libs != component.libraries.length) {
throw "Didn't get the same number of libraries: $libs when reading with "
"BinaryBuilderWithMetadata and ${component.libraries.length} "
"when reading with BinaryBuilder";
}
component = new Component();
new BinaryBuilder(bytes).readComponentSource(component);
return true;
} catch (e, st) {
print("Error for $dill:");
print(e);
print(st);
print("");
print("--------------------");
print("");
return false;
}
}