Skip to content

Commit 698b341

Browse files
authored
Properly type the Map and Set objects (#5623)
I went ahead and checked if the Map or Set objects had unknown types at the time of their declaration in the language server. These are the things I found. This fixes #5617.
2 parents 6d408bd + 2ff1b40 commit 698b341

21 files changed

+106
-80
lines changed

src/actions/profile-view.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,10 @@ function _findOtherVisibleThread(
12711271
const localTracks = getLocalTracks(getState(), globalTrack.pid);
12721272
const localTrackOrder = getLocalTrackOrder(getState(), globalTrack.pid);
12731273
const hiddenLocalTracks = getHiddenLocalTracks(getState(), globalTrack.pid);
1274-
const localTrackIndexesToIgnore = localTrackIndexesToIgnoreByPid
1275-
? (localTrackIndexesToIgnoreByPid.get(globalTrack.pid) ?? new Set())
1276-
: new Set();
1274+
const localTrackIndexesToIgnore: Set<TrackIndex> =
1275+
localTrackIndexesToIgnoreByPid
1276+
? (localTrackIndexesToIgnoreByPid.get(globalTrack.pid) ?? new Set())
1277+
: new Set();
12771278

12781279
for (const trackIndex of localTrackOrder) {
12791280
const track = localTracks[trackIndex];

src/app-logic/url-handling.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function convertHiddenLocalTracksByPidFromString(
635635
return new Map();
636636
}
637637

638-
const hiddenLocalTracksByPid = new Map();
638+
const hiddenLocalTracksByPid = new Map<Pid, Set<TrackIndex>>();
639639

640640
for (const stringPart of rawText.split('~')) {
641641
if (!stringPart.includes('-')) {
@@ -679,7 +679,7 @@ function convertLocalTrackOrderByPidFromString(
679679
return new Map();
680680
}
681681

682-
const localTrackOrderByPid = new Map();
682+
const localTrackOrderByPid = new Map<Pid, TrackIndex[]>();
683683

684684
for (const stringPart of rawText.split('~')) {
685685
if (!stringPart.includes('-')) {
@@ -1018,12 +1018,10 @@ const _upgraders: {
10181018
.join('~');
10191019
}
10201020
if (query.thread) {
1021-
const selectedThreads = new Set(
1021+
const selectedThreads = new Set<number>(
10221022
query.thread.split(',').map((n: string) => +n)
10231023
);
1024-
query.thread = encodeUintSetForUrlComponent(
1025-
selectedThreads as Set<number>
1026-
);
1024+
query.thread = encodeUintSetForUrlComponent(selectedThreads);
10271025
}
10281026

10291027
// In this version, uintarray-encoding started supporting a range syntax:

src/components/shared/AssemblyView-codemirror.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function addressTimingsToLineTimings(
149149
addressTimings: AddressTimings,
150150
map: AddressToLineMap
151151
): LineTimings {
152-
const totalLineHits = new Map();
152+
const totalLineHits = new Map<LineNumber, number>();
153153
for (const [address, hitCount] of addressTimings.totalAddressHits) {
154154
const line = map.addressToLine(address);
155155
if (line !== null) {
@@ -158,7 +158,7 @@ function addressTimingsToLineTimings(
158158
}
159159
}
160160

161-
const selfLineHits = new Map();
161+
const selfLineHits = new Map<LineNumber, number>();
162162
for (const [address, hitCount] of addressTimings.selfAddressHits) {
163163
const line = map.addressToLine(address);
164164
if (line !== null) {

src/components/tooltip/GCMarker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function _filterInterestingPhaseTimes(
466466
/*
467467
* Build the tree.
468468
*/
469-
const tree = new Map();
469+
const tree = new Map<string, PhaseTreeNode>();
470470
for (const phase of phaseTimes) {
471471
const components = phase.name.split('.');
472472
_treeInsert(tree, components, phase);

src/profile-logic/call-node-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ export class CallNodeInfoInverted implements CallNodeInfo {
11611161
// Pass 1: Count the deep nodes per func, and build up a list of funcs.
11621162
// We will need to create a child for each deep node func, and each child will
11631163
// need to know how many deep nodes it has.
1164-
const deepNodeCountPerFunc = new Map();
1164+
const deepNodeCountPerFunc = new Map<IndexIntoFuncTable, number>();
11651165
const callNodeTable = this._callNodeTable;
11661166
for (let i = 0; i < parentDeepNodeCount; i++) {
11671167
const selfNode = parentSelfNodes[i];
@@ -1212,7 +1212,7 @@ export class CallNodeInfoInverted implements CallNodeInfo {
12121212
// partitions; one partition per child, in the right order.
12131213
const startIndexPerChild = new Uint32Array(childCount);
12141214
const deepNodeCountPerChild = new Uint32Array(childCount);
1215-
const funcToChildIndex = new Map();
1215+
const funcToChildIndex = new Map<IndexIntoFuncTable, number>();
12161216

12171217
let nextChildStartIndex = 0;
12181218
for (let childIndex = 0; childIndex < childCount; childIndex++) {

src/profile-logic/import/art-trace.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
// Parses the ART trace format and converts it to the Gecko profile format.
55

6+
import type {
7+
IndexIntoFrameTable,
8+
IndexIntoStackTable,
9+
} from 'firefox-profiler/types';
10+
611
// These profiles are obtained from Android in two ways:
712
// - Programmatically, from the Debug API: https://developer.android.com/studio/profile/cpu-profiler#debug-api
813
// - Or via the profiler UI in Android Studio.
@@ -566,7 +571,7 @@ function procureSamplingInterval(trace: ArtTrace) {
566571

567572
// Gather up to 500 time deltas between method actions on a thread.
568573
const deltas: number[] = [];
569-
const previousTimestampByThread = new Map();
574+
const previousTimestampByThread = new Map<number, number>();
570575
const numberOfActionsToConsider = Math.min(500, methodActions.length);
571576
for (let i = 0; i < numberOfActionsToConsider; i++) {
572577
const { tid, globalTime } = methodActions[i];
@@ -621,7 +626,7 @@ export function getSpecialCategory(
621626
return s.substring(0, firstPeriodPos);
622627
}
623628

624-
const significantSegmentCounter = new Map();
629+
const significantSegmentCounter = new Map<string, number>();
625630
for (let i = 0; i < methods.length; i++) {
626631
const significantSegment = getSignificantNamespaceSegment(
627632
methods[i].className
@@ -791,8 +796,8 @@ class ThreadBuilder {
791796

792797
_currentStack: number | null = null;
793798
_nextSampleTimestamp = 0;
794-
_stackMap = new Map();
795-
_frameMap = new Map();
799+
_stackMap = new Map<string, IndexIntoStackTable>();
800+
_frameMap = new Map<number, IndexIntoFrameTable>();
796801
_registerTime = 0;
797802
_name;
798803
_pid;
@@ -943,7 +948,7 @@ export function convertArtTraceProfile(
943948
const { summaryDetails, threads, methods, methodActions } = trace;
944949
const categoryInfo = new CategoryInfo(methods);
945950
const methodMap = new Map(methods.map((m) => [m.methodId, m]));
946-
const threadBuilderMap = new Map();
951+
const threadBuilderMap = new Map<number, ThreadBuilder>();
947952

948953
if (methodActions.length > 0) {
949954
for (let i = 0; i < methodActions.length; i++) {

src/profile-logic/import/chrome.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ function getThreadInfo(
396396

397397
profile.threads.push(thread);
398398

399-
const nodeIdToStackId = new Map();
399+
const nodeIdToStackId = new Map<number | void, IndexIntoStackTable | null>();
400400
nodeIdToStackId.set(undefined, null);
401401

402-
const threadInfo = {
402+
const threadInfo: ThreadInfo = {
403403
thread,
404404
nodeIdToStackId,
405405
funcKeyToFuncId: new Map(),
@@ -518,8 +518,8 @@ async function processTracingEvents(
518518
ensureExists(profile.meta.categories)
519519
);
520520

521-
const threadInfoByPidAndTid = new Map();
522-
const threadInfoByThread = new Map();
521+
const threadInfoByPidAndTid = new Map<string, ThreadInfo>();
522+
const threadInfoByThread = new Map<RawThread, ThreadInfo>();
523523
for (const profileEvent of profileEvents) {
524524
// The thread info is all of the data that makes it possible to process an
525525
// individual thread.
@@ -574,7 +574,7 @@ async function processTracingEvents(
574574
} = thread;
575575

576576
if (nodes) {
577-
const parentMap = new Map();
577+
const parentMap = new Map<number, number>();
578578
for (const node of nodes) {
579579
const { callFrame, id: nodeIndex } = node;
580580
let parent: number | void = undefined;

src/profile-logic/import/linux-perf.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import type { MixedObject } from 'firefox-profiler/types';
5+
import type {
6+
IndexIntoFrameTable,
7+
IndexIntoStackTable,
8+
MixedObject,
9+
} from 'firefox-profiler/types';
610

711
/**
812
* The "perf script" format is the plain text format that is output by an
@@ -118,7 +122,7 @@ export function convertPerfScriptProfile(
118122
};
119123
const stringTable: string[] = [];
120124

121-
const stackMap = new Map();
125+
const stackMap = new Map<string, IndexIntoStackTable>();
122126
function getOrCreateStack(frame: number, prefix: number | null) {
123127
const key = prefix === null ? `${frame}` : `${frame},${prefix}`;
124128
let stack = stackMap.get(key);
@@ -130,7 +134,7 @@ export function convertPerfScriptProfile(
130134
return stack;
131135
}
132136

133-
const frameMap = new Map();
137+
const frameMap = new Map<string, IndexIntoFrameTable>();
134138
function getOrCreateFrame(frameString: string): number {
135139
let frame = frameMap.get(frameString);
136140
if (frame === undefined) {

src/profile-logic/js-tracer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function getScriptLocationToFuncIndex(
3838
sources: SourceTable
3939
): ScriptLocationToFuncIndex {
4040
const { funcTable } = thread;
41-
const scriptLocationToFuncIndex = new Map();
41+
const scriptLocationToFuncIndex: ScriptLocationToFuncIndex = new Map();
4242
for (let funcIndex = 0; funcIndex < funcTable.length; funcIndex++) {
4343
if (!funcTable.isJS[funcIndex]) {
4444
continue;

src/profile-logic/marker-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export function correlateIPCMarkers(
484484
recvThreadName: formatThreadName(recvTid),
485485
};
486486

487-
const addedThreadIds = new Set();
487+
const addedThreadIds = new Set<number>();
488488
if (startEndpointMarker) {
489489
addedThreadIds.add(startEndpointMarker.tid);
490490
correlations.set(
@@ -1331,7 +1331,7 @@ export function groupScreenshotsById(
13311331
getMarker: (markerIndex: MarkerIndex) => Marker,
13321332
markerIndexes: MarkerIndex[]
13331333
): Map<string, Marker[]> {
1334-
const idToScreenshotMarkers = new Map();
1334+
const idToScreenshotMarkers = new Map<string, Marker[]>();
13351335
for (const markerIndex of markerIndexes) {
13361336
const marker = getMarker(markerIndex);
13371337
const { data } = marker;

0 commit comments

Comments
 (0)