Commit Graph

119 Commits

Author SHA1 Message Date
Anthony Latsis
39649161d0 Gardening: See to some missing newline warnings 2021-02-12 17:00:47 +03:00
Slava Pestov
996100cfd1 ASTScope: Remove old SourceRange machinery 2020-10-07 12:33:58 -04:00
Slava Pestov
2e67c135fd ASTScope: Rework ConditionalClauseScopes
The top-level scope for a conditional clause with a pattern is now
ConditionalClausePatternUseScope, which introduces the pattern's
bindings.

Since the patterns are not visible in their own initializer, a new
ConditionalClauseInitializerScope is used for the initializer.
While it is nested inside of the ConditionalClausePatternUseScope,
it's lookup parent skips one level, giving us the desired behavior.
2020-10-07 12:33:29 -04:00
Slava Pestov
f8fb071f0f ASTScope: Remove ASTScopeImpl::getDeclContext() 2020-09-25 02:40:13 -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
Slava Pestov
32957259e8 ASTScope: Remove VarDeclScope 2020-09-23 13:09:01 -04:00
Slava Pestov
fd53040932 ASTScope: Refactor DeclAttribute scopes
DifferentiableAttr, SpecializeAttr and CustomAttr create scopes
because lookups can be performed from inside them. Previously
we would sort DifferentiableAttr and SpecializeAttr by source
order, but we consider that a declaration may also have more
than one _kind_ of attribute requiring special handling.

The case where this comes up is properties that have both a
DifferentiableAttr and CustomAttr. This fixes test failures in
AutoDiff tests with subsequent commits in this PR.
2020-09-23 13:09:00 -04:00
Slava Pestov
b7bd4fb8b3 ASTScope: Remove 'history' vector 2020-09-22 13:42:48 -04:00
Robert Widmann
d93c6d8b12 Remove Cascading Computations from ASTScope 2020-09-21 10:42:33 -06:00
Slava Pestov
9b851bf8cb ASTScope: Collapse PureFunctionBodyScope and MethodBodyScope
This centralizes some invariants around the 'self' parameter.
While all ConstructorDecls and DestructorDecls have a 'self',
even if they're invalid because they're not nested inside a type,
we don't want to consider this as the base 'self' for lookups.

Eg, consider this invalid code:

class C {
  func f() {
    init() {
      x
    }
  }
}

The base for the lookup should be f.self, not f.init.self.
2020-09-18 15:05:48 -04:00
Slava Pestov
3801d16d6f ASTScope: Simplify representation of closures
Let's use a ClosureParametersScope for all closures, even those
without an 'in' keyword. This eliminates the need for the
ClosureBodyScope and WholeClosureScope.

Also, let's move the lookup of capture list bindings from
CaptureParametersScope to CaptureListScope. This eliminates the
need for CaptureParametersScope to store a reference to the
capture list, which allows us to remove the AbstractClosureScope
base class entirely.
2020-09-17 14:46:47 -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
d260fbb9b1 ASTScope: More accurate modeling of 'case' statements
In a code snippet like the following,

  static func ==(a: Foo, b: Foo) -> Bool {
    switch (a, b) {
    case (.x(let aa), .x(let bb)) where condition(aa, bb),
         (.y(let aa), .y(let bb)) where condition(aa, bb):
      return aa == bb
    default:
      return false
    }
  }

The CaseStmt defines two patterns, both of which bind
'aa' and 'bb'. The first 'aa'/'bb' are in scope inside the
first 'where' clause, and the second 'aa'/'bb' are in scope
inside the second 'where' clause.

Furthermore, the parser creates a "fake" VarDecl for
'aa' and 'bb' to represent the phi node merging the two
values along the two control flow paths; these are in scope
inside the body.

Model this situation by introducing a new CaseLabelItemScope
for the 'where' clauses, and a CaseStmtBodyScope for the
body.
2020-09-16 00:21:13 -04:00
Doug Gregor
827ec9d28e [ASTScope] Use ASTScope to find fallthrough source/dest cases.
Rather than depending on the tracking of state in switch cases to
remember the case statements that are the source and destination for a
`fallthrough` statement, compute them using ASTScope to find the
nearest enclosing case (the source) and then find the next case in the
same `switch` statement (the destination).
2020-08-02 10:29:42 -07:00
Doug Gregor
0d90adf1b5 [ASTScope] Implement lookup for visible labeled statements.
Use the scope map to implement lookup for the labeled statements that
are visible from a given source location, which is a lexical property
that is currently handled with stateful tracking in the type checker.

