Skip to content

Conversation

@agarny
Copy link
Contributor

@agarny agarny commented Oct 16, 2024

Fixes #1244.

Indeed, we want to be able to tell the generator to track/untrack some model variables. So, to have those `model()` and `setModel()` methods make the generator model-specific when we want it to be usable for any model, hence now the `interfaceCode()` and `implementationCode()` methods taking a model as a parameter.
@agarny agarny force-pushed the issue1244 branch 4 times, most recently from 2867e43 to ceb1d55 Compare October 18, 2024 03:08
Someone might have a version of llvm-cov and llvm-profdata that they use and which is not located in /Library/Developer/CommandLineTools/usr/bin. This means that they will need to provide LLVM_BIN_DIR which is not ideal, not least since there are PREFERRED_LLVM_COV_NAMES and PREFERRED_LLVM_PROFDATA_NAMES to play with, if needed.
Copy link
Contributor

@hsorby hsorby left a comment

Choose a reason for hiding this comment

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

What is the thinking behind always passing an analyser model to the generator class, as opposed to setting the analyser model for the generator to work on?

@hsorby
Copy link
Contributor

hsorby commented Nov 20, 2025

Other than this question:

What is the thinking behind always passing an analyser model to the generator class, as opposed to setting the analyser model for the generator to work on?

I am happy with this work.

@agarny
Copy link
Contributor Author

agarny commented Nov 20, 2025

What is the thinking behind always passing an analyser model to the generator class, as opposed to setting the analyser model for the generator to work on?

Oops, I went through the inline comments completely overlooking this one.

Anyway, are you talking about methods like un/trackAllConstants(), un/trackAllComputedConstants(), etc. that take an analyser model as an input? If so, it's because a generator can be reused with different analyser models. This is why we don't allow the creation of a generator for a given analyser model.

@hsorby
Copy link
Contributor

hsorby commented Nov 20, 2025

You are asking the Generator to hold a map of analysermodels and their map of tracked and untracked variables. The Generator should really be stateless. I have three problems with this approach:

  1. mTrackedVariables will never shrink while the generator object is alive
  2. This is not thread safe
  3. The genereator is responsible for the lifecycle management of the mTrackedVariables when that is not its concern

For me the tracked varaibles belong with the AnalyserModel itself. Alternatively, you could create a generation context that holds the tracked variable information, and generator profile and you pass the AnalyserModel and GenerationContext when asking the generator to generate. This also means that the Generator doesn’t hold a reference to a generator profile this is passed in when the generation happens. For me this would be a massive archetictural improvement for the library.

@agarny
Copy link
Contributor Author

agarny commented Nov 20, 2025

The un/tracking of variables is only relevant in the context of code generation, which is why mTrackedVariables is managed by the generator. To have mTrackedVariables managed by the analyser model would prevent the analyser model from being used to generate code with different un/tracked variables, so I don't think the analyser model should manage mTrackedVariables.

You are asking the Generator to hold a map of analysermodels and their map of tracked and untracked variables. The Generator should really be stateless. I have three problems with this approach:

  1. mTrackedVariables will never shrink while the generator object is alive

Correct, although we could always a method to reset mTrackedVariables, if needed.

  1. This is not thread safe

True, but then again the generator is not thread-safe to start with.

  1. The genereator is responsible for the lifecycle management of the mTrackedVariables when that is not its concern

For me the tracked varaibles belong with the AnalyserModel itself. Alternatively, you could create a generation context that holds the tracked variable information, and generator profile and you pass the AnalyserModel and GenerationContext when asking the generator to generate. This also means that the Generator doesn’t hold a reference to a generator profile this is passed in when the generation happens. For me this would be a massive archetictural improvement for the library.

I agree, a better approach would be to have a new class (GeneratorContext) that manages un/tracked variables for a given analyser model. Kind of similar to what was done with GeneratorProfile, which means that we would then have Generator::context() and Generator::setContext(const GeneratorContextPtr &context).

However, I would do that as part of a different GitHub issue. Time is pressing.

@hsorby
Copy link
Contributor

hsorby commented Nov 20, 2025

This PR also:

@nickerso nickerso merged commit 55666de into cellml:main Nov 24, 2025
14 checks passed
@agarny agarny deleted the issue1244 branch November 24, 2025 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code generator: allow for variables to be tracked/untracked

3 participants