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

[WIP] Refactor: Lint tool (Rust ver.) #103

Closed
wants to merge 1 commit into from

Conversation

He1pa
Copy link
Contributor

@He1pa He1pa commented Jul 7, 2022

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

2. What is the scope of this PR (e.g. component or file name):

KCLVM/kclvm/sema/src/resolver
KCLVM/kclvm/error
KCLVM/kclvm/ast/walker.rs

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

Add lint check in resolver.

1. Add warning level diagnotics, including 'UnusedImportWarning', 'ReimportWarning' and 'ImportPostionWarning'

2. Add 'lint_check_module' method to Resolver and is called in the 'check()' method.

3. Add KCL Lint stuct, For details see issue #109

fix #102, #109

Now, these diags are only stored in resolver.handler.diagonstics and are not thrown to the user.

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other
    KCLVM/kclvm/sema/src/resolver/test.rs::test_lint()

6. Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

7. Benchmark

  • resolve_program()
    • resolve single file
      Before
      image
      After
      image
    • resolve 6 files
      Before
      image
      After
      image

@ldxdl
Copy link
Contributor

ldxdl commented Jul 7, 2022

Pls benchmark resolver's core function.

@He1pa He1pa self-assigned this Jul 7, 2022
@coveralls
Copy link
Collaborator

coveralls commented Jul 7, 2022

Pull Request Test Coverage Report for Build 2867182406

  • 499 of 714 (69.89%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 59.771%

Changes Missing Coverage Covered Lines Changed/Added Lines %
kclvm/error/src/error.rs 1 8 12.5%
kclvm/sema/src/lint/lint.rs 280 291 96.22%
kclvm/ast/src/walker.rs 46 243 18.93%
Totals Coverage Status
Change from base Build 2861308171: 0.2%
Covered Lines: 22888
Relevant Lines: 38293

💛 - Coveralls

@He1pa He1pa added enhancement New feature or request tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc. error-handling Issues or PRs related to kcl error handling feat resolver labels Jul 7, 2022
@He1pa He1pa added this to the v0.4.3 Release milestone Jul 7, 2022
kclvm/sema/src/resolver/test_data/a.k Outdated Show resolved Hide resolved
kclvm/error/src/lib.rs Outdated Show resolved Hide resolved
kclvm/error/src/error.rs Outdated Show resolved Hide resolved
kclvm/error/src/error.rs Show resolved Hide resolved
kclvm/sema/src/resolver/import.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/import.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/import.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/mod.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/import.rs Outdated Show resolved Hide resolved
@He1pa He1pa force-pushed the unused_import_check branch 2 times, most recently from 02a0b71 to cf76721 Compare July 13, 2022 03:42
Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

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

Pls add more unit tests in kclvm_ast and kclvm_error crate.

@He1pa He1pa force-pushed the unused_import_check branch 2 times, most recently from 2b4eb8e to 89621fe Compare July 15, 2022 08:06
@He1pa He1pa changed the title feat: reslover, add reimport and unusedimport check in resolver. Refactor: Lint toos (Rust, ver.) Jul 15, 2022
@He1pa He1pa changed the title Refactor: Lint toos (Rust, ver.) Refactor: Lint tool (Rust, ver.) Jul 15, 2022
@He1pa He1pa requested review from Peefy and ldxdl July 15, 2022 08:53
@He1pa He1pa force-pushed the unused_import_check branch from 89621fe to f6b5b71 Compare July 18, 2022 11:31
@He1pa He1pa changed the title Refactor: Lint tool (Rust, ver.) Refactor: Lint tool (Rust ver.) Jul 19, 2022
@He1pa He1pa force-pushed the unused_import_check branch 4 times, most recently from ec7c365 to 371b1eb Compare July 21, 2022 06:50
@He1pa He1pa force-pushed the unused_import_check branch 2 times, most recently from 04094d6 to 944f143 Compare July 25, 2022 07:07
kclvm/sema/src/resolver/import.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/import.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

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

Improvement suggestions implemented by lint.rs, due to the lack of symbol table information in LintContext, functions such as check_identifier, check_schema_attr and record_use are implemented in a tricky way, which is part of the symbol table implementation (we can query the variable type and whether the variable has been used. )

kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint.rs Outdated Show resolved Hide resolved
@He1pa He1pa changed the title Refactor: Lint tool (Rust ver.) [WIP] Refactor: Lint tool (Rust ver.) Jul 27, 2022
@He1pa He1pa force-pushed the unused_import_check branch 5 times, most recently from ba6160b to c258c2f Compare August 8, 2022 04:23
@He1pa He1pa force-pushed the unused_import_check branch from f75c767 to 6a8ee73 Compare August 15, 2022 15:19
@He1pa He1pa changed the title [WIP] Refactor: Lint tool (Rust ver.) Refactor: Lint tool (Rust ver.) Aug 15, 2022
Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

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

remove samples/a.json

kclvm/src/main.rs Outdated Show resolved Hide resolved
@He1pa He1pa force-pushed the unused_import_check branch 3 times, most recently from 78fee86 to 568be41 Compare August 16, 2022 05:58
@He1pa He1pa requested a review from Peefy August 16, 2022 06:47
Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

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

Important things:

  1. move lint.rs and lint_def.rs to the lint module
  2. re-org the lint module
  • lint.rs
  • lint_def.rs
  • macros.rs

kclvm/error/src/error.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/var.rs Show resolved Hide resolved
kclvm/sema/src/resolver/mod.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint_def.rs Outdated Show resolved Hide resolved
kclvm/sema/src/resolver/lint_def.rs Outdated Show resolved Hide resolved
@He1pa He1pa force-pushed the unused_import_check branch 2 times, most recently from 819a931 to f76f8a5 Compare August 16, 2022 10:23
1. Add warning level diagnotics, including 'UnusedImportWarning', 'ReimportWarning' and 'ImportPostionWarning'

2. Add 'lint_check_module' method to Resolver and is called in the 'check()' method.

3. Add KCL Lint stuct, For details see issue kcl-lang#109

fix kcl-lang#102, kcl-lang#109
@He1pa He1pa force-pushed the unused_import_check branch from f76f8a5 to ea28cc7 Compare August 16, 2022 10:26
@He1pa He1pa changed the title Refactor: Lint tool (Rust ver.) [WIP] Refactor: Lint tool (Rust ver.) Aug 16, 2022
@He1pa
Copy link
Contributor Author

He1pa commented Aug 16, 2022

This pr is being split into multiple sub-pr and will be closed when complete.

@Peefy
Copy link
Contributor

Peefy commented Aug 17, 2022

Split large WIP PRs into smaller ones

@Peefy Peefy closed this Aug 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request error-handling Issues or PRs related to kcl error handling feat resolver tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Reimport and Unusedimport check in Resolver::import
4 participants