Commit Graph

109 Commits

Author SHA1 Message Date
fischertony
6f08216936 Sema: Support where clauses on contextually generic decls 2020-03-05 04:37:12 +03: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
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
David Ungar
87799339c7 Eagerly expand function bodies before type-checking them, which scrambles them. 2019-11-06 10:36:14 -08:00
David Ungar
f162a84e01 Factoring 2019-11-02 20:44:03 -07:00
David Ungar
3cd1d9a739 Fix boundary condition test in scope search. 2019-11-02 10:48:16 -07: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
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
6e7db41a7c Crash compilation for ASTScope lookup into an inactive clause 2019-10-16 14:20:00 -07:00
David Ungar
a9ab4aa8c2 Use SeparateCaching 2019-10-09 22:33:39 -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
b943a3987f Use separate bool to record expansion 2019-09-22 17:59:40 -07:00
David Ungar
9674643779 Comment out potential debugging code issue. 2019-09-22 17:59:40 -07:00
David Ungar
683310eb74 Ever expansion detection. WIP 2019-09-22 17:59:40 -07:00
David Ungar
80e7a1f8fc Remove debug code 2019-09-22 17:59:39 -07:00
David Ungar
603cc05289 WIP lazy whole scopes 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
e3f7760154 Add explanations to all asserts. 2019-09-17 16:30:25 -07:00
David Ungar
8ebba23b06 Add ASTScope_unreachable 2019-09-17 16:03:05 -07:00
David Ungar
3966d086a5 When ASTScope assertions fails, direct user to try disabling ASTScopes. 2019-09-17 15:56:33 -07:00
David Ungar
03a89c7c8a Reuse pointer 2019-09-14 13:41:16 -07:00
David Ungar
7992e1c6c4 Lots of cleanups, renamings, etc. 2019-08-26 16:55:18 -07:00
David Ungar
b02b4b00ef Cleanup and fixes, also 1st cut at lazy. 2019-08-13 17:48:06 -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
44c62485e6 Rm redundant computeSelfDCForParemt 2019-06-12 21:24:54 -07:00
David Ungar
3e958442fa Clean up 2019-06-12 12:00:37 -07:00
David Ungar
72b20967f3 Outer generics 2019-06-12 11:42:11 -07:00
David Ungar
2f2bbfb14c Better method scope lookup 2019-06-12 10:46:30 -07:00
David Ungar
b418588d88 Fix 2019-06-12 09:59:17 -07:00
David Ungar
4122438f86 Outline lookInGenericsAndSelfType 2019-06-12 08:11:27 -07:00
David Ungar
55323bbab8 Typos, etc. 2019-06-12 07:48:05 -07:00
David Ungar
9b40b3974b Rephrase comment 2019-06-12 07:40:21 -07:00
David Ungar
69f6b41a13 Use unique_ptr for Scope, getScope returns a reference 2019-06-12 07:29:00 -07:00
David Ungar
6a8d91f673 fmt 2019-06-10 13:18:58 -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
253f16b76d WIP 2019-06-08 09:34:16 -07:00
David Ungar
3abfa1f384 WIP 2019-06-08 09:08:49 -07:00
David Ungar
1e9bc8465b Minor cleaning 2019-06-05 16:09:47 -07:00
David Ungar
670eb61f8e Spell out GTX 2019-06-05 15:54:10 -07:00
David Ungar
73279c99fb Upto findLookupParentForUse 2019-06-05 09:04:38 -07:00
David Ungar
606ce7b8cb pattern fixes 2019-06-04 20:50:59 -07:00
David Ungar
94bd4a801a fmt 2019-06-04 18:11:35 -07:00
David Ungar
8ff4309580 WIP, unfmt 2019-06-04 17:14:32 -07:00
David Ungar
ad77af1b87 Catch top-level dependency for use under pattern.
var x = 3
_ = x
2019-06-03 21:13:25 -07:00
David Ungar
8e729aa75e Fix 2019-06-02 16:27:27 -07:00
David Ungar
5043d56889 Don’t ignore implicit statements. 2019-06-02 09:28:20 -07:00