Skip to content

Fix no return static analysis error in SchedulerPriorityUtils.h#47911

Closed
acoates-ms wants to merge 5 commits into
facebook:mainfrom
acoates-ms:defaultswitch
Closed

Fix no return static analysis error in SchedulerPriorityUtils.h#47911
acoates-ms wants to merge 5 commits into
facebook:mainfrom
acoates-ms:defaultswitch

Conversation

@acoates-ms
Copy link
Copy Markdown
Contributor

Summary:

In react-native-windows our static analysis tools report an error for timeoutForSchedulerPriority due to cases where it may not always return a value. This is an upstreaming of the patch we have to fix that error.

Changelog:

[INTERNAL] [FIXED] - Fix no return static analysis error in SchedulerPriorityUtils.h

Test Plan:

Building should be sufficient.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Microsoft Partner: Microsoft Partner labels Nov 22, 2024
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 22, 2024
case SchedulerPriority::IdlePriority:
return std::chrono::minutes(5);
default:
react_native_assert(false && "Unsupported SchedulerPriority value");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you place the return outside the switch/case? Otherwise this suppresses any Clang warnings for switch/case exhaustiveness if a new enum value is added.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also do LOG(FATAL) in some places which is marked as [[noreturn]], and will run in release builds, but either should be fine.

return std::chrono::seconds(10);
case SchedulerPriority::IdlePriority:
return std::chrono::minutes(5);
default:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn’t very clear here.

We build with Clang “-Wswitch-enum”, which will create a warning/error if switch case does not handle a specific enum value.

That means if we add a new SchedulerPriority, we get a build error to tell us where we need to handle the new case. Unless we have a “default”. Having a default satisfies exhaustiveness, but means that adding support for a new enum value is now a runtime error instead of a compile error.

So, we want to avoid default cases, in any switch where we want new enum values to be handled.

But we can return a value, or fatal, after the switch/case, to satisfy MSVC, and let it know that the function will either return a value, or throw/terminate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that makes sense. I didn't really think about it, and just did a search for LOG(FATAL) was used in switches elsewhere. This is the one I "copied":

LOG(FATAL) << "Unexpected CppMountItem type: " << mountItemType;

I guess that should probably also be updated to avoid the default, but I'll leave that outside the scope of this change.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

react_native_assert(false && "Unsupported SchedulerPriority value");
return SchedulerPriority::NormalPriority;
}
LOG(FATAL) << "Unknown SchedulerPriority";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically this should be [[noreturn]] (RNW Glog stub has dtor be noreturn?)

But not sure MSVC likes that I guess? https://github.com/google/glog/blob/6c5c692c8e423f651c74de9477ff0b5a59008bcc/src/striplog_unittest.cc#L53

Does RNW require the return after this?

@NickGerleman
Copy link
Copy Markdown
Contributor

iOS CI failures are from this diff. Feel free to just use react_native_assert if it's easier.

Likely missing glog dep from podspec. CocoaPods logic is a bit messy, so it might just be a missing dep, or might be more complicated.

2024-12-09T23:44:16.9459900Z › 🟠 ld/Products/Debug-iphonesimulator/React-debug -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-featureflags -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-jsc -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-jsi -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-jsiexecutor -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-jsinspector -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-logger -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-perflogger -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-performancetimeline -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-rendererconsistency -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-rendererdebug -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-runtimescheduler -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/React-utils -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/ReactCommon -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/SocketRocket -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/Yoga -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/fmt -F/Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Products/Debug-iphonesimulator/glog -filelist /Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-idlecallbacksnativemodule.build/Objects-normal/x86_64/idlecallbacksnativemodule.LinkFileList -install_name @rpath/idlecallbacksnativemodule.framework/idlecallbacksnativemodule -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-idlecallbacksnativemodule.build/Objects-normal/x86_64/idlecallbacksnativemodule_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -stdlib\=libc++ -fobjc-arc -fobjc-link-runtime -framework FBReactNativeSpec -framework JavaScriptCore -framework ReactCommon -framework React_jsc -framework React_runtimescheduler -framework folly -framework jsi -framework jsireact -framework Foundation -Xlinker -no_adhoc_codesign -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-idlecallbacksnativemodule.build/Objects-normal/x86_64/idlecallbacksnativemodule_dependency_info.dat -o /Users/runner/Library/Developer/Xcode/DerivedData/HelloWorld-czqnsntrjgyngsfxcbfgwyssconw/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-idlecallbacksnativemodule.build/Objects-normal/x86_64/Binary/idlecallbacksnativemodule
2024-12-09T23:44:16.9495510Z › 🟠 ld: Undefined symbols:
2024-12-09T23:44:16.9496350Z › 🟠   google::LogMessage::stream(), referenced from:
2024-12-09T23:44:16.9497800Z › 🟠       facebook::react::timeoutForSchedulerPriority(facebook::react::SchedulerPriority) in NativeIdleCallbacks.o
2024-12-09T23:44:16.9501100Z › 🟠   google::LogMessageFatal::LogMessageFatal(char const*, int), referenced from:
2024-12-09T23:44:16.9503320Z › 🟠       facebook::react::timeoutForSchedulerPriority(facebook::react::SchedulerPriority) in NativeIdleCallbacks.o
2024-12-09T23:44:16.9504820Z › 🟠   google::LogMessageFatal::~LogMessageFatal(), referenced from:
2024-12-09T23:44:16.9506520Z › 🟠       facebook::react::timeoutForSchedulerPriority(facebook::react::SchedulerPriority) in NativeIdleCallbacks.o
2024-12-09T23:44:16.9508320Z › 🟠 clang: error: linker command failed with exit code 1 (use -v to see invocation)

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Dec 12, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@NickGerleman merged this pull request in 849407a.

facebook-github-bot pushed a commit that referenced this pull request Dec 12, 2024
Summary:
`react_native_assert` on iOS uses glog under the hood, and #47911 added usage to a new podspec, which means new entire binary under some build modes. Need to add missing dependency I think?

Changelog: [Internal]

Pull Request resolved: #48241

Test Plan: tes_ios_helloworld passes with DynamicLibraries

Reviewed By: cipolleschi

Differential Revision: D67141052

Pulled By: NickGerleman

fbshipit-source-id: 299a499f40e9b54c4aca5d6e1c95c43ce933fb2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Microsoft Partner: Microsoft Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants