From 9e8224cc5973d5d3d919b154d78352fe193a1376 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Fri, 14 Oct 2022 17:36:20 -0400 Subject: [PATCH] Pass `init` to E0007 diagnostic I'm not sure why exactly but previously this diagnostic message was unusually slow to typecheck. Lifting the getter for init outside of the diagnostic to the callsite seems to fix the hotspot. Probably some interaction with string interpolation, or something else. Test case: ran `yarn ts:analyze-trace`, hotspot for Diagnostic.ts no longer present --- compiler/forget/src/Diagnostic.ts | 3 ++- compiler/forget/src/IR/Hook.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/forget/src/Diagnostic.ts b/compiler/forget/src/Diagnostic.ts index 8362e3c6f2..c60fd588b5 100644 --- a/compiler/forget/src/Diagnostic.ts +++ b/compiler/forget/src/Diagnostic.ts @@ -154,6 +154,7 @@ export type DiagnosticOpts = path: NodePath; context: { callee: NodePath | NodePath[]; + init: NodePath | NodePath[]; }; } | { code: "E0008"; path: NodePath; context: { input: NodePath } } @@ -224,7 +225,7 @@ function getDiagnosticMessage(opts: DiagnosticOpts): DiagnosticMessage { body: `\`${getSource( opts.context.callee )}\` does not have a return value.`, - suggestion: `Do \`${getSource(opts.path.get("init"))}\` instead.`, + suggestion: `Do \`${getSource(opts.context.init)}\` instead.`, }; case "E0008": return { diff --git a/compiler/forget/src/IR/Hook.ts b/compiler/forget/src/IR/Hook.ts index 9c040881dd..5623e6ef70 100644 --- a/compiler/forget/src/IR/Hook.ts +++ b/compiler/forget/src/IR/Hook.ts @@ -505,11 +505,12 @@ function matchHookCallRetVals( function matchVoid(_pattern: Void, lvals: NodePath) { if (lvals.isPatternLike()) { + let init = lvals.parentPath.get("init"); let callee = lvals.parentPath.get("init.callee"); context.createDiagnostic({ code: "E0007", path: lvals.parentPath, - context: { callee }, + context: { callee, init }, }); } }