On Friday, 13 April 2018 at 22:29:25 UTC, Steven Schveighoffer
wrote:
On 4/13/18 5:57 PM, Jonathan M Davis wrote:
On Friday, April 13, 2018 16:15:21 Steven Schveighoffer via
Digitalmars-d
I don't know if the compiler can determine if a version
statement
affects the layout, I suppose it could, but it would have to
compile
both with and without the version to see. It's probably an
intractable
problem.
Also, does it really matter? If there's a mismatch, then
you'll get a linker
error, so it's not like you're going to get subtle bugs out of
the deal or
anything like that. I don't see why detection is an issue here.
Well, for layout changes, there is no linker error. It's just
one version of the code thinks the layout is one way, and
another version thinks it's another way. This is definitely
bad, and causes memory corruption errors.
But I don't think it's a problem we can "solve" exactly.
-Steve
@JonathanDavis, the original post goes through an example where
you won't get a compile-time or link-time error...it results in a
very bad runtime stack stomp.
@Steven You're just addressing the example I gave and not
thinking of all the other ways version (or other compiler flags)
could change things. For example, you could have version code
inside a template that changes mangling because it is no longer
inferred to be pure/safe/whatever.
The point is, this is a solvable problem. All we need to do is
save the compiler configuration (i.e. versions/special flags that
affects compilation) used when compiling a library and use that
information when we are interpreting the module's source as as an
"pre-compiled import". Interpreting a module with a different
version than was compiled can create any error you can possibly
come up with and could manifest at any time (i.e. compile-time,
link time, runtime).
The jist is that if we don't solve this, then it's up to the
applications to use the same versions that were used to compile
all their pre-compiled D libraries...and if they don't...all bets
are off. They could run into any error at any time and the
compiler/type system can't help them.