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

Wrong instance variables size for C++ and C# #257

Open
GreyCat opened this issue Sep 20, 2017 · 1 comment
Open

Wrong instance variables size for C++ and C# #257

GreyCat opened this issue Sep 20, 2017 · 1 comment

Comments

@GreyCat
Copy link
Member

GreyCat commented Sep 20, 2017

From #1197, original by @crackedmind:

For example:

  1. Open vlq_base128_le
  2. Read this

This particular implementation supports serialized values to up 8 bytes long.

  1. Compile this template for C++ or C#
  2. And now we see that compiler uses only 32-bit integer for instance variables
@GreyCat
Copy link
Member Author

GreyCat commented Sep 20, 2017

This is more or less known problem, and it exists for the languages which use many different integer types for various purposes. See for example:

Unfortunately, it's relatively sophisticated problem, which balances between several facts:

  • Strong typed languages use extremely complex rules of integer type coercion, and in some cases these rules differ in different languages. For example, what's the result of adding signed 8-bit int and unsigned 16-bit integer? What it could be assigned to and thus converted explicitly/implicity?
  • Some language features are available strictly for certain integer types. For example, in Java one can't use 64-bit integers as array indexes.

KS's design decision on this was to ignore that complex set of rules altogether and just use "one size fits most" integer type for every particular language, where we're enduring any integer calculations. It's what's called CalcIntType in the code, and given that we want all types to be determined in precompile time (i.e. we don't want it to act differently for every target language), so it maps to what's considered to be "most common" and "most usable" for every language.

Probably we could at least somehow alleviate this problem by using "largest possible" integer type instead of "one size fits most one". It would raise some other problems, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants