Skip to content

Commit

Permalink
Merge pull request numba#65 from kc611/pre_commit
Browse files Browse the repository at this point in the history
Added pre commit configuration
  • Loading branch information
esc authored Jun 22, 2023
2 parents 5cc6853 + 0da13a0 commit 6f20097
Show file tree
Hide file tree
Showing 19 changed files with 608 additions and 352 deletions.
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
exclude: |
(?x)^(
docs/.*
)$
repos:
# Checks for debug statements and merge conflicts
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: debug-statements
- id: check-merge-conflict
# Pyupgrade: upgrades older python syntax to newer one
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py38-plus"]
# Black
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3
args: ["--line-length=79"]
# Autoflake: removes unused imports and variables
- repo: https://github.com/humitos/mirrors-autoflake.git
rev: v1.1
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
# Manual Linting: Flake 8
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
# Static Type checking: MyPy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
hooks:
- id: mypy
additional_dependencies:
- types-filelock
- types-setuptools
30 changes: 14 additions & 16 deletions numba_rvsdg/core/datastructures/basic_block.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dis
from collections import ChainMap
from typing import Tuple, Dict, List
from dataclasses import dataclass, field, replace
from dataclasses import dataclass, replace

from numba_rvsdg.core.utils import _next_inst_offset

Expand Down Expand Up @@ -202,35 +201,35 @@ class SyntheticBlock(BasicBlock):
"""The SyntheticBlock represents a artificially added block in a
structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticExit(SyntheticBlock):
"""The SyntheticExit class represents a artificially added exit block
in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticReturn(SyntheticBlock):
"""The SyntheticReturn class represents a artificially added return block
in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticTail(SyntheticBlock):
"""The SyntheticTail class represents a artificially added tail block
in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticFill(SyntheticBlock):
"""The SyntheticFill class represents a artificially added fill block
in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticAssignment(SyntheticBlock):
Expand All @@ -247,6 +246,7 @@ class SyntheticAssignment(SyntheticBlock):
the variable name to the value that is is assigned when
the block is executed.
"""

variable_assignment: dict = None


Expand All @@ -264,6 +264,7 @@ class SyntheticBranch(SyntheticBlock):
The value table maps variable values to the repective jump target
to be executed on the basis of that value.
"""

variable: str = None
branch_value_table: dict = None

Expand Down Expand Up @@ -320,23 +321,20 @@ class SyntheticHead(SyntheticBranch):
"""The SyntheticHead class represents a artificially added head block
in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticExitingLatch(SyntheticBranch):
"""The SyntheticExitingLatch class represents a artificially added exiting latch
block in a structured control flow graph (SCFG).
"""The SyntheticExitingLatch class represents a artificially added
exiting latch block in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
class SyntheticExitBranch(SyntheticBranch):
"""The SyntheticExitBranch class represents a artificially added exit branch
block in a structured control flow graph (SCFG).
"""The SyntheticExitBranch class represents a artificially added
exit branch block in a structured control flow graph (SCFG).
"""
pass


@dataclass(frozen=True)
Expand Down Expand Up @@ -364,7 +362,7 @@ class RegionBlock(BasicBlock):
kind: str = None
parent_region: "RegionBlock" = None
header: str = None
subregion: "SCFG" = None
subregion: "SCFG" = None # noqa
exiting: str = None

def replace_header(self, new_header):
Expand All @@ -384,5 +382,5 @@ def replace_exiting(self, new_exiting):
----------
new_exiting: str
The new exiting block of the region represented by the RegionBlock.
"""
"""
object.__setattr__(self, "exiting", new_exiting)
1 change: 0 additions & 1 deletion numba_rvsdg/core/datastructures/block_names.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

BASIC = "basic"

PYTHON_BYTECODE = "python_bytecode"
Expand Down
13 changes: 8 additions & 5 deletions numba_rvsdg/core/datastructures/byte_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from numba_rvsdg.core.datastructures.flow_info import FlowInfo
from numba_rvsdg.core.utils import _logger, _LogWrap

from numba_rvsdg.core.transformations import restructure_loop, restructure_branch
from numba_rvsdg.core.transformations import (
restructure_loop,
restructure_branch,
)


@dataclass(frozen=True)
Expand Down Expand Up @@ -97,10 +100,10 @@ def _restructure_loop(self):
def _restructure_branch(self):
"""Restructures the branches within the corresponding SCFG.
Creates a deep copy of the SCFG and performs the operation to
restructure branch constructs within the control flow. It applies
the restructuring operation to both the main SCFG and any
subregions within it. It returns a new ByteFlow object with
Creates a deep copy of the SCFG and performs the operation to
restructure branch constructs within the control flow. It applies
the restructuring operation to both the main SCFG and any
subregions within it. It returns a new ByteFlow object with
the updated SCFG.
Returns
Expand Down
7 changes: 4 additions & 3 deletions numba_rvsdg/core/datastructures/flow_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ def build_basicblocks(self: "FlowInfo", end_offset=None) -> "SCFG":
scfg = SCFG()
offsets = sorted(self.block_offsets)
# enumerate names
names = dict(
(offset, scfg.name_gen.new_block_name(block_names.PYTHON_BYTECODE)) for offset in offsets
)
names = {
offset: scfg.name_gen.new_block_name(block_names.PYTHON_BYTECODE)
for offset in offsets
}
if end_offset is None:
end_offset = _next_inst_offset(self.last_offset)

Expand Down
Loading

0 comments on commit 6f20097

Please sign in to comment.