Commit Graph

386 Commits

Author SHA1 Message Date
Jordan Rose
e34a6a1105 [PrintAsObjC] Look through "compatibility" typealiases (#20027)
These handle imported types that have been renamed in a /later/ Swift
version than the one being used; for consistency when deserializing
from a swiftmodule, the latest name is always used. This is important
because it might mean we can avoid importing the framework that a name
comes from; a forward declaration might be sufficient if it's an ObjC
class or protocol.

rdar://problem/45491607
2018-10-25 08:26:17 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -07:00
Jordan Rose
71760bcc4e Replace StringMap with DenseMap when the keys don't need to be owned
StringMap always copies its strings into its own storage. A DenseMap
of StringRefs has the same caveats as any other use of StringRef, but
in the cases I've changed the string has very clear ownership that
outlives the map.

No functionality change, but should reduce memory usage and malloc
traffic a little.
2018-09-13 15:15:27 -07:00
Jordan Rose
f68054470d Merge pull request #19167 from jrose-apple/proper-property-properties
[PrintAsObjC] Use 'unsafe_unretained' to print 'unowned', not 'assign'
2018-09-10 16:14:57 -07:00
Jordan Rose
340090c6af [PrintAsObjC] Refactor printing of property ownership attributes
Exhaustively switch over reference types, so that we'll know if any
new ones are added, and factor out a repeated check to see if
something's a retainable object type.

No functionality change.
2018-09-10 14:33:05 -07:00
Jordan Rose
0bcf355bc8 [PrintAsObjC] Use 'unsafe_unretained' to print 'unowned', not 'assign'
The ObjC generator previously preserved a subtle difference between
'unowned' and 'unowned(unsafe)' / Unmanaged by printing the former as
'assign' and the latter as 'unsafe_unretained'. Upstream Clang,
however, has gotten a new warning to discourage the use of 'assign'
with reference-countable types at all. Since it was always a subtle
distinction, just go with the new convention and print
'unsafe_unretained' for 'unowned' properties as well.

rdar://problem/44290715
2018-09-10 14:32:32 -07:00
Jordan Rose
37ec248823 Add ModuleDecl::ReverseFullNameIterator
Package up the logic that generates a full Clang module name, so that
(a) we don't have to deal with clang::Module in quite as many places
in the /Swift/ compiler, and (b) we can avoid the cost of a temporary
string in a few places.

The main places where this is /not/ adopted is where we don't just
want to know the parent module name, but actually the module itself.
This is mostly indexing-related queries, which use the very similar
ModuleEntity class also defined in Module.h. I didn't quite see an
obvious way to unify these, but that might be where we want to go.

No functionality change.
2018-09-06 19:53:59 -07:00
Jordan Rose
ad7bbdfbd6 [PrintAsObjC] Handle generic typealiases (#18941)
(either explicitly generic ones, or those embedded in generic contexts)

Previously we tried to look at the typealias decl's underlying type,
but that might have generic parameters in it. Oops. Use the
NameAliasType's desugared type instead.

Also, drop half-baked support for `@objc typealias`, which isn't
supported. (It's not an unreasonable feature, but the bits that were
there weren't implemented correctly.)

rdar://problem/43347303
2018-08-24 08:57:22 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Doug Gregor
2c519b8b53 Eliminate two trivial uses of lookupQualified(Type, ...). 2018-08-14 01:05:43 -07:00
swift-ci
71f0248b0a Merge remote-tracking branch 'origin/master' into master-next 2018-08-06 11:07:55 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
swift-ci
7e623dd927 Merge remote-tracking branch 'origin/master' into master-next 2018-08-01 11:09:11 -07:00
Jordan Rose
2dcac4bcb2 Merge pull request #18408 from jrose-apple/default-on-your-futures
[SIL] Don't drop a default when switching on a non-exhaustive enum

rdar://problem/42775178
2018-08-01 10:54:19 -07:00
Jordan Rose
b25e561e82 Rename EnumDecl::isExhaustive to isFormallyExhaustive
...in preparation for an isEffectivelyExhaustive coming in the next
commit.
2018-07-31 19:01:00 -07:00
swift-ci
5830e237ff Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 13:29:50 -07:00
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
swift-ci
7296555ad7 Merge remote-tracking branch 'origin/master' into master-next 2018-07-30 11:49:04 -07:00
Jordan Rose
2d88bb6721 Merge pull request #18081 from pitiphong-p/objc-rename-attribute
Use the custom @objc name in the available attribute when generates ObjC headers

https://bugs.swift.org/browse/SR-8231
2018-07-30 11:35:52 -07:00
swift-ci
fd7d5c86dd Merge remote-tracking branch 'origin/master' into master-next 2018-07-29 19:29:07 -07:00
Mark Lacey
ffb74a5a87 [PrintAsObjC] Replace a couple uses of getInput() with getParams(). 2018-07-29 14:27:25 -07:00
Pitiphong Phongpattranont
e006d700e0 Change from early exit to assert instead 2018-07-25 15:16:02 +07:00
Pitiphong Phongpattranont
a2c877a4f3 Rename renamedFuncDecl to renamedDecl 2018-07-25 14:07:27 +07:00
Pitiphong Phongpattranont
acd28c4915 Fallback to the name in the Attribute when found duplicated candidates 2018-07-24 13:55:50 +07:00
Pitiphong Phongpattranont
f852f3f82e Change the type of D parameter to ValueDecl 2018-07-24 08:50:23 +07:00
Pitiphong Phongpattranont
18ac6f9340 Mark the renamedFuncDecl variable as const 2018-07-24 08:49:57 +07:00
Pitiphong Phongpattranont
045fb7cd65 Fix the wrong checking condition on the case where both of them should be instance members or otherwise 2018-07-22 00:09:37 +07:00
Pitiphong Phongpattranont
16ccb19e81 Ditch the unneccessary Optional type on renamedFuncDecl variable 2018-07-21 22:13:37 +07:00
Pitiphong Phongpattranont
4661166ea1 Pass the UnqualifiedLookup::Flags::TypeLookup option when doing the Type lookup 2018-07-21 22:13:37 +07:00
Pitiphong Phongpattranont
7a9b890cc7 Rename findRenamedDecl method to printRenameForDecl 2018-07-21 22:13:30 +07:00
Pitiphong Phongpattranont
7da1f303c1 Use the custom @objc name in the Availablity attributes on classes and protocols when generates the ObjC header 2018-07-21 17:40:41 +07:00
Pitiphong Phongpattranont
12d0024188 Reserve the white spaces 2018-07-21 17:40:41 +07:00
Pitiphong Phongpattranont
d0801890ec Use the custom @objc name in the Availablity attributes when generates the ObjC header 2018-07-21 17:40:41 +07:00
swift-ci
403cb35abc Merge remote-tracking branch 'origin/master' into master-next 2018-07-20 00:29:49 -07:00
Slava Pestov
fd8a7b8d01 PrintAsObjC: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:25:21 -07:00
swift-ci
60de11c4f0 Merge remote-tracking branch 'origin/master' into master-next 2018-07-11 19:29:17 -07:00
Jordan Rose
c8b61f990b Merge pull request #17615 from maniramezan/master
[SR-2250] Include Foundation framework instead of minimal NSObject.h
2018-07-11 19:14:49 -07:00
swift-ci
c616a40bf6 Merge remote-tracking branch 'origin/master' into master-next 2018-07-03 14:09:31 -07:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
Mani Ramezan
3c824ddaa5 Include Foundation framework instead of minimal NSObject.h
This change is for preventing scenarios like https://bugs.swift.org/projects/SR/issues/SR-2250
2018-06-28 19:27:24 -04:00
Bob Wilson
1386e82e19 [master-next] Update for Clang r331155
CharSourceRange now requires the use of getBegin()
2018-05-04 18:02:50 -07:00
Huon Wilson
0516915a81 [PrintAsObjC] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:07 +10:00
Jordan Rose
d734ce800c [PrintAsObjC] Sort imports alphabetically. (#15899)
This ensures that 'Foo' always gets imported before 'Foo_Private'.
This shouldn't strictly be necessary but does end up with more
reliable results in practice.

rdar://problem/36159006
2018-04-12 20:57:42 -07:00
Doug Gregor
b2b69e8abf Rename BoundNameAliasType to NameAliasType.
NameAliasType is dead! Long live NameAliasType!
2018-03-25 21:35:17 -07:00
Doug Gregor
c43f96a855 [AST] Remove now-unused NameAliasType. 2018-03-25 21:35:16 -07:00
Doug Gregor
bde6401f5b Support BoundNameAliasType everywhere we support NameAliasType.
This doesn't have a specific effect now, because all of these places
are likely to only see NameAliasType, but it is refactoring with the
intent of eliminating NameAliasType entirely.
2018-03-25 20:46:07 -07:00
Jordan Rose
1b1a4cb22e [PrintAsObjC] Use enum_extensibility to represent @_frozen
Previously (a03c40cb2c) we assumed all Swift enums were non-frozen in
ObjC, a weird choice in retrospect. Now that we actually distinguish
frozen and non-frozen enums in Swift, we can use the
'enum_extensibility' attribute to mark them as open or closed in ObjC.

Note that this only matters for Swift libraries compiled with
-enable-resilience, i.e. those that might get a new implementation at
runtime. Everyone else is now declaring a "closed" enum, matching the
behavior in Swift.
2018-03-20 14:49:11 -07:00
Mark Lacey
85f25003ce Replace uses of getOptionalObjectType(bool &).
Instead, use the one that doesn't have a reference parameter.
2018-03-16 21:19:49 -07:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00