Skip to content

Commit 136ab73

Browse files
Bump egglog version which adds span tracking
1 parent 448056f commit 136ab73

File tree

11 files changed

+325
-205
lines changed

11 files changed

+325
-205
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/egglog/bindings.pyi

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class EGraph:
3232
record: bool = False,
3333
) -> None: ...
3434
def commands(self) -> str | None: ...
35-
def parse_program(self, __input: str, /) -> list[_Command]: ...
35+
def parse_program(self, __input: str, /, filename: str | None = None) -> list[_Command]: ...
3636
def run_program(self, *commands: _Command) -> list[str]: ...
3737
def extract_report(self) -> _ExtractReport | None: ...
3838
def run_report(self) -> RunReport | None: ...
@@ -56,6 +56,25 @@ class EGraph:
5656
class EggSmolError(Exception):
5757
context: str
5858

59+
##
60+
# Spans
61+
##
62+
63+
@final
64+
class SrcFile:
65+
def __init__(self, name: str, contents: str | None = None) -> None: ...
66+
name: str
67+
contents: str | None
68+
69+
@final
70+
class Span:
71+
def __init__(self, file: SrcFile, start: int, end: int) -> None: ...
72+
file: SrcFile
73+
start: int
74+
end: int
75+
76+
DUMMY_SPAN: Span = ...
77+
5978
##
6079
# Literals
6180
##
@@ -92,17 +111,20 @@ _Literal: TypeAlias = Int | F64 | String | Bool | Unit
92111

93112
@final
94113
class Lit:
95-
def __init__(self, value: _Literal) -> None: ...
114+
def __init__(self, span: Span, value: _Literal) -> None: ...
115+
span: Span
96116
value: _Literal
97117

98118
@final
99119
class Var:
100-
def __init__(self, name: str) -> None: ...
120+
def __init__(self, span: Span, name: str) -> None: ...
121+
span: Span
101122
name: str
102123

103124
@final
104125
class Call:
105-
def __init__(self, name: str, args: list[_Expr]) -> None: ...
126+
def __init__(self, span: Span, name: str, args: list[_Expr]) -> None: ...
127+
span: Span
106128
name: str
107129
args: list[_Expr]
108130

@@ -142,7 +164,8 @@ class TermDag:
142164

143165
@final
144166
class Eq:
145-
def __init__(self, exprs: list[_Expr]) -> None: ...
167+
def __init__(self, span: Span, exprs: list[_Expr]) -> None: ...
168+
span: Span
146169
exprs: list[_Expr]
147170

148171
@final
@@ -172,43 +195,50 @@ _Change: TypeAlias = Delete | Subsume
172195

173196
@final
174197
class Let:
175-
def __init__(self, lhs: str, rhs: _Expr) -> None: ...
198+
def __init__(self, span: Span, lhs: str, rhs: _Expr) -> None: ...
199+
span: Span
176200
lhs: str
177201
rhs: _Expr
178202

179203
@final
180204
class Set:
181-
def __init__(self, lhs: str, args: list[_Expr], rhs: _Expr) -> None: ...
205+
def __init__(self, span: Span, lhs: str, args: list[_Expr], rhs: _Expr) -> None: ...
206+
span: Span
182207
lhs: str
183208
args: list[_Expr]
184209
rhs: _Expr
185210

186211
@final
187212
class Change:
213+
span: Span
188214
change: _Change
189215
sym: str
190216
args: list[_Expr]
191-
def __init__(self, change: _Change, sym: str, args: list[_Expr]) -> None: ...
217+
def __init__(self, span: Span, change: _Change, sym: str, args: list[_Expr]) -> None: ...
192218

193219
@final
194220
class Union:
195-
def __init__(self, lhs: _Expr, rhs: _Expr) -> None: ...
221+
def __init__(self, span: Span, lhs: _Expr, rhs: _Expr) -> None: ...
222+
span: Span
196223
lhs: _Expr
197224
rhs: _Expr
198225

199226
@final
200227
class Panic:
201-
def __init__(self, msg: str) -> None: ...
228+
def __init__(self, span: Span, msg: str) -> None: ...
229+
span: Span
202230
msg: str
203231

204232
@final
205233
class Expr_: # noqa: N801
206-
def __init__(self, expr: _Expr) -> None: ...
234+
def __init__(self, span: Span, expr: _Expr) -> None: ...
235+
span: Span
207236
expr: _Expr
208237

209238
@final
210239
class Extract:
211-
def __init__(self, expr: _Expr, variants: _Expr) -> None: ...
240+
def __init__(self, span: Span, expr: _Expr, variants: _Expr) -> None: ...
241+
span: Span
212242
expr: _Expr
213243
variants: _Expr
214244

@@ -256,17 +286,19 @@ class Schema:
256286

257287
@final
258288
class Rule:
289+
span: Span
259290
head: list[_Action]
260291
body: list[_Fact]
261-
def __init__(self, head: list[_Action], body: list[_Fact]) -> None: ...
292+
def __init__(self, span: Span, head: list[_Action], body: list[_Fact]) -> None: ...
262293

263294
@final
264295
class Rewrite:
296+
span: Span
265297
lhs: _Expr
266298
rhs: _Expr
267299
conditions: list[_Fact]
268300

269-
def __init__(self, lhs: _Expr, rhs: _Expr, conditions: list[_Fact] = []) -> None: ... # noqa: B006
301+
def __init__(self, span: Span, lhs: _Expr, rhs: _Expr, conditions: list[_Fact] = []) -> None: ... # noqa: B006
270302

