Commit Graph

2951 Commits

Author SHA1 Message Date
Slava Pestov
8075b09b9b ClangImporter: Set the 'throws' bit on a few CallExprs
This allows Sema to skip checking external definitions altogether.
2019-05-23 10:40:34 -04:00
Slava Pestov
57254cb6e3 ClangImporter: Build type-checked AST for constants 2019-05-23 10:40:34 -04:00
Slava Pestov
7a630f40c4 ClangImporter: Track raw types of imported struct and enum wrappers
These will be used shortly to avoid name lookups into the imported type.
2019-05-23 10:40:34 -04:00
Slava Pestov
95843e372c ClangImporter: Remove ConstantConvertKind::{Coerce,Downcast} 2019-05-23 10:40:34 -04:00
Ben Langmuir
2210d24b48 [clang-importer] Fix option -disable-modules-validate-system-headers
This option stopped working when clang changed its default behaviour to
-fmodules-validate-system-headers; we now need to explicitly disable it
to preserve the behaviour of our flag.

rdar://problem/50908762
2019-05-17 16:22:37 -07:00
Alexis Laferrière
9c4c30413b Merge pull request #24591 from xymus/req-sig-request
GSB: Lazy requirement signature
2019-05-10 08:47:27 -07:00
Rintaro Ishizaki
d3d30ee246 [Serialization] Support Swift only system module
Previously 'isSystemModule()' returns true only if the module is:
- Standard library
- Clang module and that is `IsSystem`
- Swift overlay for clang `IsSystem` module

Now:
- Clang module and that is `IsSystem`; or
- Swift overlay for clang `IsSystem` module
- Swift module found in either of these directories:
  - Runtime library directoris (including stdlib)
  - Frameworks in `-Fsystem` directories
  - Frameworks in `$SDKROOT/System/Library/Frameworks/` (Darwin)
  - Frameworks in `$SDKROOT/Library/Frameworks/` (Darwin)

rdar://problem/50516314
2019-05-08 17:03:06 -07:00
Alexis Laferrière
3dd54c24d1 Remove explicit calls to computeRequirementSignature
We can rely on lazy calls to getRequirementSignature instead.
2019-05-08 14:28:35 -07:00
Rintaro Ishizaki
6956089b0b [CodeCompletion] Complete Swift only module name after 'import'
rdar://problem/39392446
2019-05-08 10:11:52 -07:00
Slava Pestov
3371080b9f ClangImporter: Built type-checked expressions in union and indirect field accessors
When we remove Sema's UsedConformances list, conformances to _BridgedStoredNSError
are checked from SILGen, where its too late to check function bodies of synthesized
functions.

We could solve this by adding a callback to type check a synthesized function's
body, but in fact all synthesized functions are rather trivial so it's better to
build their bodies fully type checked.

