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

Compilation fails due to comparison of big integers #320

Closed
treiher opened this issue Jul 3, 2020 · 5 comments · Fixed by #326
Closed

Compilation fails due to comparison of big integers #320

treiher opened this issue Jul 3, 2020 · 5 comments · Fixed by #326
Assignees
Labels
bug generator Related to generator package (SPARK code generation)

Comments

@treiher
Copy link
Collaborator

treiher commented Jul 3, 2020

As we have no type checking in our model, all field values are converted to a common integer type in the SPARK code before any calculation or comparison. Currently, Bit_Length is used for this purpose. While it makes sense to use this type for length calculations, it prevents the comparison of big integers. Here is an example:

package Test is

   type B is range 17179869177 .. 17179869178 with Size => 35;

   type D is
      message
         A : B
            then C
               with Length => 8
               if A = 17179869177;
         C : Opaque;
      end message;

end Test;
rflx-test-d.ads:6:01: error: instantiation error at rflx-test-generic_d.ads:210
rflx-test-d.ads:6:01: error: value not in range of type "Bit_Length" defined at rflx-rflx_generic_types.ads:11, instance at rflx-rflx_types.ads:6
rflx-test-d.ads:6:01: error: "Constraint_Error" would have been raised at run time

   compilation of rflx-test-d.ads failed
210                Types.Bit_Length (Get_A (Ctx)) = 17179869177

To cover all possible integer types, we would have to use a non-wrapping 64-bit modular type. The drawback of such a type is that current GNAT versions do not check overflows for exponentiations. Maybe we could prohibit the use of exponentiations in conditions as a workaround? @senier @jklmnn

@treiher treiher added bug generator Related to generator package (SPARK code generation) labels Jul 3, 2020
@treiher treiher added this to To do in RecordFlux 0.4.1 via automation Jul 3, 2020
@jklmnn
Copy link
Member

jklmnn commented Jul 3, 2020

Is there a realistic case where we would have to convert an arbitrary high number to Bit_Length? Where does Types.Bit_Length (Get_A (Ctx)) = 17179869177 originate from?

@treiher
Copy link
Collaborator Author

treiher commented Jul 3, 2020

Is there a realistic case where we would have to convert an arbitrary high number to Bit_Length?

All field values used in length aspects need to be converted to Bit_Length (or at least the final result of the calculation), as this is the base type used for indexing the buffer. I'm not sure what you mean with "arbitrary high number". Of course it doesn't make sense to calculate lengths which are bigger than the index type. But the upper bound is not fixed (cf. #317).

Where does Types.Bit_Length (Get_A (Ctx)) = 17179869177 originate from?

From the condition if A = 17179869177 in the specification. All field values are currently converted to Bit_Length. This doesn't make sense for the shown example, but is necessary when fields with different types are used in one expression or compared with each other, e.g. Types.Bit_Length (Get_A (Ctx)) = Types.Bit_Length (Get_X (Ctx)). For arbitrary big integer types Bit_Length is not usable, that is why I was thinking about using a non-wrapping 64-bit modular type instead.

@jklmnn
Copy link
Member

jklmnn commented Jul 3, 2020

I think we should use a separate modular type solely for comparisons of field values. Length calculations should be in the Bit_Length type. I think that an upper bound of 2 ** 63 - 1 bit for the length of a field or message is sufficient for any real world protocol.

@treiher
Copy link
Collaborator Author

treiher commented Jul 3, 2020

Length calculations should be in the Bit_Length type. I think that an upper bound of 2 ** 63 - 1 bit for the length of a field or message is sufficient for any real world protocol.

I agree, but Bit_Length does not have an upper bound of 2**63 - 1 by default, but (2**31 - 1) * 8. And the user can choose an arbitrary other bound. For further discussions in that direction please use #317.

I think we should use a separate modular type solely for comparisons of field values.

That is what my original proposal was about. But this still does not answer my question. We are supporting 64-bit integer fields, so we also have to support comparisons of 64-bit integer fields. To repeat my original question:

To cover all possible integer types, we would have to use a non-wrapping 64-bit modular type. The drawback of such a type is that current GNAT versions do not check overflows for exponentiations. Maybe we could prohibit the use of exponentiations in conditions as a workaround?

@jklmnn
Copy link
Member

jklmnn commented Jul 3, 2020

That is what my original proposal was about.

I mixed that up with the length discussion. I think we should prohibit exponentiations. When we find a protocol that requires this we might have to change that but I think this is quite unlikely.

@treiher treiher mentioned this issue Jul 3, 2020
26 tasks
@treiher treiher self-assigned this Jul 6, 2020
@treiher treiher moved this from To do to In progress in RecordFlux 0.4.1 Jul 6, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
RecordFlux 0.4.1 automation moved this from In progress to Done Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 8, 2020
treiher added a commit that referenced this issue Jul 9, 2020
treiher added a commit that referenced this issue Jul 9, 2020
@treiher treiher mentioned this issue Jul 14, 2020
4 tasks
treiher added a commit that referenced this issue Jul 23, 2020
treiher added a commit that referenced this issue Jul 23, 2020
treiher added a commit that referenced this issue Jul 23, 2020
treiher added a commit that referenced this issue Jul 23, 2020
treiher added a commit that referenced this issue Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug generator Related to generator package (SPARK code generation)
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants