Skip to content

Commit

Permalink
Version 2.19.0-388.0.dev
Browse files Browse the repository at this point in the history
Merge bdf996a into dev
  • Loading branch information
Dart CI committed Nov 10, 2022
2 parents 78743e0 + bdf996a commit 3a02210
Show file tree
Hide file tree
Showing 48 changed files with 579 additions and 166 deletions.
9 changes: 9 additions & 0 deletions pkg/analysis_server/lib/src/analytics/analytics_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ class AnalyticsManager {
}
}

/// Record that the given [command] was executed.
void executedCommand(String command) {
var requestData =
_getRequestData(Method.workspace_executeCommand.toString());
requestData.addEnumValue('command', command);
}

/// Record that the given [notification] was received and has been handled.
void handledNotificationMessage(
{required NotificationMessage notification,
Expand All @@ -111,6 +118,8 @@ class AnalyticsManager {
var options = LspInitializationOptions(params.initializationOptions);
var paramNames = <String>[
if (options.closingLabels) 'closingLabels',
if (options.completionBudgetMilliseconds != null)
'completionBudgetMilliseconds',
if (options.flutterOutline) 'flutterOutline',
if (options.onlyAnalyzeProjectsWithOpenFiles)
'onlyAnalyzeProjectsWithOpenFiles',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ExecuteCommandHandler
'${params.command} is not a valid command identifier', null);
}

server.analyticsManager.executedCommand(params.command);
final workDoneToken = params.workDoneToken;
final progress = workDoneToken != null
? ProgressReporter.clientProvided(server, workDoneToken)
Expand Down
25 changes: 25 additions & 0 deletions pkg/analysis_server/test/src/analytics/analytics_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ class AnalyticsManagerTest with ResourceProviderMixin {
]);
}

void test_server_request_workspaceExecuteCommand() {
_defaultStartup();
var params = ExecuteCommandParams(command: 'doIt');
var request = RequestMessage(
jsonrpc: '',
id: Either2.t1(1),
method: Method.workspace_executeCommand,
params: params.toJson());
manager.startedRequestMessage(request: request, startTime: _now());
manager.executedCommand('doIt');
manager.executedCommand('doIt');
manager.sentResponseMessage(
response: ResponseMessage(jsonrpc: '', id: Either2.t1(1)));
manager.shutdown();
analytics.assertEvents([
_ExpectedEvent.session(),
_ExpectedEvent.request(parameters: {
'latency': _IsPercentiles(),
'method': Method.workspace_executeCommand.toString(),
'duration': _IsPercentiles(),
'command': '{"doIt":2}'
}),
]);
}

