Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta-ticket: Remove runtime dependency on everything via sage_eval #33802

Open
mkoeppe opened this issue May 4, 2022 · 5 comments
Open

Meta-ticket: Remove runtime dependency on everything via sage_eval #33802

mkoeppe opened this issue May 4, 2022 · 5 comments

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented May 4, 2022

sage_eval evaluates a string using the globals of sage.all.

It is used in some constructors and other functions - but in most uses, likely just a few bindings, namely those emitted by the preparser, are needed. We create a module sage.repl.preparse_bindings for these bindings (Ellipsis, ellipsis_range, ellipsis_iter, Integer, RealNumber, ComplexNumber, var, symbolic_expression, ...)

It is also used by sage_input to verify inputs. We run the verification with a smaller module first before falling back to sage.all

Tickets:

See also:

CC: @kwankyu @kliem @jhpalmieri @spaghettisalat @jcamp0x2a

Component: refactoring

Branch/Commit: u/mkoeppe/remove_runtime_dependency_on_everything_via_sage_eval @ 3552523

Issue created by migration from https://trac.sagemath.org/ticket/33802

@mkoeppe mkoeppe added this to the sage-9.7 milestone May 4, 2022
@mkoeppe

This comment has been minimized.

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented May 5, 2022

@mkoeppe
Copy link
Contributor Author

mkoeppe commented May 5, 2022

Commit: 3552523

@mkoeppe
Copy link
Contributor Author

mkoeppe commented May 5, 2022

comment:4

With this change:

diff --git a/src/sage/misc/sage_eval.py b/src/sage/misc/sage_eval.py
index ebd9ad6f3d..57419a8ba9 100644
--- a/src/sage/misc/sage_eval.py
+++ b/src/sage/misc/sage_eval.py
@@ -182,7 +182,13 @@ def sage_eval(source, locals=None, cmds='', preparse=True):
     if locals is None:
         locals = {}
 
-    import sage.all
+    if cmds:
+        import sage.all
+        globals = sage.all.__dict__
+    else:
+        import sage.repl.preparse_expression_runtime
+        globals = sage.repl.preparse_expression_runtime.__dict__
+
     if cmds:
         cmd_seq = cmds + '\n_sage_eval_returnval_ = ' + source
         if preparse:
@@ -192,10 +198,10 @@ def sage_eval(source, locals=None, cmds='', preparse=True):
             source = preparser.preparse(source)
 
     if cmds:
-        exec(cmd_seq, sage.all.__dict__, locals)
+        exec(cmd_seq, globals, locals)
         return locals['_sage_eval_returnval_']
     else:
-        return eval(source, sage.all.__dict__, locals)
+        return eval(source, globals, locals)
 

there are only a few failures (except for growth_group.py)

$ ./sage -tp $(git grep -l sage_eval)
....
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/rings/asymptotic/growth_group.py  # 460 doctests failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/rings/polynomial/polynomial_element.pyx  # 3 doctests failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/rings/complex_mpfr.pyx  # 3 doctests failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/matrix/matrix1.pyx  # 6 doctests failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/misc/sage_eval.py  # 3 doctests failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/rings/polynomial/multi_polynomial_ring.py  # 1 doctest failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/rings/asymptotic/misc.py  # 21 doctests failed
sage -t --random-seed=131777733077912989056233344518802251877 src/sage/symbolic/units.py  # 2 doctests failed

New commits:

3552523src/sage/repl/preparse_expression_runtime.py: New

@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 May 8, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.8, sage-9.9 Jan 7, 2023
@mkoeppe mkoeppe modified the milestones: sage-10.0, sage-10.1 Apr 30, 2023
@mkoeppe mkoeppe removed this from the sage-10.1 milestone Aug 7, 2023
@mkoeppe mkoeppe changed the title Remove runtime dependency on everything via sage_eval Meta-ticket: Remove runtime dependency on everything via sage_eval Jul 21, 2024
@mkoeppe mkoeppe added this to the sage-10.5 milestone Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant