Skip to content
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

Roll buildroot to pick up disable NSAsserts in release builds #53005

Closed
wants to merge 2 commits into from

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented May 23, 2024

Roll flutter/buildroot#860 "Disable NSAsserts in release builds"

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman jmagman changed the title Roll buildroot Roll buildroot to pick up disable NSAsserts in release builds May 23, 2024
bc-lee added a commit to bc-lee/flutter-engine that referenced this pull request May 26, 2024
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.
@zanderso
Copy link
Member

From PR review triage: If it's not possible to roll a buildroot change into the engine as a fast follow-on, then the best practice would be to revert the buildroot change in case other changes to the buildroot need to be rolled in.

auto-submit bot pushed a commit that referenced this pull request May 30, 2024
…53048)

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 like `assert` or `NSAssert` does. For example, the following code will be expanded like this:
code:
```c++
FML_DCHECK(status == kCVReturnSuccess && pxbuffer != nullptr) <<
   "Failed to create pixel buffer";
```
expanded code:
```c++
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:
```c++
NSAssert(status == kCVReturnSuccess && pxbuffer != NULL, @"Failed to create pixel buffer.");
```

expanded code:
```c++
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.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
@jmagman
Copy link
Member Author

jmagman commented May 30, 2024

Roger, will do that next time.
#53048 just merged so I'll merge on top. If it still doesn't work I'll revert the buildroot PR.

@jmagman
Copy link
Member Author

jmagman commented May 30, 2024

 ❌ Failures for clang-tidy on /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm:
 /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm:140:38: error: Dictionary value cannot be nil [clang-analyzer-osx.cocoa.NilArg,-warnings-as-errors]
   140 |   NSMutableDictionary* keyMessage = [@{
       |                                      ^
   141 |     @"keymap" : @"macos",
   142 |     @"type" : type,
       |               ~~~~
 /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm:114:3: note: 'type' initialized to nil
   114 |   NSString* type;
       |   ^~~~~~~~~~~~~~
 /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm:115:3: note: Control jumps to the 'default' case at line 134
   115 |   switch (event.type) {
       |   ^
 /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm:135:7: note: Loop condition is false.  Exiting loop
   135 |       NSAssert(false, @"Unexpected key event type (got %lu).", event.type);
       |       ^
 ../../../flutter/prebuilts/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSException.h:134:40: note: expanded from macro 'NSAssert'
   134 | #define NSAssert(condition, desc, ...) do {} while (0)
       |                                        ^
 /Volumes/Work/s/w/ir/cache/builder/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterChannelKeyResponder.mm:140:38: note: Dictionary value cannot be nil
   140 |   NSMutableDictionary* keyMessage = [@{
       |                                      ^
   141 |     @"keymap" : @"macos",
   142 |     @"type" : type,
       |               ~~~~

Still failing:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8746478531016733745/+/u/test:_test:_lint_host_debug/stdout

@jmagman
Copy link
Member Author

jmagman commented May 31, 2024

Closing for now. flutter/buildroot#864

@jmagman jmagman closed this May 31, 2024
@jmagman jmagman deleted the buildroot-roll branch May 31, 2024 22:19
auto-submit bot pushed a commit that referenced this pull request Nov 15, 2024
If we disable the NSAssert during release mode, this code will continue after NSAssert failure, which will then pass a `nil` value into a dictionary (which cannot have a nil value), hence the clang-tidy warning here #53005 (comment)

*List which issues are fixed by this PR. You must list at least one issue.*
flutter/flutter#148279
flutter/flutter#157837

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…6588)

If we disable the NSAssert during release mode, this code will continue after NSAssert failure, which will then pass a `nil` value into a dictionary (which cannot have a nil value), hence the clang-tidy warning here flutter/engine#53005 (comment)

*List which issues are fixed by this PR. You must list at least one issue.*
flutter#148279
flutter#157837

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants