Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 4 deletions src/trailmark/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
Annotation,
AnnotationKind,
AssetValue,
DeclaredContract,
EntrypointKind,
EntrypointTag,
TrustLevel,
TypeConstraint,
)
from trailmark.models.edges import CodeEdge, EdgeConfidence, EdgeKind
from trailmark.models.graph import CodeGraph
Expand All @@ -29,7 +27,6 @@
"CodeEdge",
"CodeGraph",
"CodeUnit",
"DeclaredContract",
"EdgeConfidence",
"EdgeKind",
"EntrypointKind",
Expand All @@ -38,6 +35,5 @@
"Parameter",
"SourceLocation",
"TrustLevel",
"TypeConstraint",
"TypeRef",
]
23 changes: 0 additions & 23 deletions src/trailmark/models/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,3 @@ class EntrypointTag:
trust_level: TrustLevel = TrustLevel.UNTRUSTED_EXTERNAL
description: str | None = None
asset_value: AssetValue = AssetValue.LOW


@dataclass(frozen=True)
class TypeConstraint:
"""A constraint on a parameter's type or value domain."""

parameter_name: str
declared_type: str | None = None
value_constraint: str | None = None


@dataclass(frozen=True)
class DeclaredContract:
"""What a function declares it accepts/returns.

Captured from type annotations, docstrings, assertions,
and explicit validation. Separate from effective input domain,
which is determined by graph reachability analysis.
"""

parameter_types: tuple[TypeConstraint, ...] = ()
return_constraint: str | None = None
validation_notes: tuple[str, ...] = ()
27 changes: 0 additions & 27 deletions src/trailmark/parsers/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
from pathlib import Path
from typing import TYPE_CHECKING

from trailmark.models.annotations import (
DeclaredContract,
TypeConstraint,
)
from trailmark.models.edges import CodeEdge, EdgeKind
from trailmark.models.graph import CodeGraph
from trailmark.models.nodes import (
BranchInfo,
CodeUnit,
NodeKind,
Parameter,
SourceLocation,
TypeRef,
)
Expand Down Expand Up @@ -207,28 +202,6 @@ def compute_complexity(branches: list[BranchInfo]) -> int:
return 1 + len(branches)


def build_contract(
params: list[Parameter],
return_type: TypeRef | None,
) -> DeclaredContract | None:
"""Build a DeclaredContract from extracted parameter types."""
constraints: list[TypeConstraint] = []
for p in params:
if p.type_ref is not None:
constraints.append(
TypeConstraint(
parameter_name=p.name,
declared_type=p.type_ref.name,
)
)
if not constraints and return_type is None:
return None
return DeclaredContract(
parameter_types=tuple(constraints),
return_constraint=return_type.name if return_type else None,
)


def add_module_node(
root: Node,
file_path: str,
Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/c/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
collect_body_info,
compute_complexity,
make_location,
Expand Down Expand Up @@ -231,7 +230,6 @@ def _extract_function(

complexity = compute_complexity(branches)
location = make_location(node, file_path)
contract = build_contract(params, return_type)
docstring = _extract_docstring(node)

unit = CodeUnit(
Expand All @@ -249,9 +247,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, module_id, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(calls, func_id, module_id, file_path, graph)


Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/cairo/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
collect_body_info,
compute_complexity,
make_location,
Expand Down Expand Up @@ -411,7 +410,6 @@ def _extract_function(

branches, exception_types, calls = _collect_func_body(body, file_path)
complexity = compute_complexity(branches)
contract = build_contract(params, return_type)
docstring = _extract_docstring(node)

unit = CodeUnit(
Expand All @@ -429,9 +427,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, owner, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(calls, func_id, module_id, container_id, file_path, graph)


Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/cpp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
collect_body_info,
compute_complexity,
make_location,
Expand Down Expand Up @@ -430,7 +429,6 @@ def _extract_function(

complexity = compute_complexity(branches)
location = make_location(node, file_path)
contract = build_contract(params, return_type)
docstring = _extract_docstring(node)

unit = CodeUnit(
Expand All @@ -448,9 +446,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, container_id, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/csharp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
compute_complexity,
make_location,
module_id_from_path,
Expand Down Expand Up @@ -303,10 +302,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, container_id, func_id)

contract = build_contract(params, return_type)
if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/erlang/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
compute_complexity,
make_location,
module_id_from_path,
Expand Down Expand Up @@ -164,7 +163,6 @@ def _create_function_node(
calls = _collect_calls(clause)
exception_types = _collect_exceptions(calls)
complexity = compute_complexity(branches)
contract = build_contract(params, return_type)
docstring = _extract_docstring(clause)

unit = CodeUnit(
Expand All @@ -183,9 +181,6 @@ def _create_function_node(
add_contains_edge(graph, module_id, func_id)
seen_funcs[name] = func_id

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(calls, func_id, module_id, file_path, graph)


Expand Down
9 changes: 0 additions & 9 deletions src/trailmark/parsers/go/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
collect_body_info,
compute_complexity,
make_location,
Expand Down Expand Up @@ -196,7 +195,6 @@ def _extract_function(
file_path,
)
complexity = compute_complexity(branches)
contract = build_contract(params, return_type)
docstring = _extract_docstring(node)

unit = CodeUnit(
Expand All @@ -214,9 +212,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, module_id, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down Expand Up @@ -252,7 +247,6 @@ def _extract_method(
file_path,
)
complexity = compute_complexity(branches)
contract = build_contract(params, return_type)
docstring = _extract_docstring(node)

unit = CodeUnit(
Expand All @@ -270,9 +264,6 @@ def _extract_method(
graph.nodes[method_id] = unit
add_contains_edge(graph, type_id, method_id)

if contract is not None:
graph.annotations.setdefault(method_id, [])

_add_call_edges(
calls,
method_id,
Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/haskell/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
compute_complexity,
make_location,
module_id_from_path,
Expand Down Expand Up @@ -339,7 +338,6 @@ def _create_function_node(
branches = _collect_branches(node, file_path)
calls = _collect_calls(node)
complexity = compute_complexity(branches)
contract = build_contract(params, return_type)
docstring = _extract_docstring(node)

unit = CodeUnit(
Expand All @@ -358,9 +356,6 @@ def _create_function_node(
add_contains_edge(graph, owner, func_id)
seen_funcs[name] = func_id

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(calls, func_id, module_id, container_id, file_path, graph)


Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/java/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
compute_complexity,
make_location,
module_id_from_path,
Expand Down Expand Up @@ -269,10 +268,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, container_id, func_id)

contract = build_contract(params, return_type)
if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down
9 changes: 0 additions & 9 deletions src/trailmark/parsers/javascript/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
collect_body_info,
compute_complexity,
make_location,
Expand Down Expand Up @@ -233,7 +232,6 @@ def _extract_function_expr(

complexity = compute_complexity(branches)
location = make_location(func_node, file_path)
contract = build_contract(params, None)

unit = CodeUnit(
id=func_id,
Expand All @@ -249,9 +247,6 @@ def _extract_function_expr(
graph.nodes[func_id] = unit
add_contains_edge(graph, module_id, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down Expand Up @@ -443,7 +438,6 @@ def _extract_function(

complexity = compute_complexity(branches)
location = make_location(node, file_path)
contract = build_contract(params, None)

unit = CodeUnit(
id=func_id,
Expand All @@ -459,9 +453,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, container_id, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down
5 changes: 0 additions & 5 deletions src/trailmark/parsers/php/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from trailmark.parsers._common import (
add_contains_edge,
add_module_node,
build_contract,
compute_complexity,
make_location,
module_id_from_path,
Expand Down Expand Up @@ -294,7 +293,6 @@ def _extract_function(

complexity = compute_complexity(branches)
location = make_location(node, file_path)
contract = build_contract(params, return_type)

unit = CodeUnit(
id=func_id,
Expand All @@ -311,9 +309,6 @@ def _extract_function(
graph.nodes[func_id] = unit
add_contains_edge(graph, container_id, func_id)

if contract is not None:
graph.annotations.setdefault(func_id, [])

_add_call_edges(
calls,
func_id,
Expand Down
Loading
Loading