Commit Graph

160 Commits

Author SHA1 Message Date
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Ben Barham
a6f99a08c4 [rebranch][ClangImporter] Update hashExtension to use HashBuilder
llvm-project updated `hashExtension` in
655bea4226b401a11164f99c6344e38d8742b8e4 to use a `HashBuilder` rather
than `hash_code`. Update use in ClangImporter.
2021-11-13 15:33:09 +10:00
Becca Royal-Gordon
689c2a510e [ClangImporter] Fix (lack of) name importing for ObjC ivars
When apple/swift#39664 moved the logic for generating anonymous fields' names from ImportDecl to ImportName, it inadvertently replaced a check that the decl was *precisely* `clang::FieldDecl` with a check that it was `FieldDecl` *or a subclass*. This could cause a crash when it tried to call `FieldDecl::getFieldIndex()`, which doesn't work properly on instance variables even though `ObjCIvarDecl` is a subclass of `FieldDecl`. The easiest way to reproduce this is to use a bit field in a class's instance variables, since clang inserts an anonymous instance variable after it for padding.

This commit adds a test of a bit field instance variable and fixes the bug. It also adds a PrettyStackTrace frame in the Swift lookup table preparation code, which should make other bugs like this easier to diagnose.

Fixes rdar://85173321.
2021-11-09 17:54:53 -08:00
zoecarver
f8abf50855 [cxx-interop] Bump data length to use uint32_t.
We're seeing some C++ projects that cause an integer overflow when this is only 16 bits.
2021-10-22 14:40:21 -07:00
Doug Gregor
b86e39d614 Remove "spawn" modifier 2021-07-26 10:22:02 -07:00
Saleem Abdulrasool
714eaefc78 Importer: remove ImportAsMember support
This functionality is not actively in use and the last usage of this has
been removed.  Remove the infrastructure that is no longer in need.
2021-03-22 08:53:56 -07:00
Becca (née Brent) Royal-Gordon
0f6925020b Merge pull request #36198 from beccadax/a-swift-by-any-other-name-would-warn-as-bleat
Fix rebranch SwiftNameAttr warning regression
2021-03-01 22:06:38 -08:00
Becca Royal-Gordon
4e0905ae3f Fix rebranch SwiftNameAttr warning regression
A change in the new clang branch seems to have caused it to start applying SwiftNameAttrs to forward declarations. We have apparently always tried to add these forward declarations to the lookup tables in PCH files, but never diagnosed the resulting failures because they did not have SwiftNameAttrs. Now they do, so we started emitting incorrect warnings.

We *probably* don’t need to process these at all, but there’s a risk of unintended behavior changes from that; instead, this commit takes a conservative approach and simply suppresses the warnings like we always have.

Fixes rdar://74710976.
2021-03-01 15:33:05 -08:00
Doug Gregor
77105a4ee5 Enable SE-0297: Concurrency Interoperability with Objective-C 2021-02-24 14:18:16 -08:00
Arnold Schwaighofer
ca9e258dd1 Adjust to removal of RecordLayout.h header 2020-12-08 11:58:32 -08:00
Doug Gregor
1e5d30f5ca [Concurrency] Import Objective-C methods with completion handlers as async
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:

    - (void)fetchShareParticipantWithUserRecordID:(CKRecordID
*)userRecordID
            completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler;

With the experimental concurrency model, this would import as:

    func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant?

The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.

async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.

Note that this only covers the Clang importer portion of this task.
2020-08-27 21:30:13 -07:00
Marcel Hlopko
cb537b41fb [cxx-interop] Import typedef-ed template instantiations #32950 (#33451)
This is a roll-forward of https://github.com/apple/swift/pull/32950, with explicit c++17 version removed from tests. This is not needed since C++17 is the default anyway.

--

In this PR we teach `ClangImporter` to import typedef statements with template instantiation as its underlying type.

```c++
template<class T>
struct MagicWrapper {
  T t;
};

struct MagicNumber {};

typedef MagicWrapper<MagicNumber> WrappedMagicNumber;
```

will be made available in Swift as if `WrappedMagicNumber` is a regular struct. 

In C++, multiple distinct typedeffed instantiations resolve to the same canonical type. We implement this by creating a hidden intermediate struct that typedef aliasses.

The struct is named as `__CxxTemplateInst` plus Itanium mangled type of the instantiation. For the example above the name of the hidden struct is `__CxxTemplateInst12MagicWrapperI11MagicNumberE`. Double underscore (denoting a reserved C++ identifier) is used to discourage direct usage. We chose Itanium mangling scheme because it produces valid Swift identifiers and covers all C++ edge cases.

Imported module interface of the example above:

```swift
struct __CxxTemplateInst12MagicWrapperI11MagicNumberE {
  var t: MagicNumber
}
struct MagicNumber {}
typealias WrappedMagicNumber = __CxxTemplateInst12MagicWrapperI11MagicNumberE
```

We modified the `SwiftLookupTable` logic to show hidden structs in `swift_ide_test` for convenience.

