Commit Graph

27 Commits

Author SHA1 Message Date
Ben Langmuir
34da079aa6 Pass DynamicLookupInfo through VisibleDeclConsumers NFC
This commit adds a new type DynamicLookupInfo that provides information
about how a dynamic member lookup found a particular Decl. This is
needed to correctly handle KeyPath dynamic member lookups, but for now
just plumb it through everywhere.
2019-05-06 10:02:39 -07:00
Rintaro Ishizaki
6e0b8c2b67 [CodeCompletion] Completion support for static subscript
rdar://problem/49131687
2019-04-19 21:36:17 -07:00
Joe Groff
a8c2b50bd8 Merge pull request #22072 from jckarter/opaque-type-runtime
Opaque types with resilience
2019-04-18 14:52:31 -07:00
Argyrios Kyrtzidis
86e4467c52 Merge pull request #24072 from benlangmuir/kpdml-ide
Code-completion, indexing, cursor-info, etc. for KeyPath dynamic member lookup
2019-04-17 16:12:58 -07:00
Joe Groff
71912bbfd6 AST: Represent OpaqueTypeDecls.
To represent the abstracted interface of an opaque type, we need a generic signature that refines
the outer context generic signature with an additional generic parameter representing the underlying
type and its exposed constraints. Opaque types also need to be keyed by their originating decl, so
that we can treat values of the same opaque type as the same. When we check a FuncDecl with an
opaque type specified as its return type, create an OpaqueTypeDecl and associate it with the
originating decl. (A representation for *types* derived from the opaque decl will come next.)
2019-04-17 14:43:32 -07:00
Ben Langmuir
ae4827a437 [code-completion] Avoid name copy for non dynamic member types
Per review feedback. Also add some test cases that should fail dynamic
member lookup.
2019-04-17 09:50:24 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -04:00
Ben Langmuir
8d4447c1d7 [code-completion] Add completion for keypath dynamic member lookup
Looks into the root type of the keypath to find additional members. This
does not currently map the type of the completion to the subscript's
return type.

rdar://49029126
2019-04-16 15:37:32 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Rintaro Ishizaki
232e4a459c Merge pull request #23332 from rintaro/ide-completion-conformance-rdar36594731
[AST] Don't return decls from unsatisfied conformance
2019-03-25 16:30:22 -07:00
Rintaro Ishizaki
c01799cbcf [AST] Prefer available member in lookupVisibleDecls()
'init?()' and 'init()' are considerd conflicting. But user can declare
both if only one of them is available.

rdar://problem/47408946
2019-03-18 16:08:21 -07:00
Rintaro Ishizaki
dcb1db26bb [AST] Don't return decls from unsatisfied conformance
When a type conditionally conforms to a protocol, it used to provide
symbols from extension to that protocol.
e.g.:

  protocol P {}
  extension P {
    func foo() {}
  }

  struct S<T> {}
  extension S: P where T == Int {}

  func test(val: S<String>) {
    val.#^COMPLETE^#
  }

This should not provide `foo()` method.

rdar://problem/36594731
2019-03-15 15:52:07 -07:00
Rintaro Ishizaki
b006c7c9b8 [AST] Don't return inapplicable decls in lookupVisibleDecls
rdar://problem/45340583 / https://bugs.swift.org/browse/SR-9027
rdar://problem/36594731
2019-03-14 12:57:37 -07:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Pavel Yaskevich
5426e0df9e [AST] Decl::is*AccessibleFrom methods should respect access control flag
Otherwise integrated REPL and other tools like LLDB would produce
incorrect results or crash.

Resolves: rdar://problem/30933988
2019-01-11 17:30:10 -08:00
Slava Pestov
033321fc32 LookupVisibleDecls: Remove unnecessary resolveExtension() call 2019-01-08 22:58:12 -05:00
Slava Pestov
46dd33aa54 LookupVisibleDecls: Remove an unused variable 2019-01-08 16:51:20 -05:00
Slava Pestov
f7e39447a7 LookupVisibleDecls: Find generic parameters in methods inside extensions
The logic here had diverged from UnqualifiedLookup. One day we'll merge
the two, for now clean it up a bit to match.

Note that all generic parameters now have 'Reason' reported as 'Local'.
I don't believe this really matters.

Fixes <rdar://problem/20530021>.
2019-01-08 16:51:20 -05:00
Slava Pestov
146f1a5ab6 LookupVisibleDecls: Fix duplicate completion results when inheritance is used with protocol conformance
Consider this setup:

protocol Proto {
  func foo() {}
}

class Base : Proto {
  func foo() {}
}

class Derived : Base {
  ...
}

When completing members of a Derived instance, we find both the protocol's
foo() and the base class's foo(). These have the following types:

- Proto.foo: <Self : Proto> (Self) -> () -> ()
- Base.foo: (Base) -> () -> ()

If we simply substitute the base type (Derived) into the type of the protocol
member, we get (Derived) -> () -> (), which is different than the type of
Base.foo, so we get both declarations in the completion list.

Instead, use the 'Self' type for the specific class of the conformance,
which in this case is 'Base' even if we're looking at members of 'Derived'.

Fixes <rdar://problem/21161476>, <https://bugs.swift.org/browse/SR-1181>.
2019-01-08 16:51:20 -05:00
Slava Pestov
3c0206d72e LookupVisibleDecls: Remove RestateFilteringConsumer
It's no longer needed after the previous set of changes, and removing it
fixes a crash.

Fixes <rdar://problem/46853611>.
2019-01-08 00:14:52 -05:00
Slava Pestov
6fd25fd521 LookupVisibleDecls: Process associated types in OverrideFilteringConsumer too 2019-01-08 00:14:52 -05:00
Slava Pestov
7d33177b84 LookupVisibleDecls: Don't use getReasonForSuper() for members of protocols and superclass constraints on an archetype
Semantically, these are not superclass/refined-protocol members.
If I have a generic parameter <T : P & Q>, then when looking at
a value of type T, members of P and Q are at the same "level" as
if I had a value of type (P & Q).
2019-01-08 00:14:52 -05:00
Slava Pestov
9ab18f6595 LookupVisibleDecls: Also substitute when the base type is an archetype 2019-01-08 00:14:52 -05:00
Slava Pestov
e563296447 LookupVisibleDecls: Use TypeBase::getMetatypeInstanceType() 2019-01-08 00:14:52 -05:00
Slava Pestov
0e458900b1 Sema: Remove hack introduced by 31245556
It looks like Type::subst() was subsequently fixed for GenericFunctionTypes
in 06d16795 so we can remove this hack.
2019-01-08 00:14:52 -05:00
Argyrios Kyrtzidis
75ab0a5f36 [AST] Break dependency cycle between swiftAST and swiftSema
AST/LookupVisibleDecls.cpp has a dependency on swiftSema by having doGlobalExtensionLookup call into swift::isExtensionApplied,
and doGlobalExtensionLookup is ultimately used by the other global functions in that file.
Break the cycle by moving the file into the swiftSema library.
2018-12-06 22:52:38 -08:00