For now, merely assert that the results of this approach are identical
to the state tracked in the statement type checker.
2020-07-30 23:55:10 -07:00
Doug Gregor
6c959af579 [ASTScope] Model "do" statements in the scope map 2020-07-30 22:18:27 -07:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00
Dan Zheng
6c29939f59 [AutoDiff upstream] Add @differentiable ASTScope support. (#29171)
`@differentiable` attributes may contain `where` clauses referencing generic
parameters from some generic context, just like `@_specialize` attributes.

Without special ASTScope support for `@differentiable` attributes,
ASTScopeLookup.cpp logic tries to resolve the generic parameter `DeclName`s in
`where` clauses based on source location alone
(`ASTScopeImpl::findChildContaining`) and fails.

The fix is to add a special `DifferentiableAttributeScope`, mimicking
`SpecializeAttributeScope`. Every `@differentiable` attribute has its own scope,
derived from the declaration on which it is declared. Unlike `@_specialize`,
`@differentiable` may also be declared on `AbstractStorageDecl` declarations
(subscripts and variables).

Upstreams https://github.com/apple/swift/pull/27451.

Progress towards TF-828: upstream `@differentiable` attribute type-checking.
2020-01-13 17:48:44 -08:00
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Robert Widmann
56b6e53dae Remove raw references to PatternBindingEntry APIs
Switch most callers to explicit indices.  The exceptions lie in things that needs to manipulate the parsed output directly including the Parser and components of the ASTScope.  These are included as friend class exceptions.
2019-10-17 13:31:14 -07: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
e59196cb62 Remove too-restrictive assertion 2019-09-22 17:59:40 -07:00
David Ungar
10583f89c6 Ensure that reexpansion does not lose scopes. 2019-09-22 17:59:40 -07:00
David Ungar
c808eb5a27 Don't try to expand ASTSourceFileScope when eagerly building. 2019-09-22 17:59:40 -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
3966d086a5 When ASTScope assertions fails, direct user to try disabling ASTScopes. 2019-09-17 15:56:33 -07:00
Sasha Krassovsky
1e414f7fb6 Fix warnings in AST 2019-09-13 09:57:48 -07:00
David Ungar
7992e1c6c4 Lots of cleanups, renamings, etc. 2019-08-26 16:55:18 -07:00
David Ungar
f64033a2d2 Manual rebase with master 2019-08-06 22:13:20 -07:00
David Ungar
3a3145c0f4 Alternate SelfDC computation, fixes, and cleanups.
ASTScopeLookup by default
Create empty fn bodies for IDE tests.
Include initializer source range for property wrappers.
Add -disable-astscope-lookup
2019-06-23 09:17:09 -07:00
David Ungar
455b344397 fmt 2019-06-10 15:38:01 -07:00
David Ungar
f203509250 fixes, unfmted, rm startLocAccordingToCondition 2019-06-10 14:03:34 -07:00
David Ungar
17bb03112e new cond use scheme 2019-06-10 13:18:18 -07:00
David Ungar
7d1f024e07 WIP unfmt 2019-06-10 12:10:21 -07:00
David Ungar
a724ff1446 undo lastAdopter transfer and rename, fix use expansion, rm depth 2019-06-09 09:57:32 -07:00
David Ungar
3abfa1f384 WIP 2019-06-08 09:08:49 -07:00
David Ungar
670eb61f8e Spell out GTX 2019-06-05 15:54:10 -07:00
David Ungar
05d38e0c53 Source range optimization 2019-06-05 14:15:47 -07:00
David Ungar
dd5d4ab492 Rm unused 2019-06-05 08:33:03 -07:00
David Ungar
1c0da7511c Renaming 2019-06-05 08:31:00 -07:00
David Ungar
23bddf12b4 Format 2019-05-31 21:03:05 -07:00
David Ungar
005e259247 compiles, unfmt 2019-05-31 21:02:19 -07:00
David Ungar
e6012a4809 fixes 2019-05-31 13:56:29 -07:00
David Ungar
2e7756c5c9 WP Redoing 2019-05-30 21:59:07 -07:00
David Ungar
10affe2b3b Cosmetic fixes. 2019-05-28 15:46:32 -07:00
David Ungar
3f820c374e Some review tweaks. 2019-05-28 11:12:12 -07:00
David Ungar
663760e3b7 ASTOOScope ontology 2019-05-28 10:48:22 -07:00
Slava Pestov
18dc8d4bd1 AST: Fix ASTScope lookup for invalid extensions
If there are no braces, the start and end location of the range is
the same token, so don't create a TypeOrExtensionBody scope at all.

NFC for now, but this problem causes some tests to fail once we
enable cycle diagnostics.
2019-04-22 22:22:23 -04:00