Start by building fully checked expressions for various accessors in ClangImporter.
2019-05-08 01:09:33 -04:00
Ben Langmuir
34da079aa6 Pass DynamicLookupInfo through VisibleDeclConsumers NFC
This commit adds a new type DynamicLookupInfo that provides information
about how a dynamic member lookup found a particular Decl. This is
needed to correctly handle KeyPath dynamic member lookups, but for now
just plumb it through everywhere.
2019-05-06 10:02:39 -07:00
Jordan Rose
517f5d6b6a [ClangImporter] Retire the term "adapter" in favor of "overlay" (#24427)
Way back in Swift 1 I was trying to draw a distinction between
"overlays", separate libraries that added Swift content to an existing
Objective-C framework, and "the Swift part of a mixed-source
framework", even though they're implemented in almost exactly the same
way. "Adapter module" was the term that covered both of those. In
practice, however, no one knew what "adapter" meant. Bring an end to
this confusion by just using "overlay" within the compiler even for
the mixed-source framework case.

No intended functionality change.
2019-05-03 11:11:58 -07:00
Jordan Rose
6060557148 Merge pull request #24316 from jrose-apple/its-like-a-burrito
[ClangImporter] Handle NS_TYPED_ENUMs of NSUIntegers in non-system headers
2019-04-27 15:19:45 -07:00
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Jordan Rose
3498ca8d21 [ClangImporter] Simplify handling of BOOL/Boolean slightly
At least as far as ImportHint was concerned, these two mapped types
were being treated the same.

No functionality change.
2019-04-26 11:30:14 -07:00
Jordan Rose
0ff871a798 [ClangImporter] Handle NS_TYPED_ENUMs of NSUIntegers in system headers
The special rule for NSUInteger in system headers was colliding with
the behavior of NS_TYPED_ENUM (swift_newtype/swift_wrapper). Let
NS_TYPED_ENUM take precedence here.

(I also future-proofed this for BOOL and Boolean, but those don't
NS_TYPED_ENUM correctly right now for another reason: Bool is bridged
to Objective-C via NSNumber, but ObjCBool is not, even though it could
be.)

rdar://problem/50076612
2019-04-26 11:30:14 -07:00
Saleem Abdulrasool
83b290438c Windows: bridge BOOL to Bool
This allows the conversion of the Windows `BOOL` type to be converted to
`Bool` implicitly.  The implicit bridging allows for a more ergonomic
use of the native Windows APIs in Swift.

Due to the ambiguity between the Objective C `BOOL` and the Windows
`BOOL`, we must manually map the `BOOL` type to the appropriate type.
This required lifting the mapping entry for `ObjCBool` from the mapped
types XMACRO definition into the inline definition in the importer.

Take the opportunity to simplify the mapping code.

Adjust the standard library usage of the `BOOL` type which is now
eclipsed by the new `WindowsBool` type, preferring to use `Bool`
whenever possible.

Thanks to Jordan Rose for the suggestion to do this and a couple of
hints along the way.
2019-04-25 17:52:08 -07:00
Stephen Canon
9136ed23ed Add check that vector element type can be imported ... (#23885)
... before attempting to import the vector type.
(<rdar://problem/49677353>)
2019-04-09 11:27:02 -04:00
Brent Royal-Gordon
972eda2316 [NFC] AST-level support for static subscripts
* Moves the IsStatic flag from VarDecl to AbstractStorageDecl.
* Adds a StaticSubscriptKind to SubscriptDecl.
* Updates serialization for these changes.
* Updates SubscriptDecl constructor call sites for these changes.
2019-04-01 18:04:00 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Harlan Haskins
714a2b4044 Merge pull request #23173 from harlanhaskins/never-trust-the-system
[ParseableInterface] Serialize module into buffer and load from it
2019-03-22 21:37:49 -07:00
Stephen Canon
1a9ae47d06 Teach the importer to import any clang vector type as SIMDn<Scalar>. (#23454)
* Teach the importer to import any vector type as SIMDN<Scalar>.

Instead of having a known set of vector types, check to see if the
element type conforms to SIMDScalar; if it does, see if we have a
SIMDN defined with the right number of elements. If both are satisfied,
import the vector type as that Swift type.

By making this change, we gain the ability to import vector types
that aren't defined in terms of the Darwin simd module, which lets
us use C API with vector types on other platforms. It also lets us
import *every* vector type that Swift can represent, rather than the
small subset that are currently hardcoded.

* Increased test coverage for increased SIMD types that we can import.

Includes some minor cleanup from review. Also eliminates the old
simd_sans_simd test, since we can now import all of these types even when the simd module isn't imported.
2019-03-22 22:11:22 -04:00
Harlan Haskins
5a29cdc118 [ClangImporter] Allow importing without a resource dir on non-Darwin
Previously, we would assert that there's a runtime resource dir
available, but then accept the possibility of no glibc.modulemap. We
should just do the same thing for 'no resource dir' as 'no module map'.
2019-03-22 17:29:11 -07:00
Jordan Rose
61d3b0d4ec [ClangImporter] Avoid unneeded copy for getExportedModuleName
std::string -> StringRef of long-lived backing storage.

No functionality change.
2019-03-21 15:16:21 -07:00
Duncan P. N. Exon Smith
43e771e55b Reapply ClangImporter changes to leverage Clang's module cache
This reapplies four commits for the ClangImporter.  They broke the build
on master because the associated commits on swift-clang's
swift-5.1-branch never made it to stable due to automerger woes.  This
time I'll push everything through manually.

These are the commits being reapplied:

- a42bc62397 "ClangImporter: Share a module cache between CompilerInstances"
- 9eed34235b "ClangImporter: Adjust to r355777, PCMCache => ModuleCache"
- da8a1c57e8 "ClangImporter: Use the new CacheGeneratedPCH in Clang"
- 2134b17a20 "ClangImporter: Test that PCHs are actually cached in memory"

rdar://problem/48545366
2019-03-20 09:59:58 -07:00
Davide Italiano
8a015a54ff Revert "ClangImporter: Use the new CacheGeneratedPCH in Clang"
This reverts commit da8a1c57e8.
2019-03-18 11:30:43 -07:00
Davide Italiano
d3c699ae88 Revert "ClangImporter: Share a module cache between CompilerInstances"
This reverts commit a42bc62397.
2019-03-18 11:30:34 -07:00
Davide Italiano
c189561ff4 Revert "ClangImporter: Adjust to r355777, PCMCache => ModuleCache"
This reverts commit 9eed34235b.
2019-03-18 11:30:23 -07:00
Duncan P. N. Exon Smith
6eed1f9a39 Merge pull request #23248 from dexonsmith/PR-48740787.master
[master] Fix filesystem race in bridging PCH emission/loading
2019-03-18 09:31:03 -07:00
Brent Royal-Gordon
450aba71c0 Search for SwiftShims in SDK (#23287)
…but only if the compiler resource directory doesn’t have them. These will move to the SDK soon.
2019-03-14 17:34:58 -07:00
Duncan P. N. Exon Smith
da8a1c57e8 ClangImporter: Use the new CacheGeneratedPCH in Clang
This flag causes the generated PCH to be written into the in-memory
module cache.  Every CompilerInstance that tries to read the PCH will
use it rather than reading a potentially-since-overwritten version from
the filesystem.

rdar://problem/48740787
(cherry picked from commit 236fc19121)
2019-03-12 11:43:18 -07:00
Duncan P. N. Exon Smith
a42bc62397 ClangImporter: Share a module cache between CompilerInstances
Share an in-memory module cache between Clang compiler instances to
maintain a consistent view of the implicitly-generated PCMs, protecting
against filesystem races.  This cache is more robust after r355778.

Note that there are still potential races for PCHs; I'll fix that in a
follow-up.

rdar://problem/48545366
(cherry picked from commit bf0e9a70c6)
2019-03-12 11:43:18 -07:00
Duncan P. N. Exon Smith
9eed34235b ClangImporter: Adjust to r355777, PCMCache => ModuleCache
Upstream Clang renamed getPCMCache() to getModuleCache() in r355777,
stopped passing it the Preprocessor passing it directly to ASTReader
instead.  Adapt to those API changes.

rdar://problem/48545366
(cherry picked from commit 131cff72b2)
2019-03-12 11:43:17 -07:00
Gwen Mittertreiner
8a6d28c7d0 Fix the Rest of the Windows Driver Tests 2019-03-06 14:23:49 -08:00
Devin Coughlin
b3ff2d8816 [ClangImporter] Update diagnostic to refer to "macOS" instead of "OS X" 2019-03-03 16:42:17 -08:00
Devin Coughlin
8b14600372 [ClangImporter] Refactor availability attribute importing logic. NFC.
Refactor the PlatformAvailability logic for determining
which Clang availability attributes are relevant when importing. The goal
is to separate the logic for attribute relevance for a given platform from
the logic to determine whether a deprecated attribute should be imported as
unavailable in Swift.

This also makes it possible for the "deprecated-as-unavailable" logic to
refer to the underlying Clang declaration, which is functionality that will
be used in a later commit.

This commit has no intended functional change.

Part of rdar://problem/48348822
2019-03-03 14:29:50 -08:00
Saleem Abdulrasool
9934532e07 cmake: switch host libraries to use target_link_libraries
This is a follow up to the discussion on #22740 to switch the host
libraries to use the `target_link_libraries` rather than the
`LINK_LIBRARIES` special handling.  This allows the dependency to be
properly tracked by CMake and allows us to use the more modern syntax.
2019-02-22 15:28:07 -08:00
Bob Wilson
213efe089c Merge commit '06120c9d9d1a28275a0ecd7466775b1d71716be7' into stable-update-5.1 2019-02-17 10:20:59 -08:00
Saleem Abdulrasool
8719f5276c ClangImporter: adjust for SVN r349901
The constructor for `DeclRefExpr` now takes a `Context` parameter to avoid the
call to `getASTContext`.  Adjust the invocation accordingly.
2019-02-08 14:22:57 -08:00
Max Desiatov
37f8268ae7 Fix compatibility with upstream clang changes 2019-02-08 14:22:56 -08:00
Saleem Abdulrasool
db1c894aa0 ClangImporter: update for SVN r345605
Update for API changes in clang SVN r345605.
2019-02-08 14:22:56 -08:00
Saleem Abdulrasool
562e6f5e96 ClangImporter: adjust for SVN r345637
`ObjC1` has been removed from clang.  Use `ObjC` to detect if Objective-C
language support is enabled.
2019-02-08 14:22:56 -08:00
Slava Pestov
dffa29fd0d AST: Remove a few uses of FunctionType::Param::getOldType() 2019-02-07 23:46:31 -05:00
Bob Wilson
b0dd41b8ab [master-next] Use the new AST getBeginLoc API instead of getLocStart
The getLocStart API is deprecated and slated for removal from LLVM
very soon. Switch to use getBeginLoc instead. I did not see any uses
of the corresponding getLocEnd API.
2019-02-07 16:53:03 -08:00
adrian-prantl
7e3357a39b Merge pull request #22313 from adrian-prantl/47600180
Cache clang ASTFile information in swift::Module (NFC from the outside).
2019-02-03 10:06:11 -08:00
Adrian Prantl
761e9a0fb2 Cache clang ASTFile information in swift::Module (NFC from the outside).
The loading of additional modules by Sema may trigger an out-of-date
PCM rebuild in the Clang module dependencies of the additional
module. A PCM rebuild causes the ModuleManager to unload previously
loaded ASTFiles. For this reason we must use the cached ASTFile
information here instead of the potentially dangling pointer to the
ASTFile that is stored in the clang::Module object.

This fixes a crash in IRGenDebugInfo when generation DIModule context
chains.

rdar://problem/47600180
2019-02-01 17:34:10 -08:00
Doug Gregor
d0dc64ef64 [Clang importer] Type parameters substituted with existentials aren't Hashable
As a follow-on to the fix for rdar://problem/47564982, a type
parameter in a generic Objective-C class whose type bounds include
both a NSObject-derived superclass and a protocol would have been
classified has being Hashable, when in fact the corresponding
existential type will not conform to Hashable. Only allow hashability
when there are no protocol requirements.
2019-02-01 12:39:26 -08:00
Doug Gregor
9084682b00 [Clang importer] Existentials do not conform to Hashable.
Fixes rdar://problem/47564982.
2019-02-01 11:45:16 -08:00
Saleem Abdulrasool
052c89d7fc ClangImporter: make bridging header more portable
`#import` on Windows is problematic at as the default behaviour in C/C++
mode is to be an import of a type library (COM feature).  This can be
adjusted by always enabling Objective-C interop on Windows, but the
runtime is not always built with ObjC interop.

Unfortunately, always using `#include` breaks semantics on Apple where
some places rely on the include-once semantics of `#import`.

For now, control the inclusion technique to be based on whether ObjC
interop is enabled or not.
2019-01-17 13:57:08 -08:00