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

Datalog Scope Analysis #70

Draft
wants to merge 65 commits into
base: master
Choose a base branch
from
Draft

Conversation

Kixiron
Copy link
Contributor

@Kixiron Kixiron commented Nov 2, 2020

Scope analysis using ddlog. Implements incremental scope analysis using a datalog variant allowing concise and high-level descriptions of analyses, with future goals towards writing more complex analyses, code path analysis and even type checking within datalog.

(Un)implemented bits

  • no-undef
  • no-unused-vars
  • no-use-before-define
  • no-shadow
  • typeof-undef
  • no-unused-labels
  • Exporting of scopes to allow other rules access to data
  • Testing, lots of it
    • Per-rule tests
    • Make tests only enable the rules they're testing
    • Make tests that check combinations of errors instead of singular ones
  • Nice(r) errors, preferably with suggestions
  • Configuration of rules
  • Dev docs

Code Structure

  • crates/rslint_scope/ contains all analysis-related code
  • src/analyzer/ contains the ast->ddlog translation code
  • src/datalog.rs contains the ddlog program instance & the interface for interacting with it
  • ddlog/ contains the written datalog rules
  • generated/ contains the code generated by ddlog

Prior Art & Resources

@RDambrosio016 RDambrosio016 added C-enhancement Category: enhancement T-Runner This issue primary relates to the lint runner, rslint_core labels Nov 2, 2020
@RDambrosio016
Copy link
Collaborator

I think instead of making the diagnostics ourselves, we should just return an additional structure, maybe ScopeFacts which just contains vectors with locations/extra info for these errors. I think computing some of the errors in ddlog is helpful but ddlog shouldnt be making diagnostics.

@Kixiron
Copy link
Contributor Author

Kixiron commented Nov 2, 2020

That's what I do currently, ddlog's output relations are combined into the DerivedFacts struct here which are then made into diagnostics here, ddlog has no knowledge of diagnostics (although it could potentially do so)

@RDambrosio016
Copy link
Collaborator

The current way of how errors are emitted and registered is very janky (although its temporary). Firstly, rslint_scope cannot depend on rslint_core, it needs to be the other way around, rules will grab the scope and emit errors based on that.

@Stupremee
Copy link
Member

Stupremee commented Nov 11, 2020

Don't forget to add the rslint_scope module in the dev docs in website/docs/dev/architecture.md

@Kixiron Kixiron force-pushed the scope-analytics branch 2 times, most recently from 242350f to a9ce335 Compare November 15, 2020 00:34
@Kixiron Kixiron force-pushed the scope-analytics branch 3 times, most recently from 834a63a to 63b609d Compare November 20, 2020 18:09
@Kixiron
Copy link
Contributor Author

Kixiron commented Nov 21, 2020

@RDambrosio016 @Stupremee Can y'all fancy up the rule impls, I'm not sure how to make the actually emitted errors good

@Kixiron Kixiron force-pushed the scope-analytics branch 4 times, most recently from c5cca5a to a7e55b4 Compare November 26, 2020 23:41
@Kixiron Kixiron force-pushed the scope-analytics branch 6 times, most recently from 9b9c00a to 7976ce7 Compare December 16, 2020 03:11
@Kixiron Kixiron force-pushed the scope-analytics branch 2 times, most recently from 4c7338c to eb49202 Compare December 22, 2020 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-scope C-enhancement Category: enhancement T-Runner This issue primary relates to the lint runner, rslint_core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants