-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add space complexity tracker for #9203 #9237
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
Closed
anatoliykmetyuk
wants to merge
1
commit into
scala:master
from
dotty-staging:space-complexity-tracker
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2861,7 +2861,39 @@ class Typer extends Namer | |
final def adapt(tree: Tree, pt: Type)(using Context): Tree = | ||
adapt(tree, pt, ctx.typerState.ownedVars) | ||
|
||
private def adapt1(tree: Tree, pt: Type, locked: TypeVars, tryGadtHealing: Boolean)(using Context): Tree = { | ||
// See https://github.com/lampepfl/dotty/issues/9203 for why this is needed | ||
// So far it is guarding only `adapt1` since that's the highest known entry point | ||
// stack call where the detection for the debugging of #9203 is possible. | ||
private inline def spaceComplexityTracker[T](tree: Tree)(task: => T)(using Context) = | ||
def size = ctx.base.uniquesSizes.values | ||
.map { case (size, _, _) => size }.sum | ||
val before = size | ||
val res = task | ||
val after = size | ||
val delta = after - before | ||
if delta > 100000 | ||
println( // ctx.warning does not output the message in this place, probably waits | ||
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. Why not emit an error as we do in Inliner.scala#L132? There we return an |
||
// for the checking to finish – which never happens under the conditions | ||
// `spaceComplexityTracker` was designed to track and report. | ||
s""" | ||
|[${Console.YELLOW}warn${Console.RESET}] Created ${delta} unique type objects on typecheck | ||
|of the following tree in ${ctx.source}: | ||
| | ||
|${tree.show} | ||
| | ||
|The meaning of this is that the compiler is doing an unreasonable amount | ||
|of work while compiling your code. The compilation may take a lot of time | ||
|and heap space. This situation can happen, e.g., when the lookup space for | ||
|givens is too large. To resolve the problem, try to eliminate the offending | ||
|code snippet from your program and rephrase your program using fewer advanced | ||
|features. | ||
""".stripMargin) | ||
ctx.reporter.flush() | ||
end if | ||
res | ||
end spaceComplexityTracker | ||
|
||
private def adapt1(tree: Tree, pt: Type, locked: TypeVars, tryGadtHealing: Boolean)(using Context): Tree = spaceComplexityTracker(tree) { | ||
assert(pt.exists && !pt.isInstanceOf[ExprType] || ctx.reporter.errorsReported) | ||
def methodStr = err.refStr(methPart(tree).tpe) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should probably not be a constant. We should have a setting that allows us to modify this limit. We should probably use
XmaxInlinedTrees
(and maybe rename it).