271303
@final
272304
class RunConfig:
@@ -322,24 +354,28 @@ _ExtractReport: TypeAlias = Variants | Best
322354

323355
@final
324356
class Saturate:
357+
span: Span
325358
schedule: _Schedule
326-
def __init__(self, schedule: _Schedule) -> None: ...
359+
def __init__(self, span: Span, schedule: _Schedule) -> None: ...
327360

328361
@final
329362
class Repeat:
363+
span: Span
330364
length: int
331365
schedule: _Schedule
332-
def __init__(self, length: int, schedule: _Schedule) -> None: ...
366+
def __init__(self, span: Span, length: int, schedule: _Schedule) -> None: ...
333367

334368
@final
335369
class Run:
370+
span: Span
336371
config: RunConfig
337-
def __init__(self, config: RunConfig) -> None: ...
372+
def __init__(self, span: Span, config: RunConfig) -> None: ...
338373

339374
@final
340375
class Sequence:
376+
span: Span
341377
schedules: list[_Schedule]
342-
def __init__(self, schedules: list[_Schedule]) -> None: ...
378+
def __init__(self, span: Span, schedules: list[_Schedule]) -> None: ...
343379

344380
_Schedule: TypeAlias = Saturate | Repeat | Run | Sequence
345381

@@ -361,9 +397,10 @@ class Datatype:
361397

362398
@final
363399
class Declare:
400+
span: Span
364401
name: str
365402
sort: str
366-
def __init__(self, name: str, sort: str) -> None: ...
403+
def __init__(self, span: Span, name: str, sort: str) -> None: ...
367404

368405
@final
369406
class Sort:
@@ -421,9 +458,10 @@ class Simplify:
421458

422459
@final
423460
class Calc:
461+
span: Span
424462
identifiers: list[IdentSort]
425463
exprs: list[_Expr]
426-
def __init__(self, identifiers: list[IdentSort], exprs: list[_Expr]) -> None: ...
464+
def __init__(self, span: Span, identifiers: list[IdentSort], exprs: list[_Expr]) -> None: ...
427465

428466
@final
429467
class QueryExtract:
@@ -433,14 +471,16 @@ class QueryExtract:
433471

434472
@final
435473
class Check:
474+
span: Span
436475
facts: list[_Fact]
437-
def __init__(self, facts: list[_Fact]) -> None: ...
476+
def __init__(self, span: Span, facts: list[_Fact]) -> None: ...
438477

439478
@final
440479
class PrintFunction:
480+
span: Span
441481
name: str
442482
length: int
443-
def __init__(self, name: str, length: int) -> None: ...
483+
def __init__(self, span: Span, name: str, length: int) -> None: ...
444484

445485
@final
446486
class PrintSize:

python/egglog/builtins.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def implies(self, other: BoolLike) -> Bool: ...
8484
converter(bool, Bool, Bool)
8585

8686
# The types which can be convertered into an i64
87-
i64Like = Union["i64", int] # noqa: N816
87+
i64Like: TypeAlias = Union["i64", int] # noqa: N816, PYI042
8888

8989

9090
class i64(Expr, builtin=True): # noqa: N801
@@ -186,7 +186,7 @@ def bool_ge(self, other: i64Like) -> Bool: ...
186186
def count_matches(s: StringLike, pattern: StringLike) -> i64: ...
187187

188188

189-
f64Like = Union["f64", float] # noqa: N816
189+
f64Like: TypeAlias = Union["f64", float] # noqa: N816, PYI042
190190

191191

192192
class f64(Expr, builtin=True): # noqa: N801
@@ -518,7 +518,8 @@ def _convert_function(a: FunctionType) -> UnstableFn:
518518
return_tp, *arg_tps = get_type_args()
519519
a.__annotations__ = {
520520
"return": return_tp,
521-
**dict(zip(a.__code__.co_varnames, arg_tps, strict=True)),
521+
# The first varnames should always be the arg names
522+
**dict(zip(a.__code__.co_varnames, arg_tps, strict=False)),
522523
}
523524
# Modify name to make it unique
524525
# a.__name__ = f"{a.__name__} {hash(a.__code__)}"

python/egglog/egraph.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ def _facts_to_check(self, fact_likes: Iterable[FactLike]) -> bindings.Check:
11881188
facts = _fact_likes(fact_likes)
11891189
self._add_decls(*facts)
11901190
egg_facts = [self._state.fact_to_egg(f.fact) for f in _fact_likes(facts)]
1191-
return bindings.Check(egg_facts)
1191+
return bindings.Check(bindings.DUMMY_SPAN, egg_facts)
11921192

11931193
@overload
11941194
def extract(self, expr: EXPR, /, include_cost: Literal[False] = False) -> EXPR: ...
@@ -1232,7 +1232,11 @@ def extract_multiple(self, expr: EXPR, n: int) -> list[EXPR]:
12321232

12331233
def _run_extract(self, typed_expr: TypedExprDecl, n: int) -> bindings._ExtractReport:
12341234
expr = self._state.typed_expr_to_egg(typed_expr)
1235-
self._egraph.run_program(bindings.ActionCommand(bindings.Extract(expr, bindings.Lit(bindings.Int(n)))))
1235+
self._egraph.run_program(
1236+
bindings.ActionCommand(
1237+
bindings.Extract(bindings.DUMMY_SPAN, expr, bindings.Lit(bindings.DUMMY_SPAN, bindings.Int(n)))
1238+
)
1239+
)
12361240
extract_report = self._egraph.extract_report()
12371241
if not extract_report:
12381242
msg = "No extract report saved"

0 commit comments

Comments
 (0)