Commit Graph

2529 Commits

Author SHA1 Message Date
Anthony Latsis
492156c10f Remove SubscriptDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Anthony Latsis
21faa48298 Remove FuncDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Anthony Latsis
3de97908e4 [NFC] Avoid passing a TypeLoc to AccessorDecl::create 2020-08-18 23:01:34 +03:00
swift_jenkins
9ab003bcf9 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-14 15:14:01 -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
Nathan Hawes
f0c8b8e571 Manually merge remote-tracking branch 'upstream/master' into HEAD
Conflicts:
	include/swift/AST/PrettyStackTrace.h
2020-08-14 11:06:27 -07:00
David Zarzycki
1e940c2c7e [NFC] Fix -Wsuggest-override warnings
LLVM, as of 77e0e9e17daf0865620abcd41f692ab0642367c4, now builds with
-Wsuggest-override. Let's clean up the swift sources rather than disable
the warning locally.
2020-08-13 16:17:46 -04: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
Nathan Hawes
607e2b8822 Manually merge remote-tracking branch 'upstream/master' into HEAD 2020-08-04 13:47:48 -07:00
swift-ci
b2d2cf05b6 Merge pull request #33252 from zoecarver/cxx/rename-is-cxx-non-trivial 2020-08-04 11:23:31 -07:00
zoecarver
6e4e478047 [NFC] [cxx-interop] Rename IsCxxNotTriviallyCopyable -> IsCxxNonTrivial.
`IsCxxNonTrivial` is set for a variety or reasons, for example, it's set
when the struct contains bitfields, has a custom destructor, or a custom
copy constructor. The name `IsCxxNotTriviallyCopyable` only implies the
latter.
2020-08-04 08:45:15 -07:00
swift-ci
a0a181159c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-31 16:07:19 -07:00
Slava Pestov
38477ade9c ClangImporter: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:02 -04:00
swift-ci
0d8e3e1d71 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-07-29 09:14:39 -07:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Nathan Hawes
9d4ed5f39c Manually merge remote-tracking branch 'upstream/master' into manually-merge-master-to-master-rebranch 2020-07-20 16:09:55 -07:00
Michael Gottesman
092edd6621 [ast] Rename VarPattern -> BindingPattern.
VarPattern is today used to implement both 'let' and 'var' pattern bindings, so
today is already misleading. The reason why the name Var was chosen was done b/c
it is meant to represent a pattern that performs 'variable binding'. Given that
I am going to add a new 'inout' pattern binding to this, it makes sense to
give it now a better fitting name before I make things more confusing.
2020-07-16 18:56:01 -07:00
Nathan Hawes
244dc4a768 [AST] Rename PlatformKind::OSX to PlatformKind::macOS
Because the names are coming from a .def file used for printing too, this
simplifies the printing logic as well.
2020-07-08 16:29:31 -07:00
Michael Forster
8ab0f51a3c Merge pull request #32262 from martinboehme/replace-ishidden
Replace clang::Decl::isHidden() with clang::Sema::isVisible()
2020-07-08 19:05:42 +02:00
zoecarver
0605ef4c6c [verifier] [cxx-interop] Remove empty return result from constructors.
Set the synthesized constructor's return result to nullptr and add an ASTVerifier check that the constructor's return statement does not contain a result.
2020-07-07 10:04:09 -07: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
swift_jenkins
afd634985a Merge remote-tracking branch 'origin/master' into master-next 2020-07-01 21:38:26 -07:00
Doug Gregor
1867e0d6de [Clang importer] Remove the OS_object objc_runtime_visible hack.
The Clang importer has an old hack that makes OS_object and its subclasses
implicitly "objc_runtime_visible" (which maps to the "runtime" foreign
class kind in Swift). Now that the headers in the SDK all use the
appropriate annotation, remove the hack.

