Commit Graph

317 Commits

Author SHA1 Message Date
Xi Ge
64082e122f SourceKit: checking context match before calling TypeBase::getMemberSubstitutions(const DeclContext *dc). rdar://28780008
TypeBase::getMemberSubstitutions(const DeclContext *dc) collects type
substitution information when a decl context can be treated as part of the
type definition. However, we call it without checking whether the
part-of-whole relationship really holds. This patch checks the
pre-condition before calling it to fix a crash.
2016-10-24 13:28:13 -07:00
Xi Ge
e01f0ac8b9 [SourceKit][DocInfo] For enum element decls, inherit their parent enum decls' deprecated attributes, if there are any. rdar:// 28802301 2016-10-21 12:49:59 -07:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Michael Ilseman
8923a12585 [ASTPrinter] Switch to new ParameterTypeFlags
Switch printing off of using Function's ExtInfo for autoclosure and
escaping, and onto the ParameterTypeFlags, which let us do precise and
accurate context-sensitive printing of these parameter type
attributes. This fixes a huge list of issues where we were printing
@escaping for things like optional ObjC completion handlers, among
many others. We now correctly print @escaping in more places, and
don't print it when it's not correct.

Also updates the dumper to be consistent and give a good view of the
AST as represented in memory. Tests updated, more involved testing
coming soon.
2016-09-22 12:24:02 -07:00
Doug Gregor
8fb4deece8 Merge pull request #4509 from IngmarStein/master
[ClangImporter] import compound macros independent of order
2016-09-19 22:02:19 -07:00
practicalswift
8d6251de66 [gardening] Fix accidental uses of \t 2016-09-17 13:15:26 +02:00
Doug Gregor
7e2efe5591 [Type checker] Infer @objc for protocol conformances in other extensions.
Expand the scope of @objc inference for witnesses to encompass
witnesses that are in a different extension from that of the
conformance, including cases where one or the other is in the nominal
type declaration itself.

Fixes rdar://problem/26892526.
2016-09-06 13:04:00 -07:00
Chris Lattner
7479810870 Merge pull request #4619 from rintaro/SE-0081-astprinter
[SE-0081] Update ASTPrinter for SE-0081
2016-09-03 18:10:51 -07:00
Rintaro Ishizaki
229beac813 [SE-0081][ASTPrinter] Move where clause to the end of declaration 2016-09-04 02:42:56 +09:00
Ingmar Stein
98240ab871 [ClangImporter] import compound macros independent of order
This patch fixes an importer problem which occurred for macros defined
in terms of two other macros which might not have been imported before.
For example, the macro CPU_TYPE_X86_64 (defined as CPU_TYPE_X86 |
CPU_ARCH_ABI64) in Foundation wasn't imported although the importing
logic was implemented.

importMacro is now called for each of the constituents before checking
the constant value.
2016-09-03 16:43:11 +02:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Ben Langmuir
6acdf89671 [cursor-info] Wrap @escaping/@autoclosure in attribute.builtin tags
I misled Argyrios into thinking we only had a wrapper for the name when
we also have one for the whole attribute.  Fix that for @escaping and
@autoclosure.

rdar://problem/27867763
2016-08-26 14:21:16 -07:00
Nate Cook
4bd257bb43 [stdlib] Update test for doc changes 2016-08-12 15:16:20 -05:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Argyrios Kyrtzidis
80b3f56b40 [AST] Fix the cursor-info tests with these changes:
- Make sure VarDecls have an associated TypeLoc, like ParamDecls do, then use it for printing the VarDecl's type.
This is done by moving ParamDecl's TypeLoc up to the VarDecl.
This is useful for being able to display the parameter names of function types embedded in VarDecls.

- Use the result TypeLoc of functions for printing. This enables printing parameter names of function types embedded in return types.

- Make sure to annotate attributes while they are printed.
2016-08-09 20:52:09 -07:00
Nate Cook
1b9b0ffd0a [stdlib] Fix test for documentation changes 2016-08-05 20:14:59 -05:00
Jordan Rose
b4e6f45083 [ClangImporter] Don't bridge weak and unsafe_unretained properties.
...to value types. Do continue bridging BOOL to Bool and such.

If the Objective-C API author went out of their way to indicate
ownership, they're probably using the reference semantics for
something. Give them the benefit of the doubt and leave the properties
declared using reference types. (It's not that they wouldn't work
correctly using Any, but that it's obscuring the intended interface.
And any /specific/ bridged value types /might/ actually cause issues
by causing copies.)

There is one wrinkle here involving declarations in the "accessibility
protocols" on Apple platforms, which sometimes use methods and
sometimes properties. The Swift compiler already deals with these by
always importing these as methods, so treat these like any other
methods and use value types when relevant.

rdar://problem/27526957
2016-08-03 20:43:35 -07:00
Michael Ilseman
c37751ae96 [noescape by defaul] make noescape the default
This flips the switch to have @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
2016-07-29 13:49:08 -07:00
Argyrios Kyrtzidis
62f30d50d2 [SourceKit] For clang enums imported as error domains, make sure to use unique USRs.
Error domain enums are imported with synthesizing something like this:

 struct MyError {
     enum Code : Int32 {
         case errFirst
         case errSecond
     }
     static var errFirst: MyError.Code { get }
     static var errSecond: MyError.Code { get }
 }

The clang enum and enum constants are associated with both the
struct/nested enum, and the static vars/enum cases.
But we want unique USRs for the above symbols, so use the clang USR
for the enum and enum cases, and the Swift USR for the struct and vars.

rdar://27550967
2016-07-27 21:42:36 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Joe Groff
5bfd6cc0c7 Update SourceKit tests for id-as-Any. 2016-07-25 06:40:36 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Doug Gregor
80f0852504 [SE-0091] Allow 'static' operators to be declared within types and extensions thereof.
Allow 'static' (or, in classes, final 'class') operators to be
declared within types and extensions thereof. Within protocols,
require operators to be marked 'static'. Use a warning with a Fix-It
to stage this in, so we don't break the world's code.

Protocol conformance checking already seems to work, so add some tests
for that. Update a pile of tests and the standard library to include
the required 'static' keywords.

There is an amusing name-mangling change here. Global operators were
getting marked as 'static' (for silly reasons), so their mangled names
had the 'Z' modifier for static methods, even though this doesn't make
sense. Now, operators within types and extensions need to be 'static'
as written.
2016-07-18 23:18:57 -07:00
Xi Ge
3cc0b1df61 [libIDE] When printing type interface, ensure we translate 'Self' to the type under printing. rdar://27306890 (#3514) 2016-07-14 15:50:49 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Xi Ge
64efa48c65 [SourceKit][DocInfo] When the underlying type of a type alias decl exists, report the conformances of the underlying type. rdar://26408167 (#3394)
Showing only the conforming associated types provides
little information to doc viewers. This patch digs the
underlying type of an associated type to report the
conformance info of those.
2016-07-07 16:24:01 -07:00
Ingmar Stein
4f800f8a21 [ClangImporter] Import preprocessor constants with a cast
Addresses SR-1509 by adding a heuristic to import numeric literals with a
type cast. Two new cases have been added for macros with 4 or 5 tokens
to cover cases with or without sign tokens.
2016-06-29 23:01:30 +02:00
Brian Croom
98e3ca8bc4 Annotate some SourceKit tests that fail on Linux.
* A bunch of them require objc_interop because they import code containing
  Objective-C.
* Many others fail on Ubuntu 14.04 because the C++ there doesn't have a
  functional std::regex implementation which is required by the
  `complete-test` tool.

It may be possible to adjust some of these tests in the future to not
need these extra requirements, but this is a straightforward way to
clean up Linux test results for now.
2016-06-14 08:55:48 -04:00
Dmitri Gribenko
d5157c85da Fix test SourceKit/DocSupport/doc_clang_module.swift 2016-06-09 07:57:28 -07:00
Arnold Schwaighofer
f9e1d53523 Disable failing test for now
This started failing after one of the two commits:

[stdlib] Add missing discardableResult attribute
Fixes SR-1695: Option Set insert needs @discardableResult

[gardening] Remove unused diagnostic
attr_warn_unused_result_mutable_variable

These commits seem harmless so I disabled the test pending further
investigation.

rdar://26718415
2016-06-09 07:09:18 -07:00
Nate Cook
8e2ec66bdc [stdlib] Remove 'Returns' fields from initializers
This includes an updated fixture for `SourceKit/DocSupport/
doc_clang_module.swift', which depends on the OptionSet documentation.
2016-05-27 10:10:56 -05:00
Nate Cook
dee12dca75 [stdlib] Update tests for new String documentation
In addition to a new test fixture for 'SourceKit/DocSupport/
doc_clang_module.swift', this removes the check for an ASCII-only
generated standard library interface from 'SourceKit/InterfaceGen/
gen_stdlib.swift'.
2016-05-22 03:11:00 -05:00
Jordan Rose
2fa3da4089 Drop the notion of "alias" names for CF types.
Previously we imported a Core Foundation type "CCFooRef" as "CCFoo",
but also provided a typealias "CCFooRef". In Swift 3, we decided to
mark "CCFooRef" unavailable to force developers to consistently use
"CCFoo". Now that we have infrastructure to mark /all/ renamed
declarations as unavailable, just use that to track the renaming,
i.e. pretend that "CCFooRef" was the "Swift 2" name for the type.

This doesn't change the conflict resolution behavior: if there's
another name "CCFoo" in the same module, the CF type will be
imported as just "CCFooRef".

Groundwork cleanup for rdar://problem/26347297, which notes that our
import-as-member fix-its use the "Ref" names rather than the short
names.
2016-05-19 13:21:47 -07:00
Nate Cook
982e3d09f8 [stdlib] Revise documentation for new indexing model
This revises and expands on documentation for the new collection methods
for working with indices and the revised Swift 3 set APIs. In addition,
it includes documentation for the new range types.
2016-05-19 10:16:14 -05:00
Dmitri Gribenko
9aece73efb stdlib: add migration aids for SetAlgebra API
rdar://problem/26227732
2016-05-17 20:06:59 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04:00
Trent Nadeau
6e327b4ddb Updated stdlib to use @discardableResult and _ = . 2016-05-11 22:53:37 -04:00
Nate Cook
dfa89150c8 [stdlib] Update test depending on doc comments 2016-05-09 16:41:44 -05:00
Jorge Bernal
0a3f913b20 SE-0070: Make Optional Requirements Objective-C-only.
Optional protocol requirements now require an explicit @objc attribute.

Fixes SR-1395
2016-05-06 11:05:52 +02:00
practicalswift
d804026b34 [gardening] Fix "a" vs. "an" issues. 2016-05-01 13:29:57 +02:00
Nate Cook
21df5f203a [stdlib] Fix errant tests
- A benchmark method was renamed during the Set API batch revisions
- The SourceKit test that includes stdlib docs needed a new fixture
2016-04-27 11:13:44 -05:00
Dmitri Gribenko
263d6a4135 Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-04-26 21:15:13 -07:00
Dave Abrahams
debde16e2c Merge set-api branch into swift-3-indexing-model 2016-04-26 15:56:42 -07:00
Doug Gregor
2477206ed4 [Clang importer] Mark discardableResult attribute "implicit".
The Clang importer implicitly synthesizes @discardableResult for
nearly all imported functions. Printing this attribute in the
generated interface leads to a lot of noise. Mark it as implicit so we
don't print it.
2016-04-26 14:48:39 -07:00
Dmitri Gribenko
b75d2b9df4 Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-04-25 13:50:09 -07:00
Nate Cook
099c395473 Fix test expectation for SourceKit test that depends on stdlib docs 2016-04-25 12:59:39 -05:00
Xi Ge
c4d7b1a185 ASTPrinter: never synthesize extensions for raw types of enum decls.
Even thought raw types are specified in inheritance clauses, their
members are not usable through an enum instance. Thus, there is no
point to synthesize their members.
2016-04-22 22:52:46 -07:00
Dmitri Gribenko
0984f81a50 Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-04-22 18:56:35 -07:00
Jordan Rose
7ad6a8bd61 [test] Fix SourceKit tests for 2e38280.
Also filed <rdar://problem/25858559> "SourceKit response info for
enum shouldn't include members of the raw type" to keep it from
happening again.
2016-04-21 11:50:27 -07:00
Dmitri Gribenko
fc8d62dfbb Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-04-18 14:40:06 -07:00