This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

#import future (summary and proposed solutions)


Summary

Here's a summary of what we've I've found out so far about #import.

1. #import has been obsolete for 5 years and deprecated with a warning for 3.
2. Apple's compiler has the warning switched off by default. GNUStep uses
-Wno-import. Thus, many users aren't aware of (1). They will never become
aware unless something changes.
3. Apple's Objective-C docs say that #import is recommended.
4. Apple's Foundation headers aren't protected against multiple inclusion, so
users couldn't switch to #include if they wanted to.
5. GNUStep does recommend against using #import, but (4) means that many
users use #import anyway to be portable.
6. At present, PCH doesn't work with #import. (It doesn't work for Objective-C
either; I have a patch for that, but can't test it until we do something about
#import.)
7. The docs for #import are vague about its precise semantics, and the wording is
subtly different between Apple's Objective-C docs and cpplib's docs. The
common phrasing is that #import prevents multiple inclusion of "the same
file", without elaboration on what "the same" might mean.
8. Apple's #import implementation differs from the FSF GCC version.
Two significant areas of difference are:
a. Apple's implementation considers files to be the same if they have the same
filename and inode (but not device) number, while the FSF GCC version
considers files to be the same if they are accessed by the same simplified
path.
b. Apple's implementation won't #import a file if it's been previously
#included; FSF GCC will.
9. Apple's implementation is known to have failure cases if the name and inode
number just happen to match.
10. On Darwin, inode numbers are 32 bits, so there's no way they can be
permanently consistent when (for instance) NFS-mounting a filesystem with
64-bit inode numbers. Thus, saving them in a file is not a good idea.

Impossible solutions

Here are a bunch of solutions that I considered and rejected.

1. Remove #import.
There are too many headers that require #import, both in Apple's system and
in other software. Getting them all changed would be more work than I can
put into the project.
2. Don't make #import work with PCH.
This would mean that we'd never have working PCH for Objective-C. Since Apple
currently has two other similar solutions that do work, it'd mean we'd be
keeping one around forever, and maintaining it. That's too expensive.
3. Make #import work differently, but only when a PCH file is used, for instance
suppress 8(b) above.
That breaks one of the fundamental principles of PCH files, which is that
the compiler should produce the same results whether or not you're using one.
4. Save and restore enough state so that #import can work just as it did before.
This requires saving absolute pathnames and/or device and inode numbers.
These aren't guaranteed to be valid in the context where the PCH file is used.
For instance, this would prevent building a PCH on one machine and copying it
to a bunch of machines in a build farm.

Possible solutions

These are the solutions that I've considered and not yet rejected.

5. Change the semantics of #import so that it's a semantic property of the token
stream.
This is the patch I posted. It changes #import so that "the same file" means
that the name by which it's referenced in the source is the same.
6. Use checksums to determine "same file"-ness, but otherwise as before.
This would be OK, although not great, for the FSF semantics; the cost of using
checksums would only be required once #import was used, although it would then
apply to every new file seen. Unfortunately, for the Apple semantics, it
would require checksumming every #included file at PCH creation time,
whether or not #import was used, in case someone later #import-ed one of those
files. I'll try this out to see how bad it is.
[Of course, with this solution you would avoid checksumming any file more than
once per compiler run.]
7. Use checksums, but only for #import; make #import and #include independent.
8. Use checksums, but don't implement 8(b).
(3) and (4) are intermediate points between (1) and (2); they have less cost
but change semantics more.
9. Implement (2) but remove #import from C and C++.
This would restrict the cost to Objective-C users.
10. Allow #import only when some special flag (-fallow-import?) was passed, then
use checksums.
I don't really like special flags, but this would have the advantage that
you could switch #import off by default, encouraging people to not use it...

#pragma once

Of these, solutions (6) and (8) allow "#pragma once" to also work with PCH files. I don't care if "#pragma once" works or not, but perhaps others might.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]