Skip to content
Merged
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
40 changes: 26 additions & 14 deletions mathics/eval/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@
hook_exit_fn: Optional[Callable] = None


def print_evaluate(expr, evaluation, status: str, fn: Callable, orig_expr=None):
"""
Called from a decorated Python @trace_evaluate .evaluate()
method when TraceActivate["evaluate" -> True]
def skip_trivial_evaluation(expr, status: str, orig_expr=None) -> bool:
"""
Look for uninteresting evaluations that we should avoid showing
printing tracing status or stopping in a debugger.

if evaluation.definitions.timing_trace_evaluation:
evaluation.print_out(time.time() - evaluation.start_time)

# Test and dispose of various situations where showing information
# is pretty useless: evaluating a Symbol is the Symbol.
# Showing the return value of a ListExpression literal is
# also useless.
This includes things like:
* the evaluation is a literal that evaluates to the same thing,
* evaluating a Symbol which the Symbol.
* Showing the return value of a ListExpression literal
"""
from mathics.core.symbols import Symbol, SymbolConstant

if isinstance(expr, Symbol) and not isinstance(expr, SymbolConstant):
return
return True

if (
status == "Returning"
Expand All @@ -42,11 +39,26 @@ def print_evaluate(expr, evaluation, status: str, fn: Callable, orig_expr=None):
and hasattr(orig_expr, "is_literal")
and orig_expr.is_literal
):
return
return True

if orig_expr == expr:
# If the two expressions are the same, there is no point in
# repeating the output.
return True

return False


def print_evaluate(expr, evaluation, status: str, fn: Callable, orig_expr=None):
"""
Called from a decorated Python @trace_evaluate .evaluate()
method when TraceActivate["evaluate" -> True]
"""

if evaluation.definitions.timing_trace_evaluation:
evaluation.print_out(time.time() - evaluation.start_time)

if skip_trivial_evaluation(expr, status, orig_expr):
return

indents = " " * evaluation.recursion_depth
Expand Down Expand Up @@ -108,7 +120,7 @@ def wrapper(expr, evaluation) -> Any:
if not skip_call:
result = func(expr, evaluation)
if trace_evaluate_on_return is not None and not was_boxing:
trace_evaluate_on_return(result, evaluation, "Returning", func, expr)
trace_evaluate_on_return(result, evaluation, "Returning", expr, result)
evaluation.is_boxing = was_boxing
return result

Expand Down
Loading