Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 1355873003: Throw Error on unreachable code rather than a String. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/ssa/builder.dart
diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
index 068c836ceb74564cd907b764134fc9c43f7f5988..dea6da6f8cc2a35a6ed92750e30cb16b8b7fcd57 100644
--- a/pkg/compiler/lib/src/ssa/builder.dart
+++ b/pkg/compiler/lib/src/ssa/builder.dart
@@ -1632,15 +1632,9 @@ class SsaBuilder extends ast.Visitor
var emptyParameters = parameters.values.where((p) =>
p.instructionType.isEmpty && !p.instructionType.isNullable);
if (emptyParameters.length > 0) {
- String message = compiler.enableMinification
- ? 'unreachable'
- : 'unreachable: ${functionElement} because: ${emptyParameters}';
- // TODO(sra): Use a library function that throws a proper error object.
- push(new HForeignCode(
- js.js.parseForeignJS('throw "$message"'),
- backend.dynamicType,
- <HInstruction>[],
- isStatement: true));
+ addComment('${emptyParameters} inferred as [empty]');
+ pushInvokeStatic(function.body, backend.assertUnreachableMethod, []);
+ pop();
return closeFunction();
}
}
@@ -1648,6 +1642,19 @@ class SsaBuilder extends ast.Visitor
return closeFunction();
}
+ /// Adds a JavaScript comment to the output. The comment will be omitted in
+ /// minified mode. Each line in [text] is preceded with `//` and indented.
+ /// Use sparingly. In order for the comment to be retained it is modeled as
+ /// having side effects which will inhibit code motion.
+ // TODO(sra): Figure out how to keep comment anchored without effects.
+ void addComment(String text) {
+ add(new HForeignCode(
+ js.js.statementTemplateYielding(new js.Comment(text)),
+ backend.dynamicType,
+ <HInstruction>[],
+ isStatement: true));
+ }
+
HGraph buildCheckedSetter(VariableElement field) {
openFunction(field, field.node);
HInstruction thisInstruction = localsHandler.readThis();
« no previous file with comments | « pkg/compiler/lib/src/js_backend/type_variable_handler.dart ('k') | sdk/lib/_internal/js_runtime/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698