Fixes rdar://problem/64778416.
2020-06-30 09:31:30 -07:00
Jonas Devlieghere
66bddd6e4c [ClangImporter] Adjust for LLVM API change 2020-06-29 15:29:16 -07:00
swift_jenkins
8dadaedfd9 Merge remote-tracking branch 'origin/master' into master-next 2020-06-26 16:38:38 -07:00
zoecarver
096777eda7 [cxx-interop] Do not give the default C++ constructor's return statement a result.
The default C++ object constructor assigns the newly created object out of the function so, it should not return a value. Returning a value will trigger SILGen assertions.
2020-06-24 14:02:02 -07:00
swift_jenkins
0831f9eaf1 Merge remote-tracking branch 'origin/master' into master-next 2020-06-16 10:19:55 -07:00
Argyrios Kyrtzidis
f89a385756 [ClangImporter] Follow-up for #32214, fix assertion hit due to missing check 2020-06-15 18:28:26 -07:00
swift_jenkins
abe81545ed Merge remote-tracking branch 'origin/master' into master-next 2020-06-10 16:39:16 -07:00
Argyrios Kyrtzidis
a3ce4621a2 Merge pull request #32214 from akyrtzi/clang-include-inherited-convenience-inits-for-members
[ClangImporter] Make sure that inherited convenience constructors are included in members of `IterableDeclContext`
2020-06-10 16:29:41 -07:00
Argyrios Kyrtzidis
915e215a3d [ClangImporter] Make sure that inherited convenience constructors are included in members of IterableDeclContext
Previously inherited constructors would be skipped from added in member list, depending on the order of request evaluator calls.
This was a regression compared to swift 5.2
2020-06-10 13:23:12 -07:00
swift_jenkins
0b350f6562 Merge remote-tracking branch 'origin/master' into master-next 2020-06-10 11:38:51 -07:00
Robert Widmann
ca728917e1 Merge pull request #32138 from AnthonyLatsis/eliminate-typeloc
Sema: Remove TypeLoc from ExplicitCastExpr (via TypeExpr)
2020-06-10 11:28:50 -07:00
Martin Boehme
fc1cf3b203 Replace clang::Decl::isHidden() with clang::Sema::isVisible().
clang::Decl::isHidden() is misleadingly named (see the associated FIXME
comment) and doesn't do what we want when
`-fmodules-local-submodule-visibility` is turned on.

This change alone isn't unfortunately enough to make Swift work with
`-fmodules-local-submodule-visibility`. For one thing, Clang's
Objective-C component  doesn't work correctly with
`-fmodules-local-submodule-visibility`:

https://bugs.llvm.org/show_bug.cgi?id=46248

However, in the meantime, we should still clean up our use of
clang::Decl::isHidden().
2020-06-09 15:17:49 +02:00
Anthony Latsis
4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Karoy Lorentey
57ea964f2c Merge commit '3eb82c183662945687f48e11c09828f551b34858' into master-next
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:58:37 -07:00
Karoy Lorentey
68351d2110 Revert "Merge remote-tracking branch 'origin/master-next'"
This reverts commit 1c9b0908e6, reversing
changes made to 3eb82c1836.
2020-06-08 16:48:38 -07:00
Karoy Lorentey
1c9b0908e6 Merge remote-tracking branch 'origin/master-next'
# Conflicts:
#	include/swift/Frontend/FrontendInputsAndOutputs.h
2020-06-08 16:43:40 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
swift_jenkins
102ab6c4d3 Merge remote-tracking branch 'origin/master' into master-next 2020-05-22 13:40:25 -07:00
Hamish Knight
bc618a9763 [ClangImporter] Avoid calling into ObjCSelector lookup
The ClangImporter currently calls into
`ObjCSelector`'s `lookupDirect` in a couple of
places, stashing the selector in a DenseMap to try
and avoid re-entrancy problems.

However this will become a problem once
`ObjCSelector`'s `lookupDirect` is both
requestified and starts pulling in members from
the main module, so migrate the ClangImporter off
calling it.

Fortunately most of its uses only care about decls
with associated Clang nodes. For those cases, we
can use the existing member table, making sure to
populate it with any method we import.

In one case, the ClangImporter needs to check to
see if there's a deserialized Swift method with a
matching selector. Instead of calling through to
`lookupDirect`, let's just query the Swift module
loaders directly.
2020-05-21 09:19:02 -07:00
swift_jenkins
4775ae99ec Merge remote-tracking branch 'origin/master' into master-next 2020-05-13 08:18:45 -07:00
Michael Forster
e69abeba53 Classify C++ structs as loadable or address-only (#31707)
* Classify C++ structs as loadable or address-only

C++ structs are only loadable if they are trivially copyable.

Resolves SR-12472.
2020-05-13 17:16:47 +02:00
swift_jenkins
64add03f2e Merge remote-tracking branch 'origin/master' into master-next 2020-05-08 11:45:03 -07:00
Arnold Schwaighofer
e12698d7a0 Merge remote-tracking branch 'origin/master' into master-next 2020-05-08 07:22:20 -07:00
Dmitri Gribenko
2842748442 Improved a comment 2020-05-08 15:41:10 +02:00
Michael Forster
07c9fdd9e6 Synthesize memberwise initializers despite member functions
Previously unimportable member functions inhibited the synthesis of
memberwise initializers.
2020-05-08 14:26:21 +02:00
Michael Forster
d611b4c4f5 Synthesize memberwise initializers despite AccessSpecDecl
Previously the mere presence of `public:` or `private:` inhibited the
synthesis of memberwise initializers.
2020-05-07 17:44:41 +02:00
Shoaib Meenai
b59ffe0edf [ClangImporter] Adjust for LLVM changes
https://github.com/llvm/llvm-project/commit/9721fbf85b83 refactors the
enum; adjust Swift accordingly.
2020-04-29 15:28:08 -07:00