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

Evaluation of modular integers in mathematical expressions #727

Closed
treiher opened this issue Aug 10, 2021 · 0 comments · Fixed by #1249
Closed

Evaluation of modular integers in mathematical expressions #727

treiher opened this issue Aug 10, 2021 · 0 comments · Fixed by #1249
Assignees
Labels
architectural decision Discussion of design decision small Effort of one person-day or less specification Related to specification package (e.g., specification parsing)

Comments

@treiher
Copy link
Collaborator

treiher commented Aug 10, 2021

Context and Problem Statement

The use of different integer types in mathematical expressions could lead to ambiguities, especially when modular integers are involved.

Example (cf. #726)

   type Length is mod 2**8;

   type Packet is
      message
         Length_1 : Length;
         Length_2 : Length
            then Payload
               with Size => Length_2 * 256 + Length_1
               if (Length_2 * 256 + Length_1) mod 8 = 0;
         Payload : Opaque;
      end message;

The target type of a size aspect is user-defined and could be a modular integer as well as a range integer (cf. #317). Assuming a target type with a maximum value of >= 2**16 - 1 the result of Length_2 * 256 + Length_1 will fit in the target type. In SPARK Length_2 * 256 can only be evaluated, if 256 is converted to the target type before evaluation, as 256 is outside the range of Length. Also Length_2 and Length_1 have to be converted to the target type, as mathematical operations on different integer types are not allowed in SPARK. Due to the necessary conversions, Length_1 as well as Length_2 are not evaluated as modular integers, which is unexpected.

Considered Options

O1 Explicit type conversions

Adding explicit type conversions and considering different integer types always as incompatible would remove the ambiguities.

+ Flexible
Complex

O2 Remove modular integers

Modular integers are not strictly needed, as the mod operator can be used instead.

+ Simplifies language
Specification of range integers is more cumbersome

The drawbacks can be alleviated by changing the syntax of range integer declarations. Currently, the range as well as the size of a range integer must be defined. In many cases, the range can be inferred from the size or the size can be inferred from the upper bound.

Possible syntax: type Length is range with Size => 8 or type Length is range 0 .. 2**8 - 1 instead of type Length is range 0 .. 2**8 - 1 with Size => 8

Decision Outcome

O2. We decided to just remove modular integers for now. The syntax for range integers can be optimized at a later time.

@treiher treiher added specification Related to specification package (e.g., specification parsing) architectural decision Discussion of design decision labels Aug 10, 2021
@treiher treiher added this to To do in RecordFlux Future via automation Aug 10, 2021
@senier senier moved this from Medium to High in RecordFlux Future Nov 1, 2022
@senier senier removed this from High in RecordFlux Future Nov 1, 2022
@senier senier added this to To do in RecordFlux 0.8 via automation Nov 1, 2022
@senier senier added the small Effort of one person-day or less label Nov 1, 2022
@treiher treiher self-assigned this Nov 4, 2022
@treiher treiher moved this from To do to Implementation in RecordFlux 0.8 Nov 4, 2022
treiher added a commit that referenced this issue Nov 7, 2022
treiher added a commit that referenced this issue Nov 7, 2022
@treiher treiher moved this from Implementation to Review in RecordFlux 0.8 Nov 7, 2022
treiher added a commit that referenced this issue Nov 8, 2022
RecordFlux 0.8 automation moved this from Review to Done Nov 8, 2022
treiher added a commit that referenced this issue Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architectural decision Discussion of design decision small Effort of one person-day or less specification Related to specification package (e.g., specification parsing)
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants