Commit Graph

184 Commits

Author SHA1 Message Date
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
David Ungar
785117d909 Clarify name to be subjunctive. 2019-11-06 10:37:07 -08:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
David Ungar
4ab5c6b620 Better debugging code 2019-10-18 16:44:49 -07:00
Slava Pestov
a6b5824dac AST: Correctly set parent DeclContext of ParamDecls in EnumElementDecls
When an EnumElementDecl is parsed, we create the parameter list before
creating the EnumElementDecl itself, so we have to re-parent those
ParamDecls just like we do for functions and subscripts.
2019-10-08 18:39:00 -04:00
David Ungar
c25de6af75 Merge pull request #27221 from davidungar/A-9-17-astscope-off
[NFC, NameLookup, ASTScope] Bug fix for eager scope tree construction & better failure messages
2019-09-22 19:10:58 -07:00
David Ungar
a9a9069591 change compare-to-astScope-lookup to crosscheck-unqualified-lookup 2019-09-22 17:59:39 -07:00
David Ungar
87535dfd84 Silence a warning 2019-09-22 17:59:39 -07:00
David Ungar
b47bd97a3b De-experimentalify 2019-09-22 17:59:39 -07:00
David Ungar
7736009f92 Fix debug code 2019-09-22 17:59:39 -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
David Ungar
968c5a8282 Eager tree building for primaries 2019-09-13 17:22:50 -07:00