-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add a switch for reporting expensive statements #37785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
52e2ce9
ebf8288
86fbb03
3fac294
3ddf1ff
36b2865
8f5e138
2e2dfd4
906c503
9d24de1
e15bec8
ca645f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4482,6 +4482,10 @@ | |
"category": "Error", | ||
"code": 6236 | ||
}, | ||
"Heuristically reports statements that appear to contribute disproportionately to check time.": { | ||
"category": "Message", | ||
"code": 6237 | ||
}, | ||
|
||
"Projects to reference": { | ||
"category": "Message", | ||
|
@@ -5984,5 +5988,10 @@ | |
"Invalid value for 'jsxFragmentFactory'. '{0}' is not a valid identifier or qualified-name.": { | ||
"category": "Error", | ||
"code": 18035 | ||
}, | ||
|
||
"Checking this statement may result in the creation of as many as {0} types and {1} symbols.": { | ||
"category": "Warning", | ||
"code": 19000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, since this felt like a new kind of diagnostic, I added a new code range. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,7 +440,7 @@ namespace ts { | |
createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)), | ||
createWatchStatusReporter(sys, buildOptions) | ||
); | ||
updateSolutionBuilderHost(sys, cb, buildHost); | ||
updateSolutionBuilderHost(sys, reportDiagnostic, cb, buildHost); | ||
const builder = createSolutionBuilderWithWatch(buildHost, projects, buildOptions, watchOptions); | ||
builder.build(); | ||
return builder; | ||
|
@@ -453,7 +453,7 @@ namespace ts { | |
createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)), | ||
createReportErrorSummary(sys, buildOptions) | ||
); | ||
updateSolutionBuilderHost(sys, cb, buildHost); | ||
updateSolutionBuilderHost(sys, reportDiagnostic, cb, buildHost); | ||
const builder = createSolutionBuilder(buildHost, projects, buildOptions); | ||
const exitStatus = buildOptions.clean ? builder.clean() : builder.build(); | ||
return sys.exit(exitStatus); | ||
|
@@ -492,7 +492,7 @@ namespace ts { | |
s => sys.write(s + sys.newLine), | ||
createReportErrorSummary(sys, options) | ||
); | ||
reportStatistics(sys, program); | ||
reportStatistics(sys, program, reportDiagnostic); | ||
cb(program); | ||
return sys.exit(exitStatus); | ||
} | ||
|
@@ -516,7 +516,7 @@ namespace ts { | |
reportDiagnostic, | ||
reportErrorSummary: createReportErrorSummary(sys, options), | ||
afterProgramEmitAndDiagnostics: builderProgram => { | ||
reportStatistics(sys, builderProgram.getProgram()); | ||
reportStatistics(sys, builderProgram.getProgram(), reportDiagnostic); | ||
cb(builderProgram); | ||
} | ||
}); | ||
|
@@ -525,12 +525,13 @@ namespace ts { | |
|
||
function updateSolutionBuilderHost( | ||
sys: System, | ||
reportDiagnostic: DiagnosticReporter, | ||
cb: ExecuteCommandLineCallbacks, | ||
buildHost: SolutionBuilderHostBase<EmitAndSemanticDiagnosticsBuilderProgram> | ||
) { | ||
updateCreateProgram(sys, buildHost); | ||
buildHost.afterProgramEmitAndDiagnostics = program => { | ||
reportStatistics(sys, program.getProgram()); | ||
reportStatistics(sys, program.getProgram(), reportDiagnostic); | ||
cb(program); | ||
}; | ||
buildHost.afterEmitBundle = cb; | ||
|
@@ -549,14 +550,15 @@ namespace ts { | |
|
||
function updateWatchCompilationHost( | ||
sys: System, | ||
reportDiagnostic: DiagnosticReporter, | ||
cb: ExecuteCommandLineCallbacks, | ||
watchCompilerHost: WatchCompilerHost<EmitAndSemanticDiagnosticsBuilderProgram>, | ||
) { | ||
updateCreateProgram(sys, watchCompilerHost); | ||
const emitFilesUsingBuilder = watchCompilerHost.afterProgramCreate!; // TODO: GH#18217 | ||
watchCompilerHost.afterProgramCreate = builderProgram => { | ||
emitFilesUsingBuilder(builderProgram); | ||
reportStatistics(sys, builderProgram.getProgram()); | ||
reportStatistics(sys, builderProgram.getProgram(), reportDiagnostic); | ||
cb(builderProgram); | ||
}; | ||
} | ||
|
@@ -581,7 +583,7 @@ namespace ts { | |
reportDiagnostic, | ||
reportWatchStatus: createWatchStatusReporter(system, configParseResult.options) | ||
}); | ||
updateWatchCompilationHost(system, cb, watchCompilerHost); | ||
updateWatchCompilationHost(system, reportDiagnostic, cb, watchCompilerHost); | ||
watchCompilerHost.configFileParsingResult = configParseResult; | ||
return createWatchProgram(watchCompilerHost); | ||
} | ||
|
@@ -602,7 +604,7 @@ namespace ts { | |
reportDiagnostic, | ||
reportWatchStatus: createWatchStatusReporter(system, options) | ||
}); | ||
updateWatchCompilationHost(system, cb, watchCompilerHost); | ||
updateWatchCompilationHost(system, reportDiagnostic, cb, watchCompilerHost); | ||
return createWatchProgram(watchCompilerHost); | ||
} | ||
|
||
|
@@ -616,9 +618,21 @@ namespace ts { | |
} | ||
} | ||
|
||
function reportStatistics(sys: System, program: Program) { | ||
function reportStatistics(sys: System, program: Program, reportDiagnostic: DiagnosticReporter) { | ||
let statistics: Statistic[]; | ||
const compilerOptions = program.getCompilerOptions(); | ||
|
||
if (compilerOptions.expensiveStatements) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're really only diagnostics for the pretty-printing. Otherwise, they seem like they belong with the statistics. |
||
for (const expensiveStatement of program.getExpensiveStatements()) { | ||
reportDiagnostic( | ||
createDiagnosticForNode( | ||
expensiveStatement.node, | ||
Diagnostics.Checking_this_statement_may_result_in_the_creation_of_as_many_as_0_types_and_1_symbols, | ||
expensiveStatement.typeDelta, | ||
expensiveStatement.symbolDelta)); | ||
} | ||
} | ||
|
||
if (canReportDiagnostics(sys, compilerOptions)) { | ||
statistics = []; | ||
const memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first
Warning
. It feels pretty distinct to me, but it doesn't really matter one way or the other.