Bug 1585519 - Part 2: Add MOZ_UNLIKELY to error handling code in auto-generated code. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Mon, 07 Oct 2019 05:11:19 +0000
changeset 496478 d34594143118bcfd489a5a13de958e8e24ad62ab
parent 496477 8ea58e64530bb0fc2996d7f2a922eb67d1dabe78
child 496479 e8cbe45ac45286ea9e45343e7e9c324f0af33906
push id97270
push userarai_a@mac.com
push dateMon, 07 Oct 2019 05:16:21 +0000
treeherderautoland@b7dd0f12d98b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1585519
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1585519 - Part 2: Add MOZ_UNLIKELY to error handling code in auto-generated code. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D48014
js/src/frontend/BinASTParser.cpp
js/src/frontend/binast/src/main.rs
--- a/js/src/frontend/BinASTParser.cpp
+++ b/js/src/frontend/BinASTParser.cpp
@@ -1572,17 +1572,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedBlockScope(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedBlockScope) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedBlockScope)) {
     return raiseInvalidKind("AssertedBlockScope", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceAssertedBlockScope(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -1633,17 +1633,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedBoundName(
     AssertedScopeKind scopeKind, const ListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedBoundName) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedBoundName)) {
     return raiseInvalidKind("AssertedBoundName", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result, parseInterfaceAssertedBoundName(
                                  start, kind, fields, scopeKind, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -1688,17 +1688,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedBoundNamesScope(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedBoundNamesScope) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedBoundNamesScope)) {
     return raiseInvalidKind("AssertedBoundNamesScope", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result, parseInterfaceAssertedBoundNamesScope(
                                  start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -1750,17 +1750,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedDeclaredName(
     AssertedScopeKind scopeKind, const ListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedDeclaredName) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedDeclaredName)) {
     return raiseInvalidKind("AssertedDeclaredName", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result, parseInterfaceAssertedDeclaredName(
                                  start, kind, fields, scopeKind, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -1817,17 +1817,17 @@ template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedParameterScope(
     MutableHandle<GCVector<JSAtom*>> positionalParams,
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedParameterScope) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedParameterScope)) {
     return raiseInvalidKind("AssertedParameterScope", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceAssertedParameterScope(start, kind, fields,
                                                    positionalParams, context));
   MOZ_TRY(guard.done());
 
@@ -1947,17 +1947,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedScriptGlobalScope(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedScriptGlobalScope) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedScriptGlobalScope)) {
     return raiseInvalidKind("AssertedScriptGlobalScope", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result, parseInterfaceAssertedScriptGlobalScope(
                                  start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -2008,17 +2008,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseAssertedVarScope(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::AssertedVarScope) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::AssertedVarScope)) {
     return raiseInvalidKind("AssertedVarScope", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceAssertedVarScope(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -2247,17 +2247,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<ParseNode*> BinASTParser<Tok>::parseBindingIdentifier(
     const FieldOrListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::BindingIdentifier) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::BindingIdentifier)) {
     return raiseInvalidKind("BindingIdentifier", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceBindingIdentifier(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -2302,17 +2302,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<ParseNode*> BinASTParser<Tok>::parseBlock(
     const FieldOrListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::Block) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::Block)) {
     return raiseInvalidKind("Block", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result, parseInterfaceBlock(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
 }
@@ -2448,17 +2448,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<LexicalScopeNode*> BinASTParser<Tok>::parseCatchClause(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::CatchClause) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::CatchClause)) {
     return raiseInvalidKind("CatchClause", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result,
                      parseInterfaceCatchClause(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -2777,17 +2777,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<ParseNode*> BinASTParser<Tok>::parseDirective(
     const ListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::Directive) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::Directive)) {
     return raiseInvalidKind("Directive", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result,
                      parseInterfaceDirective(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -3429,17 +3429,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<ListNode*> BinASTParser<Tok>::parseFormalParameters(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::FormalParameters) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::FormalParameters)) {
     return raiseInvalidKind("FormalParameters", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceFormalParameters(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -3488,17 +3488,17 @@ template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseFunctionExpressionContents(
     uint32_t funLength, ListNode** paramsOut, ListNode** bodyOut,
     const FieldOrRootContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::FunctionExpressionContents) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::FunctionExpressionContents)) {
     return raiseInvalidKind("FunctionExpressionContents", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceFunctionExpressionContents(
                   start, kind, fields, funLength, paramsOut, bodyOut, context));
   MOZ_TRY(guard.done());
 
@@ -3578,17 +3578,17 @@ template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseFunctionOrMethodContents(
     uint32_t funLength, ListNode** paramsOut, ListNode** bodyOut,
     const FieldOrRootContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::FunctionOrMethodContents) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::FunctionOrMethodContents)) {
     return raiseInvalidKind("FunctionOrMethodContents", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceFunctionOrMethodContents(
                   start, kind, fields, funLength, paramsOut, bodyOut, context));
   MOZ_TRY(guard.done());
 
@@ -3651,17 +3651,17 @@ template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseGetterContents(
     uint32_t funLength, ListNode** paramsOut, ListNode** bodyOut,
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::GetterContents) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::GetterContents)) {
     return raiseInvalidKind("GetterContents", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceGetterContents(start, kind, fields, funLength,
                                            paramsOut, bodyOut, context));
   MOZ_TRY(guard.done());
 
@@ -3709,17 +3709,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 template <typename Tok>
 JS::Result<ParseNode*> BinASTParser<Tok>::parseIdentifierExpression(
     const FieldOrListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::IdentifierExpression) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::IdentifierExpression)) {
     return raiseInvalidKind("IdentifierExpression", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceIdentifierExpression(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -4301,17 +4301,17 @@ template <typename Tok>
 JS::Result<Ok> BinASTParser<Tok>::parseSetterContents(
     uint32_t funLength, ListNode** paramsOut, ListNode** bodyOut,
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::SetterContents) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::SetterContents)) {
     return raiseInvalidKind("SetterContents", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceSetterContents(start, kind, fields, funLength,
                                            paramsOut, bodyOut, context));
   MOZ_TRY(guard.done());
 
@@ -4482,17 +4482,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<CaseClause*> BinASTParser<Tok>::parseSwitchCase(
     const ListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::SwitchCase) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::SwitchCase)) {
     return raiseInvalidKind("SwitchCase", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result,
                      parseInterfaceSwitchCase(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -4531,17 +4531,17 @@ JS::Result<CaseClause*> BinASTParser<Tok
 template <typename Tok>
 JS::Result<ParseNode*> BinASTParser<Tok>::parseSwitchDefault(
     const FieldContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::SwitchDefault) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::SwitchDefault)) {
     return raiseInvalidKind("SwitchDefault", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(result,
                      parseInterfaceSwitchDefault(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
@@ -4939,17 +4939,17 @@ JS::Result<ParseNode*> BinASTParser<Tok>
 template <typename Tok>
 JS::Result<ParseNode*> BinASTParser<Tok>::parseVariableDeclarator(
     const ListContext& context) {
   BinASTKind kind;
   BinASTFields fields(cx_);
   AutoTaggedTuple guard(*tokenizer_);
 
   MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-  if (kind != BinASTKind::VariableDeclarator) {
+  if (MOZ_UNLIKELY(kind != BinASTKind::VariableDeclarator)) {
     return raiseInvalidKind("VariableDeclarator", kind);
   }
   const auto start = tokenizer_->offset();
   BINJS_MOZ_TRY_DECL(
       result, parseInterfaceVariableDeclarator(start, kind, fields, context));
   MOZ_TRY(guard.done());
 
   return result;
--- a/js/src/frontend/binast/src/main.rs
+++ b/js/src/frontend/binast/src/main.rs
@@ -2255,17 +2255,17 @@ impl CPPExporter {
             content_kind =
                 self.canonical_list_parsers.get(&parser.elements).unwrap() // Each list parser has a deduplicated representative
                     .name.to_class_cases(),
             empty_check =
                 if parser.supports_empty {
                     "".to_string()
                 } else {
                     format!("
-    if (length == 0) {{
+    if (MOZ_UNLIKELY(length == 0)) {{
         return raiseEmpty(\"{kind}\");
     }}
 ",
                         kind = kind)
                 },
             call = self.get_method_call("item",
                                         &parser.elements, "", "",
                                         &extra_args,
@@ -2541,17 +2541,17 @@ impl CPPExporter {
             // Generate public method
             buffer.push_str(&format!("{first_line}
 {{
     BinASTKind kind;
     BinASTFields fields(cx_);
     AutoTaggedTuple guard(*tokenizer_);
 
     MOZ_TRY(tokenizer_->enterTaggedTuple(kind, fields, context, guard));
-    if (kind != BinASTKind::{kind}) {{
+    if (MOZ_UNLIKELY(kind != BinASTKind::{kind})) {{
         return raiseInvalidKind(\"{kind}\", kind);
     }}
     const auto start = tokenizer_->offset();
 {call}
     MOZ_TRY(guard.done());
 
     return result;
 }}