Feature: Variable usage checker #159

Closed
opened 2023-11-03 19:27:57 +00:00 by deavmi · 19 comments
Owner

What is this?

We can add a component to the dependency generator which tracks the usage of variables. We can then call something like touch(Varable) whenever one is referenced.

This can then increment an entry in a hashmap.

For the quickest implementation for then comparing we should touch(Variable) on declaration as well and not just reference. Therefore we have them all in the hashmap and can find all 0 count ones, (or well, 1 count actually). Anything with a count of 1 is then unused and we can warn the user about this.

Todo

  • Add hit count mechanism with touch(Variable)
  • Whenever a variable is referenced, whereever, add code to call touch(Variable)
  • Have a method which collects all 1-count variables and then returns them as an array of string[] for their identifiers
  • Compiler integration to print these out at some stage

Tests

  • Add a unittest for this, can be very basic

Documentation

  • Document the option typecheck:warnUnusedVars
## What is this? We can add a component to the dependency generator which tracks the usage of variables. We can then call something like `touch(Varable)` whenever one is referenced. This can then increment an entry in a hashmap. For the quickest implementation for then comparing we should `touch(Variable)` on **declaration** as well and **not just** reference. Therefore we have them all in the hashmap and can find all `0` count ones, (or well, `1` count actually). Anything with a count of `1` is then unused and we can warn the user about this. ## Todo - [x] Add hit count mechanism with `touch(Variable)` - [x] Whenever a variable is referenced, whereever, add code to call `touch(Variable)` - [x] Have a method which collects all `1`-count variables and then returns them as an array of `string[]` for their identifiers - [x] Compiler integration to print these out at some stage ### Tests - [x] Add a unittest for this, can be very basic ### Documentation - [x] Document the option `typecheck:warnUnusedVars`
deavmi changed title from ### Ideation: Variable usage checker to 🧠 Ideation: Variable usage checker 2023-11-03 19:28:09 +00:00
deavmi added this to the Dependency tree, type-checking and codegen project 2023-11-03 19:28:14 +00:00
deavmi self-assigned this 2023-11-03 19:28:16 +00:00
deavmi added the due date 2023-11-07 2023-11-03 19:28:24 +00:00
deavmi added reference vardec_varass_dependency 2023-11-03 19:28:28 +00:00
deavmi added the
dependency
question
labels 2023-11-03 19:28:38 +00:00
deavmi added spent time 2023-11-03 19:55:17 +00:00
10 minutes
deavmi started working 2023-11-03 19:55:20 +00:00
deavmi changed reference from vardec_varass_dependency to feature/unused_vars_detection 2023-11-03 20:16:36 +00:00
deavmi stopped working 2023-11-03 20:19:20 +00:00
24 minutes
deavmi started working 2023-11-03 20:19:25 +00:00
Author
Owner

Got most of it done, the API and the usage of touch(Variable) where it needs to be.

Got most of it done, the API **and** the usage of `touch(Variable)` where it needs to be.
deavmi stopped working 2023-11-03 20:19:43 +00:00
18 seconds
deavmi added spent time 2023-11-03 21:17:39 +00:00
5 minutes
deavmi started working 2023-11-03 21:17:42 +00:00
Author
Owner

Added a check in dependencyCheck() for unused variables and prints them out

Added a check in `dependencyCheck()` for unused variables and prints them out
deavmi stopped working 2023-11-03 21:37:11 +00:00
19 minutes 29 seconds
deavmi started working 2023-11-03 22:51:04 +00:00
Author
Owner

Let's gooo!

image

Let's gooo! ![image](/attachments/f068c43f-eccc-49aa-a539-3a3609a6163c)
232 KiB
deavmi stopped working 2023-11-03 22:51:51 +00:00
47 seconds
deavmi started working 2023-11-04 10:30:23 +00:00
Author
Owner

I think where we print it out, or run through the check is important. That or I have yet to touch(Variable) in the following case:

module unused_vars;

int j;

void thing()
{
    j = 1;
}

