Commit Graph

96 Commits

Author SHA1 Message Date
Ben Barham
ddddc667c8 Merge exported modules with the same public name in generated interface
If a module has the same `public-module-name` as the module being
generated and its import is exported, merge it into the same generated
interface.

Fix various always-imported modules from being printed while here and
update all the tests that checked for them.

Resolves rdar://137887712.
2025-05-02 10:59:15 -07:00
QuietMisdreavus
60ef958116 don't break a doc comment with a regular comment (#66136)
rdar://95307936
2023-05-30 08:44:02 -06:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Alex Hoppen
a7dcd4604e [SourceKit] Add an operator syntax kind
This will allow us to do semantic highlighting for operators in SourceKit-LSP.
2022-07-25 07:19:49 +02:00
Slava Pestov
9aaea55cf7 Sema: Simplify logic for building extension generic signature 2022-05-25 21:42:34 -04:00
Robert Widmann
d5c226d55f Propagate Qualified Type Printing in Ambiguous Situations In More Cases
Ultimately this is to support the disambiguation of protocol requirements when printing stubs. This allows us to disambiguate the case where two modules declare a nominal type, and when that type appears in a protocol requirement. In such a case, we now fully qualify the types involved.

Fixing this also appears to now be consistently printing module qualification in many more places, hence the updates to the IDE/SourceKit tests.

rdar://72830118
2022-01-25 14:03:11 -08:00
Rintaro Ishizaki
6e69a44c3d [ASTPrinter] Intorduce 'IntroducerKeyword' name kind
For more fine grained annoations. For now, it's handled as the same as
'Keyword' name kind.

Fix an issue where 'extension' wasn't marked as "keyword".

Also, move 'static' priting out of 'SkipIntroducerKeywords' guard
because 'static' is not an declaration introducer.
2021-07-29 12:50:24 -07:00
Alex Hoppen
9ba892c5af [ASTPrinter] Fix issue printing Self resolved to a generic type
When printing a type in type through `ASTPrinter::printTransformedTypeWithOptions`, we are removing any contextual types by mapping the type out of context. However, when substituting `Self` (or any other type member) with their concrete type from `CurrentType`, we might re-introduce contextual types.

To fix this, make sure that `CurrentType` is always an interface type that has all contextual types removed.

Fixes rdar://76021569
2021-04-12 10:39:09 +02:00
Anthony Latsis
4ce7a2d060 CodeCompletion: Annotate archetypes, generic parameters and dependent members 2020-10-27 14:39:52 +03:00
Nathan Hawes
e68ab1da8e [SourceKit/DocSupport] Don't synthesize extensions for inherited protocol conformances.
The Base class already includes them, so don't duplicate them in its
subclasses. Also stops us including members from extensions of the base class
itself.

Resolves rdar://problem/50960433
2020-07-21 11:53:06 -07:00
Nathan Hawes
9bcb54910e [AST] Prefer the 'macOS' spelling over 'OSX' when printing the platform kind.
This affects module interfaces, interface generation in sourcekitd, and
diagnostics. Also fixes a fixit that was assuming the 'OSX' spelling when
computing the source range to replace.

Resolves rdar://problem/64667960
2020-07-08 13:51:25 -07:00
Nathan Hawes
51bace649b [IDE][SourceKit/DocSupport] Add members of underscored protocol extensions in extensions of conforming types.
We would previously hide the protocol, its extensions and members, but the '_'
prefix really just means the protocol itself isn't intended for clients, rather
than its members.

This also adds support for 'fully_annotated_decl' entries in doc-info for
extensions to be consistent with every other decl, and removes the
'fully_annotated_generic_signature' entry we supplied as a fallback.

Also fixes several bugs with the synthesized extensions mechanism:
- The type sustitutions applied to the extension's requirements were computed
  using the extension itself as the decl context rather than the extension's
  nominal. The meant the extension's requirements themselves were assumed to
  hold when determining the substitutions, so equality constraints were always
  met. Because of this extension members were incorrectly merged with the base
  nominal or its extensions despite having additional constraints.
- Types within the requirements weren't being transformed when printed (e.g.
  'Self.Element' was printed rather than 'T') both in the interface output and
  in the requirements list. We were also incorrectly printing requirements
  that were already satisfied once the base type was subsituted in.
- If both the protocol extension and 'enabling' extension of the base nominal
  that added the protocol conformance had conditional requirements, we were
  only printing the protocol extension's requirements in the synthesized
  extension.
- The USR and annotated decl output embedded in the 'key.doc.full_as_xml'
  string for synthesized members were printed to match their original context, rather than
  the synthesized one.

