Commit Graph

146 Commits

Author SHA1 Message Date
Ellie Shin
89fb5ff3fc Merge branch 'main' into es-param 2021-11-08 17:55:25 -08:00
Ellie Shin
06683cda43 Add module alias lookup option enum
Pass the enum param to ASTContext::getRealModuleName
2021-11-08 17:51:27 -08:00
Robert Widmann
c23a617da2 [NFC] Clean Up Unused Fields in Unqualified Lookup
* Drop some unused fields
* const-qualify a consumption method that is logically const - though it
  isn't physically const given the mutating use in
  ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers
* Privatize some internal fields
2021-11-05 11:25:15 -07:00
Ellie Shin
66d64b610d Updates params to ASTContext::getRealModuleName 2021-10-29 01:52:33 -07:00
elsh
daf07c0306 Update getRealModuleName
Assert map is empty in setModuleAliases
Update doc comments
2021-10-28 23:43:16 -07:00
Ellie Shin
757e3b1d61 Update lib/AST/UnqualifiedLookup.cpp
Co-authored-by: Becca Royal-Gordon <beccadax@apple.com>
2021-10-28 23:03:05 -07:00
elsh
10a96dff57 Module Aliasing: do not allow module real names to appear in source files / only allow aliases
Resolves rdar://83592084
2021-10-28 02:36:59 -07:00
Holly Borla
d9951bed23 [Property Wrappers] Add a request to synthesize the local wrapped value
variable for a parameter with an attached property wrapper.
2021-02-25 18:35:13 -08:00
Doug Gregor
8c123e8505 [Concurrency] Hard-code support for importing @MainActor.
Our name lookup rules for the resolution of custom attributes don't
allow for them to find MainActor within the _Concurrency library.
Therefore, hardcode @MainActor to map to _Concurrency.MainActor.

While here, make sure we drop concurrency-specific attributes that
show up in Clang attributes when we aren't in concurrency mode.
2021-01-08 17:03:50 -08:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Arnold Schwaighofer
96a0d0e584 Rename various IncludeUsableFromInlineAndInlineable to IncludeUsableFromInline
`@inlinable` implies `@usableFromInline`.

NFC intended.
2020-10-14 07:57:25 -07:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Slava Pestov
fbb97b9e26 AST: Fix an assertion in UnqualifiedLookup to use CharSourceRanges 2020-10-07 12:33:58 -04:00
Slava Pestov
554e0f97e6 AST: Find local property wrappers in ASTScope::lookupLocalDecls()
Two fixes here:

- The ASTScopeDeclConsumerForLocalLookup needs to visit auxiliary variables
- preCheckExpression() should call ASTScope::lookupLocalDecls() even when
  parser lookup is enabled, since otherwise we won't be able to find
  auxiliary decls in the current DeclContext.
2020-10-02 14:40:11 -04:00
Slava Pestov
95c4a97507 Merge pull request #34135 from slavapestov/simulate-parser-lookup
Implement backward-compatible closure capture behavior with parser lookup disabled
2020-10-02 11:45:39 -04:00
Holly Borla
355fbb3a8b Merge pull request #34109 from hborla/local-property-wrappers
[Property Wrappers] Support local property wrappers
2020-10-01 22:45:41 -07:00
Slava Pestov
f738a57040 ASTScope: Remove DeclVisibilityKind parameter from AbstractASTScopeDeclConsumer::consume()
It wasn't used for anything, and it was always set based on whether
the declaration in question was a GenericTypeParamDecl, a ParamDecl,
or something else.
2020-10-01 23:50:16 -04:00
Slava Pestov
8168dda2bc AST: Remove dead code from ASTScopeDeclConsumerForUnqualifiedLookup::consume() 2020-10-01 23:50:16 -04:00
Slava Pestov
28388384f2 AST: UnqualifiedLookup only finds forward references to outer local bindings when IncludeOuterResults is set
The old behavior was that ASTScope would introduce all VarDecls
defined in a BraceStmt at the beginning of the BraceStmt.

I recently enabled the use of PatternEntryDeclScopes, which
introduce the binding at its actual source location instead of
at the beginning of the parent statement.