As this reports 1 unused variable, but that is NOT true.

I think where we print it out, or run through the check is important. That **or** I have yet to `touch(Variable)` in the following case: ```d module unused_vars; int j; void thing() { j = 1; } ``` As this reports 1 unused variable, but that is **NOT** true.
Author
Owner

I think where we print it out, or run through the check is important. That or I have yet to touch(Variable) in the following case:

module unused_vars;

int j;

void thing()
{
    j = 1;
}

As this reports 1 unused variable, but that is NOT true.

I think I am doing this stuff too early?

> I think where we print it out, or run through the check is important. That **or** I have yet to `touch(Variable)` in the following case: > > ```d > module unused_vars; > > int j; > > void thing() > { > j = 1; > } > ``` > > As this reports 1 unused variable, but that is **NOT** true. I think I am doing this stuff too early?
Author
Owner

I think where we print it out, or run through the check is important. That or I have yet to touch(Variable) in the following case:

module unused_vars;

int j;

void thing()
{
    j = 1;
}

As this reports 1 unused variable, but that is NOT true.

I think I am doing this stuff too early?

Problem demystified 🔎

I found it, we use a seperate DNodeGenerator for the functions. We need some over-arching mechanism to group these altogether. Perhaps, placing the touching mechanism in the TypeChecker as a place-of-precense that both seperate instances of DNodeGenerator can then touch on.

> > I think where we print it out, or run through the check is important. That **or** I have yet to `touch(Variable)` in the following case: > > > > ```d > > module unused_vars; > > > > int j; > > > > void thing() > > { > > j = 1; > > } > > ``` > > > > As this reports 1 unused variable, but that is **NOT** true. > > I think I am doing this stuff too early? ## Problem demystified 🔎 I found it, we use a seperate `DNodeGenerator` for the functions. We need some over-arching mechanism to group these altogether. Perhaps, placing the touching mechanism in the `TypeChecker` as a place-of-precense that both seperate instances of `DNodeGenerator` can then touch on.
deavmi stopped working 2023-11-04 11:02:42 +00:00
32 minutes 19 seconds
deavmi added spent time 2023-11-04 11:10:52 +00:00
10 minutes
deavmi started working 2023-11-04 11:10:54 +00:00
Author
Owner

I think where we print it out, or run through the check is important. That or I have yet to touch(Variable) in the following case:

module unused_vars;

int j;

void thing()
{
    j = 1;
}

As this reports 1 unused variable, but that is NOT true.

I think I am doing this stuff too early?

Problem demystified 🔎

I found it, we use a seperate DNodeGenerator for the functions. We need some over-arching mechanism to group these altogether. Perhaps, placing the touching mechanism in the TypeChecker as a place-of-precense that both seperate instances of DNodeGenerator can then touch on.

I got this implemented and it works!

image

> > > I think where we print it out, or run through the check is important. That **or** I have yet to `touch(Variable)` in the following case: > > > > > > ```d > > > module unused_vars; > > > > > > int j; > > > > > > void thing() > > > { > > > j = 1; > > > } > > > ``` > > > > > > As this reports 1 unused variable, but that is **NOT** true. > > > > I think I am doing this stuff too early? > > ## Problem demystified 🔎 > > I found it, we use a seperate `DNodeGenerator` for the functions. We need some over-arching mechanism to group these altogether. Perhaps, placing the touching mechanism in the `TypeChecker` as a place-of-precense that both seperate instances of `DNodeGenerator` can then touch on. > > I got this implemented and it works! ![image](/attachments/861d47fd-306a-4f1f-b595-9aaf306c1ce7)
Author
Owner

What is this?

We can add a component to the dependency generator which tracks the usage of variables. We can then call something like touch(Varable) whenever one is referenced.

This can then increment an entry in a hashmap.

For the quickest implementation for then comparing we should touch(Variable) on declaration as well and not just reference. Therefore we have them all in the hashmap and can find all 0 count ones, (or well, 1 count actually). Anything with a count of 1 is then unused and we can warn the user about this.

