Commit Graph

101 Commits

Author SHA1 Message Date
Robert Widmann
50d9ab6694 [NFC] Drop some unnecesary interface type forcing 2019-09-24 10:12:16 -07:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Doug Gregor
d8b745db77 Add a request to lazily parse function bodies.
Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.
2019-08-31 16:23:08 -07:00
eeckstein
903eeb220b Revert "Add a request to lazily parse function bodies." 2019-08-31 12:29:01 +02:00
Doug Gregor
7ce3553c45 Merge pull request #26972 from DougGregor/request-function-body-parse
Add a request to lazily parse function bodies.
2019-08-30 21:57:15 -07:00
Doug Gregor
2ab05a6835 Add a request to lazily parse function bodies.
Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.
2019-08-30 16:48:23 -07:00
Slava Pestov
2256b1fcc2 AST: Introduce namelookup::getAllImports() to replace forAllVisibleModules() 2019-08-29 15:57:38 -04:00
Slava Pestov
37f308b8d3 AST: Change lookupInModule() to take a DeclContext instead of a module and extra imports
Also get rid of the 'accessPath' parameter.
2019-08-28 21:09:23 -04:00
Slava Pestov
b3d95d7968 AST: removeShadowedDecls() takes a DeclContext instead of a ModuleDecl
This allows shadowing rules to depend on the current SourceFile and
not just the current ModuleDecl. For now, this isn't actually
taken advantage of.
2019-08-28 15:41:03 -04:00
Slava Pestov
d13353f43a AST: Split off ModuleNameLookup.h from NameLookup.h 2019-08-23 23:35:25 -04:00
Nathan Hawes
ed54b94563 [IDE][Sema] Fix code completion unreachable/hang in TypeBase::getContextSubtitutions
There are paths from Code completion giving it an UnboundGenericType, which it
doesn't expect.

This patch:
1) Updates the code completion paths to not attempt substitution on
   UnboundGenericTypes
2) Updates getContextSubstitutions to assert and break out of the loop when
   given an unhandled type to avoid hanging release builds if a similar bug
   occurs in future.

Resolves rdar://problem/53959978
2019-08-22 17:47:15 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
David Zarzycki
f40c5cf046 NFC: Fix -Wdocumentation warning 2019-08-07 07:55:37 +01:00
Xi Ge
9065ae93f6 IDE+Evaluator: refactor the sema implementation of hasDynamicMemberLookupAttribute as a request and move the function wrapper to libIDE. NFC 2019-07-31 11:30:25 -07:00
Xi Ge
7658d63d62 IDE+Evaluator: refactor IDE type-checking utilities for subscript decl into requests
We used to have a function getRootAndResultTypeOfKeypathDynamicMember to return
both the root and result type of a subscript. This patch splits the function
into two functions returning root type and result type respectively. It also refactors
the implementation into the evaluator model.
2019-07-30 11:54:16 -07:00
Xi Ge
77ba3a21b4 IDE+Evaluator: refactor the implementation of two type checker utilities to evaluator requests. NFC
IDE functionality needs some internal type checking logics, e.g. checking
whether an extension is applicable to a concrete type. We used to directly
expose an header from sema called IDETypeChecking.h so that IDE functionalities
could invoke these APIs. The goal of the commit and following commits is to
expose evaluator requests instead of directly exposing function entry points from
sema so that we could later move IDETypeChecking.h to libIDE and implement these functions
by internally evaluating these requests.
2019-07-22 12:49:36 -07:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Rintaro Ishizaki
9f02fa7b06 [CodeCompletion] Map the result type for keypath member lookup
rdar://problem/50073837
2019-06-24 12:34:31 -07:00
Ben Langmuir
d65254c054 Add doc comments to the new lookupVisible* functions 2019-05-13 16:41:32 -07:00
Ben Langmuir
636d63e609 [code-completion] Handle nested keypath dynamic lookup correctly
If the root type of the KeyPath also has dynamic member lookup, we need
to look through it.

rdar://problem/50450037
2019-05-13 14:32:33 -07:00
Ben Langmuir
8f38e4b765 [code-completion] Avoid invalid member substitution for keypath dynamic lookup
When performing keypath dynamic member lookup, avoid substituting the
base type in override detection and completion, as the base type of the
lookup is not the base type of the member. For now, we just avoid the
substitution entirely to fix potential crashes; in a future commit we
will change to using the subscript return type and substituting with the
base type of the subscript instead of the base type of the lookup.

rdar://50449788
2019-05-06 10:02:39 -07:00
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