Co-authored-by: Rosica Dejanovska <rosica@google.com>
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
Co-authored-by: Robert Widmann <devteam.codafi@gmail.com>
2020-08-14 20:51:16 +02:00
Meghana Gupta
6b61818fff Revert "[cxx-interop] Import typedef-ed template instantiations (#32950)"
This reverts commit 643aa2d896.
2020-08-12 12:37:13 -07:00
Marcel Hlopko
643aa2d896 [cxx-interop] Import typedef-ed template instantiations (#32950)
In this PR we teach `ClangImporter` to import typedef statements with template instantiation as its underlying type.

```c++
template<class T>
struct MagicWrapper {
  T t;
};

struct MagicNumber {};

typedef MagicWrapper<MagicNumber> WrappedMagicNumber;
```

will be made available in Swift as if `WrappedMagicNumber` is a regular struct. 

In C++, multiple distinct typedeffed instantiations resolve to the same canonical type. We implement this by creating a hidden intermediate struct that typedef aliasses.

The struct is named as `__CxxTemplateInst` plus Itanium mangled type of the instantiation. For the example above the name of the hidden struct is `__CxxTemplateInst12MagicWrapperI11MagicNumberE`. Double underscore (denoting a reserved C++ identifier) is used to discourage direct usage. We chose Itanium mangling scheme because it produces valid Swift identifiers and covers all C++ edge cases.

Imported module interface of the example above:

```swift
struct __CxxTemplateInst12MagicWrapperI11MagicNumberE {
  var t: MagicNumber
}
struct MagicNumber {}
typealias WrappedMagicNumber = __CxxTemplateInst12MagicWrapperI11MagicNumberE
```

We modified the `SwiftLookupTable` logic to show hidden structs in `swift_ide_test` for convenience.

Resolves https://bugs.swift.org/browse/SR-12591.

Co-authored-by: Rosica Dejanovska <rosica@google.com>
Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
Co-authored-by: Robert Widmann <devteam.codafi@gmail.com>
2020-08-12 16:54:22 +02:00
Michael Forster
26358c4588 Import member operator functions as static members (#32293)
This adds support to `ClangImporter` to import C++ member function operators as static methods into Swift, which is part of SR-12748.

The left-hand-side operand, which gets passed as the `this` pointer to the C++ function is represented as an additional first parameter in the Swift method. It gets mapped back in SILGen.

Two of the tests are disabled on Windows because we can't yet call member functions correctly on Windows (SR-13129).
2020-07-03 11:06:22 +02:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Arnold Schwaighofer
0c99cd9734 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 08:00:41 -08:00
Robert Widmann
518ab9f22f [NFC] Unblock Lazy Member Loading For Import-As-Member
Lazy member loading had an antagonistic relationship with the import-as-member facilities. The member tables were stored in a hash map that is keyed by serialized declaration context.  While this was good for importing the entire member set of a given extension, it's in the complete wrong order for lazy member loading, which wants the same data keyed by base name.

Given that it is annoying to redo the globals-as-member tables to support one use case or the other, coupled with the fact that optimizing for one use-case automatically pessimizes the other, just take a page from rdar://18696086 and store the same information twice in two separate formats each optimized for the task at hand.

Preliminary benchmarks indicate that this leads to a 5% reduction in Clang-Imported entities which will drastically speed up most apps that use Dispatch and CoreGraphics.
2020-01-08 21:25:00 -08:00
Francis Visoiu Mistrih
47c6ce2af7 [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream
The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This
updates the uses in swift.

See r365091 [Bitcode] Move Bitstream to a separate library.

(cherry picked from commit 1cd8e19357)
2019-11-12 10:46:07 -08:00
JF Bastien
e56e311a23 Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update

Upstream change in rL364464 broke downstream Swift.

(cherry picked from commit 50de105bf1)

 Conflicts:
	lib/Serialization/Deserialization.cpp
	lib/Serialization/ModuleFile.cpp
	tools/driver/modulewrap_main.cpp
2019-11-12 10:46:07 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Saleem Abdulrasool
1955746c6f ClangImporter: repair a merge conflict
`llvm::make_unique` has been replaced with `std::make_unique`.  Adjust
the master-next branch accordingly.
2019-10-30 10:04:23 -07:00
swift-ci
89318956f7 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 09:10:41 -07:00
Jordan Rose
8168669a27 [ClangImporter] Diagnose bad swift_name attributes better
1. Set the diagnostic location to where the attribute was written (or
   to the Clang decl's source, if the attribute came from API notes)

2. Add a note to contact the owners of the framework to make it clear
   that the client of the framework didn't do anything wrong.

rdar://problem/52736145
2019-10-28 22:08:26 -07:00
swift-ci
bd3c1a1b9f Merge remote-tracking branch 'origin/master' into master-next 2019-08-29 14:29:44 -07:00
Jordan Rose
11e206af7a Remove explicit seeds from string hashes that are compiler-dependent
The one for enum raw value checking isn't serialized anywhere, so we
can use normal in-process hashing. The ones in the Clang importer's
lookup tables are serialized, but the lookup table is already only
valid for a particular compiler build anyway (it goes into a Clang
PCM, which has the full compiler version in its cache key).
2019-08-29 09:19:49 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Pavel Yaskevich
3d01a3d723 Merge remote-tracking branch 'origin/master' into master-next 2019-08-02 09:57:06 -07:00
pschuh
2a2ed0f843 [C++ Interop] Implement lookup within namespace. (#26439)
Known problems:
- The same namespace in multiple c++ modules will be subtly confused when doing
  lookup.
2019-08-01 18:21:08 -07:00
swift-ci
9894743d4f Merge remote-tracking branch 'origin/master' into master-next 2019-07-09 11:50:28 -07:00
Parker Schuh
fa69a73ee4 Add -enable-cxx-interop flag and support for extern "C" {} 2019-07-08 11:43:35 -07:00
Francis Visoiu Mistrih
1cd8e19357 [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream
The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This
updates the uses in swift.

See r365091 [Bitcode] Move Bitstream to a separate library.
2019-07-03 15:40:03 -07:00
JF Bastien
50de105bf1 Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update

Upstream change in rL364464 broke downstream Swift.
2019-07-01 10:08:41 -07:00
Jordan Rose
e75c035772 [ClangImporter] Clean up some casts/deletes using forward declarations (#19367)
No functionality change.
2018-09-18 10:34:50 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
swift-ci
4a1824018d Merge remote-tracking branch 'origin/master' into master-next 2018-06-21 11:49:28 -07:00
Jordan Rose
26325e8301 [ClangImporter] Put the Swift compiler version into the module hash (#17344)
This is overkill when we could just be better about updating the
lookup table version, but it's hard to remember to do that when
changing something in ImportName.cpp or whatever.
2018-06-21 11:40:16 -07:00
swift-ci
2a0e83dc0d Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 11:00:19 -07:00
Jordan Rose
864bf89f69 [ClangImporter] Handle lookup tables with many entries (#17265)
In particular, there are frameworks with more than 65536 entries for
'init' as a base name.

I can't think of a test case for this besides actually adding such a
massive framework, but the assertions that were added here should
catch the issue in Debug builds if it ever comes up again. I'm going
to go harden everything else that uses this API next.

rdar://problem/40828315
2018-06-18 08:39:55 -07:00
Bob Wilson
d933b5d60c Merge remote-tracking branch 'origin/master' into master-next 2018-06-15 20:20:25 -07:00
Jordan Rose
570ed72ea5 Add assertions to prevent truncation when using llvm::endian::Writer (#17266)
Also, stop serializing a few constant values, saving a tiny bit of
space in swiftmodule files.
2018-06-15 19:26:35 -07:00
swift-ci
7fff7b3ddf Merge remote-tracking branch 'origin/master' into master-next 2018-05-21 21:49:25 -07:00
Rintaro Ishizaki
b3453c17fe [ClangImporter] Take isCompatibilityAlias() into account in interface printing (#16625)
If the Clang declrations are *types*, canonical declaration in Swift is
imported for newest version of Swift. In interface generation, if the
declaration is versioned and it's imported as a member in either or both
version of Swift, we have to take compatibility typealias into account.

* Fixed 'ClangModuleUnit::getTopLevelDecls' to take isCompatibilityAlias() into account
* Fixed bugs in ClangImporter where member-to-member versioned types aren't properly imported.
  * Fixed 'SwiftDeclConverter::importFullName' to check equality of getEffectiveContext()
  * Fixed 'importer::addEntryToLookupTable' to check equality of getEffectiveContext()
    (moved 'ClangImporter::Implementation::forEachDistinctName' to 'NameImporter')
2018-05-22 13:38:45 +09:00
Bob Wilson
1fc7f1391e [master-next] Update endian stream interface to match Clang r332757 2018-05-19 22:19:35 -07:00
swift-ci
cb7f139ad1 Merge remote-tracking branch 'origin/master' into master-next 2018-04-03 13:39:21 -07:00
Doug Gregor
24b96a7480 Delay import-as-member resolution even without an explicit swift_name.
When forming the Swift name lookup tables, import-as-member'd
declarations can precede the declaration of the context into which
they'll be imported as a member. In such cases, we already had logic
to delay the resolution until the end of the model (when the context
must be complete).

However, we would only delay when there is a swift_name attribute on
the declaration, which is... conceptually correct. If the swift_name
exists but is versioned (e.g., it is present only for Swift 4+), and
we're building before the swift_name took effect (e.g., in Swift 3
mode), the swift_name is buried under a "versioned" attribute in the
Clang AST. Therefore, we would end up dropping the declaration from
the name lookup table, which almost doesn't matter, except...

Serialization records the newest names for such declarations (e.g.,
Swift 4+ name in this case), so deserialization would fail to find the
declaration that had been dropped, causing a crash.

Eliminate the "optimization" that looks for the swift_name attribute
before delaying the resolution of such a declaration, so we'll visit
these later. Fixes rdar://problem/39115605.
2018-04-03 11:26:05 -07:00
swift-ci
d80ce649ed Merge remote-tracking branch 'origin/master' into master-next 2018-03-16 03:09:03 -07:00