Skip to content

METK-183 MarsLanguage immutable + lazy loading + caching - #270

Open
danovaro wants to merge 7 commits into
developfrom
feature/METK-183-language-immutable
Open

danovaro wants to merge 7 commits into
developfrom
feature/METK-183-language-immutable

Conversation

@danovaro

@danovaro danovaro commented Sep 17, 2026

Copy link
Copy Markdown
Member

Description

MarsLanguage is now immutable and values for inheritance are stored in a separate context (a MarsRequest)
Given its immutability, it can now be cached

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

📋 Metkit Documentation 📋
https://sites.ecmwf.int/docs/metkit/pull-requests/PR-270

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Shared mutable caching is thread-unsafe, and inheritance context handling introduces cross-verb and sequential-expansion regressions.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Introduces cached MarsLanguage instances and moves inheritance state into request contexts.

Changes:

  • Adds process-wide language caching and const interfaces.
  • Refactors inheritance handling into MarsRequest contexts.
  • Updates ODB integration and tests for the new API.

mars2grib documentation: ✅ in sync — no impacted files under src/metkit/mars2grib or tests/mars2grib.

File summaries
File Description
src/metkit/mars/MarsLanguage.cc Implements caching and context-based expansion.
src/metkit/mars/MarsLanguage.h Exposes cached language API.
src/metkit/mars/MarsExpansion.cc Manages expansion contexts.
src/metkit/mars/MarsExpansion.h Removes owned languages and reset API.
src/metkit/mars/Type.cc Removes inheritance state.
src/metkit/mars/Type.h Updates type state interface.
src/metkit/mars/TypeEnum.cc Removes redundant reset.
src/metkit/mars/TypeEnum.h Removes reset declaration.
src/metkit/mars/TypeParam.cc Removes redundant reset.
src/metkit/mars/TypeParam.h Removes reset declaration.
src/metkit/odb/OdbDecoder.cc Uses cached language.
src/metkit/odb/OdbMetadataDecoder.cc Accepts const language.
src/metkit/odb/OdbMetadataDecoder.h Stores const language reference.
src/metkit/odb/OdbToRequest.cc Uses cached language.
tests/test_date.cc Updates language access.
tests/test_expand.cc Updates language access.
tests/test_language.cc Updates language access.
tests/test_mars_language.cc Updates language access.
tests/test_mars_language_strict.cc Updates language access.
tests/test_obstype.cc Updates language access.
tests/test_param_axis.cc Supplies expansion context.
tests/test_step.cc Updates language access.
tests/test_time.cc Updates language access.
tests/test_type_levelist.cc Updates language access.
Review details

Suppressed comments (2)

src/metkit/mars/MarsExpansion.cc:42

  • This overload also shares one inheritance context across all verbs, changing the prior per-language behavior. Mixed-verb MarsRequest batches can inherit parameters from an unrelated verb; select a separate context keyed by lang.verb() for each item.
    MarsRequest ctx;

src/metkit/mars/MarsExpansion.cc:56

  • This local context is discarded after every call. Previously a MarsExpansion retained inheritance in its per-verb MarsLanguage until reset(), so sequential expand(request) calls on the same object inherited from one another. Store per-verb contexts on MarsExpansion (and preserve an explicit way to clear them) so this public overload does not silently lose that behavior.
    MarsRequest ctx;
    return language(request.verb()).expand(request, ctx, inherit_, strict_);
  • Files reviewed: 24/24 changed files
  • Comments generated: 4
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/metkit/mars/MarsExpansion.cc Outdated
Comment thread src/metkit/mars/MarsLanguage.cc
Comment thread src/metkit/mars/MarsLanguage.cc
Comment thread src/metkit/mars/MarsLanguage.h
@codecov-commenter

codecov-commenter commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.08264% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.63%. Comparing base (5f653d0) to head (ab14f35).

Files with missing lines Patch % Lines
src/metkit/mars/MarsExpansion.cc 50.00% 9 Missing ⚠️
src/metkit/mars/MarsLanguage.cc 91.17% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #270      +/-   ##
===========================================
- Coverage    46.70%   46.63%   -0.07%     
===========================================
  Files          471      471              
  Lines        21868    21859       -9     
  Branches      1531     1530       -1     
===========================================
- Hits         10214    10195      -19     
- Misses       11654    11664      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Rust bridge attempts to copy a non-copyable MarsLanguage returned by const reference.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 31/31 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@danovaro
danovaro force-pushed the feature/METK-183-language-immutable branch 4 times, most recently from 851ca16 to 66cd7d2 Compare September 18, 2026 13:27
@danovaro
danovaro force-pushed the feature/METK-183-language-immutable branch from 66cd7d2 to ab14f35 Compare September 18, 2026 14:27

@simondsmart simondsmart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. The only thing I would really consider is if the context should have its own type (i.e. there might be something other than the mars request that we want to carry along. And it means that there is no ambiguity as to the order of the arguments)

std::unique_ptr<MarsRequestWrapper> MarsRequestWrapper::expand(bool inherit, bool strict) const {
metkit::mars::MarsLanguage lang(request_.verb());
auto expanded = lang.expand(request_, inherit, strict);
metkit::mars::MarsRequest ctx;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap the context in its own type? Such that the signature becomes self-explanatory (currently it accepts two MarsRequest objects).

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.

4 participants