This patch now makes use of the new information by having
UnqualifiedLookupFlags::IncludeOuterResults toggle between
the two behaviors. When searching for outer results, we also
consider all VarDecls in a BraceStmt, not just those in scope.

This is implemented by giving AbstractASTScopeDeclConsumer a
new entry point, consumePossiblyNotInScope(). When looking up
into a BraceStmt, all VarDecls are passed in to this entry
point.

The default implementation does nothing, which means that
ASTScope::lookupSingleLocalDecl() now respects source locations
when searching for bindings, just like parse-time lookup.

However, Sema's preCheckExpression() pass, which sets
Flags::IgnoreOuterResults, will continue to find
forward-referenced VarDecls, just as it did with the old
context-based DeclContext lookup.
2020-10-01 23:46:26 -04:00
Holly Borla
9e373a2405 [Name Lookup] Remove property wrapper name lookup flags and generalize
unqualified lookup of auxiliary decl names.
2020-09-30 10:40:44 -07:00
Slava Pestov
c56ab07c77 ASTScope: Add finishLookupInBraceStmt parameter to ASTScope::lookupLocalDecls()
This will be used to implement re-declaration checking for local
declarations. Currently this is handled by parse-time lookup.

To make it work with ASTScope, we need to perform lookups that
look into the innermost local scope only; for example, this is
an invalid redeclaration:

do {
  let x = 321
  let x = 123
}

But the following is fine, even though both VarDecls are in the same
*DeclContext*:

do {
  let x = 321
  do {
    let x = 123
  }
}
2020-09-29 23:38:24 -04:00
Slava Pestov
dec9bf680e AST: Remove unused UnqualifiedLookupFactory::Consumer field 2020-09-29 23:38:24 -04:00
Slava Pestov
8920da22a6 Merge pull request #34104 from slavapestov/more-astscope-fixes
More ASTScope fixes in preparation for turning off parse-time lookup
2020-09-29 14:10:35 -04:00
Holly Borla
9b2cd5e3ff [NameLookup] Teach unqualified lookup to resolve backing property wrapper
and projected value references
2020-09-28 16:57:35 -07:00
Slava Pestov
bd7763df30 AST: Remove unused UnqualifiedLookupFactory::resultsSizeBeforeLocalsPass
This was read but never written to. I believe it was an artifact of the
pre-ASTScope lookup logic.
2020-09-28 17:50:53 -04:00
Slava Pestov
f5a03f54e1 ASTScope: Fix linker error when building without asserts 2020-09-28 17:47:09 -04:00
Slava Pestov
6b98f8f3b5 ASTScope: Add a new lookupSingleLocalDecl() entry point
This is used in a few places that used to expect parsed but
not yet type-checked code to contain DeclRefExprs that
reference local bindings.

Instead, we can call lookupSingleLocalDecl() with an
UnresolvedDeclRefExpr instead.
2020-09-25 17:59:20 -04:00
Slava Pestov
bbd79a2db2 ASTScope: unqualifiedLookup() entry point does not need the name
If we're searching for a declaration with a given name, the name
should be entirely encapsulated inside the DeclConsumer.

Otherwise, there might not be a specific name at all, if we're
performing code completion for example (once LookupVisibleDecls
starts to use ASTScope, anyway).
2020-09-25 02:40:13 -04:00
Robert Widmann
d93c6d8b12 Remove Cascading Computations from ASTScope 2020-09-21 10:42:33 -06:00
Robert Widmann
7bee5ffc0c Remove NLOptions::NL_Known* 2020-09-21 10:37:41 -06:00
Robert Widmann
ee35a4fe18 Remove NameLookupFlags::KnownPrivate 2020-09-21 10:37:41 -06:00
Slava Pestov
7cb809bf1d ASTScope: Remove old implementation of 'selfDC' computation 2020-09-18 16:11:06 -04:00
Slava Pestov
ed17c333e0 ASTScope: Compute 'selfDC' directly in ASTScopeDeclConsumerForUnqualifiedLookup
Instead of having ASTScope compute 'selfDC', the lookup
consumer can compute it on its own, by looking for
bindings named 'self'.
2020-09-18 15:05:48 -04:00
Slava Pestov
09bb3c0d30 ASTScope: Don't need to pass in a DeclContext
This was used to validate against the old lookup code, but should no
longer be needed.
2020-09-16 20:07:58 -04:00
Slava Pestov
83f49b35f2 AST: Remove old unqualified lookup implementation
Now that ASTScope is unconditionally enabled, we can remove the
old unqualified lookup implementation. Note that unqualified
lookup now either requires a source location, or must start
from a module-scope context. All existing usages should now
respect this invariant.
2020-09-06 15:53:24 -04:00
Slava Pestov
0310a701d9 AST: Remove EnableASTScope flag and force it to always be on 2020-09-04 16:15:36 -04:00
Robert Widmann
acbf927b0e [NFC] Delete ReferencedNameTracker 2020-05-21 18:54:14 -07:00
Slava Pestov
3ee2409890 SIL: Use ASTScope for SIL parsing 2020-05-08 00:31:23 -04:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Robert Widmann
94166024fa Dump all uses of the legacy referenced name tracker 2020-04-20 10:22:58 -07:00
Hamish Knight
5b99c2020f NFC: Re-organize NameBinding tests
The directory currently seems to have a mix of
tests for import resolution and name lookup.
Therefore split it into two directories;
ImportResolution and NameLookup.
2020-03-29 18:51:09 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Rintaro Ishizaki
ff2ccd485c [CodeCompletion] Workaround fast-completion issue in UnqualifiedLookup
In fast-completion, a function body can be replaced with another function
body parsed from a new buffer. In such cases, during typechecking the
expressions in the *new* function body, a source location range check in
UnqualifiedLookup didn't work well because they are not from the same
buffer.

This patch workaround it by skipping the source range checks and returns
'success' in such cases.

rdar://problem/58881999
2020-02-12 10:41:43 -08:00
Frederick Kellison-Linn
71697c37ca Allow implicit self in escaping closures when self usage is unlikely to cause cycle (#23934)
* WIP implementation

* Cleanup implementation

* Install backedge rather than storing array reference

* Add diagnostics

* Add missing parameter to ResultFinderForTypeContext constructor

* Fix tests for correct fix-it language

* Change to solution without backedge, change lookup behavior

* Improve diagnostics for weak captures and captures under different names

* Remove ghosts of implementations past

* Address review comments

* Reorder member variable initialization

* Fix typos

* Exclude value types from explicit self requirements

* Add tests

* Add implementation for AST lookup

* Add tests

* Begin addressing review comments

* Re-enable AST scope lookup

* Add fixme

* Pull fix-its into a separate function

* Remove capturedSelfContext tracking from type property initializers

* Add const specifiers to arguments

* Address review comments

* Fix string literals

* Refactor implicit self diagnostics

* Add comment

* Remove trailing whitespace

* Add tests for capture list across multiple lines

* Add additional test

* Fix typo

* Remove use of ?: to fix linux build

* Remove second use of ?:

* Rework logic for finding nested self contexts
2019-12-20 02:38:41 +00:00
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Hamish Knight
2853615880 Add type to package inputs to UnqualifiedLookupRequest
This allows us use an OptionSet parameter for
the request (as currently we can't directly use it
as a parameter due to not having an == definition
for it). It also allows us to regain default
arguments for the source loc and flag parameters.
2019-11-15 16:35:14 -08:00
Hamish Knight
acbf0b264c Remove NumUnqualifiedLookup counter
We now have an equivalent counter for
UnqualifiedLookupRequest.
2019-11-15 14:25:42 -08:00
Hamish Knight
e8c30ca1b7 Remove UnqualifiedLookup
Now that we have UnqualifiedLookupRequest, this
class no longer serves much of a purpose. Inline
its constructor logic into the request.
2019-11-15 14:25:42 -08:00
Hamish Knight
633de0241b Add UnqualifiedLookupRequest
This request performs raw unqualified lookup,
and will be used to replace the UnqualifiedLookup
type.
2019-11-15 14:25:42 -08:00