From 7f20f5cad69db9fb035bb5f4f0a331e9f8e88973 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Mon, 11 Mar 2024 23:35:18 -0700 Subject: [PATCH] Add a mechanism to separate internal and external default experiments Summary: This diff provides a temporary mechanism to allow different experiments to be enabled by default between internal and external builds of IGListKit. It works similarly to `IGListAssert` where a different copy of `IGListDefaultExperiments.h` is provided by BUCK when performing internal builds. For the open source copies of IGListKit, the standard system behaviour of triggering an `NSInconsistencyException` when an invalid batch transaction occurs is set. For internal builds, the `IGListExperimentThrowOnInconsistencyException` experiment is disabled, where invalid transactions are forwarded to `IGListAssert` instead. Differential Revision: D54571550 fbshipit-source-id: c6c339de20c24eb487846b6567d6c8bc08bc20f2 --- IGListKit.xcodeproj/project.pbxproj | 6 ++++++ Source/IGListKit/IGListAdapter.m | 5 ++++- Source/IGListKit/IGListAdapterUpdater.m | 2 ++ .../Internal/IGListDefaultExperiments.h | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Source/IGListKit/Internal/IGListDefaultExperiments.h diff --git a/IGListKit.xcodeproj/project.pbxproj b/IGListKit.xcodeproj/project.pbxproj index b8f24d66a..4e82b5257 100644 --- a/IGListKit.xcodeproj/project.pbxproj +++ b/IGListKit.xcodeproj/project.pbxproj @@ -420,6 +420,8 @@ E8D312E01FC472A60009FA2F /* IGListContentInsetTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D312DF1FC472A60009FA2F /* IGListContentInsetTests.m */; }; F102DBBB2ACE4CD500394DB7 /* IGListArrayUtilsInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = F102DBBA2ACE4CD500394DB7 /* IGListArrayUtilsInternal.m */; }; F102DBBC2ACE4CD500394DB7 /* IGListArrayUtilsInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = F102DBBA2ACE4CD500394DB7 /* IGListArrayUtilsInternal.m */; }; + F10C8F572B982EE6009F4690 /* IGListDefaultExperiments.h in Headers */ = {isa = PBXBuildFile; fileRef = F10C8F562B982DFD009F4690 /* IGListDefaultExperiments.h */; }; + F10C8F582B982EE7009F4690 /* IGListDefaultExperiments.h in Headers */ = {isa = PBXBuildFile; fileRef = F10C8F562B982DFD009F4690 /* IGListDefaultExperiments.h */; }; F10C8F5B2B9830F0009F4690 /* IGListTestCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F10C8F592B9830E6009F4690 /* IGListTestCollectionViewLayout.m */; }; F10C8F5C2B9830F1009F4690 /* IGListTestCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F10C8F592B9830E6009F4690 /* IGListTestCollectionViewLayout.m */; }; F1855A4C29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */; }; @@ -753,6 +755,7 @@ E56B7B3320A9D7100071010C /* IGListCollectionScrollingTraitsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListCollectionScrollingTraitsTests.m; sourceTree = ""; }; E8D312DF1FC472A60009FA2F /* IGListContentInsetTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListContentInsetTests.m; sourceTree = ""; }; F102DBBA2ACE4CD500394DB7 /* IGListArrayUtilsInternal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListArrayUtilsInternal.m; sourceTree = ""; }; + F10C8F562B982DFD009F4690 /* IGListDefaultExperiments.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IGListDefaultExperiments.h; sourceTree = ""; }; F10C8F592B9830E6009F4690 /* IGListTestCollectionViewLayout.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListTestCollectionViewLayout.m; sourceTree = ""; }; F10C8F5A2B9830E6009F4690 /* IGListTestCollectionViewLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IGListTestCollectionViewLayout.h; sourceTree = ""; }; F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListDiffDescriptionStringTests.m; sourceTree = ""; }; @@ -967,6 +970,7 @@ 7A02CF892361513500B49FAE /* IGListDebugger.m */, 7A02CF832361513500B49FAE /* IGListDebuggingUtilities.h */, 7A02CF8B2361513500B49FAE /* IGListDebuggingUtilities.m */, + F10C8F562B982DFD009F4690 /* IGListDefaultExperiments.h */, 7A02CF642361513300B49FAE /* IGListDisplayHandler.h */, 7A02CF802361513500B49FAE /* IGListDisplayHandler.m */, 57B22E7C2502AAC40055DC2F /* IGListItemUpdatesCollector.h */, @@ -1339,6 +1343,7 @@ 7A02CFA92361513600B49FAE /* UICollectionViewLayout+InteractiveReordering.h in Headers */, E03DEA83255C9AAC00ACCAFC /* IGListTransitionData.h in Headers */, 0A89290026CDA632003FABD8 /* IGListBatchUpdateTransaction.h in Headers */, + F10C8F582B982EE7009F4690 /* IGListDefaultExperiments.h in Headers */, 0A8928FB26CDA591003FABD8 /* IGListReloadTransaction.h in Headers */, 0A8928FA26CDA53B003FABD8 /* IGListUpdateTransactionBuilder.h in Headers */, 0A8928FE26CDA5EA003FABD8 /* IGListDataSourceChangeTransaction.h in Headers */, @@ -1410,6 +1415,7 @@ 7A02CF452361511100B49FAE /* IGListAdapterPerformanceDelegate.h in Headers */, 7A02D0022361513600B49FAE /* IGListSectionControllerInternal.h in Headers */, 7A02CFC92361513600B49FAE /* UICollectionView+IGListBatchUpdateData.h in Headers */, + F10C8F572B982EE6009F4690 /* IGListDefaultExperiments.h in Headers */, 7A02CEF12361511100B49FAE /* IGListScrollDelegate.h in Headers */, 7A02CFF62361513600B49FAE /* IGListSectionMap+DebugDescription.h in Headers */, F18CC76A29EFBD0300DC3B9A /* IGListBindingSingleSectionController.h in Headers */, diff --git a/Source/IGListKit/IGListAdapter.m b/Source/IGListKit/IGListAdapter.m index 2761206dd..70686a98e 100644 --- a/Source/IGListKit/IGListAdapter.m +++ b/Source/IGListKit/IGListAdapter.m @@ -13,11 +13,12 @@ #import #endif #import "IGListAdapterUpdater.h" -#import "IGListSupplementaryViewSource.h" #import "IGListArrayUtilsInternal.h" #import "IGListDebugger.h" +#import "IGListDefaultExperiments.h" #import "IGListSectionControllerInternal.h" +#import "IGListSupplementaryViewSource.h" #import "IGListTransitionData.h" #import "IGListUpdatingDelegate.h" #import "UICollectionViewLayout+InteractiveReordering.h" @@ -64,6 +65,8 @@ - (instancetype)initWithUpdater:(id )updater _updater = updater; _viewController = viewController; + _experiments = IGListDefaultExperiments(); + [IGListDebugger trackAdapter:self]; } return self; diff --git a/Source/IGListKit/IGListAdapterUpdater.m b/Source/IGListKit/IGListAdapterUpdater.m index 69e7367d4..54235c25e 100644 --- a/Source/IGListKit/IGListAdapterUpdater.m +++ b/Source/IGListKit/IGListAdapterUpdater.m @@ -14,6 +14,7 @@ #endif #import "IGListAdapterUpdaterHelpers.h" +#import "IGListDefaultExperiments.h" #import "IGListIndexSetResultInternal.h" #import "IGListMoveIndexPathInternal.h" #import "IGListReloadIndexPath.h" @@ -37,6 +38,7 @@ - (instancetype)init { if (self = [super init]) { _transactionBuilder = [IGListUpdateTransactionBuilder new]; _allowsReloadingOnTooManyUpdates = YES; + _experiments = IGListDefaultExperiments(); } return self; } diff --git a/Source/IGListKit/Internal/IGListDefaultExperiments.h b/Source/IGListKit/Internal/IGListDefaultExperiments.h new file mode 100644 index 000000000..bce6cf5f2 --- /dev/null +++ b/Source/IGListKit/Internal/IGListDefaultExperiments.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#if __has_include() +#import +#else +#import "IGListExperiments.h" +#endif + +/// Provides a list of experiments that are enabled by default in IGListKit. +static inline IGListExperiment IGListDefaultExperiments(void) { + return IGListExperimentThrowOnInconsistencyException; +}