mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
[vm/bytecode] Eliminate asserts from bytecode unless --enable-asserts
Total size of a large app: Before: 23681504 After: 23207344 (-463K/-2%) Size of bytecode instructions: Before: 6282376 After: 5981716 (-4.8%) Change-Id: I57703616ecc91301c928672c83571482500dc365 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101883 Reviewed-by: Régis Crelier <regis@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
0069beb7ed
commit
477ad3c0ea
7 changed files with 50 additions and 13 deletions
|
@ -50,6 +50,7 @@ const String symbolForTypeCast = ' in type cast';
|
|||
|
||||
void generateBytecode(
|
||||
ast.Component component, {
|
||||
bool enableAsserts: true,
|
||||
bool emitSourcePositions: false,
|
||||
bool emitAnnotations: false,
|
||||
bool omitAssertSourcePositions: false,
|
||||
|
@ -75,6 +76,7 @@ void generateBytecode(
|
|||
typeEnvironment,
|
||||
constantsBackend,
|
||||
environmentDefines,
|
||||
enableAsserts,
|
||||
emitSourcePositions,
|
||||
emitAnnotations,
|
||||
omitAssertSourcePositions,
|
||||
|
@ -91,6 +93,7 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
final TypeEnvironment typeEnvironment;
|
||||
final ConstantsBackend constantsBackend;
|
||||
final Map<String, String> environmentDefines;
|
||||
final bool enableAsserts;
|
||||
final bool emitSourcePositions;
|
||||
final bool emitAnnotations;
|
||||
final bool omitAssertSourcePositions;
|
||||
|
@ -139,6 +142,7 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
this.typeEnvironment,
|
||||
this.constantsBackend,
|
||||
this.environmentDefines,
|
||||
this.enableAsserts,
|
||||
this.emitSourcePositions,
|
||||
this.emitAnnotations,
|
||||
this.omitAssertSourcePositions,
|
||||
|
@ -1124,12 +1128,8 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
functionTypeParametersSet = functionTypeParameters.toSet();
|
||||
}
|
||||
// TODO(alexmarkov): improve caching in ConstantEvaluator and reuse it
|
||||
constantEvaluator = new ConstantEvaluator(
|
||||
constantsBackend,
|
||||
environmentDefines,
|
||||
typeEnvironment,
|
||||
/* enableAsserts = */ true,
|
||||
errorReporter)
|
||||
constantEvaluator = new ConstantEvaluator(constantsBackend,
|
||||
environmentDefines, typeEnvironment, enableAsserts, errorReporter)
|
||||
..env = new EvaluationEnvironment();
|
||||
|
||||
if (node.isAbstract || node is Field && !hasInitializerCode(node)) {
|
||||
|
@ -1150,7 +1150,7 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
savedAssemblers = <BytecodeAssembler>[];
|
||||
currentLoopDepth = 0;
|
||||
|
||||
locals = new LocalVariables(node);
|
||||
locals = new LocalVariables(node, enableAsserts);
|
||||
locals.enterScope(node);
|
||||
assert(!locals.isSyncYieldingFrame);
|
||||
|
||||
|
@ -2686,6 +2686,10 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
|
||||
@override
|
||||
visitAssertStatement(AssertStatement node) {
|
||||
if (!enableAsserts) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Label done = new Label();
|
||||
asm.emitJumpIfNoAsserts(done);
|
||||
|
||||
|
@ -2715,6 +2719,10 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
|
|||
|
||||
@override
|
||||
visitAssertBlock(AssertBlock node) {
|
||||
if (!enableAsserts) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Label done = new Label();
|
||||
asm.emitJumpIfNoAsserts(done);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ class LocalVariables {
|
|||
<TreeNode, VariableDeclaration>{};
|
||||
final Map<ForInStatement, VariableDeclaration> _capturedIteratorVars =
|
||||
<ForInStatement, VariableDeclaration>{};
|
||||
final bool enableAsserts;
|
||||
|
||||
Scope _currentScope;
|
||||
Frame _currentFrame;
|
||||
|
@ -175,7 +176,7 @@ class LocalVariables {
|
|||
List<VariableDeclaration> get sortedNamedParameters =>
|
||||
_currentFrame.sortedNamedParameters;
|
||||
|
||||
LocalVariables(Member node) {
|
||||
LocalVariables(Member node, this.enableAsserts) {
|
||||
final scopeBuilder = new _ScopeBuilder(this);
|
||||
node.accept(scopeBuilder);
|
||||
|
||||
|
@ -607,8 +608,19 @@ class _ScopeBuilder extends RecursiveVisitor<Null> {
|
|||
_leaveScope();
|
||||
}
|
||||
|
||||
@override
|
||||
visitAssertStatement(AssertStatement node) {
|
||||
if (!locals.enableAsserts) {
|
||||
return;
|
||||
}
|
||||
super.visitAssertStatement(node);
|
||||
}
|
||||
|
||||
@override
|
||||
visitAssertBlock(AssertBlock node) {
|
||||
if (!locals.enableAsserts) {
|
||||
return;
|
||||
}
|
||||
_visitWithScope(node);
|
||||
}
|
||||
|
||||
|
@ -1055,8 +1067,19 @@ class _Allocator extends RecursiveVisitor<Null> {
|
|||
_leaveScope();
|
||||
}
|
||||
|
||||
@override
|
||||
visitAssertStatement(AssertStatement node) {
|
||||
if (!locals.enableAsserts) {
|
||||
return;
|
||||
}
|
||||
super.visitAssertStatement(node);
|
||||
}
|
||||
|
||||
@override
|
||||
visitAssertBlock(AssertBlock node) {
|
||||
if (!locals.enableAsserts) {
|
||||
return;
|
||||
}
|
||||
_visit(node, scope: true);
|
||||
}
|
||||
|
||||
|
|
|
@ -264,6 +264,7 @@ Future<int> runCompiler(ArgResults options, String usage) async {
|
|||
outputFileName,
|
||||
environmentDefines: environmentDefines,
|
||||
genBytecode: genBytecode,
|
||||
enableAsserts: enableAsserts,
|
||||
emitBytecodeSourcePositions: emitBytecodeSourcePositions,
|
||||
emitBytecodeAnnotations: emitBytecodeAnnotations,
|
||||
dropAST: dropAST,
|
||||
|
@ -317,6 +318,7 @@ Future<Component> compileToKernel(Uri source, CompilerOptions options,
|
|||
if (genBytecode && !errorDetector.hasCompilationErrors && component != null) {
|
||||
await runWithFrontEndCompilerContext(source, options, component, () {
|
||||
generateBytecode(component,
|
||||
enableAsserts: enableAsserts,
|
||||
emitSourcePositions: emitBytecodeSourcePositions,
|
||||
emitAnnotations: emitBytecodeAnnotations,
|
||||
useFutureBytecodeFormat: useFutureBytecodeFormat,
|
||||
|
@ -646,6 +648,7 @@ Future writeOutputSplitByPackages(
|
|||
String outputFileName, {
|
||||
Map<String, String> environmentDefines,
|
||||
bool genBytecode: false,
|
||||
bool enableAsserts: true,
|
||||
bool emitBytecodeSourcePositions: false,
|
||||
bool emitBytecodeAnnotations: false,
|
||||
bool dropAST: false,
|
||||
|
@ -707,6 +710,7 @@ Future writeOutputSplitByPackages(
|
|||
generateBytecode(component,
|
||||
libraries: libraries,
|
||||
hierarchy: hierarchy,
|
||||
enableAsserts: enableAsserts,
|
||||
emitSourcePositions: emitBytecodeSourcePositions,
|
||||
emitAnnotations: emitBytecodeAnnotations,
|
||||
useFutureBytecodeFormat: useFutureBytecodeFormat,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2018, 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.
|
||||
// VMOptions=--assert_initializer
|
||||
// VMOptions=--enable-asserts
|
||||
// dart2jsOptions=--enable-asserts
|
||||
//
|
||||
// Test of asserts in initializer lists.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2011, 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.
|
||||
// VMOptions=--enable_type_checks --enable_asserts
|
||||
// VMOptions=--enable-asserts
|
||||
// dart2jsOptions=--enable-asserts
|
||||
|
||||
// Dart test program testing assert statements.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 201, 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.
|
||||
// VMOptions=--assert_initializer
|
||||
// VMOptions=--enable-asserts
|
||||
//
|
||||
// Dart test program testing assert statements.
|
||||
|
||||
|
|
|
@ -1148,8 +1148,10 @@ abstract class VMKernelCompilerMixin {
|
|||
!arguments.any((String arg) => noCausalAsyncStacksRegExp.hasMatch(arg));
|
||||
args.add('-Ddart.developer.causal_async_stacks=$causalAsyncStacks');
|
||||
|
||||
if (_useEnableAsserts) {
|
||||
args.add('--enable_asserts');
|
||||
if (_useEnableAsserts ||
|
||||
arguments.contains('--enable-asserts') ||
|
||||
arguments.contains('--enable_asserts')) {
|
||||
args.add('--enable-asserts');
|
||||
}
|
||||
|
||||
if (_configuration.useKernelBytecode) {
|
||||
|
|
Loading…
Reference in a new issue