Commit Graph

1871 Commits

Author SHA1 Message Date
swift-ci
c8576c8c26 Merge remote-tracking branch 'origin/master' into master-next 2018-01-24 17:24:57 -08:00
Jordan Rose
3f4cba25d4 Use a semantic ClangImporterSynthesizedTypeAttr for error structs
...rather than the ad hoc CustomTypeNameManglingAttr I was using
before. As John pointed out, the AST should be semantic wherever
possible.

We may someday want to get out of this being an attribute altogether,
or duplicating information that's available in the original Clang
node, by actually storing a reference to that node somewhere. This is
tricky and mixed up with deciding what hasClangNode() or
getClangDecl() would mean, though, so for now the attribute just
carries the information we need.
2018-01-24 10:57:52 -08:00
Jordan Rose
e63879dc48 [Mangling] Define "related entity" operators 'LA'...'LJ'
(and 'La'...'Lj')

Use this for the synthesized structs for error enums, as described in
the previous commit, instead of reusing the "private discriminator"
feature. I left some space in the APIs for "related entity kinds" that
are longer than a single character, but I don't actually expect to use
it any time soon. It's mostly just easier to deal with StringRef than
with a bare char.

Note that this doesn't perfectly round-trip to the old mangling; I had
it treat these nodes as private discriminators with a prefixed "$"
instead. We don't depend on that for anything, though.
2018-01-24 10:52:46 -08:00
Jordan Rose
9c1a22ad0f Mangle synthesized error structs as a variant of the imported enum
When importing a C enum with the ns_error_domain attribute, we
synthesize a struct containing an NSError object to represent errors
in that domain. That synthesized struct should have a mangled name
that ties it to the original C enum, if we want it to be stable, and
now it does.

Before: $SSC7MyErrorV (a normal struct, which is a lie)
After: $SSC11MyErrorCode13ns_error_enumLLV
  kind=Global
    kind=Structure
      kind=Module, text="__C_Synthesized"
      kind=PrivateDeclName
        kind=Identifier, text="ns_error_enum"
        kind=Identifier, text="MyErrorCode"

Using the "private discriminator" feature allows us to pack in extra
information about the declaration without changing the mangling
grammar, and without stepping on anything the importer is using.

More rdar://problem/24688918
2018-01-23 17:05:43 -08:00
swift-ci
80edad4b1b Merge remote-tracking branch 'origin/master' into master-next 2018-01-12 22:50:16 -08:00
swift-ci
87843ea998 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-12 22:39:48 -08:00
Argyrios Kyrtzidis
1423af3a91 [ClangImporter] Make sure that headers from the bridging header are considered 'isBeforeInTranslationUnit' compared to headers imported from swift code
Previously headers from the bridging header and imported modules had the exact same top location so comparison with them
was not sound. This resulted in missing documentation comments from declarations and possible assertion hits while clang
was trying to determine the comment for a declaration, but I could not create a reduced test case that triggered an assertion hit.

rdar://34925466
2018-01-12 16:26:13 -08:00
swift-ci
ecc14e57dd Merge remote-tracking branch 'origin/master' into master-next 2018-01-10 18:24:27 -08:00
swift-ci
4ba7897493 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-10 18:14:31 -08:00
Jordan Rose
b7ff0d49ef Type reconstruction: look for Clang types directly, like RemoteAST
ClangImporter::lookupTypeDecl allows a Clang type declaration to be
imported by Clang name instead of by Swift name. Now that we're using
Clang names in mangled names, that's exactly what we need to
reconstruct an AST type from a mangled name.

Also:

- Handle @compatibility_alias in ClangImporter::lookupTypeDecl

- Print errors when type reconstruction fails in swift-ide-test

- Add an extra test for RemoteAST
2018-01-09 17:55:24 -08:00
Jordan Rose
bfa4ca4f00 [ClangImporter] Add ClangImporter::lookupTypeDecl.
This lets clients look up types by their /Clang/ names. This is going
to be useful for subsequent commits, but can also have independent use
when going from a class name / selector pair.
2018-01-09 17:55:24 -08:00
Bob Wilson
a84243c4e8 master-next: Stop using -m*-version-min options for the clang importer.
As of Clang r321099, the OS version specified on the target triple is
sufficient. Note that Arnold independently came up with this same patch
in https://github.com/apple/swift/pull/13556.
2017-12-20 13:02:01 -08:00
Doug Gregor
8c05278ef3 [Clang importer] Lazily load all named members with a matching base name.
When loading the named members for a given name, we want to load all
of the members with that base name... not only the ones that match the
full name, because the lookup table is indexed by base name and
filtering too early drops candidates.

