Commit Graph

888 Commits

Author SHA1 Message Date
swift-ci
36b254df94 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-03-08 01:58:15 -08:00
swift-ci
52a9d71e70 Merge remote-tracking branch 'origin/master' into master-next 2018-03-08 01:49:10 -08:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Bob Wilson
5e4822cc4c Revert "ClangImporter: Update Swift for changes in clang (PCH + Modules issues)"
This reverts commit fa2a5779b1.

The Clang change associated with this is only on swift-5.0-branch as a
temporary solution. Bruno is working on a better fix for trunk, so the
Swift master-next branch should not include this.

rdar://problem/37828424
2018-02-23 09:54:11 -08:00
swift-ci
06b97819cf Merge remote-tracking branch 'origin/master' into master-next 2018-02-22 10:11:31 -08:00
Bruno Cardoso Lopes
fa2a5779b1 ClangImporter: Update Swift for changes in clang (PCH + Modules issues)
This sets the NeededByPCHOrCompilationUsesPCH language option when
emitting a brigding PCH.

rdar://problem/35056912
rdar://problem/30384801

Initial patch by Adrian Prantl

(cherry picked from commit 5d5f542fe4)
2018-02-22 09:59:46 -07:00
Bruno Cardoso Lopes
83052a0ea9 ClangImporter: Update Swift for changes in clang (PCH + Modules issues)
This sets the NeededByPCHOrCompilationUsesPCH language option when
emitting a brigding PCH.

rdar://problem/35056912
rdar://problem/30384801

Initial patch by Adrian Prantl

(cherry picked from commit 5d5f542fe4)
2018-02-21 13:28:33 -08:00
swift-ci
7a3969774e Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-16 12:58:13 -08:00
swift-ci
15b26e6474 Merge remote-tracking branch 'origin/master' into master-next 2018-02-16 10:09:50 -08:00
Jordan Rose
af4d4e94c8 [ClangImporter] If a submodule named 'Private' is missing, ask Clang (#14673)
Previously the recommended pattern for having a "private" interface
for a public framework that was easy to strip out was to define an
explicit submodule named 'Private'. However, that makes it all too
easy to have dependencies from the public parts of the module on the
private parts, and other such problems. We're now recommending that
the private module map instead define a parallel module named with
"_Private" as a suffix. Clang already implemented this, but Swift
didn't get the same treatment.

This fix tries to avoid hardcoding too much; it notes that this kind
of remapping is limited to the name 'Private' as the second component
of a module hierarchy, but doesn't actually encode the mapping with the
"_Private" suffix.

rdar://problem/37553763
2018-02-16 10:01:12 -08:00
swift-ci
88240e5dd8 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-13 14:18:07 -08:00
swift-ci
dd719f808a Merge remote-tracking branch 'origin/master' into master-next 2018-02-13 14:09:32 -08:00
Jordan Rose
d8948f0dfb [ClangImporter] Use unique import locations for bridging headers too (#14580)
Like 0d347ac1, but for bridging headers. We can have multiple bridging
headers if someone is sneaking them into a library target, even though
we've tried to lock down on that. Up until now we've been pretending
they're all included at offset 0 in the dummy main source file, but
that causes problems in rare occasions involving precompiled headers.

(I'm being vague about what those circumstances are because I haven't
actually nailed them down yet, nor have I reduced the reproducing
project to something that can be checked in as a regression test. But
it's something like "we encountered this header through a particular
include path, but we thought that include path led to a different
header".)

Instead, reuse the fix we had for module imports: a monotonically
increasing include location in a fake (but allocated) buffer. This
will still put the bridging header first under normal circumstances,
but will also handle a mix of module imports and extra bridging
headers being loaded.

rdar://problem/34349832
2018-02-13 14:02:05 -08:00
swift-ci
2b3154deb0 Merge remote-tracking branch 'origin/master' into master-next 2018-02-08 17:09:47 -08:00
swift-ci
f9eac55110 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-08 16:58:52 -08:00
Jordan Rose
6754cc6dd0 [ClangImporter] Handle submodule imports in bridging headers
If a bridging header imported a submodule but /not/ the top-level
module, the top-level module would never be made visible. This is a
problem since the Clang importer makes all top-level decls available
through their enclosing top-level modules, not the individual
submodules.

To fix this, stop special-casing the way we handle bridging header
imports; we can translate them from Clang Modules to Swift ModuleDecls
the same way we do for regular imports.

rdar://problem/37355259
2018-02-08 11:35:56 -08:00
swift-ci
0d66611286 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-24 17:29:14 -08:00
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