Skip to content

Commit

Permalink
Reduce misleading debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ReedOei committed Feb 3, 2020
1 parent 1b549a7 commit 4dd748d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 48 deletions.
3 changes: 1 addition & 2 deletions TODO
Expand Up @@ -7,13 +7,12 @@ Long:
Medium:
- Maybe merge type inference and execution phases in pecan/lang/ir/prog.py
- Somewhat more complicated than I originally thought because we have to move TypedIRLowering and Typed optimization into the evaluate loop
- Add an evaluate_type or something method so that we don't have to manually check the type of the nodes when running type inference
- Add new __repr__ functions that do a more standard repr (e.g., Class(field_1, field_2, ...)) that turn on with debug 2
- See if we can reduce the usage of the `type` function...
- Combine unification code for looking up dynamic calls and doing typechecking

Short:
- Move SpotFormula out of prog to keep the main program automata/library independent
- Make all parsing functions in pecan.lang.parser into proper functions (b/c it gives better debug info)
- Make settings log call a function so it desn't have to build all the strings if it's not going to display anyway
- Try projecting all at once instead of in multiple passes?

64 changes: 18 additions & 46 deletions pecan/lang/ir/prog.py
Expand Up @@ -375,32 +375,17 @@ def run_definition(self, i, d):
from pecan.lang.ir.directives import DirectiveType, DirectiveForget, DirectiveLoadAut, DirectiveImport, DirectiveShuffle
from pecan.lang.ir.praline import PralineDef, PralineExecute, PralineDisplay

settings.log(0, lambda: '[DEBUG] Processing: {}'.format(d))

# TODO: Cleanup this part relative to evaluate below (e.g., lots of repeated if tree). Instead we could add a evaluate_type method or something, and let dispatch handle it for us
if type(d) is NamedPred:
self.defs[i] = self.type_infer(d)
self.preds[d.name] = self.defs[i]
self.preds[d.name].evaluate(self)
settings.log(0, lambda: self.preds[d.name])
elif type(d) is Restriction:
d.evaluate(self)
elif type(d) is DirectiveForget:
d.evaluate(self)
elif type(d) is DirectiveType:
d.evaluate(self)
elif type(d) is DirectiveLoadAut:
d.evaluate(self)
elif type(d) is DirectiveImport:
d.evaluate(self)
elif type(d) is DirectiveShuffle:
d.evaluate(self)
elif type(d) is PralineDef:
d.evaluate(self)
elif type(d) is PralineExecute:
d.evaluate(self)
elif type(d) is PralineDisplay:
d.evaluate(self)
to_run = [DirectiveType, DirectiveForget, DirectiveLoadAut, DirectiveImport, DirectiveShuffle, Restriction, PralineDef, PralineExecute, PralineDisplay, NamedPred]

if type(d) in to_run:
settings.log(0, lambda: '[DEBUG] Processing: {}'.format(d))
if type(d) is NamedPred:
self.defs[i] = self.type_infer(d)
self.preds[d.name] = self.defs[i]
self.preds[d.name].evaluate(self)
settings.log(0, lambda: self.preds[d.name])
else:
d.evaluate(self)

def run_type_inference(self):
from pecan.lib.praline.builtins import builtins
Expand Down Expand Up @@ -430,39 +415,26 @@ def evaluate(self, old_env=None):
from pecan.lang.ir.directives import DirectiveType, DirectiveForget, DirectiveLoadAut, DirectiveImport, DirectiveShuffle
from pecan.lang.ir.praline import PralineDef, PralineExecute, PralineDisplay

to_ignore = [DirectiveType, DirectiveForget, DirectiveLoadAut, DirectiveImport, DirectiveShuffle, Restriction, PralineDef, PralineExecute, PralineDisplay]

if old_env is not None:
self.include(old_env)

succeeded = True
msgs = []

for d in self.defs:
settings.log(0, lambda: '[DEBUG] Processing: {}'.format(d))

# Ignore these constructs because we should have run them earlier in run_type_inference
# TODO: Fix here and above in run_type_inferences, all these passes are probably somewhat inefficient for larger programs and it doesn't scale particularly well
if type(d) in to_ignore:
continue

settings.log(0, lambda: '[DEBUG] Processing: {}'.format(d))
if type(d) is NamedPred:

# If we already computed it, it doesn't matter if we replace it with a more efficient version
if self.preds[d.name].body_evaluated is None:
self.preds[d.name] = d
elif type(d) is Restriction:
pass
elif type(d) is DirectiveType:
pass
elif type(d) is DirectiveForget:
pass
elif type(d) is DirectiveLoadAut:
pass
elif type(d) is DirectiveImport:
pass
elif type(d) is DirectiveShuffle:
pass
elif type(d) is PralineDef:
pass
elif type(d) is PralineExecute:
pass
elif type(d) is PralineDisplay:
pass

else:
result = d.evaluate(self)
Expand Down

0 comments on commit 4dd748d

Please sign in to comment.