Todo

  • Add hit count mechanism with touch(Variable)
  • Whenever a variable is referenced, whereever, add code to call touch(Variable)
  • Have a method which collects all 1-count variables and then returns them as an array of string[] for their identifiers
  • Compiler integration to print these out at some stage

Tests

  • Add a unittest for this, can be very basic

Documentation

  • Document the option typecheck:warnUnusedVars

Compiler integration added with a config variable

> ## What is this? > > We can add a component to the dependency generator which tracks the usage of variables. We can then call something like `touch(Varable)` whenever one is referenced. > > This can then increment an entry in a hashmap. > > For the quickest implementation for then comparing we should `touch(Variable)` on **declaration** as well and **not just** reference. Therefore we have them all in the hashmap and can find all `0` count ones, (or well, `1` count actually). Anything with a count of `1` is then unused and we can warn the user about this. > > ## Todo > > - [x] Add hit count mechanism with `touch(Variable)` > - [x] Whenever a variable is referenced, whereever, add code to call `touch(Variable)` > - [x] Have a method which collects all `1`-count variables and then returns them as an array of `string[]` for their identifiers > - [ ] Compiler integration to print these out at some stage > > ### Tests > > - [ ] Add a unittest for this, can be very basic > > ### Documentation > > - [ ] Document the option `typecheck:warnUnusedVars` Compiler integration added with a config variable
deavmi stopped working 2023-11-04 11:58:06 +00:00
47 minutes 12 seconds
deavmi started working 2023-11-04 13:51:31 +00:00
deavmi removed the
question
label 2023-11-04 13:53:05 +00:00
deavmi changed title from 🧠 Ideation: Variable usage checker to Feature: Variable usage checker 2023-11-04 13:53:17 +00:00
deavmi stopped working 2023-11-04 13:53:27 +00:00
1 minute 57 seconds
deavmi started working 2023-11-04 20:56:22 +00:00
deavmi stopped working 2023-11-04 20:57:35 +00:00
1 minute 13 seconds
deavmi started working 2023-11-05 14:25:11 +00:00
Author
Owner

What is this?

We can add a component to the dependency generator which tracks the usage of variables. We can then call something like touch(Varable) whenever one is referenced.

This can then increment an entry in a hashmap.

For the quickest implementation for then comparing we should touch(Variable) on declaration as well and not just reference. Therefore we have them all in the hashmap and can find all 0 count ones, (or well, 1 count actually). Anything with a count of 1 is then unused and we can warn the user about this.

Todo

  • Add hit count mechanism with touch(Variable)
  • Whenever a variable is referenced, whereever, add code to call touch(Variable)
  • Have a method which collects all 1-count variables and then returns them as an array of string[] for their identifiers
  • Compiler integration to print these out at some stage

Tests

  • Add a unittest for this, can be very basic

Documentation

  • Document the option typecheck:warnUnusedVars

Unit tests now added

> ## What is this? > > We can add a component to the dependency generator which tracks the usage of variables. We can then call something like `touch(Varable)` whenever one is referenced. > > This can then increment an entry in a hashmap. > > For the quickest implementation for then comparing we should `touch(Variable)` on **declaration** as well and **not just** reference. Therefore we have them all in the hashmap and can find all `0` count ones, (or well, `1` count actually). Anything with a count of `1` is then unused and we can warn the user about this. > > ## Todo > > - [x] Add hit count mechanism with `touch(Variable)` > - [x] Whenever a variable is referenced, whereever, add code to call `touch(Variable)` > - [x] Have a method which collects all `1`-count variables and then returns them as an array of `string[]` for their identifiers > - [x] Compiler integration to print these out at some stage > > ### Tests > > - [ ] Add a unittest for this, can be very basic > > ### Documentation > > - [ ] Document the option `typecheck:warnUnusedVars` Unit tests now added ✅
deavmi stopped working 2023-11-05 14:38:13 +00:00
13 minutes 2 seconds
Author
Owner

What is this?

