Type safety could prevent nuclear war

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 4 22:05:49 PST 2016


On Fri, 05 Feb 2016 04:02:41 +0000, tsbockman wrote:

> On Friday, 5 February 2016 at 03:46:37 UTC, Chris Wright wrote:
>> On Fri, 05 Feb 2016 01:10:53 +0000, tsbockman wrote:
>> The compiler doesn't have all the information you need. You could add
>> it to the build system or the linker as well as the compiler. Adding it
>> to the linker is almost identical to my previous suggestion of adding
>> optional name mangling to C.
> 
> What information, specifically, is the compiler missing?

It doesn't know what targets I'm ultimately creating, and it doesn't know 
what files have been modified that I'm about to compile (but haven't 
compiled yet).

Example 1:

I compile one .c file referencing a function:
void foo(int);

That's going to end up in libfoo.so.

I compile another .c file in the same directory defining a function:
void foo(float);

That's going to end up in libbar.so.

No bug here. (The linker should tell us if someone depends on foo from 
libbar and foo from libfoo in the same executable.)

How does your putative compiler plugin handle it? Either I have to define 
a build rule for every source file to specify where to put this symbol 
cache (and you need to add parameters for the plugin to look for multiple 
caches, because libfoo and libbar share a lot of source files), or the 
plugin gives me false positives.

Example 2:

I compile a.c:
int foo(int i) { return i + 1; }

In the course of refactoring, I delete that function from a.c and add it 
to b.c with modifications:
int foo(int i, int increment) { return i + increment; }

My build script recompiles b.c before it recompiles a.c. Your compiler 
plugin produces a build error, halting my build. I have to make clean &&  
make in order to proceed -- and that's assuming I know your tool doesn't 
work well with incremental compilation.

The first problem might be uncommon, but the second would crop up 
constantly. They have the same fix: collect the information when you 
compile, evaluate it when you link.


More information about the Digitalmars-d mailing list