Skip to content

Refactor MoveStatic #8022

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
liufengyun opened this issue Jan 17, 2020 · 3 comments · Fixed by #11126
Closed

Refactor MoveStatic #8022

liufengyun opened this issue Jan 17, 2020 · 3 comments · Fixed by #11126
Assignees
Milestone

Comments

@liufengyun
Copy link
Contributor

liufengyun commented Jan 17, 2020

Currently, the phase MoveStatic has two functionality:

  • Move @static members from the companion object A to the class A
  • Create static constructor for static fields of the class A

In an earlier phase, CheckStatic checks that @static members only locate in the companion object A. This restriction is just for semantic-correctness of user-written programs (to avoid changing the typer). For code that is synthesized from compiler phases, this restriction is annoying.

We can make @static a general mechanism in the compiler by splitting MoveStatic into two phases:

  • one phase that performs the moving (can be merged with CheckStatic)
  • one phase StaticConstructors that synthesize the static constructor for static fields.

The phase CompleteJavaEnums will benefit from the refactoring #8008.

@smarter
Copy link
Member

smarter commented Jan 17, 2020

I think we should just forbid user-code from using @static, it's a language feature which has not been properly specified and is currently really hard to use correctly (for example, if a lambda appears in a @static def, it will be translated to a non-static def, thus defeating the purpose of using @static)

@liufengyun
Copy link
Contributor Author

liufengyun commented Jan 17, 2020

Then we can change @static to be an internal annotation.

@odersky
Copy link
Contributor

odersky commented Jan 18, 2020

I would not be so rash throwing out @static. It solves real pain points of interop and getting the last drop of performance. It could need some attention to spec what it does and change the implementation to be more explicit when @static cannot be implemented correctly.

liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2021
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 15, 2021
We still keep two phases, but the code is simplified.

We cannot merge MoveStatics with CheckStatic because the early phases
are not able to handle static calls, thus it has to be at the end of
the pipeline.  Meanwhile, we want checks to happen as early as
possible, thus CheckStatic has to be in the beginning of the pipeline.
odersky added a commit that referenced this issue Jan 19, 2021
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants