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

Allow for controlling whether the minimal model listing is included in the generated model #503

Closed
chrispcampbell opened this issue Aug 15, 2024 · 1 comment · Fixed by #504 or #476
Assignees

Comments

@chrispcampbell
Copy link
Contributor

chrispcampbell commented Aug 15, 2024

In #501 we made it so that a minimal model listing is bundled with the generated model, which makes it possible to create a LookupDef without manually initializing a ModelListing. This increases the size of the generated model, but most projects will not need this functionality, so we should either make it opt-in or opt-out. I'm leaning towards making it opt-in.

Related to the above, in #472 we added support for overriding lookups at runtime, which resulted in the code generator (for both C and JS) unconditionally including a setLookup function that has a case statement for every data or lookup variable in the model. This also increases the size of the generated model, and most projects will not need this functionality, so this should also be made an opt-in thing.

@chrispcampbell
Copy link
Contributor Author

chrispcampbell commented Aug 16, 2024

TL;DR: This has no impact on existing projects. For projects that want to override lookups (or access impl variables), it will now be necessary to set a couple flags to make the code generator include the necessary support code, either in your sde.config.js or spec.json file (or in your model.csv file, if you're using plugin-config).

There were changes needed in a few different packages, as described below.

In the build package

I added support for three new optional properties in the model.spec file, which are documented in the ModelSpec interface in the build package:

  /**
   * Whether to bundle a model listing with the generated model.
   *
   * When this is true, a model listing will be bundled with the generated
   * model to allow the `runtime` package to resolve variables that are
   * referenced by name or identifier.  This listing will increase the size
   * of the generated model, so it is recommended to set this to true only
   * if it is needed.
   */
  bundleListing: boolean

  /**
   * Whether to allow lookups to be overridden at runtime using `setLookup`.
   *
   * If false, the generated model will contain a `setLookup` function that
   * throws an error, meaning that lookups cannot be overridden at runtime.
   *
   * If true, all lookups in the generated model will be available to be
   * overridden.
   *
   * If an array is provided, only those variable names in the array will
   * be available to be overridden.
   */
  customLookups: boolean | VarName[]

  /**
   * Whether to allow for capturing the data for arbitrary variables at
   * runtime (including variables that are not configured in the `outputs`
   * array).
   *
   * If false, the generated model will contain a `storeOutput` function
   * that throws an error, meaning that the data for arbitrary variables
   * cannot be captured at runtime.
   *
   * If true, all variables in the generated model will be available to be
   * captured at runtime.
   *
   * If an array is provided, only those variable names in the array will
   * be available to be captured at runtime.
   */
  customOutputs: boolean | VarName[]

In the compile and cli packages

  • Changed the C and JS code generators to respect the new properties.
  • Changed the C code generator so that it no longer generates SDE_USE_OUTPUT_INDICES; this is no longer necessary now that we have the customOutputs setting.
  • Changed the C code generator and runtime so that it no longer includes maxOutputIndices and getMaxOutputIndices; these are no longer necessary now that the runtime package was updated to allow for output indices buffers of any length.

In the plugin-config package

  • Added support for three new columns in the config/model.csv file that correspond to the new model spec settings.

In the plugin-wasm package

  • Updated the wasm plugin so that it only bundles the minimal model listing in generated-model.js (the generated wasm module) if bundleListing is set to true in the config/spec file.

In the templates and examples

  • Updated the sir example and template-default to include the new columns in model.csv (they are set to false by default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment