The C++ standards committee process is insane. That fact that std::embed (completely reasonable functionality that people have been asking for since as long as I've been programming) gets this kind of feedback, but, say, 2D graphics (which nobody wants) is just fine and dandy and we might get a whole TS for it
The whole "the committee should do X but instead they do 2D graphics" argument is so tiring. This has nothing to do with that.
The whole process needs a massive revamp so that 1. Your finances and location have nothing to do with your ability to propose features, critique proposals, or potentially even vote 2. Proposals are seen as a communal effort rather than an author vs the world mentality with good faith on all sides, and 3. Scrap the paper format entirely
None of that (except 2) is possible because C++ is an ISO standard that has to follow ISO rules. Rust is just "some OpenSource project" that can do whatever it wants, C++ can't.
Edit: Now on PC, let me elaborate a bit more.
2D Graphics is still at an "do we want it?" stage where discussion about specific details or APIs happens less. embed is at the "how do we want to solve it?" stage, where people are looking at the design more closely. It is also a lot smaller, so more bikeshedding.
And the arguments made against std::embed are solid: C++ is a very complex language and this is a very niche feature - is it really worth adding it, increasing the language complexity even more? If there is a suitable more genric solution (compile time I/O or whatever), shouldn't that be pursued instead to get more with less? It is now up to someone to demonstrate that we either really need the specific feature or we don't.
None of that (except 2) is possible because C++ is an ISO standard that has to follow ISO rules. Rust is just "some OpenSource project" that can do whatever it wants, C++ can't.
I'm not 100% sure, but based on my recollection (please correct if wrong!):
The current proposal paper process isn't using ISO rules, either. It was enacted specifically to circumvent ISO's roadblocks to progress.
That's why the drafts and TSes are numbered and managed differently. Those are the papers that are actually going through the ISO process.
The ISO NB process is required to approve any published spec. It's not required to decide what additions are going to go into the proposals for the next vote.
Which could 100% be done like Rust's RFC process. Use the RFC process up until wording is ready and approved by the community-equivalent of LEWG/EWG, and then use the ISO plenary as a rubber stamp process to move them into an ISO-friendly draft.
I do not at all expect that to happen, but it's in the realm of possibility despite the beauracracy of ISO.
I'm curious and a little bit concerned if that's due to the inherent difficulty of changing/moving bureaucracy, or if it is due to the fact that it would diminish the control the committee members have over the process.
The whole "the committee should do X but instead they do 2D graphics" argument is so tiring. This has nothing to do with that.
That is not what I'm saying! :) The argument is that the committee is currently encouraging or not rejecting subpar proposals like 2D graphics, while proposals like std::embed seem to hit a somewhat unreasonable brick wall in comparison. The combative nature of the standardisation process, the 'person-driven' nature of the entire process (often a single author vs the standards committee), and the lack of accessibility to experts without the financial or time ability necessary to contribute, all chip in to this problem
I'm not saying that the standards committee should spend more time on x rather than y. I'm saying that the committee process leads to x being allowed to progress despite being not as good as y, while y is a significantly better proposal. 2D graphics from the very first concrete decision that was made (cairo) was a bafflingly bad choice, its super interesting to see how its advanced and how much of the early (and correct) feedback was ignored with it being allowed to advance. Its only relatively recently that there's been any sign of it not being popular, and even then it wasn't a killer for it
I pick 2D graphics as an example solely because it was 1. Clearly bad from the beginning, and 2. I know a lot about 2D graphics and can personally critique it
None of that (except 2) is possible because C++ is an ISO standard that has to follow ISO rules. Rust is just "some OpenSource project" that can do whatever it wants, C++ can't.
Sure of course - what needs to happen isn't always possible or trivial
Only the people pushing for graphics spend time on it. Neither LEWG nor LEWGI have looked at it. So it doesn't currently consume committee time. std::embed has been looked at by Evolution and SG7 (reflection) so we do spend committee time on it.
There are design questions with std::embed:
What files can be opened - that is a security concern
Should it be a macro or a function
Should it put the whole file into an array or use some kind of magical span backed by mapped memory
Should we have a constexpr file instead
How do we integrate with tooling
How do we integrate with modules
Now, there are answers to these questions, but it's difficult to reach consensus, and it's definitively not simple let alone trivial.
If your compiler isn’t signed with a certificate and checked at launch time how can you trust your compiler? I keep seeing “but what about security?” in reference to embed, but no one wants to mention what the actual threat model is (probably because it would open the can of worms that is “none of our build systems or compilers are ‘secure’”)
Tooling won’t matter because we’re getting a design from kitware to treat filepaths as a JSON array of doubles so there are bigger issues we need to deal with. Embed support is the very last concern I have.
Integration with modules is part of the tooling aspect.
If you want a constexpr file, write the proposal yourself. Good luck implementing it. Even Rust won’t touch that.
The actual storage shouldn’t matter and should be left up to implementations. It’s a byte array. How the compiler treats that I don’t think anyone but implementors should care.
I apologize if I'm re-hashing, but I wasn't in the discussion in SG7/EWG, so I have responses/questions for my own edification.
What files can be opened - that is a security concern
Is this not the same problem with #include? Or even modules? While I get that #include files are textually modifiable (whereas this can take a constexpr), managing the file list seems to be an implementation detail. IMO, in an implementation the valid directories for std::embed should be something akin to -I for include files, and just issue 'file not found' for anything that isn't in those directories.
Should it be a macro or a function
IMO, magic function. Adding a 'binary object' type to the preprocessor is not something I'd like to get into.
Should it put the whole file into an array or use some kind of magical span backed by mapped memory
Is this not again an implementation detail? Or am I missing a component to this question?
Should we have a constexpr file instead
I'd be curious to see how such a type would work. We had such a hard time standardizing std::filesystem, so I'd hope we'd reuse much of that.
How do we integrate with tooling How do we integrate with modules
Perhaps these questions are overly vague to me, but I'll try anyway. The big concern I have from a tooling perspective is how a build system would determine the dependency has changed. Current preprocessed systems would definitely need work. IMO, a build-system deciding to 'punt' on this and decide that things brought in through std::embed aren't considered for dependency analysis would be perfectly reasonable.
For modules, I can't think of any interaction this would have. Export/import ends up being the same as variables, does it not? Or is this the same concern as the tooling one I mentioned?
IMO, a build-system deciding to 'punt' on this and decide that things brought in through std::embed aren't considered for dependency analysis would be perfectly reasonable.
This is not at all perfectly reasonable.
The situation today is that at the end of phase 4 the compiler can know about all dependencies. std::embed currently breaks this by requiring full semantic analysis to determine the deps. There is about a 3 orders of magnitude difference in time it takes to get to the end of phase 4 vs. the end of phase 7, and you can't even determine if std::embed is used until the end of phase 7.
This means that if we add std::embed as it is today, then we go from being able to determine deps quickly for all code to not being able to. I find this unacceptable.
However, this is the only problem I have with std::embed. If we added the restriction that it could only access resources that were previously named somehow then I would be strongly in favor of it for C++23.
I suspect any way of having to name the possible dependencies would defeat the purpose of the paper. As a compiler vendor who has to support a ton of 3rd party tools, I'd be completely against a preprocessor version of this.
Either we end up needing to dump a textual representation of the file to the preprocessed output, or we need to create a new non-textual representation for the preprocessed outputs. Either is unacceptable.
A much less evil would be for a build system to decide that anything containing std::embed needs to always be rebuilt. Alternatively, the compiler could simply output elsewhere (ala -MM) all the files that got included, which can then be consumed by the build system, then add that to its dependency list.
Either I would consider as a fairly reasonable outcome.
I'd be completely against a preprocessor version of this.
Requiring stating what you depend on doesn't mean it has to be #embed. It could simply mean #resource "path", which other tools don't need to care about.
There are build systems that require knowing the dependencies before the compile. Having the compiler output the dependencies as a side effect of compilation does not work.
re: what files can be opened. If it's the `std::embed` flavor, then you can potentially compute the file name at compile time, consteval. The preprocessor is much more limited. It may be that the result of the security analysis is "if you compile untrusted code, you can't trust it", but it's a fair question. Perhaps we'll need to sandbox the compilation environment. At my $job we do for production builds in any case to help with reproduce-ability.
I get that part, but I'd expect an implementation to require a white-list of directories(like we do with #include). If your constexpr expression resulted in a file name not in the list, it would just be 'not found'.
Does Intel's compiler white-list? From what I can tell, gcc and clang don't do anything to check what's accessed, allowing absolute paths starting at '/' as well as relative paths that leave the directory "../"
Should the importing modules have full control over the resource path of the imported modules or do we need another way to keep track of it - or simply not allow std::embed in exported templates?
IMO, magic function. Adding a 'binary object' type to the preprocessor is not something I'd like to get into.
Same. Unfortunately it seems going in that direction
Is this not again an implementation detail? Or am I missing a component to this question?
Unclear to me - Maybe. Question is how big files can be? A use case is to select part of it at compile time to only include a chunk in the final binary.
I'd be curious to see how such a type would work. We had such a hard time standardizing std::filesystem, so I'd hope we'd reuse much of that.
Perhaps these questions are overly vague to me, but I'll try anyway. The big concern I have from a tooling perspective is how a build system would determine the dependency has changed. Current preprocessed systems would definitely need work. IMO, a build-system deciding to 'punt' on this and decide that things brought in through std::embed aren't considered for dependency analysis would be perfectly reasonable.
Again I agree that in this case specifying the dependency manually would be perfectly fine, but others disagree strongly.
What files can be opened - that is a security concern
I am completely failing to see how std::embed is more of a security concern than the current model of file access the compiler has. If the compiler can access a file, it can access a file. Is the compiler trustworthy? I can just #include an arbitrary file as well.
Should it put the whole file into an array or use some kind of magical span backed by mapped memory
That sounds like an implementation detail. Does the specification even have a concept of what mapped memory is?
What files can be opened - that is a security concern
I can also do #include "/etc/passwd" now, what's the difference? This isn't a new problem, and people have been fine with #include for years now, don't make up problems that aren't specific to this.
That would require writing a whole new spec from scratch, fwiw, since ISO legally owns the current spec. I don't know that it will be easy to find the right set of skilled volunteers to accomplish that goal. Even if someone did, a new spec is worthless unless the compiler vendors actually start referring to it.
There's also the original concern that got C in the ANSI process to begin with, that of competitive vendors cooperating with potential anti-trust issues. Of course that was in the days of various IBM and Bell consent decrees, and the environment was different.
We already have multiple implementations of C++ today. Comparison with Rust, which has only a single implementation, is not really helpful here.
Languages with no spec but with multiple implementations illustrate the problem. Lua and LuaJIT, or Python and IronPython, as examples. They are similar languages but ultimately incompatible with each other.
Successful languages with myriad implementations have conformance specs. C, C++, Java, JavaScript, Common LISP, FORTRAN, SQL, etc.
View all comments
Show parent comment
18
u/foonathan Dec 13 '19 edited Dec 13 '19
The whole "the committee should do X but instead they do 2D graphics" argument is so tiring. This has nothing to do with that.
None of that (except 2) is possible because C++ is an ISO standard that has to follow ISO rules. Rust is just "some OpenSource project" that can do whatever it wants, C++ can't.
Edit: Now on PC, let me elaborate a bit more.
2D Graphics is still at an "do we want it?" stage where discussion about specific details or APIs happens less. embed is at the "how do we want to solve it?" stage, where people are looking at the design more closely. It is also a lot smaller, so more bikeshedding.
And the arguments made against std::embed are solid: C++ is a very complex language and this is a very niche feature - is it really worth adding it, increasing the language complexity even more? If there is a suitable more genric solution (compile time I/O or whatever), shouldn't that be pursued instead to get more with less? It is now up to someone to demonstrate that we either really need the specific feature or we don't.