Fixes rdar://problem/36085994.
2017-12-15 23:54:36 -08:00
Zac Bowling
f71456eb1b Define _GNU_SOURCE when importing glibc on Fuchsia (#13105)
Some functions and types are hidden behind feature flags.

_GNU_SOURCE exposes the most symbols and methods in glibc
and musl. Currently only turning it on for the Fuchsia triple.
2017-12-06 16:48:52 -08:00
Adrian Prantl
97f9e4e367 Don't pass -Werror to ClangImporter's clang when Swift is used from within LLDB.
This works a around search path problems caused by a module existing
in both the build/install directory and the source directory.

<rdar://problem/35714074>
2017-12-06 09:22:29 -08:00
Graydon Hoare
f937e33c9b [NamedLazyMemberLoading] Bail on nominals with globals-as-members. 2017-12-02 02:14:48 -08:00
Graydon Hoare
3e76aebee1 [NamedLazyMemberLoading] Support named loading from ObjC categories. 2017-12-01 16:52:25 -08:00
Graydon Hoare
8813935638 [NamedLazyMemberLoading] Bail on cases that interact with protocol member mirroring. 2017-12-01 16:52:25 -08:00
Arnold Schwaighofer
eba12a7c3e Revert "Finish and default-enable named lazy member loading" 2017-12-01 07:25:54 -08:00
Graydon Hoare
a967f8c6ea [NamedLazyMemberLoading] Support named loading from ObjC categories. 2017-11-30 22:27:58 -08:00
Graydon Hoare
b32f4f4185 [NamedLazyMemberLoading] Bail on cases that interact with protocol member mirroring. 2017-11-30 22:01:06 -08:00
Francis Ricci
3d1889c015 ClangImporter: default to ios objc runtime on non-darwin platforms
This allows objc interop to be tested on non-darwin platforms. The iOS
runtime is used because the abi is the same as the macOS abi, but without
fragility concerns.
2017-11-06 13:30:37 -08:00
Saleem Abdulrasool
4dba0a33c3 ClangImporter: allow control over ObjCInterop
Select the language for the clang importer based on the
`-enable-objc-interop` flag rather than target.  This paves the road to
enabling ObjC tests on non-Darwin targets as well as building on Darwin
without ObjC interop.
2017-11-06 13:30:36 -08:00
Saleem Abdulrasool
67fae0356c ClangImporter: minor clang-format fixing (NFC) 2017-11-06 13:30:36 -08:00
Graydon Hoare
ed0b43cbce [NamedLazyMemberLoading] Move SerialID to IDC, get extensions working. 2017-11-01 17:35:46 -07:00
Graydon Hoare
0cab561a7f [NamedLazyMemberLoading] Enable all clang::ObjCContainerDecl types. 2017-11-01 17:34:56 -07:00
Graydon Hoare
30b6fdce83 Merge pull request #12429 from graydon/named-lazy-member-loading
Named lazy member loading 1/N
2017-10-24 14:27:04 -07:00
Jordan Rose
d09669b0df Merge pull request #12169 from jrose-apple/dance-dance-deduplication
[ClangImporter] Don't add duplicate search paths
2017-10-24 11:43:13 -07:00
Graydon Hoare
cb1c8526c8 [NamedLazyMemberLoading] Address further review comments. 2017-10-20 22:48:45 -07:00
Graydon Hoare
ca3101c2af [NamedLazyMemberLoading] Sketch implementation of named protocol-member loading. 2017-10-20 22:48:43 -07:00
Jordan Rose
b53967fd19 [ClangImporter] Handle macros that are undefined and then redefined (#12413)
This includes 'LONG_MAX' in the Darwin module, which is defined by the
system and then immediately redefined by Clang's copy of limits.h.

The general strategy here is that if two definitions of a macro in the
same module are in separate explicit submodules, we need to keep track
of both of them, but if they're in the same explicit submodule then
one is probably deliberately redefining the other. This isn't fully
correct because one explicit submodule could include another explicit
submodule, but it's a good first approximation, which we can refine if
we come across problem cases in practice.

Swift /also/ has the ability to distinguish between ModuleA.MACRO and
ModuleB.MACRO if you've imported both modules, although there's an
issue that the two of them end up getting the same mangled name if you
try to use both in the same compilation unit. (Filed
rdar://problem/34968281.) That ability is preserved with this change.

All of this will likely change if/when we switch to Clang's "local
submodule visibility" mode, which is needed for the C++ Modules TS but
is also incompatible with Apple's SDKs at the moment. In that case,
macros in two separate explicit submodules will no longer have an
'override' relationship just because they're mentioned sequentially in
the module map.

rdar://problem/34413934
2017-10-13 15:08:51 -07:00
Jordan Rose
f331060ba7 [ClangImporter] Don't add duplicate search paths
Besides saving some calls to stat(), this also causes problems when
the user specifies a search path that Clang already adds by default,
like $SDKROOT/Library/Frameworks/. Why? Because Swift adds its search
paths after Clang has already configured its defaults, but Clang
reconfigures its search paths from scratch when compiling a module to
a PCM file to cache. This led to system search paths being found
sooner in the primary Clang instance than in the PCM files, which in
turn resulted in the PCM files being considered out of date.

This isn't likely to affect people much in practice, but it's better
to get right. (We ran into this during Doug's experiments in making
/System/Library/PrivateFrameworks a default search path in Clang
r313317; turns out that's problematic for other reasons as well.)

rdar://problem/34664596
2017-09-29 10:00:02 -07:00
Doug Gregor
bdc5afd69f Merge pull request #11955 from DougGregor/rexported-module-cleanup
Minor cleanups for the work to handle re-exported modules
2017-09-18 11:36:28 -07:00
Jordan Rose
82fa3627a8 Merge pull request #11867 from jrose-apple/ClangImporter-episode-V
[ClangImporter] Support Swift 5 API notes
2017-09-15 16:34:27 -07:00
Doug Gregor
fc20debc36 Jump through hoops to avoid adding a new Serialization -> clang::Module dependency. 2017-09-15 14:42:36 -07:00
Jordan Rose
9a04bee421 [ClangImporter] Turn ImportNameVersion into a struct.
...so that we don't have to keep coming back to update it every major
release. And also so we can actually put methods on it instead of
using free functions.

No intended behavior change (yet).
2017-09-15 14:30:24 -07:00
Jordan Rose
90f728a68e [ClangImporter] Check for failure in forEachDistinctName
forEachDistinctName might produce the same name for Swift 4 and Swift
5, but it's possible that for some reason the name will only work in
one mode or the other. In that case, even though we're trying the
"same" name again, we still want to invoke the callback once more.
Add a boolean return to the callback to support this.

Tests to come at the end of this patch series -- this shows up when in
Swift 3 mode and the canonical version for types is set to Swift 5.
2017-09-15 14:30:24 -07:00
Doug Gregor
21e34d78d8 const'ify an API's parameters. NFC 2017-09-15 13:52:13 -07:00
Doug Gregor
e5ebb5854f Treat entities from (private) modules as members of the re-exported module.
A public C module can be expressed as the combination of several
private modules at build time, where that structure is "collapsed"
into a single public module for client use. In such cases, the symbols
associated with the public module can actually be seen as coming from
the private module (e.g. at the time the Swift overlay is built),
which fools our overlay-specific hacks. When a module states that it
is re-exported via another, public module, teach semantic analysis to
treat the entity "as if" it came from the re-exporting public module.

Part of rdar://problem/34438586.
2017-09-14 15:09:18 -07:00
Doug Gregor
583a9c42ea [AST] Factor out the "is this in an overlay" check. 2017-09-14 15:09:18 -07:00
Jordan Rose
264ac94c44 [ClangImporter] Update for Clang-side removal of the API notes cache. (#11793)
No need to pass -fapinotes-cache-path anymore.

Non-critical follow-up for rdar://problem/31745420.
2017-09-06 17:42:33 -07:00
Jordan Rose
f8b7db4e76 Excise the terms "blacklist" and "whitelist" from Swift source. (#11687)
The etymology of these terms isn't about race, but "black" = "blocked"
and "white" = "allowed" isn't really a good look these days. In most
cases we weren't using these terms particularly precisely anyway, so
the rephrasing is actually an improvement.
2017-08-30 09:28:00 -07:00
Jordan Rose
61746b39ab [ClangImporter] Stop abusing a Clang API to avoid a use-after-free. (#11377)
In order to allow LLDB to debug an app as it was written (in theory),
we stuff a semi-preprocessed version of the bridging header into the
generated swiftmodule file, so that we can fall back on it if the
original bridging header is deleted. The specific functionality we
want is in Clang's -rewrite-includes option, but we need to write to
an in-memory buffer instead of a file.

The existing code took the meat of clang::RewriteIncludesAction and
recreated it manually. We got away with this in the past, but upstream
Clang has changed how clang::RewriteIncludesAction works, and now what
we were doing before results in the (unused) file output stream being
deallocated before the (also unused) buffering stream wrapped around
it. Rather than continue trying to half-use an existing Clang
FrontendAction, just make a new one that does the thing we want and
nothing else.

I'd like to revisit this whole idea in the future -- it doesn't
actually preserve debuggability in the case where the bridging header
may have changed, because we don't check for modifications in all the
things it includes. But for now this should preserve the existing
functionality.

rdar://problem/33693128
2017-08-07 19:10:52 -07:00
Jordan Rose
5d053d95a4 [ClangImporter] Restore proper macro shadowing rules.
Last follow-up to c3d6be64ab. Already covered by
test/ClangImporter/macros_redef.swift.

rdar://problem/32199805
2017-07-26 15:42:31 -07:00
swift-ci
6d7415e0da Merge remote-tracking branch 'origin/master' into master-next 2017-07-25 22:09:00 -07:00
John McCall
c893e955aa Propagate "-O" to Clang (as "-Os").
It affects Clang IRGen, among other things.
2017-07-26 00:32:08 -04:00
swift-ci
b4016dde18 Merge remote-tracking branch 'origin/master' into master-next 2017-07-25 06:08:49 -07:00
Kosuke Ogawa
ba12f51315 [Gardening] Fix typo: necesary -> necessary 2017-07-25 18:09:24 +09:00
swift-ci
5b15da4b32 Merge remote-tracking branch 'origin/master' into master-next 2017-07-17 14:08:49 -07:00
Jordan Rose
bc460a2321 [ClangImporter] Add fast-path lookup for error code enums as well.
These are also imported as local types, so they can have the same
issues as the previous commit.
2017-07-17 11:52:48 -07:00