Commit Graph

254 Commits

Author SHA1 Message Date
swift-ci
b5dfbfd007 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-30 06:12:15 -08:00
Arnold Schwaighofer
3822723fe2 Disable Interop/Cxx/value-witness-table/custom-destructors-non-virtual-irgen.swift on arm64e
radar://73755064
2021-01-29 10:35:53 -08:00
swift-ci
404c2bf085 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-28 13:32:22 -08:00
Zoe Carver
b5d59edeef Merge pull request #32291 from zoecarver/cxx/irgen/destructor
[cxx-interop] Add support for custom C++ destructors.
2021-01-28 13:15:49 -08:00
zoecarver
ffa0d1cf93 [cxx-interop] Add support for custom C++ destructors.
This patch adds support for custom C++ destructors. The most notable thing here, I think, is that this is the first place a struct type has a custom destructor. I suspect with more code we will expose a few places where optimization passes need to be fixed to account for this.

One of many patches to fix SR-12797.
2021-01-27 12:54:48 -08:00
swift-ci
e349794517 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 04:12:41 -08:00
Marcel Hlopko
4f5c75a236 [cxx-interop] Instantiate C++ class templates from Swift (#33284)
This PR makes it possible to instantiate C++ class templates from Swift. Given a C++ header:

```c++
// C++ module `ClassTemplates`
template<class T>
struct MagicWrapper {
  T t;
};

struct MagicNumber {};
```

it is now possible to write in Swift:

```swift
import ClassTemplates

func x() -> MagicWrapper<MagicNumber> {
  return MagicWrapper<MagicNumber>()
}
```

This is achieved by importing C++ class templates as generic structs, and then when Swift type checker calls `applyGenericArguments` we detect when the generic struct is backed by the C++ class template and call Clang to instantiate the template. In order to make it possible to put class instantiations such as `MagicWrapper<MagicNumber>` into Swift signatures, we have created a new field in `StructDecl` named `TemplateInstantiationType` where the typechecker stores the `BoundGenericType` which we serialize. Deserializer then notices that the `BoundGenericType` is actually a C++ class template and performs the instantiation logic.

Depends on https://github.com/apple/swift/pull/33420.
Progress towards https://bugs.swift.org/browse/SR-13261.
Fixes https://bugs.swift.org/browse/SR-13775.

Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
Co-authored-by: Rosica Dejanovska <rosica@google.com>
2021-01-27 13:01:20 +01:00
Arnold Schwaighofer
8242ae7458 [rebranch] Fix test/Interop/Cxx/operators tests
rdar://73591415
2021-01-26 07:48:18 -08:00
Saleem Abdulrasool
3db60d2c20 test: update Interop.cxx tests for newer clang
Clang will properly mark the C++ `this` parameter as `nonnull` and
`dereferenceable(1)` as per the C++ specification.  Update the tests to
accept the newer attributes.
2021-01-21 12:30:53 -08:00
swift-ci
e71625cff2 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-21 01:33:06 -08:00
scentini
0b3990c141 [cxx-interop] Generate IR for decls called from members (#35056)
Currently the following code doesn't work when `callConstructor()` is called from Swift:
```cc
inline int increment(int value) {
  return value + 1;
}

struct Incrementor {
  int incrementee;
  Incrementor(int value) : incrementee(increment(value)) {}
}

int callConstructor(int value) {
  return Incrementor(value).incrementee;
}
```

The issue is that we don't generate `IR` for the `increment()` function when it's only called from a constructor or a method.
Swift is aware of the existence of `increment()` and we see it in `IR` as `declare incrementEi`, however, as we don't to emit a definition, we get the following error:
```
Incrementor::Incrementor(int): error: undefined reference to 'increment(int)'
```

This PR fixes this by visiting constructors and methods in `IRGen` and calling `HandleTopLevelDecl()` with all used declarations, which results in emitting definitions for the used declarations.

Co-authored-by: Marcel Hlopko <hlopko@google.com>
2021-01-21 10:16:25 +01:00
swift-ci
a0145fe002 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-19 22:13:11 -08:00
zoecarver
c4da4975ed [NFC] Cleanup function templates implementation. Address post-commmit review comments from #33053.
Addresses the post-commit review comments from #33053. Just re-naming,
commenting, and some other small cleanups, nothing functionally
different.
2021-01-19 12:02:15 -08:00
swift-ci
4e05fc76ee Merge remote-tracking branch 'origin/main' into rebranch 2021-01-14 13:52:29 -08:00
Zoe Carver
9b0c17e363 Merge pull request #34869 from zoecarver/cxx/fix/forward-declared-with-child
[cxx-interop] Use cached record when possible.
2021-01-14 13:37:33 -08:00
zoecarver
ecd1018799 [cxx-interop] Use cached record when possible.
It is not completely uncommon for a record to get imported while
importing it's members (for example, if the member points back to the
parent record). In this case, simply use the already-imported record.
This should improve performance but also prevent an error where a member
accidentally had two parents.

This patch also moves around some of the member import/add logic to
allow for the above "optimization."
2021-01-13 11:19:36 -08:00
swift-ci
5e2c7dba68 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-13 09:12:39 -08:00
Nate Chandler
20db2c0981 Merge branch 'main' into rebranch
Conflicts:
	include/swift/Basic/AnyValue.h
2021-01-12 16:30:02 -08:00
Saleem Abdulrasool
357face86e test: introduce new target-swiftxx-frontend for C++ interop
Add an convert to the new `target-swiftxx-frontend` substitution in lit
to control the C++ interop enabling in Swift.  This allows for a single
site which will enable control of both an overridden standard (for
testing multiple C++ standards) and simplify writing tests.
2021-01-12 11:45:36 -08:00
Saleem Abdulrasool
9ba7bf78db Interop: use new target-clangxx for building C++ code
This enables control over the C++ flags used during testing for the C++
interop from a single location rather than having to alter all the
tests.
2021-01-12 08:29:24 -08:00
Saleem Abdulrasool
8a9f179f0a Interop: remove -O in test
Now that the integral constants are being materialized when importing
`constexpr` from C++, we can avoid the need for the optimizer to inline
the value.  Remove this workaround.
2021-01-11 23:23:26 +00:00
Saleem Abdulrasool
99ac668638 Merge pull request #35320 from compnerd/lowering-standards
Interop: remove unnecessary C++ standard
2021-01-11 14:55:23 -08:00
Zoe Carver
8fb106c6e4 Merge pull request #35311 from zoecarver/cxx/inline-constexpr-vars
[cxx-interop] Inline constexpr vars.
2021-01-11 14:27:04 -08:00
Saleem Abdulrasool
f5a08e45bc Interop: restore -std=c++11 for a few tests
Restore the explicit C++ standard for these tests as the C++ compiler
invocation on Darwin uses the system compiler rather than the just built
clang, which may be sufficiently different to have different default
standards.

This will be cleaned up with the next change to introduce a new
`%target-clangxx` to control the C++ standard.
2021-01-11 11:01:44 -08:00
Saleem Abdulrasool
21732c9551 Interop: remove unnecessary C++ standard
Do not override the C++ standard explicitly when running the tests.
This will eventually be useful in allowing tests to run against
different C++ standards.
2021-01-11 08:57:56 -08:00
swift-ci
85959f9014 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-11 05:32:52 -08:00
martinboehme
c5b7e7fb9c Fix two issues with the SwiftGlibc module map (#32404)
* Fix two issues with the SwiftGlibc module map.

The issues are:

- Today, some submodules in `SwiftGlibc` fail to provide definitions that
  they should contain. As a consequence, Swift fails to import some code
  that compiles correctly with standalone Clang. As just one example,
  including `signal.h` should make the type `pid_t` available, but it
  currently does not.

- `SwiftGlibc` is not compatible with the libc++ module map. Trying to
  include libc++ headers in a C++ module imported into Swift results in an
  error message about cyclic dependencies.

This change fixes both of these issues by making it so that `SwiftGlibc`
no actually longer defines a module map for the glibc headers but merely makes
all of the symbols from those headers available in a module that can be
imported into Swift. C / Objective-C / C++ code, on the other hand, will now
include the glibc headers texually.

For more context on the two issues and this fix, see this forum
discussion:

https://forums.swift.org/t/problems-with-swiftglibc-and-proposed-fix/37594

This change only modifies `glibc.modulemap.gyb` for the time being but
leaves `bionic.modulemap.gyb` and `libc-openbsd.modulemap.gyb` unchanged. The
intent is to fix these in the same way, but it will be easier to do this
in separate PRs that can be tested individually.

Co-authored-by: zoecarver <z.zoelec2@gmail.com>
Co-authored-by: Marcel Hlopko <hlopko@google.com>
2021-01-11 14:25:41 +01:00
Alexis Laferrière
ca916e07a5 Merge pull request #35322 from xymus/rebranch-to-next
[rebranch] Cherry-pick two PRs from next
2021-01-08 16:41:48 -08:00
zoecarver
6bc2696e24 [cxx-interop] Inline constexpr vars.
If a static variable can be evaluated at compile time, create an
accessor using that value. This means static variables will always be
inlined and removed.

Note: currently this only works with numeric types.
2021-01-08 14:22:25 -08:00
swift-ci
bb58f9ff02 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-08 13:12:52 -08:00
zoecarver
549189bee6 [cxx-interop] Add "nonnull" and "dereferenceable(n)" attributes to constructor params.
This reflects a change in Clang 13's codegen. Test-only fix for swift/rebranch.
2021-01-07 15:00:34 -08:00
Saleem Abdulrasool
e600816d50 ClangImporter: synchronize clang and Swift
This synchronizes the C/C++ standard that Swift uses for the clang
importer with the defaults of the clang compiler.

The default for the C standard remains the same at `gnu11`.  However, if
clang was built with a different default C standard, that will be
preferred.

The default for the C++ standard is moved to C++14.  Although this is a
reduced version, it matches what the current clang compiler defaults to.
Additionally, if the user built clang with a different C++ standard,
that standard would be preferred.

Although the C++ support is a bit more conservative, the idea is that we
can be certain that the clang version fully supports this standard as it
it the default version for clang.

The test change made here replaces the use of `auto` type parameters to
templates which is a C++17 feature.  Reduce the example to a C++14
equivalent.

The clang version seems to behave differently in preventing the
synthesis of the constexpr value.  This persists into the newer clang
releases as well.  This is reasonable as the value does not need to be
exported necessarily and users will be able to materialize the value.
We use the optimizer to ensure that the value is inlined.

This also repairs the C++ interop tests on Windows with a newer C++
runtime from Microsoft.
2021-01-07 14:44:49 -08:00
swift_jenkins
62343a4d44 Merge remote-tracking branch 'origin/main' into next 2021-01-07 11:34:13 -08:00
Saleem Abdulrasool
df9d1e815f Interop/Cxx: explicitly require C++ for modules
The C++ interop modules require C++ support.  Explicitly require C++ as
a feature when building these modules.  This has no impact on the
changes as all the tests enable C++ already.
2021-01-06 16:59:42 -08:00
swift_jenkins
f979b095ae Merge remote-tracking branch 'origin/main' into next 2020-12-22 20:58:03 -08:00
zoecarver
8746d046a1 [cxx-interop] Define implict constructor on the definition.
Make sure that we define a C++ record's implicit constructor on the
record's definition, not just on a declaration.
2020-12-22 13:32:15 -08:00
zoecarver
7ac1b8121e [cxx-interop] Skip forward-declared nested structs.
This prevents us from accidentially adding the same sub-type twice.
2020-12-22 13:23:12 -08:00
swift_jenkins
95f0bfc440 Merge remote-tracking branch 'origin/main' into next 2020-12-16 19:09:44 -08:00
zoecarver
3c5f2c9d52 [cxx-interop] Support scoped enums (enum classes).
Simply treat scoped enums as (pre-existing) "non frozen enums". C++
scoped enums are actually imported as Swift enums (unlike other enums)
and no global variables need be created (given their "scoped" nature).
2020-12-16 13:47:55 -08:00
swift_jenkins
fc33a461de Merge remote-tracking branch 'origin/main' into next 2020-12-15 00:46:51 -08:00
Marcel Hlopko
bde9c3b683 [cxx-interop] Fix header guards in test/Interop (#35039) 2020-12-15 09:20:19 +01:00
swift_jenkins
669fb36333 Merge remote-tracking branch 'origin/main' into next 2020-12-10 23:32:30 -08:00
martinboehme
f4e74f7907 When qualifying Clang types with a module, make sure we choose a visible module (#32465)
Clang types need special treatment because multiple Clang modules can contain the same type declarations from a textually included header, but not all of these modules may be visible.

This fixes
https://bugs.swift.org/browse/SR-13032

The newly added test breaks without this fix.
2020-12-11 08:15:05 +01:00
swift_jenkins
aacd03933a Merge remote-tracking branch 'origin/main' into next 2020-12-10 06:05:40 -08:00
scentini
4f3f68ea48 Amend test to actually fail due to SR-13032 (#35038) 2020-12-10 15:02:28 +01:00
swift_jenkins
0b20fc3b0b Merge remote-tracking branch 'origin/main' into next 2020-12-08 16:42:26 -08:00
Saleem Abdulrasool
89c617ab1f Merge pull request #34919 from buttaface/android-vendor
[android] Switch armv7 vendor to 'unknown' in target triple to match other arches
2020-12-08 16:34:42 -08:00
swift_jenkins
b9cce30f96 Merge remote-tracking branch 'origin/main' into next 2020-12-04 16:19:11 -08:00
zoecarver
24aa9ac75e [cxx-interop] Add support for templated member functions.
Essentially applying the same change as for supporting templated
constructors.
2020-12-04 13:07:22 -08:00
swift_jenkins
8351c9dbf3 Merge remote-tracking branch 'origin/main' into next 2020-12-04 13:03:17 -08:00