Commit Graph

386 Commits

Author SHA1 Message Date
Tapan Thaker
bb6db49f80 [PrintAsObjC] Fixes [SR-6884]. Prints availability information for properties. (#14561) 2018-02-13 18:09:29 -08:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
be8defb29e Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes. 2018-02-05 23:59:01 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Greg Parker
4953262288 Fix a build warning. (#13985)
"specified comparator type does not provide a const call operator"
2018-01-17 14:56:22 -08:00
John McCall
52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Mark Lacey
5b7ebd7c4f IUO: Updates to PrintAsObjC to use the decl attribute for IUO.
Use the attribute to update the OptionalTypeKind used for various
decls that we print.

I added test cases to make sure we were exercising all the modified
code paths.
2018-01-11 23:48:32 -08:00
David Zarzycki
9b48b5074a [AST] Perf: Unite DictionaryType with SyntaxSugarType
1) Move existing SyntaxSugarTypes under a new subclass called UnarySyntaxSugarType.
2) Make DictionaryType subclass SyntaxSugarType.

This helps improve getDesugaredType() performance by ensuring that
ImplOrContext is stored at the same field offset in memory.

This also de-boilerplates some AST walking.
2018-01-02 15:14:07 -05:00
Jordan Rose
9a9ea6915f [PrintAsObjC] Downgrade +new unavailability to deprecation in Swift 4
The general policy has been that even if something crashes at run
time, we don't make it a hard error in Swift 4 mode (or Swift 3 mode!)
if it wasn't a hard error in Swift 4.0 (3.0). In this case, we thought
we could get away with it, and then it turns out it actually caused
some problems. (And as 2bc010681 shows, we can still make mistakes.)

This change isn't perfect because the diagnostic appears in /clients/
rather than in the module that's being compiled as Swift 4 (instead of
Swift 5). But it still means that someone who hasn't changed
/anything/ from a valid Swift 4.0 project will be able to compile
without any changes, even if they were relying on being able to call
+new when -init was unavailable for some reason.

More rdar://problem/35942058
2017-12-13 17:59:55 -08:00
Jordan Rose
7493eccaa9 [PrintAsObjC] Include a message when making +new unavailable
Another follow-up to 49c65facc9. We've seen a few people run into
this and not know what changed.