We can add a component to the dependency generator which tracks the usage of variables. We can then call something like touch(Varable) whenever one is referenced.

This can then increment an entry in a hashmap.

For the quickest implementation for then comparing we should touch(Variable) on declaration as well and not just reference. Therefore we have them all in the hashmap and can find all 0 count ones, (or well, 1 count actually). Anything with a count of 1 is then unused and we can warn the user about this.

Todo

  • Add hit count mechanism with touch(Variable)
  • Whenever a variable is referenced, whereever, add code to call touch(Variable)
  • Have a method which collects all 1-count variables and then returns them as an array of string[] for their identifiers
  • Compiler integration to print these out at some stage

Tests

  • Add a unittest for this, can be very basic

Documentation

  • Document the option typecheck:warnUnusedVars

Docs done

> ## What is this? > > We can add a component to the dependency generator which tracks the usage of variables. We can then call something like `touch(Varable)` whenever one is referenced. > > This can then increment an entry in a hashmap. > > For the quickest implementation for then comparing we should `touch(Variable)` on **declaration** as well and **not just** reference. Therefore we have them all in the hashmap and can find all `0` count ones, (or well, `1` count actually). Anything with a count of `1` is then unused and we can warn the user about this. > > ## Todo > > - [x] Add hit count mechanism with `touch(Variable)` > - [x] Whenever a variable is referenced, whereever, add code to call `touch(Variable)` > - [x] Have a method which collects all `1`-count variables and then returns them as an array of `string[]` for their identifiers > - [x] Compiler integration to print these out at some stage > > ### Tests > > - [x] Add a unittest for this, can be very basic > > ### Documentation > > - [ ] Document the option `typecheck:warnUnusedVars` Docs done
deavmi started working 2023-11-05 15:26:11 +00:00
Author
Owner

This is done, we should be able to merge soon.

This is done, we should be able to merge soon.
deavmi stopped working 2023-11-05 15:32:27 +00:00
6 minutes 16 seconds
deavmi added a new dependency 2023-11-05 15:36:34 +00:00
deavmi started working 2023-11-05 19:25:04 +00:00
Author
Owner

Added GitHub pipelines
Fixed warning message typo

Added GitHub pipelines ✅ Fixed warning message typo ✅
deavmi stopped working 2023-11-05 19:31:37 +00:00
6 minutes 33 seconds
deavmi added a new dependency 2023-11-06 09:38:26 +00:00
deavmi removed the due date 2023-11-07 2023-12-29 17:46:46 +00:00
deavmi added the due date 2024-02-29 2024-02-28 06:38:57 +00:00
deavmi modified the due date from 2024-02-29 to 2024-03-06 2024-02-28 06:39:18 +00:00
Author
Owner

I want to get this done-and-klaar tomorrow.

I want to get this done-and-klaar tomorrow.
deavmi removed the due date 2024-03-06 2024-03-31 21:08:34 +01:00
deavmi added the due date 2024-04-02 2024-03-31 21:08:39 +01:00
deavmi added this to the Performance and Clarity milestone 2024-04-01 20:01:07 +01:00
deavmi removed a dependency 2024-04-01 20:42:59 +01:00
Author
Owner

Not doing array referncing in this one, will do a seperate PR for that.

Not doing array referncing in this one, will do a seperate PR for that.
deavmi started working 2024-04-01 20:43:45 +01:00
Author
Owner

Merging...

Merging...
Author
Owner

Resolving a conmflict...

Resolving a conmflict...
Author
Owner

Resolving a conmflict...

Resolved

> Resolving a conmflict... Resolved ✅
Author
Owner

Actually resolved ... 🤡

Actually resolved ... 🤡
Author
Owner

Merged

Merged ✅
deavmi stopped working 2024-04-01 20:55:58 +01:00
12 minutes 13 seconds
Sign in to join this conversation.
No Assignees
1 Participants
Notifications
Total Time Spent: 3 hours 10 minutes
deavmi
3 hours 10 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2024-04-02

Reference: tlang/tlang#159
No description provided.