Skip to content

Commit e369af8

Browse files
Minor audit cleanups in dython transpiler and runtime
1 parent e2f1558 commit e369af8

17 files changed

Lines changed: 1142 additions & 654 deletions

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"alecthomas",
44
"allocid",
55
"amacneil",
6+
"asyncio",
67
"buildmode",
78
"BYTEA",
89
"chancreate",
@@ -11,6 +12,7 @@
1112
"cloc",
1213
"clocincludetests",
1314
"condn",
15+
"coro",
1416
"dataclass",
1517
"dbconn",
1618
"dbmate",
@@ -112,6 +114,7 @@
112114
"XDECREF"
113115
],
114116
"python.defaultInterpreterPath": "./.venv/bin/python",
117+
"mypy-type-checker.interpreter": ["./.venv/bin/python"],
115118
"python.terminal.activateEnvironment": false,
116119
"[json]": {
117120
"editor.defaultFormatter": "esbenp.prettier-vscode"

pkg/runtimes/dython/deepslate/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from deepslate.imports import pure, impure, block
2-
from deepslate.transpile import transpile_flow, flow
2+
from deepslate.transpile import flow
33
from deepslate.worker import spawn_workers, spawn_inspector, new_postgres
44
from deepslate.errors import DSError
55
from deepslate import dpslio
@@ -20,7 +20,6 @@
2020
"sleep",
2121
"json_marshal",
2222
"json_unmarshal",
23-
"transpile_flow",
2423
"flow",
2524
"pure",
2625
"impure",

pkg/runtimes/dython/deepslate/blocks.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
TriggerFunc = Callable[[Context, EventNotify], DSError | None]
3131

3232

33-
def get_return(ctx: Context, idx: int, tparam: type = object) -> Any:
34-
return ctx.get_var(f"__return_{idx}__", tparam)
33+
class ChanRef[T](str):
34+
pass
3535

3636

37-
class ChanRef[T](str):
37+
class WgRef(str):
3838
pass
3939

4040

41-
WgRef = str
42-
MutexRef = str
41+
class MutexRef(str):
42+
pass
4343

4444

4545
@dataclass
@@ -172,14 +172,14 @@ def impure_block(
172172
line: int,
173173
stmt: Callable[[Context], None],
174174
) -> AwaitBlock:
175-
def _trigger(ctx: Context, notify: EventNotify) -> None:
176-
stmt(ctx)
177-
178175
def _start(ctx: Context) -> Event:
179176
key = "impure-" + ctx.gen_key()
180177

181178
return CheckpointEvent(id=key)
182179

180+
def _trigger(ctx: Context, notify: EventNotify) -> None:
181+
stmt(ctx)
182+
183183
return await_block(line, _start, _trigger)
184184

185185

@@ -258,19 +258,23 @@ def _trigger(ctx: Context, notify: EventNotify) -> None:
258258
return await_block(line, _start, _trigger)
259259

260260

261+
def get_return(ctx: Context, idx: int, tparam: type = object) -> Any:
262+
return ctx.get_var(f"__return_{idx}__", tparam)
263+
264+
261265
def recv_any(
262266
line: int,
263267
count: int,
264268
ids: Callable[[Context], list[str]],
265-
ref: Callable[[Context, bytes, int], None],
269+
ret: Callable[[Context, bytes, int], tuple[None, None]],
266270
) -> AwaitBlock:
267271
def _make_future(idx: int) -> Future:
268272
def _start(ctx: Context) -> Event:
269273
return ChannelRecvEvent(id=ids(ctx)[idx])
270274

271275
def _trigger(ctx: Context, notify: EventNotify) -> None:
272276
if hasattr(notify, "value"):
273-
ref(ctx, notify.value, idx)
277+
ret(ctx, notify.value, idx)
274278

275279
return Future(start=_start, trigger=_trigger)
276280

pkg/runtimes/dython/deepslate/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Context:
1111
vars: dict[str, Any] = field(default_factory=dict)
1212
vars_ser: dict[str, bytes] = field(default_factory=dict)
1313

14-
def set_var(self, name: str, value: Any) -> None:
14+
def set_var(self, name: str, value: Any) -> Any:
1515
self.vars[name] = value
1616

1717
def get_var(self, name: str, tparam: type = object) -> Any:

pkg/runtimes/dython/deepslate/imports.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(
2323
) -> None:
2424
self._func = func
2525
self.metadata = metadata
26-
self.impl: Callable[..., Any] = impl if impl is not None else func
26+
self.impl = impl
2727

2828
self.__name__ = func.__name__
2929
self.__type_params__ = getattr(func, "__type_params__", ())
@@ -61,10 +61,9 @@ def decorator(stub_func: Callable[P, R]) -> DeepslateAnnotated[P, R]:
6161
return decorator
6262

6363

64-
def mark_program(func: Callable, impl: Callable | None = None) -> DeepslateAnnotated:
64+
def mark_program(func: Callable, impl: Callable) -> DeepslateAnnotated:
6565
meta = _non_block_func_metadata(func, FuncType.PROGRAM, allow_sync_primitives=True)
66-
actual = impl if impl is not None else func
67-
return DeepslateAnnotated(actual, meta, actual)
66+
return DeepslateAnnotated(impl, meta, impl)
6867

6968

7069
def _mark_pure[**P, R](func: Callable[P, R]) -> DeepslateAnnotated[P, R]:
@@ -108,8 +107,8 @@ def _non_block_func_metadata(
108107
def _block_func_metadata(impl_func: Callable, stub_func: Callable) -> FuncMetadata:
109108
impl_name = impl_func.__name__
110109
stub_name = stub_func.__name__
111-
stub_sig = inspect.signature(stub_func)
112110
impl_sig = inspect.signature(impl_func)
111+
stub_sig = inspect.signature(stub_func)
113112

114113
if _has_decorator(impl_func):
115114
return FuncMetadata(

0 commit comments

Comments
 (0)