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

refactor inference.jl into multiple files for readability/maintainability #25517

Merged
merged 1 commit into from Jan 16, 2018

Conversation

jrevels
Copy link
Member

@jrevels jrevels commented Jan 11, 2018

I would be flabbergasted if this PR passes CI as it is now. Tests now pass locally.

This PR does a bulk-refactor of inference.jl in order to make the code more readable/maintainable/hackable. One of my long-term motivations here is the development a well-versioned/defined "compiler standard library" - untangling what already exists is the first step.

Here's the summary of the changes:

  • the contents of coreimg.jl, inference.jl and codevalidation.jl now live in base/compiler/
  • Core.Inference --> Core.Compiler, and Core.InferenceParams --> Core.Compiler.Params, since these refer to more than just type inference at this point
  • Constants/structs now mostly appear in the file in which they are first used. Non-business logic methods acting on freshly-defined structs are now defined alongside the structs themselves. Non-business logic methods which don't depend on new structs are now in utilities.jl.
  • All non-alias const names are now all-caps. Type alias consts are camelcase, and function alias consts are lowercase.
  • Inference logic is split into several files (abstractinterpretation.jl, typelattice.jl, typeinf.jl, etc.)
  • All the tfunc definitions now reside in their own file.
  • Optimization logic (inlining, DCE, etc.) hasn't been broken up at all yet; it is now in optimize.jl. A future PR will be required to break it up.
  • No semantic changes, at least not on purpose.

I apologize for not breaking things up into smaller commits...it would've taken forever to do this "properly". May God have mercy on the reviewers' souls.

I also really hope that I made this at the right time...rebasing this against any other non-trivial inference PR would probably break my mind.

@ararslan ararslan added the inference Type inference label Jan 11, 2018
# Optimization* #
#################

mutable struct OptimizationState
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Should go with the optimization code.

# This struct contains information about a use of certain value (`SSAValue` or `Slot`)
# This might be a toplevel use for `Slot` in which case the `expr` field is `#undef`,
# and it only happens if the slot might be used before it's defined.
struct ValueUse
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Also part of optimization passes.

# CompilationResult #
#####################

mutable struct CompilationResult
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The name of this should be reverted. It doesn't give you compiled code, just inferred code. Also only used by inference, so it can go in that file.

@jrevels jrevels changed the title WIP: rebasing this might make me cry rebasing this might make me cry Jan 12, 2018
@jrevels jrevels changed the title rebasing this might make me cry refactor inference.jl into multiple files for readability/maintainability Jan 12, 2018
@jrevels jrevels force-pushed the jr/damnthetorpedoes branch 8 times, most recently from 3267296 to f610a64 Compare January 12, 2018 05:15
@jrevels
Copy link
Member Author

jrevels commented Jan 12, 2018

This successfully builds locally now.

alive

Haven't run the tests yet; I'll let CI run overnight and see how it fares in the morning.

@jrevels jrevels force-pushed the jr/damnthetorpedoes branch 3 times, most recently from 2e219d7 to 69015e6 Compare January 12, 2018 15:56
@jrevels
Copy link
Member Author

jrevels commented Jan 12, 2018

Tests just passed locally! Just waiting on CI now, and any additional review.

@StefanKarpinski
Copy link
Sponsor Member

AppVeyor failures are both timeouts. Want me to restart them? Or do we expect this just to timeout again?

@jrevels
Copy link
Member Author

jrevels commented Jan 12, 2018

Want me to restart them? Or do we expect this just to timeout again?

Are AppVeyor timeouts common these days? I have no reason to suspect that this PR to incur AppVeyor timeouts moreso than any other PR, so if you think it's sensible to try again, then sure, thanks!

@StefanKarpinski
Copy link
Sponsor Member

Well, you're looking good on Linux and FreeBSD. Let's see how macOS and Windows do...

@JeffBezanson
Copy link
Sponsor Member

👍 Awesome, this is a huge improvement a long time coming.

A few detail comments:

  • Const and Conditional are also lattice elements so should go in typelattice next to PartialTypeVar

  • The stuff in typelimits above the comment # limitation parameters # is not really related; maybe move to typeinfer? Or a new file inferencestate.jl?

  • I think tfuncs.jl should contain only t-functions; there are a bunch of unrelated definitions at the top.

  • Move return_type_tfunc to tfuncs

  • exprtype should go in utilities

  • return_type should also go somewhere else, maybe utilities

@jrevels jrevels force-pushed the jr/damnthetorpedoes branch 2 times, most recently from b6822ce to 396ffe7 Compare January 15, 2018 10:26
@jrevels
Copy link
Member Author

jrevels commented Jan 15, 2018

Const and Conditional are also lattice elements so should go in typelattice next to PartialTypeVar

The stuff in typelimits above the comment # limitation parameters # is not really related; maybe move to typeinfer? Or a new file inferencestate.jl?

I think tfuncs.jl should contain only t-functions; there are a bunch of unrelated definitions at the top.

Move return_type_tfunc to tfuncs

Done!

exprtype should go in utilities

Done! Also, there's more work to do splitting out code from optimize.jl, but I'm mainly leaving that to a future PR.

return_type should also go somewhere else, maybe utilities

It seems that promotion.jl expects return_type to exist, hence the stub definition before loading Base code. I've moved that stub to directly before include("promotion.jl") and added a comment to make things clearer.

Now, I've just got to get through a rebase and hope CI stays green, and this should be ready to go.

EDIT: rebase complete

EDIT 2: tests pass locally on rebased branch

…lity

- the contents of `coreimg.jl`, `inference.jl` and `codevalidation.jl` now live in `base/compiler/`
- `Core.Inference` --> `Core.Compiler`, and `Core.InferenceParams` --> `Core.Compiler.Params`, since these refer to more than just type inference at this point
- Constants/structs now mostly appear in the file in which they are first used. Non-business logic methods acting on freshly-defined structs are now defined alongside the structs themselves. Non-business logic methods which don't depend on new structs are now in `utilities.jl`.
- All non-alias `const` names are now all-caps. Type alias `const`s are camelcase, and function alias `const`s are lowercase.
- Inference logic is split into several files (`abstractinterpretation.jl`, `typelattice.jl`, `typeinf.jl`, etc.)
- All the tfunc definitions now reside in their own file.
- Optimization logic  (inlining, DCE, etc.) hasn't been broken up at all yet; it is now in `optimize.jl`. A future PR will be required to break it up.
- No semantic changes, at least not on purpose.
@jrevels
Copy link
Member Author

jrevels commented Jan 15, 2018

Okay, 64-bit Linux failed on Travis and both 32-bit and 64-bit Windows failed on AppVeyor. None of these look PR-related - Travis failed on apt-get install because it couldn't download some dependency, and both Windows failures seems to be due to missing shared object files. I restarted the relevant Travis build, hopefully I'm less unlucky this time.

Could an AppVeyor wizard restart the AppVeyor builds? Thanks!

@jrevels
Copy link
Member Author

jrevels commented Jan 16, 2018

Looks like a kind soul retriggered my AppVeyor build - 64-bit Windows passed and 32-bit simply timed out. I was also informed that I have the power to retrigger AppVeyor myself, so I've just done so. Fingers crossed for all green this time...

@JeffBezanson
Copy link
Sponsor Member

Very nice. I'll merge this now, and Jameson, Keno, and I can rebase around it.

@JeffBezanson JeffBezanson merged commit aea9155 into master Jan 16, 2018
@JeffBezanson JeffBezanson deleted the jr/damnthetorpedoes branch January 16, 2018 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants