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

linter, executor: fix the constructor linter and add it to BaseExecutor/BaseExecutorV2 #56485

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

YangKeao
Copy link
Member

@YangKeao YangKeao commented Oct 8, 2024

What problem does this PR solve?

Issue Number: close #56484

Problem Summary:

What changed and how does it work?

  1. This PR adds the constructor annotation to the struct BaseExecutor/BaseExecutorV2 to avoid constructing the struct unexpectedly.
  2. This PR fixes the invalid constructor linter, and correct some behaviors.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

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

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 8, 2024
@YangKeao YangKeao requested review from lcwangchao and yibin87 October 8, 2024 15:46
@@ -276,6 +277,8 @@ func newExecutorKillerHandler(handler signalHandler) executorKillerHandler {

// BaseExecutorV2 is a simplified version of `BaseExecutor`, which doesn't contain a full session context
type BaseExecutorV2 struct {
_ constructor.Constructor `ctor:"NewBaseExecutorV2,BuildNewBaseExecutorV2"`
Copy link
Member Author

Choose a reason for hiding this comment

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

@yibin87 PTAL. It can guarantee that BaseExecutorV2 will not be manually initialized except in NewBaseExecutorV2 and BuildNewBaseExecutorV2.

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 75.6763%. Comparing base (7daf026) to head (5c052a9).
Report is 28 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #56485        +/-   ##
================================================
+ Coverage   73.3685%   75.6763%   +2.3078%     
================================================
  Files          1624       1648        +24     
  Lines        448117     462949     +14832     
================================================
+ Hits         328777     350343     +21566     
+ Misses        99198      91374      -7824     
- Partials      20142      21232      +1090     
Flag Coverage Δ
integration 50.9497% <66.6666%> (?)
unit 73.0244% <88.8888%> (+0.5636%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9478% <ø> (ø)
parser ∅ <ø> (∅)
br 52.0099% <ø> (+6.4969%) ⬆️

Copy link
Contributor

@yibin87 yibin87 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 9, 2024
@YangKeao YangKeao force-pushed the fix-constructor-linter branch from aaf1b81 to 1ca5990 Compare October 9, 2024 06:27
@YangKeao YangKeao force-pushed the fix-constructor-linter branch from 1ca5990 to 5c052a9 Compare October 9, 2024 06:36
@@ -82,7 +90,7 @@ func getConstructorList(t types.Type) []string {
}

if fieldStruct, ok := named.Underlying().(*types.Struct); ok {
ctors = append(ctors, getConstructorList(fieldStruct)...)
ctors = append(ctors, getConstructorList(fieldStruct, nil)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let me clarify. In this PR you added ignoreFields to getConstructorList to skip some fields when recursively process struct. And I think this line is the cause of recursively processing struct. We don't need this line because WithStack still access the member of struct. Can we delete this line and delete the ignoreFields logic of getConstructorList?

Copy link
Member Author

Choose a reason for hiding this comment

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

getConstructorList should be called recursively to avoid implicitly constructing the embedded structs:

type A struct { _ constructor.Constructor `ctor:"NewA"`}
type B struct {A}
type C struct {B}

var c C

The var c C is not allowed, because it will implicitly create a A outside of its constructor. The WithStack can do nothing for it as it doesn't appear in the AST.

The ignoreFields is added in this PR to allow this situation:

func XFunc() {
    b := B {
        A: NewA()
    }
}

Preivously, the getConstructorList() of B will return NewA, and linter will give an error because it's constructed in XFunc. However, it should be allowed as the A is actually not constructed in XFunc, but in NewA.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 9, 2024
Copy link

ti-chi-bot bot commented Oct 9, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-09 03:52:49.812384383 +0000 UTC m=+1018125.232597391: ☑️ agreed by yibin87.
  • 2024-10-09 14:09:22.21797192 +0000 UTC m=+1055117.638184931: ☑️ agreed by lance6716.

@lance6716
Copy link
Contributor

/retest

Copy link

ti-chi-bot bot commented Oct 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, lance6716, yibin87

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Oct 10, 2024
@ti-chi-bot ti-chi-bot bot merged commit ffcfb5e into pingcap:master Oct 10, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix the constructor linter
4 participants