-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace several NSAssert with FML_CHECK/DCHECK to unblock the build #53048
Conversation
In flutter/buildroot#860 , disabling NSAssert in release build was added, and flutter#53005 tries to roll the change into the engine. However, the change is blocked due to several compilation errors in the engine. This is due to the fact that Google's DCHECK(in flutter engine, FML_DCHECK) does not make unused variable warning even in release build, while traditional assertion macro like assert or NSAssert does. For example, the following code will be expanded like this: code: FML_DCHECK(status == kCVReturnSuccess && pxbuffer != nullptr) << "Failed to create pixel buffer"; expanded code: true || (status == kCVReturnSuccess && pxbuffer != nullptr) ? (void)0 :: : fml::LogMessageVoidify() & ::fml::LogMessage(::fml::kLogFatal, 0, 0, nullptr).stream() However, equivalent code with NSAssert will make unused variable warning, since the expanded code doesn't have any reference to the variable: code: NSAssert(status == kCVReturnSuccess && pxbuffer != NULL, @"Failed to create pixel buffer."); expanded code: do { } while (0) To unblock the build, this CL replaces several NSAssert with FML_DCHECK in the engine codebase. This CL isn't aimed to replace all NSAssert with FML_DCHECK since discussions in flutter/buildroot#860 are not finalized whether to replace all NSAssert with FML_DCHECK or not.
NSAssert(status == kCVReturnSuccess && pxbuffer != NULL, @"Failed to create pixel buffer."); | ||
FML_DCHECK(status == kCVReturnSuccess && pxbuffer != nullptr) << "Failed to create pixel buffer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to switch this just to a FML_DCHECK
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the NSAssert
then? It sounds like we would ideally migrate them all to FML_*CHECK
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I forgot to remove that line in the last commit.
Whether to migrate all NSAssert
to FML_*CHECK
or not is up to the flutter team's decision :)
I forgot to delete the line with NSAssert in the previous commit :)
@@ -59,7 +59,7 @@ - (CVPixelBufferRef)pixelBuffer { | |||
CVPixelBufferRef pxbuffer = NULL; | |||
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, _width, _width, _pixelFormatType, | |||
(__bridge CFDictionaryRef)options, &pxbuffer); | |||
NSAssert(status == kCVReturnSuccess && pxbuffer != NULL, @"Failed to create pixel buffer."); | |||
FML_DCHECK(status == kCVReturnSuccess && pxbuffer != nullptr) << "Failed to create pixel buffer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Value stored to 'status' during its initialization is never read"
/Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm:60:12: error: Value stored to 'status' during its initialization is never read [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
60 | CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, _width, _width, _pixelFormatType,
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61 | (__bridge CFDictionaryRef)options, &pxbuffer);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hmm, why would this be happening with the FML_DCHECK
since, as you point out, it shouldn't cause unused variable warnings?
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8746648441899682977/+/u/test:_test:_lint_host_debug/stdout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'll try to run clang-tidy locally to check if there are any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another comment w.r.t. the advantages of FML_DCHECK
over NSAssert
in the context of the Flutter engine codebase. Link to the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…149367) flutter/engine@bf2e32d...4956e98 2024-05-30 yjbanov@google.com [semantics] fix dartdoc grammar (flutter/engine#53121) 2024-05-30 skia-flutter-autoroll@skia.org Roll Skia from 188ad395c3e7 to a058f601e1fb (1 revision) (flutter/engine#53131) 2024-05-30 daniel.l@hpcnt.com Replace several NSAssert with FML_CHECK/DCHECK to unblock the build (flutter/engine#53048) 2024-05-30 30870216+gaaclarke@users.noreply.github.com [Impeller] make sure buffers are 4 aligned for foreground color blending (flutter/engine#53077) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jacksongardner@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#149367) flutter/engine@bf2e32d...4956e98 2024-05-30 yjbanov@google.com [semantics] fix dartdoc grammar (flutter/engine#53121) 2024-05-30 skia-flutter-autoroll@skia.org Roll Skia from 188ad395c3e7 to a058f601e1fb (1 revision) (flutter/engine#53131) 2024-05-30 daniel.l@hpcnt.com Replace several NSAssert with FML_CHECK/DCHECK to unblock the build (flutter/engine#53048) 2024-05-30 30870216+gaaclarke@users.noreply.github.com [Impeller] make sure buffers are 4 aligned for foreground color blending (flutter/engine#53077) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jacksongardner@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
In flutter/buildroot#860, disabling
NSAssert
in release build was added, and #53005 tries to roll the change into the engine. However, the change is blocked due to several compilation errors in the engine.This is due to the fact that Google's
DCHECK
(in flutter engine,FML_DCHECK
) does not make unused variable warning even in release build, while traditional assertion macro likeassert
orNSAssert
does. For example, the following code will be expanded like this:code:
expanded code:
However, equivalent code with
NSAssert
will make unused variable warning, since the expanded code doesn't have any reference to the variable:code:
expanded code:
To unblock the build, this CL replaces several
NSAssert
withFML_DCHECK
in the engine codebase. This CL isn't aimed to replace allNSAssert
withFML_DCHECK
since discussions in flutter/buildroot#860 are not finalized whether to replace allNSAssert
withFML_DCHECK
or not.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.