Skip to content

feat: per-context giac_eval, drive wrapper_version from meson#4

Merged
s-celles merged 2 commits into
mainfrom
feat/context-aware-eval
May 13, 2026
Merged

feat: per-context giac_eval, drive wrapper_version from meson#4
s-celles merged 2 commits into
mainfrom
feat/context-aware-eval

Conversation

@s-celles
Copy link
Copy Markdown
Owner

Summary

Closes #2, closes #3.

#3 — Per-context giac_eval returning a Gen

Adds a new free-function overload

Gen giac_eval(const std::string& expr, GiacContext& ctx);

mirroring the existing giac_eval(expr) but routing parse + eval through ctx.impl_->ctx instead of the thread-local singleton. Two distinct GiacContext instances now observe independent := bindings and configuration state.

This is the missing piece that Giac.jl's giac_eval(expr, ctx::GiacContext) signature has been advertising all along — the Julia-side ctx was silently ignored at the C++ layer because no context-aware Gen-returning binding existed. Once this lands, Giac.jl's _giac_eval_string can pass ctx_ptr through and finally honour the documented isolation contract (the !!! warning blocks just added in Giac.jl#32 can be removed in the follow-up).

Both overloads are bound to Julia under the same giac_eval name with static_cast to disambiguate; CxxWrap exposes them as arity-dispatched methods.

#2 — Drive get_wrapper_version() from meson

get_wrapper_version() had "0.1.0" hardcoded while meson.build claimed 0.5.0. Now driven from meson.project_version() at build time via

add_project_arguments(
  '-DWRAPPER_VERSION="' + meson.project_version() + '"',
  language: 'cpp',
)

so bumps happen in exactly one place. Bumped 0.5.0 → 0.6.0 for the new API surface (minor bump per SemVer; existing single-arg giac_eval is preserved).

Test plan

  • meson test -C builddir — 6/6 green locally (test_eval, test_context, test_gen, test_warnings, test_predicates, test_extraction)
  • New isolation tests added:
    • C++: tests/cpp/test_context.cpp::giac_eval_with_context_returns_gen
    • Julia: tests/julia/test_context.jl "giac_eval(expr, ctx) — returns Gen and isolates bindings"
  • Version tests in C++ and Julia rewritten to accept any SemVer-shaped value rather than pinning "0.1.0"
  • CI green

s-celles added 2 commits May 11, 2026 23:43
Closes #2, closes #3.

#3: Add a new free-function overload

    Gen giac_eval(const std::string& expr, GiacContext& ctx);

that mirrors the existing `giac_eval(expr)` but routes the parse and
eval through `ctx.impl_->ctx` instead of the thread-local singleton.
Two distinct `GiacContext` instances therefore observe independent
`:=` bindings and configuration state. This is what `Giac.jl`'s
`giac_eval(expr, ctx::GiacContext)` signature has been advertising
all along — until now, the Julia-side `ctx` was silently ignored at
the C++ layer because no context-aware Gen-returning binding existed.

Bound to Julia under the same name with `static_cast` to disambiguate
the two free-function overloads (`giac_eval(expr)` and
`giac_eval(expr, ctx)`), so CxxWrap exposes both as `giac_eval` methods
that dispatch on arity.

Covered by new tests:
- C++:    tests/cpp/test_context.cpp::giac_eval_with_context_returns_gen
- Julia:  tests/julia/test_context.jl "giac_eval(expr, ctx) — returns Gen and isolates bindings"

#2: Drive `get_wrapper_version()` from `meson.project_version()` at
build time via `-DWRAPPER_VERSION="$ver"` set by `add_project_arguments`,
so the version string no longer needs to be maintained in two places.
Bumped 0.5.0 → 0.6.0 for the new API surface (minor bump per SemVer;
no breaking change — existing single-arg `giac_eval` is preserved).
Updated the C++ and Julia version tests to accept any SemVer-shaped
value rather than pinning a literal.

`meson test -C builddir`: 6/6 green locally.
Adds a C++ regression test that reproduces the exact scenario reported
in issue #3: binding y := 42 in one GiacContext and then calling
desolve(diff(y,t)=cos(t), t, y) in a fresh, independent GiacContext
must succeed (returns c_0+sin(t)). Manually verified that running the
same desolve in the same context as the binding still throws
"GIAC evaluation error: Dependent variable assigned. Run purge(y)" —
so the test is a real regression guard against context isolation
breaking in the future.

README gains one bullet under "Features" naming per-context evaluation
and linking back to the issue.
@s-celles s-celles merged commit 0ad8542 into main May 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose per-context giac_eval so Julia GiacContext provides real isolation Update wrapper version

1 participant