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

Small refactoring of explicitResultTypes #1439

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

mlachkar
Copy link
Collaborator

No description provided.

try unsafeFix()
catch {
case _: CompilerException =>
shutdownCompiler()
Copy link
Collaborator Author

@mlachkar mlachkar Jun 25, 2021

Choose a reason for hiding this comment

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

The compiler crashes sometimes because it cannot type a part of the AST. If it crashes once, it will crash again even after a retry.
Actually we do that on the file level, which means if one explicit type makes the compiler crash, we don't add any types to the entire file. Should we continue to do that ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The compiler crashes sometimes because it cannot type a part of the AST. If it crashes once, it will crash again even after a retry.

Is that the only case? ba74db3 is not very verbose, I am not sure... In any case, if you reproduced the issue, it would be good to document the cases where the compiler crashes and how it behaves via tests.

Actually we do that on the file level, which means if one explicit type makes the compiler crash, we don't add any types to the entire file. Should we continue to do that ?

Catching the exception at a more granular seems like a good idea indeed. Maybe this wasn't done for performance reason because some files would crash the compiler over and over again?

Comment on lines +103 to +120
global.value match {
case Some(value) =>
val types = new CompilerTypePrinter(value, config)
ctx.tree.collect {
case t @ Defn.Val(mods, Pat.Var(name) :: Nil, None, body)
if isRuleCandidate(t, name, mods, body) =>
fixDefinition(t, body, types)

case t @ Defn.Var(mods, Pat.Var(name) :: Nil, None, Some(body))
if isRuleCandidate(t, name, mods, body) =>
fixDefinition(t, body, types)

case t @ Defn.Def(mods, name, _, _, None, body)
if isRuleCandidate(t, name, mods, body) =>
fixDefinition(t, body, types)
}.asPatch
case None => Patch.empty
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

old code vs new code:

  • in old code, we will always traverse the entire Tree of the file even if we were not able to instantiate the global, which can only happen if the classpath is wrong
  • new code: we always instantiate the global, even if there no element (def, or var or val) in the Tree. But in the other hand we remove an indirection where we create a TypePrinter just to wrap the case where ScalafixGlobal is None.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not familiar with global, but c6014ce did introduce this for something else than an incorrect classpath it seems

@mlachkar mlachkar changed the title Small refactoring of explicitResultTypes - WIP Small refactoring of explicitResultTypes Jun 25, 2021
@mlachkar
Copy link
Collaborator Author

mlachkar commented Jul 6, 2021

Hello @olafurpg ! Could you have a look on this refactoring. As @bjaglin reported, this PR c6014ce introduced what I am changing again.
My goal is to reduce the number of abstractions, to make it easier to understand. What do you think ? Thanks !

@mlachkar
Copy link
Collaborator Author

I will merge this change! I think it's good to simplify the code for explicit result types!

@mlachkar mlachkar merged commit 58de770 into scalacenter:main Mar 16, 2022
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.

2 participants