Resolves rdar://problem/57121937
2020-06-02 15:38:34 -07:00
Nathan Hawes
a9aba54b42 [ASTPrinter][SourceKit] Print 'Any' as a keyword.
It's treated as a keyword by syntactic highlighting, but wasn't annotated as a
keyword by code completion, cursor info, or doc info.

Resolves rdar://problem/61114942
2020-04-28 13:35:06 -07:00
Nathan Hawes
af0509e106 [SourceKit/DocSupport] List generic requirements from contextual where clauses in doc info request
We previously didn't report the requirements in the where clause of 'boxes'
below because it didn't have generic parameters of its own:

public struct Box<Wrapped> {
    public func boxes() -> [Box<Wrapped.Element>] where Wrapped: Sequence { fatalError() }
}

Resolves rdar://problem/60658263
2020-04-06 11:43:14 -07:00
Xi Ge
1ca8e83aa3 Sourcekit/DocSupport: fix an assertion when generating documentation for extensions with attributes
When sanitizing the documentation comments for synthesized extensions,
we expect some text like "<declaration>extension". This isn't the case
when use-facing attributes are present.

rdar://50913510
2019-05-20 17:43:29 -07:00
Jordan Rose
42522ca4ae [ParseableInterface] Module-qualify protocol types too
Otherwise we can get in trouble when a local type is named, say,
'Sequence'.

Also contains test updates and a fix for Harlan's previous commit,
which actually affects all typealiases, not just those in the Builtin
module.
2019-03-29 08:52:22 -07:00
Xi Ge
1625bcfbba ASTPrinter: skip underscored keyword when printing for quick helps.
rdar://47777848
2019-03-13 17:53:51 -07:00
Xi Ge
c0598b9888 ASTPrinter: add an option to skip keywords with a prefix of underscore.
DocSupport will use set this flag to avoid printing __consuming, __owned, and
__shared.

rdar://47777848
2019-02-06 14:51:39 -08:00
Xi Ge
d620dfae5e Sourcekit/DocSupport: include fully annotated generic signatures for extension decls. rdar://40906297 2018-12-04 14:29:28 -08:00
Karoy Lorentey
811d3d710e [test] Update for RawRepresentable hashing changes 2018-11-22 17:16:07 +00:00
Ben Cohen
1c4ca23b7f Update SourceKit tests 2018-09-25 15:25:13 -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
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
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
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
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
Pavel Yaskevich
533171debf [Mangling/ABI] NFC: Fix SourceKit tests to reflect label mangling changes 2017-12-18 15:45:50 -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
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
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
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
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
Doug Gregor
9ff7ff73ef Fix up order-dependent test cases 2017-05-15 22:17:19 -07:00
Argyrios Kyrtzidis
9b9c84a708 Merge pull request #8972 from akyrtzi/index-external-symbol-namespacing
[index] Use a #pragma to apply module namespacing for exported ObjC header and match Swift namespaced USRs with the clang side
2017-04-24 21:13:12 -07:00
Argyrios Kyrtzidis
792d7c06a5 [test/SourceKit/DocSupport] Fix test for @objc USR change 2017-04-24 14:13:37 -07:00
Jordan Rose
129fd372d5 ASTPrinter: Qualify names when printing nested declarations.
That is, if you have this declaration:

    struct Outer {
      struct Inner {
        // ...
      }
    }

and you're just printing 'Inner', print it like this:

    struct Outer.Inner {
      // ...
    }

This comes up with the ClangImporter's import-as-member feature, and
is also about to affect how error code enums are imported as well.

This is currently only enabled in certain contexts: always when
printing interfaces, and for types (but not other members) when
printing declarations for Quick Help.

rdar://problem/28208090
2017-04-24 09:57:40 -07:00
Max Moiseev
8ca814cc8c Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-04-17 14:40:20 -07:00
Jordan Rose
2d84981fc2 Improve the mangling of typealiases.
- Allow them to use substitutions.
- Consistently use 'a' as a mangling operator.
- For generic typealiases, include the alias as context for any generic
  parameters.

Typealiases don't show up in symbol names, which always refer to
canonical types, but they are mangled for debug info and for USRs
(unique identifiers used by SourceKit), so it's good to get this
right.
2017-04-17 11:31:15 -07:00
Max Moiseev
835b8809d2 Merge branch 'master' into new-integer-protocols 2017-03-07 16:18:54 -08:00
Erik Eckstein
a04a29af4f mangling: efficient mangling of repeated substitutions
Instead of appending a character for each substitution, we now prefix the substitution with the repeat count, e.g.
AbbbbB -> A5B

The same is done for known-type substitutions, e.g.
SiSiSi -> S3i

This significantly shrinks mangled names which contain large lists of the same type, like
  func foo(_ x: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int))

rdar://problem/30707433
2017-03-05 17:41:43 -08:00