-
Notifications
You must be signed in to change notification settings - Fork 185
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
Close global after compute ondemand semanticdb files #1348
Conversation
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.
good catch! some questions/comments as I am not very familiar with Global
@@ -347,6 +348,18 @@ object MainOps { | |||
} else { | |||
args.rules.syntacticPatch(doc, args.args.autoSuppressLinterErrors) | |||
} | |||
// close global if evaluated | |||
cleanGlobalRessources(args.global) |
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.
should that be in a finally block instead?
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.
yes. but where?
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.
I don't understand your question - here?
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.
try {
val tree = LazyValue.later { () =>
args.parse(input).get: Tree
}
val doc = SyntacticDocument(input, tree, args.diffDisable, args.config)
val results = if (args.rules.isSemantic) {
val relpath = file.toRelative(args.sourceroot)
val sdoc = SemanticDocument.fromPath(
doc,
relpath,
args.classLoader,
args.symtab,
() => compileWithGlobal(args, doc)
)
val result =
args.rules.semanticPatch(sdoc, args.args.autoSuppressLinterErrors)
assertFreshSemanticDB(
input,
file,
result.fixed,
sdoc.internal.textDocument
)
result
} else {
args.rules.syntacticPatch(doc, args.args.autoSuppressLinterErrors)
}
results
} finally {
// close global if evaluated
shutdownCompiler(args.global)
}
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.
something like this ?
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.
hard to tell without proper indentation and highlighting but yes that's what I had in mind 👍 (the results
val can be removed)
acfe84d
to
01fcac8
Compare
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.
Maybe a larger question but do we want to keep supporting ondemand generation of semanticdb files in 1.0? This will require significant effort to support it with Scala 3 sources, and as far as I know, that feature is undocumented.
What are the use-cases behind it? Was that done to cover shortcomings of build tool integration? It looks like @olafurpg added it while working on ExplicitResultTypes
but the git history is not very clear.
It's useful if the semanticdb files are not present, especially if it's used through the API when we don't depend on compile task. |
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.
It's useful if the semanticdb files are not present, especially if it's used through the API when we don't depend on compile task.
We may open another issue to discuss this.
👍
LGTM (moving the call to shutdownCompiler
in a finally block would be a bonus I guess)
try finally will be usefull since wr throw a potentiel exception with the Assert. Thank you for the advise |
} else { | ||
args.rules.syntacticPatch(doc, args.args.autoSuppressLinterErrors) | ||
} | ||
} finally shutdownCompiler(args.global) |
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.
actually I guess the finally block could be scoped to where it's actually used - around the thunk calling compileWithGlobal
(or potentially move it there)?
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.
You are right, it's again on the wrong place .. we need it elsewhere, where the function is called. we don't want to open a new gloabl for each file.
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.
Nice fix!
The library API could support an enum mode to determine how to load SemanticDB files. I agree it can sometimes be confusing when the fallback triggers. |
The state before the fix. It possible to reproduce by running multiple time the test on-demand with scalacOptions
The presentation compiler is never closed.