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

Go Cleanup Built-in Rules #265

Merged
merged 56 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
872687c
Pointing to modified Go grammar for now
dvmarcilio Nov 4, 2022
fb8e013
Go: Initial boolean_expression_simplify rules
dvmarcilio Nov 6, 2022
bf726c1
Unary_expression has "hidden" field `operator`
dvmarcilio Nov 6, 2022
3833c4e
Go: simplify {true|false}_and_something...
dvmarcilio Nov 6, 2022
769ba90
Go: simplify {true|false} or something...
dvmarcilio Nov 6, 2022
fee496d
Go: converging to a standard rule formatting
dvmarcilio Nov 7, 2022
8acc48d
Go: if_cleanup && remove_unneccessary_nested_block
dvmarcilio Nov 7, 2022
215f11d
Go: TODO comment to address if w/ short stmt
dvmarcilio Nov 7, 2022
3e4e10f
Go: temp start for delete_short_v_decl
dvmarcilio Nov 7, 2022
b2b0674
'delete_immediate_if_err' working. clean rules/edges/scope later
dvmarcilio Nov 10, 2022
f4d9bac
replace_double_short_var_decl working!
dvmarcilio Nov 10, 2022
51500e1
delete_variable_declaration
dvmarcilio Nov 10, 2022
eb85d56
One intra cleanup scenario working!
dvmarcilio Nov 10, 2022
6cb92ed
Merging two rules into one
dvmarcilio Nov 10, 2022
a9530c5
Fix hole; Scope Function -> Function-Method
dvmarcilio Nov 10, 2022
8e85e59
Adding graph for current built-in rules
dvmarcilio Nov 10, 2022
e086048
Go: constant same file
dvmarcilio Nov 11, 2022
6875fbb
delete_bool_blank_identifier_short_var_declaration
dvmarcilio Nov 11, 2022
dbc86f7
Go: Removing unused param used in call
dvmarcilio Nov 14, 2022
93d0bf2
Go: delete_all_statements_after_return
dvmarcilio Nov 16, 2022
02200fa
Simplifying identity equality and inequality for {true|false|nil}
dvmarcilio Nov 16, 2022
9c89491
Go: Cleanup rules work for single short var decl
dvmarcilio Nov 16, 2022
a0435b5
delete_variable_declaration needs a constraint!
dvmarcilio Nov 17, 2022
c5de253
replace_identifier_with_value needs a constraint
dvmarcilio Nov 17, 2022
d4249aa
More meaningful names for identity rules
dvmarcilio Nov 18, 2022
e7276bc
Moving Go tests
dvmarcilio Nov 18, 2022
fcf2633
Go `delete_statement_after_return` self-edge
dvmarcilio Nov 18, 2022
de9ad4c
Removing outdated image
dvmarcilio Nov 18, 2022
0cefd06
--ignore-parser-error option. (rebased so this commit is very weird)
dvmarcilio Nov 18, 2022
ec97026
Reverting ignore_parse_error arg (rebased; commit is weird)
dvmarcilio Dec 1, 2022
5ccc4b1
Initial cleanup of go rules
dvmarcilio Dec 1, 2022
a6255e2
Go simplify_identity: wildcard for lhs and rhs
dvmarcilio Dec 1, 2022
d049ed8
Go: test for simplify if false with no alternative
dvmarcilio Dec 1, 2022
8a24525
Removing `.`s from delete_parent_assignment
dvmarcilio Dec 1, 2022
fcb1c48
`*` and `+` rules with `\n` terminator
dvmarcilio Dec 2, 2022
9439bca
Go grammar: branch on Uber tree-sitter-go repo
dvmarcilio Dec 7, 2022
533a1be
`return_cleanup` <-> `delete_stmt_after_return`
dvmarcilio Dec 7, 2022
8dba1a2
Go: removing `*` from `lhs|rhs` captures
dvmarcilio Dec 7, 2022
e2c14ec
constraint for `replace_identifier_with_value`
dvmarcilio Dec 7, 2022
7dbde04
`simplify_something_or_true` excluding calls
dvmarcilio Dec 7, 2022
2fbd662
`simplify_something_and_false` excluding calls
dvmarcilio Dec 7, 2022
5224867
Removing 'delete_parent_assignment' !
dvmarcilio Dec 7, 2022
189990c
Adding Go in PiranhaLanguage
dvmarcilio Dec 7, 2022
171d4dc
dummy 'return_cleanup' -> 'return_statement_cleanup
dvmarcilio Dec 8, 2022
7759e90
Simplifying rules for test "const_same_file"
dvmarcilio Dec 11, 2022
fb72b1f
`const_same_file` tests following conventions
dvmarcilio Dec 11, 2022
9e8faf3
Removing empty edges.toml
dvmarcilio Dec 11, 2022
67b509a
test_piranha_go: Adding needed import
dvmarcilio Dec 14, 2022
1f93f33
Using treated/treated_complement as arguments in test
dvmarcilio Dec 14, 2022
8cbbe3c
Fix .toml formatting
dvmarcilio Dec 18, 2022
0a1d8da
cleaning `remove_unnecessary_nested_block`
dvmarcilio Dec 18, 2022
bea7f6f
Cleaning `delete_statement_after_return`
dvmarcilio Dec 18, 2022
4ce2547
add missing license
dvmarcilio Dec 18, 2022
2b584aa
README: checkmarks for Go
dvmarcilio Dec 19, 2022
c8f9942
TODO on Cargo.toml to change tree-sitter-go dependency
dvmarcilio Dec 19, 2022
f0b1f55
Merge branch 'master' into go_develop
dvmarcilio Dec 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions polyglot/piranha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ tree-sitter-java = { git = "https://github.com/tree-sitter/tree-sitter-java.git"
tree-sitter-swift = { git = "https://github.com/ketkarameya/tree-sitter-swift.git", branch = "add_parser" }
tree-sitter-strings = { git = "https://github.com/ketkarameya/tree-sitter-strings.git" }
tree-sitter-python = { git = "https://github.com/tree-sitter/tree-sitter-python.git" }
tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go.git" }
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript.git" }
# TODO: tree-sitter-go should be changed either to upstream or Uber main branch
tree-sitter-go = { git = "https://github.com/uber/tree-sitter-go.git", branch = "expose_statement_list" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on our discussion, we don't need this grammar change right? Maybe we can point to main tree-sitter-go then

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 need the change to match all the contents of a block—without braces { }—in a single pass.

In principle, we could use (_)*; but then we run into the problem of multiple single-line matches (similar to #284).
For a rule such as remove_unnecessary_nested_block, replace would consider only the first match.

derive_builder = "0.11.2"
getset = "0.1.2"
pyo3 = "0.17.1"
Expand All @@ -54,4 +55,3 @@ pyo3-log = "0.7.0"
[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

128 changes: 64 additions & 64 deletions polyglot/piranha/README.md

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions polyglot/piranha/images/go_builtin_rules.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions polyglot/piranha/src/cleanup_rules/go/edges.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (c) 2022 Uber Technologies, Inc.
#
# <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of the License at
# <p>http://www.apache.org/licenses/LICENSE-2.0
#
# <p>Unless required by applicable law or agreed to in writing, software distributed under the
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing permissions and
# limitations under the License.

# The language specific rules in this file are applied after the API specific change has been performed.

# The edges in this file specify the flow between the rules.

[[edges]]
scope = "Parent"
from = "replace_expression_with_boolean_literal"
to = [
"boolean_literal_cleanup",
"statement_cleanup",
]

### boolean_literal_cleanup
[[edges]]
scope = "Parent"
from = "boolean_literal_cleanup"
to = [
"boolean_expression_simplify",
"statement_cleanup",
]

[[edges]]
scope = "Parent"
from = "boolean_expression_simplify"
to = ["boolean_literal_cleanup"]

[[edges]]
scope = "Parent"
from = "statement_cleanup"
to = ["if_cleanup"]

### statement_cleanup
[[edges]]
scope = "Function-Method"
from = "statement_cleanup"
to = ["delete_variable_declaration"]

[[edges]]
scope = "Function-Method"
from = "delete_variable_declaration"
to = ["replace_identifier_with_value"]

[[edges]]
scope = "Parent"
from = "replace_identifier_with_value"
to = ["boolean_literal_cleanup"]


### if_cleanup
[[edges]]
scope = "Parent"
from = "if_cleanup"
to = ["remove_unnecessary_nested_block"]

[[edges]]
scope = "Parent"
from = "remove_unnecessary_nested_block"
to = ["return_statement_cleanup"]

# Cycle to circumvent `delete_statement_after_return` only removing one match at a time
[[edges]]
scope = "Parent"
from = "return_statement_cleanup"
to = ["delete_statement_after_return"]

[[edges]]
scope = "Parent"
from = "delete_statement_after_return"
to = ["return_statement_cleanup"]
Loading