Commit Graph

426 Commits

Author SHA1 Message Date
Doug Gregor
72ade27956 Revert "[PrintAsObjC] Don't include the module for empty extensions"
This reverts commit 8f01b2c8f8.
2020-04-10 00:08:46 -07:00
Robert Widmann
630d0f631a Merge pull request #30606 from AnthonyLatsis/rename-getfullname
[NFC] Preparations to address the «Rename to getName?» TODO on ValueDecl::getFullName
2020-04-01 09:00:04 -07:00
Anthony Latsis
d0ae3ee580 [AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier 2020-03-29 00:35:51 +03:00
Doug Gregor
bf99f31d75 Revert "PrintAsObjc: expand module @imports to header #imports if modules are not supported"
This reverts commit a2534fa234.
2020-03-27 21:02:44 -07:00
Doug Gregor
6a7a7ff781 Revert "PrintAsObjc: strip Headers and PrivateHeaders component in header paths explicitly"
This reverts commit 411833d931.
2020-03-27 21:02:32 -07:00
Doug Gregor
ab97d50b0f Revert "PrintAsObjC: use header path relative to usr/include when importing non-framework headers"
This reverts commit ebe0a45583.
2020-03-27 21:00:51 -07:00
Xi Ge
ebe0a45583 PrintAsObjC: use header path relative to usr/include when importing non-framework headers
We could assume usr/include belongs to header search paths. If a header
is located in a deeper location inside this directory, we need to print
the additional path components.

rdar://60857172
2020-03-25 23:30:28 -07:00
Xi Ge
411833d931 PrintAsObjc: strip Headers and PrivateHeaders component in header paths explicitly
We use Header::NameAsWritten to collect the path of a header belongs to a module. Due
to an unclear clang-side issue, the path may contain "Headers/" and "PrivateHeaders/". To
walk-around this potential issue, we explicit check and remove these path components
from the Swift side.

rdar://problem/60249751
2020-03-10 14:30:09 -07:00
Alexis Laferrière
8f01b2c8f8 [PrintAsObjC] Don't include the module for empty extensions
rdar://problem/57133517
2020-03-09 14:10:44 -07:00
Alexis Laferrière
d11232b96e [PrintAsObjC] NFC Document and make isEmptyExtensionDecl public 2020-03-09 14:09:21 -07:00
Xi Ge
a2534fa234 PrintAsObjc: expand module @imports to header #imports if modules are not supported
rdar://58284119
2020-03-03 11:54:14 -08:00
Xi Ge
fa659ede76 [PrintAsObjc] add macro guard against potential recursive definitions 2020-02-05 12:37:01 -08:00
Devin Coughlin
082421048a [AST/Sema] Add availability attributes for macCatalyst
Add a platform kind and availability attributes for macCatalyst. macCatalyst
uses iOS version numbers and inherits availability from iOS attributes unless
a macCatalyst attribute is explicitly provided.
2020-01-21 20:27:14 -08:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Varun Gandhi
e7be41d0cb Merge pull request #27479 from varungandhi-apple/vg-track-clang-function-types
Track Clang function types in the AST
2019-12-04 08:47:35 -08:00
Slava Pestov
eef1428a2b PrintAsObjC: Support for blocks with __owned parameters 2019-12-02 18:41:27 -05:00
Varun Gandhi
1abd35a4c6 [NFC] Lift out common "canImportAsOptional" to a new header. 2019-11-22 12:43:07 -08:00
Hamish Knight
cb0c9adc46 Use getXXXType over getXXXDecl in a bunch of places 2019-11-07 08:26:08 -08:00
Doug Gregor
7306d1aff4 Add missing newline 2019-11-06 08:39:47 -08:00
Jacopo Andrea Giola
5902a477d4 Print IB_DESIGNABLE and IBInspectable in the generated ObjC header
Add support for @IBDesignable and @IBInspectable attribute to the
generated ObjC headers
2019-10-16 20:18:50 +02:00
Jordan Rose
a1ea211f22 Add llvm::iterator_range to LLVM.h
If we're going to get rid of swift::IteratorRange, let's make
llvm::iterator_range easy to use.

No functionality change.
2019-10-08 15:24:06 -07:00
Robert Widmann
6f3d6105c2 Switch up @objc enum printing
Now that all the raw values are computed up front, change the printer to
instead require the expression not be implicit.  Previously, a NULL
element would appear instead.
2019-10-02 16:10:15 -07:00
Robert Widmann
2fe3ce8af8 Requestify the Raw Value Accessor
Make getRawValueExpr() return a checked value.

This entails a strange kind of request that effectively acts like
a cache warmer.  In order to properly check the raw value expression for
a single case, we actually need all the other cases for the
autoincrementing synthesis logic.  The strategy is therefore to have the
request act at the level of the parent EnumDecl and check all the values
at once.  We also cache at the level of the EnumDecl so the cache
"warms" for all enum elements simultaneously.

The request also abuses TypeResolutionStage to act as an indicator for
how much information to compute.  In the minimal case, we will return
a complete accounting of (auto-incremented) raw values.  In the maximal
case we will also check and record types and emit diagnostics.  The
minimal case is uncached to support repeated evaluation.

Note that computing the interface type of an @objc enum decl *must*
force this request.  The enum's raw values are part of the ABI, and we
should not get all the way to IRGen before discovering that we cannot
possibly lay out the enum.  In the future, we might want to consider
moving this check earlier or have IRGen tolerate broken cases but for
now we will maintain the status quo and not have IRGen emit
diagnostics.
2019-10-02 16:09:25 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Brent Royal-Gordon
21426ea748 [NFC] [PrintAsObjC] Don’t cache NSCopyingType
ASTContext caches the decl and the decl caches the declared interface type, so there’s no performance win, and there isn’t a convenience win anymore either.
2019-09-18 18:05:39 -07:00
Brent Royal-Gordon
eb27a59ef2 [NFC] Add and use ASTContext::getNSCopyingDecl() 2019-09-18 15:56:16 -07:00
Jordan Rose
a3063ccfc0 [PrintAsObjC] Use TypeDeclFinder instead of custom TypeVisitor (#27189)
This is the same type-walking logic we use for access control
checking, so it had better be correct. Perfect case for DRY!

No functionality change.
2019-09-14 15:20:47 -07:00
Jordan Rose
c3db367d68 [PrintAsObjC] Simplify NSUInteger special case slightly (#27188)
Two conditions are always checked together; just have the caller do
it. No functionality change.
2019-09-14 15:20:33 -07:00
Jordan Rose
83e7763e9f [PrintAsObjC] Separate out module contents printing too (#27184)
The top-level PrintAsObjC now just covers import printing and the
near-literal prologue/epilogue text, while the decl printing (and
import collecting) is in its own file. No functionality change.
2019-09-13 20:13:59 -07:00
Jordan Rose
b2a27a50aa [PrintAsObjC] Clarify the 'specialNames' map in DeclAndTypePrinter
And comment the other cached members a little better.
2019-09-13 15:00:19 -07:00
Jordan Rose
dbbbbe5397 [PrintAsObjC] DeclAndTypePrinter::Impl doesn't need the module
It can get it from the owning DeclAndTypePrinter, and most of the time
it's only using it to get the ASTContext anyway. No functionality
change.
2019-09-13 11:14:03 -07:00
Jordan Rose
d68eae6b7a [PrintAsObjC] Fix caching of various special names
All persistent info should live in the parent DeclAndTypePrinter, not
in the Implementation helper class. We can move the rarely-used
members out too even if they're not lazily-populated.
2019-09-12 21:21:04 -07:00
Jordan Rose
6058797e06 [PrintAsObjC] Reorganize DeclAndTypePrinter fields to make more sense
No functionality change
2019-09-12 20:17:02 -07:00
Jordan Rose
11279ee01d [PrintAsObjC] Simplify tracking of @optional in protocol printing
The state for @optional vs. @required was only ever referenced from
one function, so we can just put it there.
2019-09-12 20:17:02 -07:00
Jordan Rose
efa350a05a [PrintAsObjC] Pull the actual decl/type printer out to a separate file
I've tried several times to separate the type printing from the
decl-printing and found it tricky, but at least both can be separated
from the logic of walking the top-level decls in a module and
scheduling them appropriately. No functionality change.
2019-09-12 20:17:02 -07:00
Slava Pestov
c450b45e89 AST: Clean up a couple of uses of UnqualifiedLookup
We can use type lookup in more places, and switch a couple of callers
to use qualified lookup instead.
2019-08-24 22:34:35 -04:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
Slava Pestov
1c3ac86796 AST: Banish OptionalTypeKind to ClangImporter.h
The only place this was used in Decl.h was the failability kind of a
constructor.

I decided to replace this with a boolean isFailable() bit. Now that
we have isImplicitlyUnwrappedOptional(), it seems to make more sense
to not have ConstructorDecl represent redundant information which
might not be internally consistent.

Most callers of getFailability() actually only care if the result is
failable or not; the few callers that care about it being IUO can
check isImplicitlyUnwrappedOptional() as well.
2019-08-15 18:41:42 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
5826db5d56 AST: Add AbstractFunctionDecl::hasDynamicSelfResult() and use it
This calculates a result directly from the function's result type
instead of checking a bit that was previously set by the type
checker. Also, always returns true for constructors to simplify
some callers.
2019-06-26 01:10:12 -04:00
Slava Pestov
8f22da205a Sema: Stop wrapping Self returns in protocols with DynamicSelfType 2019-06-26 01:10:11 -04:00
Rintaro Ishizaki
db2c11787b [AST] Inherit doc-brief comment from protocol, superclass, and requirement
rdar://problem/38422822
2019-06-20 10:04:05 -07:00
Jordan Rose
406a9d9cf1 Add the notion of @_implementationOnly overrides
When an @_implementationOnly import includes Objective-C categories
for existing types, it's useful to be able to override the members
provided in those categories without exposing them to clients of the
framework being built. Allow this as long as the overriding
declaration is marked as @_implementationOnly itself, with an
additional check that the type of the declaration does not change.
(Normally overrides are allowed to change in covariant ways.)

Part of rdar://50827914
2019-06-17 17:48:40 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -07:00
Slava Pestov
6e3609dc22 AST: ProtocolConformanceRef::getTypeWitnessByName() should be an instance method 2019-05-14 19:28:55 -04:00
Slava Pestov
644b6adcd2 AST: Simplify ProtocolConformanceRef::getTypeWitnessByName() 2019-05-10 15:00:48 -04:00