Skip to content

Commit 0cab446

Browse files
fkgozalifacebook-github-bot
authored andcommittedApr 15, 2021
iOS: Introduced RCT_NEW_ARCHITECTURE build flag to separate old vs new architecture
Summary: In order to move away from the legacy system (bridge etc), we need to decouple the new architecture assumptions from it. This flag and assertion functions will help track the runtime and report violations along the way. The goal is to have 0 violation before switching over to the pure new architecture. Note: this is not used right now. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D27783246 fbshipit-source-id: 61f0d77c129bddcde7f24a803432f2d359c5bff3
1 parent 5a2693d commit 0cab446

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
 

‎React/Base/RCTAssert.h

+8
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,11 @@ RCT_EXTERN NSString *RCTFormatStackTrace(NSArray<NSDictionary<NSString *, id> *>
169169
} while (0)
170170

171171
#endif
172+
173+
/**
174+
* Controls for ensuring the new architecture runtime assumption holds.
175+
* Note: this is work in progress.
176+
*/
177+
__attribute__((used)) RCT_EXTERN void RCTEnableNewArchitectureViolationReporting(BOOL enabled);
178+
__attribute__((used)) RCT_EXTERN BOOL RCTNewArchitectureViolationReportingEnabled(void);
179+
__attribute__((used)) RCT_EXTERN void RCTAssertAndTrackNewArchitectureViolation(NSString *violation);

‎React/Base/RCTAssert.m

+26
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,29 @@ RCTFatalExceptionHandler RCTGetFatalExceptionHandler(void)
230230
{
231231
return RCTCurrentFatalExceptionHandler;
232232
}
233+
234+
// New architecture section.
235+
static BOOL newArchitectureViolationReporting = NO;
236+
237+
void RCTEnableNewArchitectureViolationReporting(BOOL enabled)
238+
{
239+
newArchitectureViolationReporting = enabled;
240+
}
241+
242+
BOOL RCTNewArchitectureViolationReportingEnabled(void)
243+
{
244+
return newArchitectureViolationReporting;
245+
}
246+
247+
void RCTAssertAndTrackNewArchitectureViolation(NSString *violation)
248+
{
249+
if (!RCTNewArchitectureViolationReportingEnabled()) {
250+
return;
251+
}
252+
253+
#if RCT_NEW_ARCHITECTURE
254+
RCTAssert(0, @"New architecture violation assertion: %@", violation);
255+
#endif
256+
257+
// TODO: Actually track violations in a global space (separate from assertion).
258+
}

‎React/Base/RCTDefines.h

+10
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,13 @@
142142
@throw _RCTNotImplementedException(_cmd, [self class]); \
143143
} \
144144
_Pragma("clang diagnostic pop")
145+
146+
/**
147+
* Controls for activating the new architecture without the legacy system.
148+
* Note: this is work in progress.
149+
*/
150+
#ifdef REACT_NATIVE_FORCE_NEW_ARCHITECTURE
151+
#define RCT_NEW_ARCHITECTURE 1
152+
#else
153+
#define RCT_NEW_ARCHITECTURE 0
154+
#endif

0 commit comments

Comments
 (0)