Skip to content

Commit

Permalink
Version 3.0.0-225.0.dev
Browse files Browse the repository at this point in the history
Merge e1a2b10 into dev
  • Loading branch information
Dart CI committed Feb 10, 2023
2 parents 0ea2a1a + e1a2b10 commit 2840c5a
Show file tree
Hide file tree
Showing 17 changed files with 1,006 additions and 1,007 deletions.
87 changes: 73 additions & 14 deletions pkg/dev_compiler/lib/ddc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer' show Service, debugger;
import 'dart:io';
import 'dart:isolate';
import 'package:bazel_worker/bazel_worker.dart';
import 'package:kernel/ast.dart' show clearDummyTreeNodesParentPointer;

import 'src/compiler/shared_command.dart';
import 'src/kernel/command.dart';
Expand All @@ -29,7 +31,8 @@ Future internalMain(List<String> args, [SendPort? sendPort]) async {
: SendPortAsyncWorkerConnection(sendPort);
await _CompilerWorker(parsedArgs, workerConnection).run();
} else if (parsedArgs.isBatch) {
await runBatch(parsedArgs);
var batch = _BatchHelper();
await batch._runBatch(parsedArgs);
} else if (parsedArgs.isExpressionCompiler) {
await ExpressionCompilerWorker.createAndStart(parsedArgs.rest,
sendPort: sendPort);
Expand Down Expand Up @@ -77,26 +80,61 @@ class _CompilerWorker extends AsyncWorkerLoop {
}
}

/// Runs DDC in Kernel batch mode for test.dart.
Future runBatch(ParsedArguments batchArgs) async {
var totalTests = 0;
var failedTests = 0;
var watch = Stopwatch()..start();
class _BatchHelper {
Stopwatch watch = Stopwatch();
CompilerResult? result;
int totalTests = 0;
int failedTests = 0;

/// One can go into "leak test mode" by doing `export DDC_LEAK_TEST="true"`
/// on the terminal (I think `set DDC_LEAK_TEST="true"` on Windows).
/// Then one could run test.py, say
/// ```
/// python3 tools/test.py -t10000 -c dartdevk --nnbd weak -m release -r none \
/// --enable-asserts --no-use-sdk -j 1 co19/LanguageFeatures/
/// ```
/// and attach the leak tester via
/// ```
/// out/ReleaseX64/dart \
/// pkg/front_end/test/vm_service_for_leak_detection.dart --dart-leak-test
/// ```
final bool leakTesting = Platform.environment['DDC_LEAK_TEST'] == 'true';

/// Runs DDC in Kernel batch mode for test.dart.
Future _runBatch(ParsedArguments batchArgs) async {
_workaroundForLeakingBug();
if (leakTesting) {
var services =
await Service.controlWebServer(enable: true, silenceOutput: true);
File.fromUri(Directory.systemTemp.uri.resolve('./dart_leak_test_uri'))
.writeAsStringSync(services.serverUri!.toString());
}

print('>>> BATCH START');
watch.start();

String? line;
CompilerResult? result;
print('>>> BATCH START');

String? line;
while ((line = stdin.readLineSync(encoding: utf8))?.isNotEmpty == true) {
await _doIteration(batchArgs, line!);
_iterationDone();
}

var time = watch.elapsedMilliseconds;
print('>>> BATCH END (${totalTests - failedTests})/$totalTests ${time}ms');
}

while ((line = stdin.readLineSync(encoding: utf8))?.isNotEmpty == true) {
Future<void> _doIteration(ParsedArguments batchArgs, String line) async {
totalTests++;
var args = batchArgs.merge(line!.split(RegExp(r'\s+')));
var args = batchArgs.merge(line.split(RegExp(r'\s+')));

String outcome;
try {
result = await compile(args, compilerState: result?.kernelState);
outcome = result.success ? 'PASS' : (result.crashed ? 'CRASH' : 'FAIL');
outcome = result!.success ? 'PASS' : (result!.crashed ? 'CRASH' : 'FAIL');
} catch (e, s) {
// Clear the cache. It might have been left in a weird state.
result = null;
outcome = 'CRASH';
print('Unhandled exception:');
print(e);
Expand All @@ -107,6 +145,27 @@ Future runBatch(ParsedArguments batchArgs) async {
print('>>> TEST $outcome ${watch.elapsedMilliseconds}ms');
}

var time = watch.elapsedMilliseconds;
print('>>> BATCH END (${totalTests - failedTests})/$totalTests ${time}ms');
void _iterationDone() {
if (leakTesting) {
// Dummy tree nodes can (currently) leak though the parent pointer.
// To avoid that (here) (for leak testing) we'll null them out.
clearDummyTreeNodesParentPointer();

print('Will now wait');
debugger();
}
}

/// Workaround for https://github.com/dart-lang/sdk/issues/51317.
void _workaroundForLeakingBug() {
try {
stdin.echoMode;
} catch (e) {/**/}
try {
stdout.writeln();
} catch (e) {/**/}
try {
stderr.writeln();
} catch (e) {/**/}
}
}
8 changes: 4 additions & 4 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -688,14 +688,14 @@ class BodyBuilder extends StackListenerImpl
if (node is Pattern) {
return node;
} else if (node is Generator) {
return new ExpressionPattern(node.buildSimpleRead());
return new ConstantPattern(node.buildSimpleRead());
} else if (node is Expression) {
return new ExpressionPattern(node);
return new ConstantPattern(node);
} else if (node is ProblemBuilder) {
// ignore: unused_local_variable
Expression expression =
buildProblem(node.message, node.charOffset, noLength);
return new ExpressionPattern(expression);
return new ConstantPattern(expression);
} else {
return unhandled("${node.runtimeType}", "toPattern", -1, uri);
}
Expand Down Expand Up @@ -7854,7 +7854,7 @@ class BodyBuilder extends StackListenerImpl
List<PatternGuard> patterns = new List<PatternGuard>.generate(
switchCase.expressions.length, (int index) {
return new PatternGuard(
new ExpressionPattern(switchCase.expressions[index]));
new ConstantPattern(switchCase.expressions[index]));
});
patternSwitchCase = new PatternSwitchCase(
switchCase.fileOffset,
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/kernel/exhaustiveness.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Space convertPatternToSpace(CfeExhaustivenessCache cache, Pattern pattern,
return new Space(cache.getStaticType(type), fields);
} else if (pattern is VariablePattern) {
return new Space(cache.getStaticType(pattern.variable.type));
} else if (pattern is ExpressionPattern) {
} else if (pattern is ConstantPattern) {
return convertExpressionToSpace(
cache, pattern.expression, constants, context);
}
Expand Down
Loading

0 comments on commit 2840c5a

Please sign in to comment.