rdar://problem/35942058
2017-12-13 17:59:55 -08:00
Jordan Rose
2bc0106810 [PrintAsObjC] Reintroduce +new when reintroducing -init. (#13320)
Follow-up to 49c65facc9 to account for subclasses. An unavailable
-init makes +new unavailable, but reintroducing it in a subclass
should reintroduce +new if the root class is NSObject (where +new is
implemented).

rdar://problem/35914080
2017-12-07 15:15:43 -08:00
Jordan Rose
34e602b93a [PrintAsObjC] Don't define char{16,32}_t in C++-pre-11 (#12537)
Turns out libc++ already defines compatibility typedefs in this case,
and we don't care about any other C++ stdlibs on Apple platforms at
the moment.

rdar://problem/34861807
2017-10-23 10:46:01 -07:00
Jordan Rose
01add3aec1 [PrintAsObjC] Defend against macros named 'any' (#12396)
SourceKit uses a clever pragma to automatically attach an attribute to
every declaration in the file. However, the form of this pragma (clang
attribute push) uses a parenthesized list marked with 'any', which turns
out to be a name that people sometimes use for macros. Guard against this
using the push_macro pragma (originally from MSVC), under the assumption
that anyone who supports the highly-use-specific 'external_source_symbol'
attribute probably implements this more common extension. This does make
the generated header a little uglier, but it's not like it was really
pretty to begin with.

rdar://problem/34168022
2017-10-12 13:39:07 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
Javier Soto
f400eca692 Fix incorrect variable name 2017-10-05 17:17:43 -07:00
Javier Soto
49c65facc9 [PrintAsObjC] Attempt at fixing SR-5018: marking +new unavailable when -init is unavailable.
Currently a loop-hole exists by which one could end up invoking an unavailable -init initializer from Obj-C
when it is unavailable by using +new (which itself calls -init)

https://bugs.swift.org/browse/SR-5018
2017-10-05 16:54:55 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Jordan Rose
c4c09eaea3 [PrintAsObjC] default -> fully-covered switch
Per feedback from Doug. The last case was unreachable anyway, so no
functionality change.
2017-08-08 17:27:21 -07:00
Jordan Rose
0a2e8eb452 [PrintAsObjC] Include messages for platform always-unavailable decls.
A misplaced brace left the messages in empty space. Noticed by
inspection.
2017-08-08 17:25:04 -07:00
Jordan Rose
894cd6a64e [PrintAsObjC] Simplify loop over availability attributes.
No functionality change. Diff best viewed ignoring whitespace.
2017-08-08 17:25:04 -07:00
Jordan Rose
191e2767ab [PrintAsObjC] Print availability on classes, protocols, and categories
Now that Clang has availability diagnostics too
(-Wpartial-availability and friends) we need to get this correct, or
people will get warnings in the generated header!

rdar://problem/33313703
2017-08-08 17:25:04 -07:00
Robert Widmann
4411223156 [NFC] Switch some more of the frontend to params 2017-06-30 10:24:52 -07:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02:00
Jordan Rose
bd0cb3de8a [PrintAsObjC] Silence -Wnullability for the generated declarations. (#10247)
Since Swift 3 and Swift 4 might have different views of an Objective-C
API's nullability, we can end up with incompatible overrides,
including with inherited initializers. This is unfortunate but also
realistic; the Swift 3 code is /not/ set up to handle the new nullability
used by Swift 4 and Objective-C. Just silence the warning.

(It would be nice to not print inherited initializers at all, but that
would mean making sure there are no convenience initializers we have
to print as well. Otherwise the class would get mistaken for one
without explicit designated initializers.)

rdar://problem/32571301
2017-06-14 13:50:06 -07:00
Jordan Rose
eb9f047ad8 [PrintAsObjC] Handle the importer's compatibility typealiases. (#10042)
These are TypeAliasDecls whose Clang nodes are not TypedefNameDecls.
This worked all right for classes, but dropped the tag keyword
(e.g. 'struct') for tag decls with names of their own, and didn't
print any name at all for C types that used the
typedef-for-anonymous-tag pattern.

rdar://problem/32514335
2017-06-01 15:28:44 -07:00
Alex Hoppen
58c956a29a [Misc] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Alex Hoppen
f302afc97f Unify approach to printing declaration names (#9320)
Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:25:20 -07:00
Doug Gregor
1063b4b5fc [SE-0160] [PrintAsObjC] Adopt Clang's new diagnose_if attribute.
When available, use Clang's new diagnose_if attribute to mark
Objective-C methods/properties that were generated based on the @objc
inference rules that have been removed from Swift 4. The diagnose_if
warnings aren't likely to be accidentally disabled or hidden by other
deprecated code.

Fixes rdar://problem/32370734.
2017-05-23 22:08:11 -07:00
Doug Gregor
b610a509fc [PrintAsObjC] Handle typealiases to non-type Clang declarations.
For historic reasons, Clang's representation of an Objective-C class
declaration ObjCInterfaceDecl) and compatibility alias
(ObjCCompatibleAliasDecl) are not actually Clang TypeDecl nodes. Cope
with this in Objective-C printing, fixing rdar://problem/32308192.
2017-05-19 21:57:41 -07:00
Jordan Rose
2e47272ad3 [PrintAsObjC] Don't warn about inferred '@objc' in Swift 3 mode. (#9756)
Only do so in modes where '@objc' /is/ inferred but we're supposed to
warn about it. Neither plain old Swift 3 nor plain old Swift 4 are in
this state, but we have frontend options that allow us to set that up
for migration purposes.

rdar://problem/32284936
2017-05-19 07:33:13 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Slava Pestov
c653b9e034 PrintAsObjC: Update for primitive AnyObject 2017-05-01 19:30:43 -07:00
Doug Gregor
4f05186b88 [PrintAsObjC] Don't use take an ArrayRef into temporary storage.
ObjCSelector::getSelectorPieces() can return a pointer to *this, so
don't use it on a temporary. Fixes an ASan-detected
stack-use-after-scope, rdar://problem/31837593.
2017-04-26 22:36:23 -07:00
Argyrios Kyrtzidis
28b15852d8 Fix tests due to clang namespacing USR changes 2017-04-24 17:42:36 -07:00
Argyrios Kyrtzidis
093e826f92 [index] Use a #pragma to apply module namespacing for exported ObjC header and match Swift namespaced USRs with the clang side 2017-04-24 14:02:16 -07:00
Argyrios Kyrtzidis
0efba5f0e9 [PrintAsObjC] Make sure the preprocessor checks work in a compiler different than clang
The C preprocessor rules don't short-circuit so "#if defined(__has_feature) && __has_feature(modules)" will always fail if '__has_feature' is not defined.
2017-04-21 12:00:21 -07:00
Jordan Rose
a03c40cb2c [ClangImporter] Classify enums using flag_enum and enum_extensibility (#8910)
These new Clang attributes identify whether an enum is intended to
represent an option set or not, and whether the set of cases listed in
the enum declaration is exhaustive. (Swift doesn't currently have a
closed/open distinction for enums, so treat any C enum with
enum_extensibility as a proper closed Swift enum, like we do with
NS_ENUM.)

Enums with neither attribute will continue to be imported as unique
types.

rdar://problem/28476618
2017-04-21 08:57:27 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
dc1e681ca4 PrintAsObjC: Support for subclass existentials 2017-04-12 22:24:21 -07:00
Slava Pestov
547a4d4af5 PrintAsObjC: Tighten some screws 2017-04-12 22:24:21 -07:00
Slava Pestov
75190c7060 PrintAsObjC: Drop redundant protocols from inheritance clauses
There was a FIXME for that. Seems easy enough to address,
please shout if this breaks anything.
2017-04-12 22:24:20 -07:00
Slava Pestov
4d5e509ed2 PrintAsObjC: We don't need to print metatypes of non-@objc classes
At least, none of the existing tests hit this case.
2017-04-12 22:24:13 -07:00
Doug Gregor
6d1bc9cf03 [SE-0160] Add “deprecated” attributes to the generated headers for Swift 3 inferred @objc.
When Swift 3 infers @objc using one of the rules deprecated in Swift 4, add a “deprecated” attribute to the declarations generated Objective-C header so that Objective-C gets warnings for uses of these APIs.
2017-03-31 21:22:15 -07:00
Xi Ge
75e191f5ac AST: Summarize a commonly used call chain in AbstractFunctionDecl. NFC (#8424) 2017-03-30 10:51:10 -07:00
practicalswift
430e8d4a62 [gardening] Use "foo && isa<C>(foo)" instead of "dyn_cast_or_null<C>(foo)" when the result is unused 2017-03-28 21:48:53 +02:00
Hugh Bellamy
d9879522fb Fix top of tree Clang unused lambda capture warnings 2017-03-21 19:15:08 +07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Caleb Davenport
f0f3cc4436 Switch from std::copy_if to std::any_of. 2017-03-06 16:30:44 -05:00