Live data from Hacker News

Apple's Module proposal to replace headers for C-based languages [pdf]

llvm.org

121–130 of 187 posts

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#121
post #58

Earlier quoted context omitted.

Definitely seems like Go has led the way here. Not that there wasn't a lot of pain before, but Go's lightning compilation seems to be an impetus for the "let's finally do this" change. I have to think that this is a minor repartee between Apple and Google language groups. Google did something clever that breaks with tradition, and now Apple is doing something similarly clever yet backwards-compatible. I like this dyn…

Object Pascal did the exact same thing 20 years ago, and it was a language much more influential than Go at its time. So, I don't think Apple programmers had even to look at Go to design this feature.

Yeah. Compile times there were ridiculously fast, bordering on interactive. Go follows the same path.

Java has very fast compilation as well, due in no small part to tossing the preprocessor and having fast binary imports.

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#122
post #32
post #29

While LLVM authors probably know best, I don't understand some of his criticisms on the "Inherently Non-Scalable" slide. • M headers with N source files -> M x N build cost It's only MxN if there is no use of the "#ifndef _HEADER_H" workaround that he mentioned earlier. Wouldn't adding a preprocessor directive like "#include_once " solve this? Alternatively, these guards could be added to the headers themselves withou…

It's only MxN if there is no use of the "#ifndef _HEADER_H" workaround that he mentioned earlier. There still is a processing cost for evaluating the instruction

For GCC this is highly optimized:

"The preprocessor notices such header files, so that if the header file appears in a subsequent #include directive and FOO is defined, then it is ignored and it doesn't preprocess or even re-open the file a second time. This is referred to as the multiple include optimization."

http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#123
Overall this seems good. The lack of modules in C/C++ is a huge pain. The "link" section seems like a really leaky abstraction, though.

  module ClangAST {
    umbrella header “AST/AST.h”
    module * { }
    link “-lclangAST”
  }
This hardcodes an implementation-specific syntax and yet says nothing meaningful. Drop the "-l" and you're just restating the name of the module. What value is there in baking a command-line flag into the module definition?

P.S. I also find it strange that something intended to blend with C/C++ doesn't use semi-colons. This is just stylistic, though.

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#124

Overall I like it. I like how they are treating both C and C++ as first-class citizens of this new feature (instead of, for example, inextricably tying its design to classes and namespaces). I like that they have a plausible migration story for how to interoperate with existing header files. And the overall design really looks like something that would fit into all of the C and C++ work that I do without getting in t…

With regards to backward compatibility with include: modules will still be preprocessed before they are assembled. This is necessary to drive much of the preprocessor meta-programming that is around in various libraries and which will not go away with variadic templates due to performance reasons.

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#125
post #63

Overall I like it. I like how they are treating both C and C++ as first-class citizens of this new feature (instead of, for example, inextricably tying its design to classes and namespaces). I like that they have a plausible migration story for how to interoperate with existing header files. And the overall design really looks like something that would fit into all of the C and C++ work that I do without getting in t…

> Sure it's non-standard Doug chairs the study group that's evaluating a module system for c++ ("""Sutter announces there is a Study Group for modules and Doug Gregor is the chair.""" http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n338... ) Doug happens to be employed by Apple, but calling this "Apple's proposal" is somewhat misleading I think.

I'm wondering: All modules proposals so far have come from Daveed Vandevoorde including the last one [1].

As far as I can see clang is just the first compiler implementing this proposal which is a very important step for standardization, because prior implementation experience ends up influencing the process heavily.

[1] : www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3347.pdf

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#126
post #66

I didn't see any mention of the recursive-usage problem. How do they plan on handling co-dependant files? For example, class A's code makes use of class B. Class B's code makes use of class A. a.h looks like: class B; class A { public: void foo (B *); } a.cc looks like: #include "a.h" #include "b.h" void A::foo (B *) { b->narf (); } and b.h and b.cc use A in the same way.

I don't see what the issue is. In some sense, the proposal is to essentially do away with inserted code and instead do what Java is doing with its import statements: a public API. There's no recursion issue in Java.

I think you may be mixing this up with C's #include, which does have recursion issues, hence the need for its absurd #ifdef guards. But Apple did away with that years ago with #import, which is basically #include with built-in guards.

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#127
post #65

Earlier quoted context omitted.

