Forums
Different struct sizes
8 posts
• Page 1 of 1
Different struct sizes
Why does an empty struct have a size of 4 and not 1 like in C#?
- Chasm
- Posts: 33
Re: Different struct sizes
For contract support. Cobra adds this to structs and classes:
You can remove it with the -contracts:none option.
You can research issues like this with the -keep-intermediate-files option. The various *.cs files will be left around:
- Code: Select all
int _ih_invariantGuard;
You can remove it with the -contracts:none option.
You can research issues like this with the -keep-intermediate-files option. The various *.cs files will be left around:
"""
cobra -c -keep-intermediate-files empty-struct.cobra
cobra -c -keep-intermediate-files -contracts:none empty-struct.cobra
"""
struct S
pass
class P
def main
pass
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Different struct sizes
Unfortunately it adds it regardless of whether its needed or not (i.e if there are no contracts/invariants given).
Also it may be possible/preferable to only have it on the lowest accessible baseclass rather than each class
see notes and patch on ticket:243
Also it may be possible/preferable to only have it on the lowest accessible baseclass rather than each class
see notes and patch on ticket:243
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
Re: Different struct sizes
What is that integer for? What function does it serve? I mean does it store data or just serve as a key?
- Chasm
- Posts: 33
Re: Different struct sizes
Its a guard value to make invariant checks run only once per method
(for suppressing invariant checks inside methods called (possibly by by invariant checks).
Its bumped prior to checking and any re-entrant checks are not run if guard value non zero.
See SharpGenerator.cobra (codegen) or can see the mechanism by making a class with invariants and compiling with
-kif/keep-intermediate-files and looking at C# code generated.
Theres a fair bit of unnecessary inserted boiler plate inserted that could be optimised away.
(I see another ticket coming up)
Charles:
Slightly related:
with -contracts:methods is it intentional that both calls to the synthesized require/ensure contract methods and (possibly empty) contracts methods themselves are always generated (even if no contracts are given)?
The default inline version at least has some optimising out for non-existant contracts calls.
(for suppressing invariant checks inside methods called (possibly by by invariant checks).
Its bumped prior to checking and any re-entrant checks are not run if guard value non zero.
See SharpGenerator.cobra (codegen) or can see the mechanism by making a class with invariants and compiling with
-kif/keep-intermediate-files and looking at C# code generated.
Theres a fair bit of unnecessary inserted boiler plate inserted that could be optimised away.
(I see another ticket coming up)
Charles:
Slightly related:
with -contracts:methods is it intentional that both calls to the synthesized require/ensure contract methods and (possibly empty) contracts methods themselves are always generated (even if no contracts are given)?
The default inline version at least has some optimising out for non-existant contracts calls.
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
Re: Different struct sizes
And couldn't you make it "DependencyProperty"-esque? Basically a static dictionary of <int, int>? The object's address would be the key and the value would be the check int?
- Chasm
- Posts: 33
Re: Different struct sizes
hopscc wrote:Charles:
Slightly related:
with -contracts:methods is it intentional that both calls to the synthesized require/ensure contract methods and (possibly empty) contracts methods themselves are always generated (even if no contracts are given)?
The default inline version at least has some optimising out for non-existant contracts calls.
It's been awhile since I worked on that code, so I don't have a ready answer for you. Potential motivations that come to mind include:
-- subclassing
-- the library boundary
So if we optimize it out, we'll need to be sure some test cases are in place around those circumstances.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Different struct sizes
Chasm wrote:And couldn't you make it "DependencyProperty"-esque? Basically a static dictionary of <int, int>? The object's address would be the key and the value would be the check int?
For classes/objects, that seems workable. For structs/values, I don't think it would work.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 27 guests