Skip to content

Commit

Permalink
Merge pull request #293 from OpShin/fix/deepcopy
Browse files Browse the repository at this point in the history
Copy in right places to avoid reference capturing
  • Loading branch information
nielstron authored Dec 14, 2023
2 parents 4d91970 + efab329 commit 31c59f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions opshin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ def perform_command(args):
script_arts = PlutusContract(
built_code,
datum_type=onchain_params[0] if len(onchain_params) == 3 else None,
redeemer_type=onchain_params[1]
if len(onchain_params) == 3
else onchain_params[0],
redeemer_type=onchain_params[1 if len(onchain_params) == 3 else 0],
parameter_types=param_types,
purpose=(purpose,),
)
Expand Down
4 changes: 3 additions & 1 deletion opshin/rewrite/rewrite_inject_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def visit_Module(self, node: TypedModule) -> TypedModule:
additional_assigns.append(
TypedAssign(
targets=[TypedName(id=b.name, typ=typ, ctx=Store())],
value=RawPlutoExpr(typ=typ, expr=plt.Lambda(["_"], b.value)),
value=RawPlutoExpr(
typ=typ, expr=plt.Lambda(["_"], deepcopy(b.value))
),
)
)
md = copy(node)
Expand Down
6 changes: 4 additions & 2 deletions opshin/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import copy, deepcopy

import typing

import ast
Expand Down Expand Up @@ -154,12 +156,12 @@ def make_pattern(structure: plt.AST) -> plt.Pattern:
AdHocPattern = type(
f"AdHocPattern_{sha256(structure_serialized.encode()).digest().hex()}",
(plt.Pattern,),
{"compose": lambda self: structure},
{"compose": lambda self: deepcopy(structure)},
)
AdHocPattern = dataclass(AdHocPattern)

_patterns_cached[structure_serialized] = AdHocPattern()
return _patterns_cached[structure_serialized]
return deepcopy(_patterns_cached[structure_serialized])


def patternize(method):
Expand Down

0 comments on commit 31c59f8

Please sign in to comment.