void test_shutdownWithoutStartup() {
manager.shutdown();
analytics.assertNoEvents();
Expand Down
16 changes: 13 additions & 3 deletions pkg/dart2wasm/lib/dispatch_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ class DispatchTable {
? 1
: 0;

bool calledDynamically =
// _WasmBase and its subclass methods cannot be called dynamically
final cls = member.enclosingClass;
final isWasmType = cls != null && translator.isWasmType(cls);

final calledDynamically = !isWasmType &&
translator.dynamics.maybeCalledDynamically(member, metadata);
var selector = selectorInfo.putIfAbsent(

final selector = selectorInfo.putIfAbsent(
selectorId,
() => SelectorInfo(
translator,
Expand Down Expand Up @@ -277,11 +282,16 @@ class DispatchTable {

void build() {
// Collect class/selector combinations

// Maps class IDs to selector IDs of the class
List<List<int>> selectorsInClass = [];

for (ClassInfo info in translator.classes) {
List<int> selectorIds = [];
ClassInfo? superInfo = info.superInfo;
if (superInfo != null) {

// _WasmBase does not inherit from Object
if (superInfo != null && info.cls != translator.wasmTypesBaseClass) {
int superId = superInfo.classId;
selectorIds = List.of(selectorsInClass[superId]);
for (int selectorId in selectorIds) {
Expand Down
138 changes: 75 additions & 63 deletions pkg/dart2wasm/lib/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import 'package:wasm_builder/wasm_builder.dart' as w;
/// This class is responsible for collecting import and export annotations.
/// It also creates Wasm functions for Dart members and manages the worklist
/// used to achieve tree shaking.
class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
class FunctionCollector {
final Translator translator;

// Wasm function for each Dart function
final Map<Reference, w.BaseFunction> _functions = {};
// Names of exported functions
final Map<Reference, String> exports = {};
final Map<Reference, String> _exports = {};
// Functions for which code has not yet been generated
final List<Reference> worklist = [];
final List<Reference> _worklist = [];
// Class IDs for classes that are allocated somewhere in the program
final Set<int> _allocatedClasses = {};
// For each class ID, which functions should be added to the worklist if an
Expand Down Expand Up @@ -53,6 +53,10 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
}
}

bool isWorkListEmpty() => _worklist.isEmpty;

Reference popWorkList() => _worklist.removeLast();

void _importOrExport(Member member) {
String? importName = translator.getPragma(member, "wasm:import");
if (importName != null) {
Expand All @@ -63,7 +67,7 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
String name = importName.substring(dot + 1);
if (member is Procedure) {
w.FunctionType ftype = _makeFunctionType(
member.reference, member.function.returnType, null,
translator, member.reference, member.function.returnType, null,
isImportOrExport: true);
_functions[member.reference] =
m.importFunction(module, name, ftype, "$importName (import)");
Expand All @@ -78,20 +82,22 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
}

void addExport(Reference target, String exportName) {
exports[target] = exportName;
_exports[target] = exportName;
}

String? getExport(Reference target) => _exports[target];

void initialize() {
// Add exports to the module and add exported functions to the worklist
for (var export in exports.entries) {
for (var export in _exports.entries) {
Reference target = export.key;
Member node = target.asMember;
if (node is Procedure) {
worklist.add(target);
_worklist.add(target);
assert(!node.isInstanceMember);
assert(!node.isGetter);
w.FunctionType ftype = _makeFunctionType(
target, node.function.returnType, null,
translator, target, node.function.returnType, null,
isImportOrExport: true);
w.DefinedFunction function = m.addFunction(ftype, "$node");
_functions[target] = function;
Expand All @@ -116,14 +122,14 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {

w.BaseFunction getFunction(Reference target) {
return _functions.putIfAbsent(target, () {
worklist.add(target);
_worklist.add(target);
if (target.isAsyncInnerReference) {
w.BaseFunction outer = getFunction(target.asProcedure.reference);
return addAsyncInnerFunctionFor(outer);
}
w.FunctionType ftype = target.isTearOffReference
? translator.dispatchTable.selectorForTarget(target).signature
: target.asMember.accept1(this, target);
: target.asMember.accept1(_FunctionTypeGenerator(translator), target);
return m.addFunction(ftype, "${target.asMember}");
});
}
Expand Down Expand Up @@ -157,6 +163,12 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
}
}
}
}

class _FunctionTypeGenerator extends MemberVisitor1<w.FunctionType, Reference> {
final Translator translator;

_FunctionTypeGenerator(this.translator);

@override
w.FunctionType defaultMember(Member node, Reference target) {
Expand All @@ -168,7 +180,7 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
if (!node.isInstanceMember) {
if (target == node.fieldReference) {
// Static field initializer function
return _makeFunctionType(target, node.type, null);
return _makeFunctionType(translator, target, node.type, null);
}
String kind = target == node.setterReference ? "setter" : "getter";
throw "No implicit $kind function for static field: $node";
Expand All @@ -181,70 +193,70 @@ class FunctionCollector extends MemberVisitor1<w.FunctionType, Reference> {
assert(!node.isAbstract);
return node.isInstanceMember
? translator.dispatchTable.selectorForTarget(node.reference).signature
: _makeFunctionType(target, node.function.returnType, null);
: _makeFunctionType(translator, target, node.function.returnType, null);
}

@override
w.FunctionType visitConstructor(Constructor node, Reference target) {
return _makeFunctionType(target, VoidType(),
return _makeFunctionType(translator, target, VoidType(),
translator.classInfo[node.enclosingClass]!.nonNullableType);
}
}

w.FunctionType _makeFunctionType(
Reference target, DartType returnType, w.ValueType? receiverType,
{bool isImportOrExport = false}) {
Member member = target.asMember;
int typeParamCount = 0;
Iterable<DartType> params;
if (member is Field) {
params = [if (target.isImplicitSetter) member.setterType];
} else {
FunctionNode function = member.function!;
typeParamCount = (member is Constructor
? member.enclosingClass.typeParameters
: function.typeParameters)
.length;
List<String> names = [for (var p in function.namedParameters) p.name!]
..sort();
Map<String, DartType> nameTypes = {
for (var p in function.namedParameters) p.name!: p.type
};
params = [
for (var p in function.positionalParameters) p.type,
for (String name in names) nameTypes[name]!
];
function.positionalParameters.map((p) => p.type);
}
w.FunctionType _makeFunctionType(Translator translator, Reference target,
DartType returnType, w.ValueType? receiverType,
{bool isImportOrExport = false}) {
Member member = target.asMember;
int typeParamCount = 0;
Iterable<DartType> params;
if (member is Field) {
params = [if (target.isImplicitSetter) member.setterType];
} else {
FunctionNode function = member.function!;
typeParamCount = (member is Constructor
? member.enclosingClass.typeParameters
: function.typeParameters)
.length;
List<String> names = [for (var p in function.namedParameters) p.name!]
..sort();
Map<String, DartType> nameTypes = {
for (var p in function.namedParameters) p.name!: p.type
};
params = [
for (var p in function.positionalParameters) p.type,
for (String name in names) nameTypes[name]!
];
function.positionalParameters.map((p) => p.type);
}

List<w.ValueType> typeParameters = List.filled(typeParamCount,
translator.classInfo[translator.typeClass]!.nonNullableType);
List<w.ValueType> typeParameters = List.filled(typeParamCount,
translator.classInfo[translator.typeClass]!.nonNullableType);

// The only reference types allowed as parameters and returns on imported
// or exported functions for JS interop are `externref` and `funcref`.
w.ValueType adjustExternalType(w.ValueType type) {
if (isImportOrExport && type is w.RefType) {
if (type.heapType.isSubtypeOf(w.HeapType.func)) {
return w.RefType.func(nullable: true);
}
return w.RefType.extern(nullable: true);
// The only reference types allowed as parameters and returns on imported or
// exported functions for JS interop are `externref` and `funcref`.
w.ValueType adjustExternalType(w.ValueType type) {
if (isImportOrExport && type is w.RefType) {
if (type.heapType.isSubtypeOf(w.HeapType.func)) {
return w.RefType.func(nullable: true);
}
return type;
return w.RefType.extern(nullable: true);
}
return type;
}

List<w.ValueType> inputs = [];
if (receiverType != null) {
inputs.add(adjustExternalType(receiverType));
}
inputs.addAll(typeParameters.map(adjustExternalType));
inputs.addAll(
params.map((t) => adjustExternalType(translator.translateType(t))));
List<w.ValueType> inputs = [];
if (receiverType != null) {
inputs.add(adjustExternalType(receiverType));
}
inputs.addAll(typeParameters.map(adjustExternalType));
inputs.addAll(
params.map((t) => adjustExternalType(translator.translateType(t))));

List<w.ValueType> outputs = returnType is VoidType
? member.function?.asyncMarker == AsyncMarker.Async
? [adjustExternalType(translator.topInfo.nullableType)]
: const []
: [adjustExternalType(translator.translateType(returnType))];
List<w.ValueType> outputs = returnType is VoidType
? member.function?.asyncMarker == AsyncMarker.Async
? [adjustExternalType(translator.topInfo.nullableType)]
: const []
: [adjustExternalType(translator.translateType(returnType))];

return m.addFunctionType(inputs, outputs);
}
return translator.m.addFunctionType(inputs, outputs);
}
4 changes: 0 additions & 4 deletions pkg/dart2wasm/lib/intrinsics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class Intrinsifier {
'unary-': (b) {
b.f64_neg();
},
'roundToDouble': (b) {
b.f64_nearest();
},
'floorToDouble': (b) {
b.f64_floor();
},
Expand All @@ -88,7 +85,6 @@ class Intrinsifier {
};
static final Map<String, w.ValueType> unaryResultMap = {
'toDouble': w.NumType.f64,
'roundToDouble': w.NumType.f64,
'floorToDouble': w.NumType.f64,
'ceilToDouble': w.NumType.f64,
'truncateToDouble': w.NumType.f64,
Expand Down
9 changes: 5 additions & 4 deletions pkg/dart2wasm/lib/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ class Translator {
m.exportFunction("\$getMain", generateGetMain(mainFunction));

functions.initialize();
while (functions.worklist.isNotEmpty) {
Reference reference = functions.worklist.removeLast();
while (!functions.isWorkListEmpty()) {
Reference reference = functions.popWorkList();
Member member = reference.asMember;
var function =
functions.getExistingFunction(reference) as w.DefinedFunction;
Expand All @@ -421,7 +421,7 @@ class Translator {
? canonicalName
: "${member.enclosingLibrary.importUri} $canonicalName";

String? exportName = functions.exports[reference];
String? exportName = functions.getExport(reference);

if (options.printKernel || options.printWasm) {
if (exportName != null) {
Expand Down Expand Up @@ -540,7 +540,8 @@ class Translator {
return false;
}

bool isWasmType(Class cls) => _hasSuperclass(cls, wasmTypesBaseClass);
bool isWasmType(Class cls) =>
cls == wasmTypesBaseClass || _hasSuperclass(cls, wasmTypesBaseClass);

bool isFfiCompound(Class cls) => _hasSuperclass(cls, ffiCompoundClass);

Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3465,6 +3465,7 @@ class BodyBuilder extends StackListenerImpl
if (pattern != null) {
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
}
}
Expand Down
Loading

0 comments on commit 3a02210

Please sign in to comment.