Skip to content

refactor: make definition optional with EmptyDefinition sentinel#302

Merged
ocots merged 9 commits intomainfrom
definition
Apr 20, 2026
Merged

refactor: make definition optional with EmptyDefinition sentinel#302
ocots merged 9 commits intomainfrom
definition

Conversation

@ocots
Copy link
Copy Markdown
Member

@ocots ocots commented Apr 19, 2026

Make the definition field optional in Model and PreModel by introducing a
type hierarchy with AbstractDefinition as the abstract type, and concrete
types Definition (wrapping an Expr) and EmptyDefinition (sentinel for no
definition).

Key changes:

  • PreModel.definition defaults to EmptyDefinition() instead of nothing
  • Model is parametric on DefinitionType<<:AbstractDefinition
  • __is_definition_set(::Model) always returns true (Model is structurally complete)
  • __is_definition_set(::PreModel) returns !__is_definition_empty(pre.definition)
  • definition! setter auto-wraps Expr into Definition
  • Added expression getter: returns :(begin end) for EmptyDefinition, d.expr for Definition
  • Removed precondition on definition in build()
  • Refactored display: Base.show on AbstractDefinition with internal _print_abstract_definition
  • Split Display/print.jl into 5 focused files by responsibility
  • Moved definition setters/getters to Components/definition.jl (pattern like control.jl)
  • Moved Model definition getters to Building/model.jl (no getter on PreModel — direct field access)
  • Updated all tests to reflect new hierarchy and semantics

All 3609 tests pass.

Split the monolithic src/Display/print.jl (~505 lines) into files by
responsibility:

- ansi.jl: ANSI color helpers and __print(::Expr)
- definition.jl: __print_abstract_definition
- mathematical.jl: __print_mathematical_definition
- model.jl: Base.show / show_default for Model
- pre_model.jl: Base.show / show_default for PreModel

Pure refactor: no functional change.
Display.jl updated to include the five files in dependency order.

Related to AbstractDefinition refactor.
@ocots ocots changed the title refactor(display): split print.jl into focused files refactor: make definition optional with EmptyDefinition sentinel Apr 19, 2026
@ocots ocots added run breakage Used to trigger breakage tests. run ci Trigger CI run documentation Trigger documentation labels Apr 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 19, 2026

Breakage test results
Date: 2026-04-19 21:27:02

Name Latest Stable
CTDirect compat: v0.9.14 compat: v0.9.14
CTFlows compat: v0.9.14 compat: v0.9.14
CTSolvers compat: v0.9.14 compat: v0.9.14
OptimalControl compat: v0.9.14 compat: v0.9.14

@ocots ocots merged commit e2233e2 into main Apr 20, 2026
67 checks passed
@ocots ocots deleted the definition branch April 20, 2026 09:51
@ocots ocots mentioned this pull request Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run breakage Used to trigger breakage tests. run ci Trigger CI run documentation Trigger documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant