Commit Graph

317 Commits

Author SHA1 Message Date
Jordan Rose
b9e0d7f5b8 [AST] Fix printing of constrained protocol extensions
We wanted to omit the 'Self: TheProtocolBeingExtension' part of the
generic signature, but the logic that was there accidentally omitted
/all/ constraints on Self.
2018-08-17 19:26:47 -07:00
Jordan Rose
fa8ac95fd0 Don't print 'convenience' on protocol extension initializers (#18777)
We model them that way in the compiler, but that's not part of the
user-level language.

rdar://problem/32067077
2018-08-17 19:25:40 -07:00
Doug Gregor
e21673df9e [SourceKit] Test case fix-up because we’re not validating quite as eagerly. 2018-08-14 01:05:43 -07:00
Ben Cohen
a6952decab [stdlib] Remove inlineable annotation from transparent functions (#17800)
* Remove inlineable annotation from transparent functions
2018-07-07 08:47:02 -07:00
Doug Gregor
a66df57aaf [Mangling] Update SILGen and IRGen tests for mangling change. 2018-06-19 23:24:38 -07:00
Robert Widmann
7d82e70f2c Excise getInput() from printing
Not NFC because it changes the printing behavior for function type
parameters.  They are no longer reported as types (paren, tuple, or raw),
but as Params.
2018-06-10 19:40:26 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Xi Ge
714775eb0a DocSupport: don't assume we've printed the first extension when merging several together. rdar://39887195
When printing the content of several extensions into a
synthesized one, we shouldn't assume the first extension in the
group always gets printed.
2018-05-02 17:46:41 -07:00
Slava Pestov
392a5c2bcb AST: @usableFromInline and @inlinable are no longer user inaccessible 2018-04-26 22:58:56 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Davide Italiano
b4a19cc6ac [Mangler] Fix mangling for associated types. 2018-03-27 11:06:15 -07:00
Doug Gregor
9cfbd30215 Update SourceKit test's expected output for sugaring changes. 2018-03-25 21:35:16 -07:00
Pavel Yaskevich
4b05449c37 [GSB] Eliminate concrete potential archetypes by early substitution
To make generic signature builder more robust it's imperative to
eliminate possibility of out-of-order typealias substitution.

These changes try to make it so potential archetypes could only be
constructed with associated types by doing early concrete type (typealias)
subsitution while trying to resolve equivalence class.
2018-03-06 23:34:19 -08:00
Slava Pestov
cb1c8c8f16 AST: Simplify printExtendedTypeName() 2018-03-06 19:41:44 -08:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Xi Ge
9f39c8494d [SourceKitd] Avoid printing parent type directly on extended type. rdar:37965902 (#14892)
When printing parent type directly, we may print generic arguments and sugared
dictionary type.
2018-03-01 09:19:44 -08:00
Bartosz Polaczyk
c28302836b [SIL] Print full nested enum type name
ASTPrinter should print an extended type for enums,
(same as structs and classes) along with enum parents.
2018-02-18 16:14:42 +01:00
Huon Wilson
56cf07752d Merge pull request #14554 from huonw/doc-conditional-conformances
[IDE] Teach type checker about conditional conformance extensions.
2018-02-14 07:21:11 +11:00
Huon Wilson
cb60dbeee2 [IDE] Teach type checker about conditional conformance extensions.
Before conditional conformances, the archetypes in conformance
extensions (i.e. extension Foo: SomeProtocol) were equivalent to those
in the type decl, with the same protocol bounds and so on. The code for
printing "synthesized" members relied on this fact. This commit teaches
that code to deal with archetypes in the conditional conformance
extension when required.

Fixes rdar://problem/36553066 and SR-6930.
2018-02-13 17:37:15 +11:00
Ben Langmuir
72bde687e4 [sourcekit] Use the driver to parse command line arguments
Stop parsing frontend arguments directly and use the driver instead. The
most intersting part of this change is that it forces us to consider
whether our compiler invocation will have inputs or not.  We have
several kinds of requests that need to create a compiler instance, but
not parse any inputs (interface-generation, doc-info, and indexing when
operating on a module instead of source files).

Incidentally, add an error when trying to do doc-info on multiple source
files. This was already very broken (assertion failures and bogus source
locations), so add an error for it.

rdar://problem/17897287
2018-02-05 15:49:17 -08:00
Ben Langmuir
368e25ec05 [sourcekit] Fix tests that depend on accepting frontend arguments
These tests were relying on sourcekitd parsing as frontend instead of
using the driver.  Update them now to avoid churn when we fix command
line argument parsing in sourcekit.

The changes from clang-importer-sdk to clang-importer-sdk-nosource -I %t
are because clang-importer-sdk implies using -enable-source-import.
Rather than hack them up to use -Xfrontend, it is cleaner to just stop
using source import at all for these tests.  Incidentally, this improved
fidelity in a few places.  When using the generated swift modules we
also need to pass a target triple to sourcekit, which exposed some tests
that had mac-specific data.  This is a systemic issue for sourcekit
tests, but for now just make those few specific tests that we had
problems with run only on mac.
2018-02-05 10:09:03 -08:00
Ben Langmuir
9f3df20dbd [sourcekit] Change fallback module name to match driver
This will reduce test churn when we start using the driver to parse
arguments.  We don't really care what the module name is for these
fallback cases.
2018-02-02 10:26:58 -08:00
Xi Ge
98570550c3 [SourceKit] Report synthesized protocol conformances for DocSupport request. rdar://36882292 (#14248) 2018-01-30 13:32:50 -08:00
Jordan Rose
e63879dc48 [Mangling] Define "related entity" operators 'LA'...'LJ'
(and 'La'...'Lj')

Use this for the synthesized structs for error enums, as described in
the previous commit, instead of reusing the "private discriminator"
feature. I left some space in the APIs for "related entity kinds" that
are longer than a single character, but I don't actually expect to use
it any time soon. It's mostly just easier to deal with StringRef than
with a bare char.

Note that this doesn't perfectly round-trip to the old mangling; I had
it treat these nodes as private discriminators with a prefixed "$"
instead. We don't depend on that for anything, though.
2018-01-24 10:52:46 -08:00
Jordan Rose
9c1a22ad0f Mangle synthesized error structs as a variant of the imported enum
When importing a C enum with the ns_error_domain attribute, we
synthesize a struct containing an NSError object to represent errors
in that domain. That synthesized struct should have a mangled name
that ties it to the original C enum, if we want it to be stable, and
now it does.

Before: $SSC7MyErrorV (a normal struct, which is a lie)
After: $SSC11MyErrorCode13ns_error_enumLLV
  kind=Global
    kind=Structure
      kind=Module, text="__C_Synthesized"
      kind=PrivateDeclName
        kind=Identifier, text="ns_error_enum"
        kind=Identifier, text="MyErrorCode"

Using the "private discriminator" feature allows us to pack in extra
information about the declaration without changing the mangling
grammar, and without stepping on anything the importer is using.

More rdar://problem/24688918
2018-01-23 17:05:43 -08:00
Jordan Rose
59b5e2ec0d Mangle an anonymous C enum using its enclosing typedef, like C++ does
Without this, we would fall back to a Swift name even for C types that
we can expect to have stable names for linkage purposes.
2018-01-10 15:38:07 -08:00
Jordan Rose
38e2cfe1e2 Mangle imported declarations using their C names.
This makes them consistent no matter what shenanigans are pulled by
the importer, particularly NS_ENUM vs. NS_OPTIONS and NS_SWIFT_NAME.

The 'NSErrorDomain' API note /nearly/ works with this, but the
synthesized error struct is still mangled as a Swift declaration,
which means it's not rename-stable. See follow-up commits.

The main place where this still falls down is NS_STRING_ENUM: when
this is applied, a typedef is imported as a unique struct, but without
it it's just a typealias for the underlying type. There's also still a
problem with synthesized conformances, which have a module mangled
into the witness table symbol even though that symbol is linkonce_odr.

rdar://problem/31616162
2018-01-09 17:55:24 -08:00
Jordan Rose
18689fe223 [Mangling] Uniformly use "So" for imported decls.
...and repurpose "SC" for (C)lang-importer-synthesized decls, instead
of just decls that are C-like instead of ObjC-like. (See next commits.)
2018-01-09 17:55:23 -08:00
Pavel Yaskevich
533171debf [Mangling/ABI] NFC: Fix SourceKit tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Argyrios Kyrtzidis
9093dd7528 [test/SourceKit] Re-enable and update tests after recent stdlib changes
rdar://35799113
2017-12-05 10:23:14 -08:00
John Fairhurst
388fffcc35 [SourceKit] XML-escape swift declarations from clang modules 2017-12-04 12:48:20 -08:00
Ben Cohen
c481806339 XFAIL one more SourceKit unexpected difference test 2017-12-01 16:29:38 -08:00
Nathan Hawes
01e538951f [SourceKit][DocInfo] Avoid outputing identifier annotations for ranges already covered by parameter/argument annotations
Resolves rdar://problem/20799943
2017-11-16 18:25:03 -08:00
Nathan Hawes
7403e779ad [ASTWalker|Refactoring] Walk generic params and requirements in source order for subscript decls
Also handle requirements in non-trailing where clauses (for -swift-version 3)
Resolves rdar://problem/34859742
2017-11-16 16:02:12 -08:00
Nathan Hawes
351238a199 [ASTWalker/index] Walk into the trailing where clause on extension decls so we don't miss the type references there. 2017-10-27 19:27:10 -07:00
Pavel Yaskevich
8f26fb88d4 [Mangling] Improve handling of the variadic function parameters
Currently when function types like `(_: Int...) -> Void` are mangled
their names are going to include enclosing sugar BoundGenericType(Array),
which is not necessary and doesn’t play well with `AnyFunctionType::Param`
which strips the sugar away.

Resolves: rdar://problem/34941557
2017-10-17 00:16:12 -07:00
Doug Gregor
6e6b6b9837 [Mangler] Only mangle new requirements for constrained extensions.
Rather than mangling the complete generic signature of a constrained
extension, only mangle the requirements not already satisfied by the
nominal type. For example, given:

    extension Dictionary where Value: Equatable {
      // OLD: _T0s10DictionaryV2t3s8HashableRzs9EquatableR_r0_lE3baryyF
      // NEW: _T0s10DictionaryV2t3s9EquatableR_rlE3baryyF
      public func bar() { }
   }

In the existing mangling, we mangle the `Key: Hashable` requirement that’s
part of the generic signature. With this change, we only mangle the new
requirement (`Value: Equatable`).

This is a win for constrained extensions *except* in the case of a
constrained extension of a nominal type with a single, unconstrained
generic parameter:

    extension Array where Element: Equatable {
      // OLD: _T0Sa2t3s9EquatableRzlE3baryyF
      // NEW would be: _T0Sa2t3s9EquatableRzrlE3baryyF
      public func bar() { }
    }

Check explicily for this shortcut mangling and fall back to the old
path, so this change is a strict improvement.
2017-10-11 19:23:58 -07:00
Max Moiseev
0a69646df4 [test] Address the sourcekit test failures 2017-09-29 11:26:56 -07:00
Marcelo Fabri
09ede06f80 [ASTPrinter] Add trailing space after operator declaration (SR-3891) 2017-09-17 16:09:48 -03:00
Slava Pestov
696694b61d Update some IDE tests 2017-09-14 01:15:31 -07:00
John McCall
171d45d8c9 Move more of the signature validation of accessors into Sema.
Use this to remove the last bit of the hack to suppres noescape on setter
arguments.  Add a more comprehensive test of noescape's interaction with
accessors.
2017-09-13 01:11:00 -04:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Arnold Schwaighofer
f442dd93bd CompilerInvocation: If no optimization flag is set default to Onone
I noticed in a follow-up patch that if you just swiftc without passing Onone
these flags are not set and sometimes happen to default to right thing ... or
not; as can be seen by the test cases modified. For example, at Onone we are
supposed to include an extra swift module "SwiftOnoneSupport".
2017-08-04 11:49:16 -07:00
Jordan Rose
7efdfb4167 [ClangImporter] Fix macros defined in terms of other macros.
...which didn't do the right thing in the presence of ModuleMacro,
depending on the order the macros were referenced. Already covered by
test/ClangImporter/macros.swift, but it actually seems to improve the
behavior of some of the SourceKit tests as well.

Continuing rdar://problem/32199805, which is just "get macros working
with clang::ModuleMacro".
2017-07-26 15:42:31 -07:00
Jordan Rose
88556eec94 Avoid building conformance lookup tables when we don't have to.
- Deinitializers never get a custom Objective-C name.
- Classes and protocols are never bridged themselves; that only matters
  for structs and enums.

This avoids another circularity issue like the one in a8bc132565,
where the Clang importer ends up importing a class and hands it to the
type checker, which then asks about conformances. The conformance
lookup table goes to add the extension from the Swift module, except
that the Swift module is what asked for the import in the first place.

It's possible there's a more general solution here, but this
particular change is good even in the non-crashy cases, and definitely
safe for Swift 4.0. Even if the test case is even more idiosyncratic
than the last one.

The test case change for SourceKit is probably due to the first
category not triggering the import of the other two
categories. Changes in import order have been known to affect source
compatibility, though not frequently. However, categories are not
intended to be ordered in the first place. There's still more we can
do in this space, and implicitly depending on these calls /outside/ of
the importer to control category import order was quite brittle
anyway.

SR-5330 / rdar://problem/32677610
2017-07-05 11:23:27 -07:00
Doug Gregor
be5bc3fd07 [GSB] Eliminate two more uses of ArchetypeResolutionKind::AlwaysPartial.
We don't need to force the creation of potential archetypes when
finding anchors, because new potential archetypes will only be created
by this process in ill-formed generic signatures. Tolerate failure
whenever this happens (for now) and the failure paths will become dead
once AlwaysPartial is eliminated fully.
2017-06-28 06:23:52 -07:00
Robert Widmann
6509f78f13 tests: replace remaining 'mkdir -p' calls with %empty-directory(...)'
These changes were made manually.
2017-06-04 11:08:39 -07:00
Slava Pestov
9487a1e786 Update and un-XFAIL doc_clang_module test 2017-05-17 00:39:46 -07:00