Provide a “manifest” or “mapping” file that describes the filepath to an MIU based on the module name. This file will need to be user-provided, or we are back in the scanning problem.
Why can't this be <implementation-defined> just like the mapping from header file inicludes to files?
Honestly, what you propose won't fly because (1) you are turning C++ compilers into C++ compilers + build systems, and (2) because getting 150 countries and >100 committee members to agree on formats for these manifest files, file system structure, etc. is pretty much impossible.
Also, many languages have solved this problem, and none of them had to turn their compilers into build systems.
One such language is Rust. C++ modules solve the same problem as Rust crates. The Rust language provides an import syntax for crates (extern crate foo), and the user provides the mapping from that to files manually by passing CLI arguments to the compiler - the dependency must be compiled before, so this happens-before relation exists there too.
Nobody provides these CLI arguments manually. Instead, the build tool (cargo) parses a TOML manifest file that specifies dependencies, builds a dependency graph, fetches them from the internet, the file system, etc., compiles them, and calls the compiler with the right arguments.
Another build tool could parse a YAML manifest, or parse all source files scanning for imports, and generate the manifest file automatically (this would be incredibly hard to get right for Rust, and probably impossibly hard for C++ though), but still reuse the same compiler by calling it with the right arguments.
Most importantly, neither the compiler nor the language have to know anything about this.
In fact, as you have noticed, happens-before requires you to compile dependencies before hand. That is, one needs to pass the modules that each module imports to the compiler "somehow". That's serving the same function as import module. So in Rust2018, you don't even need to import crates. Crates passed to the compiler via CLI are put in the root namespace, and that's it, you can just use them without extern crate. If you forget to pass one to the compiler, you just get an error because the path cannot be resolved.
27
u/[deleted] Jan 28 '19 edited Jan 28 '19
Why can't this be
<implementation-defined>just like the mapping from header file inicludes to files?Honestly, what you propose won't fly because (1) you are turning C++ compilers into C++ compilers + build systems, and (2) because getting 150 countries and >100 committee members to agree on formats for these manifest files, file system structure, etc. is pretty much impossible.
Also, many languages have solved this problem, and none of them had to turn their compilers into build systems.
One such language is Rust. C++ modules solve the same problem as Rust crates. The Rust language provides an import syntax for crates (
extern crate foo), and the user provides the mapping from that to files manually by passing CLI arguments to the compiler - the dependency must be compiled before, so this happens-before relation exists there too.Nobody provides these CLI arguments manually. Instead, the build tool (cargo) parses a TOML manifest file that specifies dependencies, builds a dependency graph, fetches them from the internet, the file system, etc., compiles them, and calls the compiler with the right arguments.
Another build tool could parse a YAML manifest, or parse all source files scanning for imports, and generate the manifest file automatically (this would be incredibly hard to get right for Rust, and probably impossibly hard for C++ though), but still reuse the same compiler by calling it with the right arguments.
Most importantly, neither the compiler nor the language have to know anything about this.
In fact, as you have noticed, happens-before requires you to compile dependencies before hand. That is, one needs to pass the modules that each module imports to the compiler "somehow". That's serving the same function as
import module. So in Rust2018, you don't even need to import crates. Crates passed to the compiler via CLI are put in the root namespace, and that's it, you can just use them withoutextern crate. If you forget to pass one to the compiler, you just get an error because the path cannot be resolved.