Skip to content
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

Merged
merged 1 commit into from
Mar 4, 2021

Conversation

mlachkar
Copy link
Collaborator

@mlachkar mlachkar commented Mar 4, 2021

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.

image

Copy link
Collaborator

@bjaglin bjaglin left a 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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. but where?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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)
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this ?

Copy link
Collaborator

@bjaglin bjaglin Mar 4, 2021

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)

@mlachkar mlachkar force-pushed the global branch 2 times, most recently from acfe84d to 01fcac8 Compare March 4, 2021 13:59
@mlachkar mlachkar requested a review from bjaglin March 4, 2021 14:00
Copy link
Collaborator

@bjaglin bjaglin left a 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.

@mlachkar
Copy link
Collaborator Author

mlachkar commented Mar 4, 2021

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. I agree it's confusing not to know if Scalafix is compiling files, or relying on existing semanticdb files, using interactive global (which up to the latest release, was not giving the same diagnostics for example)

Copy link
Collaborator

@bjaglin bjaglin left a 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)

@mlachkar
Copy link
Collaborator Author

mlachkar commented Mar 4, 2021

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)
Copy link
Collaborator

@bjaglin bjaglin Mar 4, 2021

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)?

Copy link
Collaborator Author

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.

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

@olafurpg
Copy link
Contributor

olafurpg commented Mar 4, 2021

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.

@mlachkar mlachkar merged commit fd1ceef into scalacenter:master Mar 4, 2021
@bjaglin bjaglin mentioned this pull request Apr 15, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants