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

Make dead code indexing use a Model to index classes #562

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Jun 19, 2024

This is the first PR on a sequence moving the dead code analysis use the Model introduced in #557 rather than its custom indexer.

In this PR we migrate the indexing of classes:

  • Make Deadcode::Index take a Model (bc18520)
  • Remove classes indexing from Deadcode::Indexer (9433fda)
  • Make the Deadcode::Plugins take Model::SymbolDef when calling on_define_class (6359779)

There is no behavior change: no tests are changed.

This PR is easier to review commit by commit.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
# end
# end
# ~~~
sig { params(indexer: Indexer, definition: Definition).void }
def on_define_class(indexer, definition)
sig { params(symbol_def: Model::Class, definition: Definition).void }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be abstract?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't want to crash when calling on_define_class to a plugin that do nothing with it, we just want it to no-op.

We _could_refactor this to have multiple interfaces:

module ClassPlugin
  interface!

  sig { abstract.void }
  def on_define_class; end

and then let the plugins cherry pick the interfaces they want to implement.

But in practice I just rely on YJIT to optimize this empty calls away.

@Morriar Morriar merged commit 1b21d29 into main Jun 20, 2024
8 checks passed
@Morriar Morriar deleted the at-model-deadcode-classes branch June 20, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chore task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants