Closed Bug 1603919 Opened 4 years ago Closed 4 years ago

Replace MOZ_FALLTHROUGH macro with C++17's [[fallthrough]] attribute in htmlparser code generator

Categories

(Core :: DOM: HTML Parser, task, P3)

task

Tracking

()

RESOLVED FIXED
mozilla73
Tracking Status
firefox73 --- fixed

People

(Reporter: cpeterson, Assigned: hsivonen)

References

Details

Attachments

(2 files, 3 obsolete files)

Bug 1570499 is replacing Mozilla's MOZ_FALLTHROUGH macro with C++17's [[fallthrough]] attribute. Some of these MOZ_FALLTHROUGH uses are in generated htmlparser code. This bug updates the htmlparser's code generator to emit [[fallthrough]] instead of MOZ_FALLTHROUGH.

Unfortunately, the MOZ_FALLTHROUGH_ASSERT macro (to assert on case fallthrough in debug builds) is still necessary after switching from MOZ_FALLTHROUGH (i.e. [[clang::fallthrough]]) to [[fallthrough]] because:

  • MOZ_ASSERT(false) followed by [[fallthrough]] triggers a -Wunreachable-code warning in DEBUG builds
  • but MOZ_ASSERT(false) without [[fallthrough]] triggers a -Wimplicit-fallthrough warning in NDEBUG builds.

Bug 1600545 removed useless #includes from many .cpp files, including some of htmlparser's generated .cpp files without updating the htmlparser code generator:

https://hg.mozilla.org/mozilla-central/rev/1f438b01c7801e7d750c4297330669621d3b7a4f

Bug 1446097 reformatted some headers and whitespace in htmlparser's generated code without updating the htmlparser code generator:

https://hg.mozilla.org/mozilla-central/rev/6af1f5ac596b4aa0a87f8a8151395c692eb81a58

Blocks: 1600545, 1446097
See Also: → 1424548

Henri, I'm not sure how to submit changes for https://hg.mozilla.org/projects/htmlparser/ via Phabricator. Here is a patch file. If you'd like me to submit the change some other way, just let me know.

Mozilla bug 1603919 - Replace MOZ_FALLTHROUGH macro with C++17's [[fallthrough]] attribute in htmlparser code generator r?hsivonen

Bug 1570499 is replacing Mozilla's MOZ_FALLTHROUGH macro with C++17's [[fallthrough]] attribute. Some of these MOZ_FALLTHROUGH uses are in generated htmlparser code. This changeset updates the htmlparser's code generator to emit [[fallthrough]] instead of MOZ_FALLTHROUGH.

Attachment #9115977 - Flags: feedback?(hsivonen)

Bug 1600545 removed useless #includes from many .cpp files, including some of htmlparser's generated .cpp files [1] without updating the htmlparser code generator. This changeset restores these #includes so mozilla-central's htmlparser code matches the output of make sync.

Ideally, the htmlparser code generator would be updated to not emit these #includes. However, I don't know where these includes are coming from because I don't see the substring nsITimer.h in the code generator's Java code.

[1] https://hg.mozilla.org/mozilla-central/rev/1f438b01c7801e7d750c4297330669621d3b7a4f

Bug 1446097 reformatted some headers and whitespace in htmlparser's generated code [1] without updating the htmlparser code generator. This changeset restores these #includes and whitespace so mozilla-central's htmlparser code matches the output of make named_characters.

Ideally, the htmlparser code generator would be updated to emit those #includes and whitespace.

[1] https://hg.mozilla.org/mozilla-central/rev/6af1f5ac596b4aa0a87f8a8151395c692eb81a58

Depends on D57231

Comment on attachment 9115977 [details] [diff] [review]
htmlparser-replace-MOZ_FALLTHROUGH-with-fallthrough.patch

Review of attachment 9115977 [details] [diff] [review]:
-----------------------------------------------------------------

This probably won't work, because `[[fallthrough]] is a syntax error in Java 5. This needs the detector to special-case the symbol `MOZ_FALLTHROUGH` to output `[[fallthrough]]`.
Attachment #9115977 - Flags: feedback?(hsivonen) → feedback-
Attached patch Translator patchSplinter Review

(Using feedback? for r?, since r? is unavailable.)

Attachment #9115977 - Attachment is obsolete: true
Attachment #9115978 - Attachment is obsolete: true
Attachment #9116363 - Flags: feedback?(cpeterson)

Let's deal with "part 2" in bug 1604456.

Attachment #9116363 - Attachment is patch: true

(In reply to Henri Sivonen (:hsivonen) from comment #5)

This probably won't work, because [[fallthrough]] is a syntax error in Java 5. This needs the detector to special-case the symbolMOZ_FALLTHROUGHto output[[fallthrough]]`.

[[fallthrough]] will be a syntax error for the Java parser even though it's still wrapped in a // CPPONLY: [[fallthrough]]; comment?

Comment on attachment 9116363 [details] [diff] [review]
Translator patch

Review of attachment 9116363 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM

::: translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java
@@ +81,4 @@
>          reservedWords.add("unicode");
>      }
>  
> +	private static final String[] TREE_BUILDER_INCLUDES = { "nsContentUtils", "nsAtom", "nsHtml5AtomTable",

I assume you verified that the generated htmlparser still compiles with mozilla-central?

I see there are references to nsITimer.h header and code in parser/html/nsHtml5StreamParser.h and .cpp. They're not generated files, but perhaps there is some accidental header dependency with the generated nsHtml5TreeBuilder files.
Attachment #9116363 - Flags: feedback?(cpeterson) → feedback+

(In reply to Chris Peterson [:cpeterson] from comment #10)

Comment on attachment 9116363 [details] [diff] [review]
Translator patch

Review of attachment 9116363 [details] [diff] [review]:

LGTM

::: translator-src/nu/validator/htmlparser/cpptranslate/CppTypes.java
@@ +81,4 @@

     reservedWords.add("unicode");
 }
  • private static final String[] TREE_BUILDER_INCLUDES = { "nsContentUtils", "nsAtom", "nsHtml5AtomTable",

I assume you verified that the generated htmlparser still compiles with
mozilla-central?

I did.

Pushed by hsivonen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0a5c779695ad
Use [[fallthrough]] instead of MOZ_FALLTHROUGH in generated HTML parser code. r=cpeterson
Assignee: cpeterson → hsivonen
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla73
Attachment #9115979 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: