Skip to content

RFC: Model_of aspect - #223

Open
tonunaks wants to merge 2 commits into
masterfrom
mr/naks_model_of
Open

RFC: Model_of aspect#223
tonunaks wants to merge 2 commits into
masterfrom
mr/naks_model_of

Conversation

@tonunaks

Copy link
Copy Markdown
Collaborator

No description provided.

@tonunaks tonunaks self-assigned this May 14, 2026
@tonunaks tonunaks linked an issue May 14, 2026 that may be closed by this pull request
@tonunaks
tonunaks force-pushed the mr/naks_model_of branch 2 times, most recently from 9092c05 to ed4b2a4 Compare May 28, 2026 14:54
@tonunaks
tonunaks force-pushed the mr/naks_model_of branch from ed4b2a4 to ed96937 Compare July 9, 2026 13:32
Comment thread features/model_of.md Outdated
Comment thread features/model_of.md Outdated
Comment thread features/model_of.md Outdated
Comment thread features/model_of.md Outdated
@tonunaks

tonunaks commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

@MartinClochardPro, please check if the validity rule on line 153 is now appropriate? I rephrased it to reference Assertion_Policy now

Comment thread features/model_of.md
```
decoration_unit ::=
"model" "package" package_name "is"
{ decorated_subprogram_declaration }

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.

The grammar only admits decorated_subprogram_declaration, is subprogram-only the intended final scope? SPARK contracts also operates on packages/types/globals. Worth a line in the RFC on whether that's in or out.

Comment thread features/model_of.md
Comment on lines +243 to +247
A given subprogram may carry contracts in at most one of the main unit and the
sidecar unit. If both files supply a pre- or postcondition for the same
subprogram, the model decorator tool reports an error indicating the conflicting
line in each file. This rule prevents silent shadowing of production contracts
by sidecar contracts.

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.

I think this contradict what's stated at lines 157-159.

Comment thread features/model_of.md
function Sqrt (X : Float) return Float
--# @Source_Reference@ 3 "my_math_models.ads" 1
with
--# @Source_Reference@ 5 "my_math_models.ads"

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.

Shouldn't line number be 4 here (and therefore no marker at all)?

Comment thread features/model_of.md
Post => Sqrt'Result >= 0.0;
--# @Source_Reference@ 3 "my_math.ads" 2
function Log (X : Float) return Float;
end My_Math;

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.

Is it expected that the private part of my_math.ads is missing from this unit?

Comment thread features/model_of.md
line in each file. This rule prevents silent shadowing of production contracts
by sidecar contracts.

If a sidecar unit exists for a package without a corresponding main source

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 feels counter intuitive: the feature is meant to stay "read-only" on the sources I guess, so creating a unit here seems odd. Why not make it a hard error instead? Reconstructing a spec from its contracts also looks non-trivial?

Comment thread features/model_of.md
-- additional included packages
with Helper_Package; use Helper_Package;

model package My_Math is

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.

The model keyword distinguishes decorated declarations from the ones copied through verbatim, but that could be an aspect instead of new vocabulary:

function Pow (X, Y : Float) return Float
   with Model,  Pre  => Greater_Than (X, 0.0), Post => Greater_Than (Pow'Result, 0.0);

This reuses Ada's existing aspect grammar (no new keyword, no new gramme rule,…), and would greatly simplify tooling: libadalang could parse sidecar units with its normal grammar, and LKQL rules and IDE support (navigation, completion, highlighting) would work out of the box.

It would also read better when decorating an entity that is itself named Model:

model procedure Model with-- vs.
procedure Model with Model, …

Comment thread features/model_of.md
and define a helper function in the model package:

```ada
-- my_math_models.adb (sidecar body, not compiled by the regular build)

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.

The RFC doesn't define a naming convention for the model unit files. Could it either define one or state explicitly that naming is unconstrained? This also brings gprbuild support into play: how sidecar units are linked to their Ada specifications, and how they are kept out of the build.

I would propose .adm: it keeps the same base name as the spec/body, and makes clear that it isn't Ada code. gprbuild could likely handle that easily, extending the existing naming attributes accordingly.

Comment thread features/model_of.md
decoration_aspect_list ::=
decoration_aspect { "," decoration_aspect }

decoration_aspect ::=

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.

I think the original issue for that feature wasn't limited to SPARK aspects: #197. In particular, the GNAT SAS team is interested in taint aspects. The rule should be generalized to all aspects that have no effect on execution, not just the SPARK ones.

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.

[feature] Model_Of aspect to specify external subprograms

4 participants