diff --git a/src/profile-logic/marker-data.js b/src/profile-logic/marker-data.js index 7887d3628a..3d31ed39aa 100644 --- a/src/profile-logic/marker-data.js +++ b/src/profile-logic/marker-data.js @@ -496,9 +496,9 @@ export function deriveMarkersFromRawMarkerTable( // In the case of separate markers for the start and end of an interval, // merge the payloads together, with the end data overriding the start. function mergeIntervalData( - startData: MarkerPayload, - endData: MarkerPayload - ): MarkerPayload { + startData: MarkerPayload | null, + endData: MarkerPayload | null + ): MarkerPayload | null { if (!startData && !endData) { return null; } diff --git a/src/profile-logic/process-profile.js b/src/profile-logic/process-profile.js index 53add8a524..14541240fa 100644 --- a/src/profile-logic/process-profile.js +++ b/src/profile-logic/process-profile.js @@ -661,13 +661,16 @@ function _processStackTable( * synchronous stack. Otherwise, if it happened before, it was an async stack, and is * most likely some event that happened in the past that triggered the marker. */ -function _convertStackToCause(data: any): any { +function _convertStackToCause(data: MarkerPayload_Gecko) { if ('stack' in data && data.stack && data.stack.samples.data.length > 0) { const { stack, ...newData } = data; const stackIndex = stack.samples.data[0][stack.samples.schema.stack]; const time = stack.samples.data[0][stack.samples.schema.time]; if (stackIndex !== null) { - newData.cause = { tid: stack.tid, time, stack: stackIndex }; + return { + ...newData, + cause: { tid: stack.tid, time, stack: stackIndex }, + }; } return newData; } @@ -679,7 +682,7 @@ function _convertStackToCause(data: any): any { * from a gecko payload. */ function _convertPayloadStackToIndex( - data: MarkerPayload_Gecko + data: MarkerPayload_Gecko | null ): IndexIntoStackTable | null { if (!data) { return null; @@ -714,7 +717,7 @@ function _processMarkers(geckoMarkers: GeckoMarkerStruct): {| let hasMemoryAddresses; for (let markerIndex = 0; markerIndex < geckoMarkers.length; markerIndex++) { - const geckoPayload: MarkerPayload_Gecko = geckoMarkers.data[markerIndex]; + const geckoPayload = geckoMarkers.data[markerIndex]; if (geckoPayload) { switch (geckoPayload.type) { @@ -844,8 +847,8 @@ function convertPhaseTimes( * the GC information. */ function _processMarkerPayload( - geckoPayload: MarkerPayload_Gecko -): MarkerPayload { + geckoPayload: MarkerPayload_Gecko | null +): MarkerPayload | null { if (!geckoPayload) { return null; } @@ -904,10 +907,14 @@ function _processMarkerPayload( } } default: - // Coerce the payload into a MarkerPayload. This doesn't really provide - // any more type safety, but it shows the intent of going from an object - // without much type safety, to a specific type definition. - return (payload: MarkerPayload); + // `payload` is currently typed as the result of _convertStackToCause, which + // is MarkerPayload_Gecko where `stack` has been replaced with `cause`. This + // should be reasonably close to `MarkerPayload`, but Flow doesn't work well + // with our MarkerPayload type. So we're coerce this return value to `any` + // here, and then to `MarkerPayload` as the return value for this function. + // This doesn't provide type safety but it shows the intent of going from an + // object without much type safety, to a specific type definition. + return (payload: any); } } diff --git a/src/profile-logic/profile-data.js b/src/profile-logic/profile-data.js index 992b8f0a3c..f7535ffa4a 100644 --- a/src/profile-logic/profile-data.js +++ b/src/profile-logic/profile-data.js @@ -3091,8 +3091,8 @@ export function replaceStackReferences( // Markers function replaceStackReferenceInMarkerPayload( - oldData: MarkerPayload - ): MarkerPayload { + oldData: MarkerPayload | null + ): MarkerPayload | null { if (oldData && 'cause' in oldData && oldData.cause) { // Replace the cause with the right stack index. // Use (...: any) because our current version of Flow has trouble with diff --git a/src/test/fixtures/profiles/gecko-profile.js b/src/test/fixtures/profiles/gecko-profile.js index 9d7d86bfb3..2ec9204c65 100644 --- a/src/test/fixtures/profiles/gecko-profile.js +++ b/src/test/fixtures/profiles/gecko-profile.js @@ -336,7 +336,7 @@ type TestDefinedGeckoMarker = {| +endTime: Milliseconds | null, +phase: MarkerPhase, +category?: IndexIntoCategoryList, - +data?: MarkerPayload_Gecko, + +data?: MarkerPayload_Gecko | null, |}; function _createGeckoThreadWithMarkers( diff --git a/src/test/fixtures/profiles/processed-profile.js b/src/test/fixtures/profiles/processed-profile.js index e7b046d046..a10cbddcac 100644 --- a/src/test/fixtures/profiles/processed-profile.js +++ b/src/test/fixtures/profiles/processed-profile.js @@ -75,7 +75,7 @@ export type TestDefinedMarkers = Array< MarkerName, MarkerTime, // start time MarkerTime | null, // end time - MarkerPayload | MockPayload + MarkerPayload | MockPayload | null ] >; @@ -86,7 +86,7 @@ export type TestDefinedRawMarker = {| +endTime: Milliseconds | null, +phase: MarkerPhase, +category?: IndexIntoCategoryList, - +data?: MarkerPayload, + +data?: MarkerPayload | null, |}; export type TestDefinedJsTracerEvent = [ @@ -131,7 +131,7 @@ export function addMarkersToThreadWithCorrespondingSamples( const startTime = tuple[1]; // Flow doesn't support variadic tuple types. const maybeEndTime = (tuple: any)[2] || null; - const payload: MarkerPayload = (tuple: any)[3] || null; + const payload: MarkerPayload | null = (tuple: any)[3] || null; markersTable.name.push(stringTable.indexForString(name)); if (maybeEndTime === null) { diff --git a/src/types/gecko-profile.js b/src/types/gecko-profile.js index 54337729d5..dd5b05ef2d 100644 --- a/src/types/gecko-profile.js +++ b/src/types/gecko-profile.js @@ -44,7 +44,7 @@ export type GeckoMarkerTuple = [ Milliseconds | null, MarkerPhase, IndexIntoCategoryList, - MarkerPayload_Gecko + MarkerPayload_Gecko | null ]; export type GeckoMarkers = { @@ -70,7 +70,7 @@ export type GeckoMarkerStruct = {| startTime: Milliseconds[], endTime: Milliseconds[], phase: MarkerPhase[], - data: MarkerPayload_Gecko[], + data: Array, category: IndexIntoCategoryList[], length: number, |}; diff --git a/src/types/markers.js b/src/types/markers.js index a996bd64c6..e8c2921343 100644 --- a/src/types/markers.js +++ b/src/types/markers.js @@ -766,8 +766,7 @@ export type MarkerPayload = | MediaSampleMarkerPayload | JankPayload | BrowsertimeMarkerPayload - | NoPayloadUserData - | null; + | NoPayloadUserData; export type MarkerPayload_Gecko = | GPUMarkerPayload @@ -795,6 +794,4 @@ export type MarkerPayload_Gecko = | $ReplaceCauseWithStack | $ReplaceCauseWithStack | $ReplaceCauseWithStack - | $ReplaceCauseWithStack - // Payloads can be null. - | null; + | $ReplaceCauseWithStack; diff --git a/src/types/profile-derived.js b/src/types/profile-derived.js index 2b86b325a6..d8f413437c 100644 --- a/src/types/profile-derived.js +++ b/src/types/profile-derived.js @@ -197,7 +197,7 @@ export type Marker = {| name: string, category: IndexIntoCategoryList, threadId: Tid | null, - data: MarkerPayload, + data: MarkerPayload | null, incomplete?: boolean, |}; diff --git a/src/types/profile.js b/src/types/profile.js index ff995f28fa..4638e1acc0 100644 --- a/src/types/profile.js +++ b/src/types/profile.js @@ -253,7 +253,7 @@ export type ProfilerMarkerPayload = { * it into a structured marker. */ export type RawMarkerTable = {| - data: MarkerPayload[], + data: Array, name: IndexIntoStringTable[], startTime: Array, endTime: Array,