Compile time is usually fine if you build your code so that dependencies are simple as intermediate .o files are only built in dependency chains. Link time is much higher on larger projects, which this still fails to solve. Knowing your shit gets you further than language changes here. For ref, I've been writing c since 1986 and I've seen proposals like this come and go lots and every one doesn't end up with an impro…

I've used Oberon, which has a module system quite similar to this, quite heavily, and the way to diminish link time is to not link, instead use dynamic loading: leaf modules are loadable and unloadable, nonleaf modules can be made leaf by unloading all their descendants. Gives you the possibility for immediacy/flow, that a good REPL does. For many cases, you get edit/compile/run cycles measured in (often single-digit…

Agree with this completely.

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#128
post #113

Earlier quoted context omitted.

That Apple uses C++ (you could also have mentioned LLVM) does not change their production and API being mostly C or Obj-C, and thus their proposals are usually for C. A previous examples was blocks, they created those for C and Obj-C, they can be used from C++ but are completely incompatible with C++11 lambdas as far as I know.

You can now implicitly cast lambdas to blocks, although they're otherwise completely separate (and must be - C++'s approach wouldn't easily translate to C).

They can be cast the other way, too. No?

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#129
post #101

Earlier quoted context omitted.

No, the issue is not just poor implementation. Problems like O(M*N) bloat and scope pollution are fundamental design flaws with the preprocessor header system. Almost every widespread modern language (all except JavaScript? [1]) has a built-in module system. Adding modules to C is not just some sort of hack to work around preprocessor limitations. Instead I'd say that the C preprocessor is a hack to work around lack…

You can add some functionality to limit scope and implement a caching system (which is also proposed here) to deal with M*N issues with a focus on keeping backwards compatibility. E.g. the caching is done automatically, the scope spamming control is a best effort solution based on static analysis (for example). Moving from headers to modules is a fundamental change in how the language operates and is guaranteed to fu…

> You can add some functionality to limit scope and implement a caching system (which is also proposed here) to deal with M*N issues with a focus on keeping backwards compatibility.

You can't cache the AST of a #include'd file without breaking the standardized semantics of #include. ccache (which is what you're basically proposing) gets away with it by just ignoring the standard and shrugging if some legal programs break horribly when it's used. The Standards Committee doesn't have that luxury.

You can't change existing functionality while "keeping backwards compatibility". The draft Modules proposal does a much better job of backwards compatibility than what you're proposing, because it allows #include to continue to have the same semantics it has always had, and even provides a clean way forward for using both #include and modules in the same translation unit.

> Moving from headers to modules is a fundamental change in how the language operates and is guaranteed to further break compatibility between compilers further.

How would a standardized module system "break compatibility" between standards compliant compilers? The title of this story is completely misleading: this isn't "Apple's" proposal, this is about LLVM's implementation of the Standard Committee's Module Working Group's draft proposal.

> I worry that jumping to add these features to the language standard is premature

The committee was worried about that too; that's why the draft proposal was held out of C++11 so that vendors could try out implementing it and see how it fared in the real world.

> we should instead look further to optimizations within the preprocessor and linker to see if we can improve performance first.

It's not as though nobody has ever tried to improve pre-processor or linker performance; people have have been looking at those issues since the beginning of C. There is, fundamentally, no way to improve the performance of the current system without breaking semantic compatibility with existing programs.

Re: Apple's Module proposal to replace headers for C-based languages [pdf]

#130
post #74

Anyone know where I can read more detail about this proposal? It looks really interesting, but there are a couple of things I'm not clear on from the pdf: How do you get away from creating a header file for a closed source module? Without a header, how would users of your module know what they can call? Can you perform reflection on a module to inspect it? Is there some kind of tool proposed, like javadoc or pydoc, t…

I know nothing about this proposal, but I can make educated guesses on all of these: Creating header: the module needs only the public information for a closed source module. You could generate it from a .h file if you are a consumer of a closed source module, or if you are the producer of the module, you could potentially ship either pre-generated modules or all the information needed to generate a module. javadoc,…

Thanks, I think you're probably right - the modules would have to have enough information in their compiled form that your compiler could introspect them without needing the source. The proposal wouldn't be much use if that weren't true.

Re: templates, I thought the expensive part of template processing was code generation rather than parsing. Would caching the AST really be that much of a saving? I admit I've never tried profiling it to find out...

Post reply on HN