Commit Graph

222 Commits

Author SHA1 Message Date
Pavel Yaskevich
b7860ea055 [TypeChecker] Split for-in sequence into parsed and type-checked versions 2022-05-30 23:17:41 -07:00
Josh Soref
81d3ad76ac Spelling ast (#42463)
* spelling: accessor

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: accommodates

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: argument

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: associated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: belongs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: bookkeeping

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: building

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clonable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: closure

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: concatenated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conformance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: context

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: correspondence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declarations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declared

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: defining

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: delayed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependency

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deployed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: descendants

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnose

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: equitable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: evaluation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: exclusivity

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expressed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: for

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: foreign

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: function

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: identifier

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: implicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: indices

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: information

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interchangeable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interface

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: introduced

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: invalid

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: kind-in

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: least

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: library

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: location

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: namespace

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonexistent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: not

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: number

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: obtains

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: opaque

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overridden

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: precede

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preceding

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: property

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: protocol

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: qualified

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: recognized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: recursively

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: references

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: relaxing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: represented

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: request

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requirement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requirements

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: retrieve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: returned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfy

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: scanner

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: siblings

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplified

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: something

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: source

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specializations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specially

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: statement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: stripped

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: structure

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: substitution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transform

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transformed

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transitively

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transparent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: typecheck

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unknown

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unlabeled

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unqualified

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: whether

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: with

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: scanner

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 12:57:16 -07:00
Doug Gregor
55067ba028 Support named opaque result types for properties.
Add lookup scopes for the generic parameters of a named opaque result
type and clean up the code that finds the opaque substitutions.
2022-01-04 21:14:39 -08:00
Doug Gregor
ed79bab966 Implement name lookup into named opaque result types of subscripts 2022-01-04 21:14:04 -08:00
Doug Gregor
791c9c7d13 Implement most of the semantic analysis for named opaque result types.
Address small gaps in several places to make named opaque result types
partially work:

* Augment name lookup to look into the generic parameters when inside the
result type, which is used both to create structure and add requirements
via a `where` clause.
* Resolve opaque generic type parameter references to
OpaqueTypeArchetypeType instances, as we do for the "some" types
* Customize some opaque-type-specific diagnostics and type printing to
refer to the opaque generic parameter names specifically
* Fix some minor issues with the constraint system not finding
already-opened opaque generic type parameters and with the handling of
the opaque result type candidate set.

The major limitation on opaque types, where we cannot add requirements
that aren't strictly protocol or superclass requirements on the
generic parameters, remains. Until then, named opaque result types are
no more expressive than structural opaque result types.
2022-01-04 21:14:04 -08:00
Hamish Knight
01a082a058 [AST] Adopt ArgumentList
Switch out the representation of argument lists
in various AST nodes with ArgumentList.
2021-09-01 18:40:23 +01:00
Becca Royal-Gordon
59bb325e4b [NFC] Factor out ASTContext operator news
Many, many, many types in the Swift compiler are intended to only be allocated in the ASTContext. We have previously implemented this by writing several `operator new` and `operator delete` implementations into these types. Factor those out into a new base class instead.
2021-08-19 11:19:52 -07:00
Robert Widmann
d52b33d409 Special-case Pattern Binding Decls Created by LLDB
When LLDB wraps a user-defined expression in the REPL, it takes something like this
```
<expr>
```

and turns it into (very very abstractly)

```
var result
do {
  result = <expr>
}
print(result)
```

In the process, it creates an implicit pattern binding and an implicit do block. Of these, only the implicit do is considered by ASTScope lookup to be relevant. This presents a problem when <expr> is or contains a closure, as the parameters of that closure are defined within a scope that will never be expanded. Thus,

```
> [42].map { x in x } // <- cannot find 'x' in scope
```

This patch provides the Swift half of the fix wherein we privilege pattern bindings created by the debugger and look through them to the underlying user expression when performing ASTScope expansion.

rdar://78256873
2021-06-01 22:25:17 -07:00
Holly Borla
97ecb9435f [ASTScope] Always skip implicit attributes.
ASTScope only cares about attributes when lookup can be done inside of the
attribute, which isn't the case for implicit attributes because they're
typically built fully type-checked. This also avoids a crash when an
implicit attribute does not have a source range.
2021-04-06 16:38:46 -07:00
zoecarver
a5c7ab14c4 [nfc] Add comment describing when there may not be a parent source file.
Add a comment explaining that C++ function wont have an attached parent
source file. Refs #35311.
2021-01-11 20:54:34 -08:00
zoecarver
6bc2696e24 [cxx-interop] Inline constexpr vars.
If a static variable can be evaluated at compile time, create an
accessor using that value. This means static variables will always be
inlined and removed.

Note: currently this only works with numeric types.
2021-01-08 14:22:25 -08:00
Slava Pestov
b1f9c10d07 ASTScope: Small optimization to ASTScopeImpl memory layout
Combine the wasExpanded flag with the parent pointer, and remove
the haveAddedCleanup flag since it's no longer necessary now that
"re-expansion" is gone.
2020-12-18 15:43:33 -05:00
Slava Pestov
0fa84c14a0 ASTScope: Remove the ExpandASTScopeRequest
This doesn't really fit the request evaluator model since the
result of evaluating the request is the new insertion point,
but we don't have a way to get the insertion point of an
already-expanded scope.

Instead, let's change the callers of the now-removed
expandAndBeCurrentDetectingRecursion() to instead call
expandAndBeCurrent(), while checking first if the scope was
already expanded.

Also, set the expanded flag before calling expandSpecifically()
from inside expandAndBeCurrent(), to ensure that re-entrant
calls to expandAndBeCurrent() are flagged by the existing
assertion there.

Finally, replace a couple of existing counters, and the
now-gone request counter with a single ASTScopeExpansions
counter to track expansions.
2020-12-18 15:43:33 -05:00
Slava Pestov
6599bef24a ASTScope: Fix assertion with pattern bindings that don't introduce any variables
We would get confused if we saw a PatternBindingDecl where
one entry introduced a binding, and the other did not.

Thanks to @DougGregor for the test case!
2020-11-04 03:12:38 -05:00
Slava Pestov
b13ce50448 Merge pull request #34232 from slavapestov/misc-astscope-cleanups
One last round of ASTScope cleanups
2020-10-10 00:06:11 -04:00
Slava Pestov
ef26ecfb13 ASTScope: Allocate list of local bindings for BraceStmt in the ASTContext
Scopes need to register cleanups for non-trivial ivars in the ASTContext.
Instead of doing that here, let's just change the SmallVectors into
ArrayRefs.

Fixes <rdar://problem/69908937>.
2020-10-08 19:05:21 -04:00
Slava Pestov
885f6ebba3 ASTScope: Rename addChildrenForAllLocalizableAccessorsInSourceOrder() 2020-10-08 16:08:10 -04:00
Slava Pestov
ea9f84f66e ASTScope: Remove addSiblingsToScopeTree() 2020-10-08 16:08:10 -04:00
Slava Pestov
89ea51e90c ASTScope: Remove isLocalizable() 2020-10-08 16:08:10 -04:00
Slava Pestov
c5e1388245 ASTScope: Remove cull() 2020-10-08 16:08:09 -04:00
Slava Pestov
14620a34db ASTScope: Remove source range sorting 2020-10-07 23:28:29 -04:00
Slava Pestov
0c11fad5bd ASTScope: Don't silently drop duplicate AST nodes
Instead, let's rely on the existing source range assertions.
They will fire if we add two nodes with overlapping or
equal source ranges.
2020-10-07 23:28:29 -04:00
Slava Pestov
996100cfd1 ASTScope: Remove old SourceRange machinery 2020-10-07 12:33:58 -04:00
Slava Pestov
771fd6e9d1 ASTScope: Redo assertions to look at CharSourceRanges 2020-10-07 12:33:58 -04:00
Slava Pestov
b8cccb1ef8 ASTScope: Fix SourceFileScope source range
A SourceFile might contain TopLevelCodeDecls with guard statements,
which introduce names until the end of the file, so plumb that
through.
2020-10-07 12:33:30 -04:00
Slava Pestov
dac68ca047 ASTScope: Fix TopLevelCodeScope source range
Top-level code can contain guard statements which introduce
bindings until the end of the parent scope, so plumb that
through.
2020-10-07 12:33:29 -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
4f1ab9d8e5 ASTScope: Directly calculate end location of GuardStmtScope and PatternEntryDeclScope
Today, the reported source range of a GuardStmtScope is just that of
the statement itself, ending after the 'else' block. Similarly, a
PatternEntryDeclScope ends immediately after the initializer
expression.

Since these scopes introduce names until the end of the parent
BraceStmt (meaning they change the insertion point), we were
relying on the addition of child scopes to extend the source
range.

While we still need the hack for extending source ranges to deal
with string interpolation, at least in the other cases we can
get rid of it.

Note that this fixes a bug where a GuardStmtScope would end
before an inactive '#if' block if the inactive '#if' block was
the last element of a BraceStmt.
2020-10-02 23:49:59 -04:00
Slava Pestov
8b2cf55b70 ASTScope: Push isLocalBinding down from AbstractPatternEntryScope to PatternEntryDeclScope 2020-10-02 22:12:39 -04:00
Slava Pestov
4648587326 ASTScope: Move sortBySourceRange() and cull() calls out of addSiblingsToScopeTree() 2020-10-02 22:12:39 -04:00
Slava Pestov
3ec4ced57d ASTScope: Don't handle top-level bindings in a SourceFile for now 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
Slava Pestov
445d747622 AST: Move GenericParamList and friends to GenericParamList.{h,cpp} 2020-09-29 19:51:03 -04:00
Slava Pestov
49e371c563 ASTScope: Remove crossCheckWithAST() 2020-09-25 02:40:13 -04:00
Slava Pestov
5461508cd7 ASTScope: Remove isATypeDeclScope() 2020-09-23 22:37:00 -04:00
Slava Pestov
c5edc4574d ASTScope: PatternEntryDeclScope changes the insertion point for local bindings
This gives us the desired behavior, where local bindings are in
scope after their definition.

Note that BraceStmt still introduces all bindings at the beginning,
but now we change BraceStmt to only introduce local functions and
types, allowing us to disable parse-time lookup.
2020-09-23 22:37:00 -04:00
Slava Pestov
7c43e1010f ASTScope: Remove getEnclosingAbstractStorageDecl() 2020-09-23 13:09:01 -04:00
Slava Pestov
32957259e8 ASTScope: Remove VarDeclScope 2020-09-23 13:09:01 -04:00
Slava Pestov
de08e25ddf ASTScope: Remove AbstractPatternEntryScope::isLastEntry() 2020-09-23 13:09:00 -04:00
Slava Pestov
9119f736ed ASTScope: PatternEntryInitializerScope does not change the insertion point 2020-09-23 13:09:00 -04:00
Slava Pestov
f1d2db5eb4 ASTScope: ParameterListScope does not change the insertion point 2020-09-23 13:09:00 -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
87593fc0be ASTScope: Fold AbstractFunctionBodyScope into FunctionBodyScope 2020-09-23 13:09:00 -04:00
Slava Pestov
62764bb9ef ASTScope: Assert that we don't re-expand 2020-09-23 01:26:06 -04:00
Slava Pestov
eedcc6da0e ASTScope: Remove re-expansion mechanism 2020-09-23 01:26:06 -04:00
Slava Pestov
2e5e94ff51 ASTScope: SourceFile scopes are always current 2020-09-23 01:26:06 -04:00
Slava Pestov
b670453bd8 ASTScope: PatternBindingEntry scopes are always current 2020-09-23 01:26:06 -04:00
Slava Pestov
d3d1ceec58 ASTScope: AbstractFunctionBodyScope scopes are always current 2020-09-23 01:26:06 -04:00
Slava Pestov
8f586d011c ASTScope: TopLevelCodeDecl scopes are always current 2020-09-23 01:26:06 -04:00
Slava Pestov
d664f5d905 ASTScope: IterableDeclContext bodies are always current 2020-09-23 01:26:06 -04:00