Commit Graph

603 Commits

Author SHA1 Message Date
Ravi Kandhadai
4264b39b23 Merge pull request #26969 from ravikandhadai/oslog-user-model
[Sema Diagnostics] Add Miscellaneous Sema diagnostics to enforce that the new os log APIs and atomics are passed constants for certain arguments
2020-04-07 13:23:10 -07:00
Ravi Kandhadai
b57a1d7c0e [Sema] Add miscellaneous sema diagnostics to check that the new os log
APIs and atomic operations are passed compile-time constants for
certain arguments.
2020-04-06 18:41:13 -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
Slava Pestov
319a026a9a Sema: Always compute captures when we type check a function body 2020-04-03 18:14:36 -04:00
Slava Pestov
2c2d087242 Sema: More accurate VarDeclUsageChecker analysis with local functions
We used to take all the captures of a local function and treat them all
as read and write usages of vars from an outer scope. Instead, let's
refactor the analysis to walk into local functions.
2020-04-03 18:07:08 -04:00
Slava Pestov
93f0faf109 Sema: Fix false-positive var => let warning in VarUsageDeclChecker
Fixes <rdar://problem/60563962>.
2020-04-03 17:27:43 -04:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Pavel Yaskevich
16c1f50eda [ConstraintSystem] Diagnose incorrect use of _ during constraint generation
`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
2020-03-24 16:51:44 -07:00
Suyash Srijan
a5241edae9 [MiscDiagnostics] Suppress KVO warning when the property has an explicit setter (#30098) 2020-02-27 22:41:50 +00:00
Doug Gregor
be8b9e5ef4 [Constraint solver] Always produce optional types for '?' patterns. 2020-02-24 00:48:14 -08:00
Holly Borla
778f8941ee [MiscDiagnostics] Walk into the body of a non single-statement closure
if the closure had a function builder transform applied.

This way, function builder closures can have syntactic restrictions
diagnosed the same way as other expressions.
2020-02-04 16:29:02 -08:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00
Brent Royal-Gordon
c504eb1b0a Warn if magic identifiers don’t match
When wrapping a function which is supposed to capture the caller’s location, there’s always a risk that the wrapper won’t capture the information the wrapped function wants; for instance, you might pass `(…, line, column)` where the callee expected `(…, column, line)`.

This commit emits a warning when a call passes an explicit argument to something that has a default argument, and that explicit argument is itself a parameter with a default argument, and both parameters use magic identifiers, but they use *different* magic identifiers.  This is partially in support of concise #file, but applies to all magic identifiers.

Fixes rdar://problem/58588633.
2020-01-21 14:28:16 -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
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
da88512eda [NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified() 2019-12-11 00:55:17 -08:00
Brent Royal-Gordon
9a57554bdf [NFC] DeclNameRef-ify qualified and unqualified lookup 2019-12-11 00:55:17 -08:00
Rintaro Ishizaki
83f9a52cb8 Merge pull request #28362 from owenv/improve_trailing_closure_in_condition_diag_2
[Parse] Reapply trailing closure in condition fix and downgrade to warning
2019-11-22 17:05:48 +09:00
Owen Voorhees
a3946cdb50 Revert "Revert "[Diagnostic] Improve diagnostic for trailing closures in statement conditions (#25165)""
This reverts commit e3a6b67c63.
2019-11-19 13:24:20 -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
3aa7158d6c Switch UnqualifiedLookup callers over to UnqualifiedLookupRequest 2019-11-15 14:25:42 -08:00
Robert Widmann
911e749e4e [Sema] Suggest #selector(self.foo) instead of #selector(TypeName.foo) when possible
When inside a declaration or extension of TypeName, humans usually don't write
the full typename like #selector(TypeName.foo), but instead prefer the neater
form #selector(self.foo). The compiler has enough information to do this too.

Fixes rdar://problem/2528469
2019-11-11 12:35:03 -08:00
Suyash Srijan
fab6ce9587 [MiscDiagnostics] Diagnose passing a non-@objc dynamic KeyPath property to KVO observe method 2019-11-08 18:52:43 +00:00
Hamish Knight
be8415371a performSyntacticExprDiagnostics doesn't need a TypeChecker 2019-11-07 12:41:37 -08:00
Hamish Knight
bd6fd38eb2 performStmtDiagnostics doesn't need a TypeChecker 2019-11-07 12:41:37 -08:00
Hamish Knight
d8dfbbcd9f performAbstractFuncDeclDiagnostics doesn't need a TypeChecker 2019-11-07 12:41:37 -08:00
Hamish Knight
fb55c032f8 diagnoseUnownedImmediateDeallocation doesn't need a TypeChecker 2019-11-07 12:41:37 -08:00
Hamish Knight
b57c86dc1c fixItEncloseTrailingClosure doesn't need a TypeChecker 2019-11-07 12:41:36 -08:00
Hamish Knight
cb0c9adc46 Use getXXXType over getXXXDecl in a bunch of places 2019-11-07 08:26:08 -08:00
Hamish Knight
18088b04f0 [AST] Consolidate Obj-C types on ASTContext
This commit moves the getNSObjectType and
getObjCSelectorType methods from TypeChecker
onto ASTContext. In addition, it moves the
FOR_KNOWN_FOUNDATION_TYPES macro into a separate
file to define each of the Obj-C type decls
we want to have access to.
2019-11-07 08:26:08 -08:00
Robert Widmann
7b9d28d7ba Make diagnoseSelfAssignment a utility 2019-11-06 15:08:59 -08:00
Robert Widmann
4996858c4d Re-implement isInvalid for ValueDecls 2019-10-30 15:09:14 -07:00
Robert Widmann
da2b063af9 Make calls to lookupMember actually look static 2019-10-30 12:55:42 -07:00
Robert Widmann
bcf03aa019 Make getDeclTypeCheckingSemantics a utility 2019-10-30 12:55:10 -07:00
Hamish Knight
642f58d641 Make checkUnsupportedProtocolType a static member 2019-10-30 07:56:32 -07:00
Robert Widmann
3b829943af Uniformly iterate over the pattern binding entry indices
Clarify a bunch of C-style for loops and remove a ton of references to getPatternList().
2019-10-17 13:39:07 -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
Robert Widmann
7c1e3949ed [NFC] Refactor Override Fixit Emission
Refactor diagnostic emission so it lazily emits notes and fixits.
This is a necessary evil in a world where an arbitrary request can also
emit diagnostics, especially circularity diagnostics.  In the future, we
should assert in the evaluator that there is no active diagnostic to
catch the rest of these.
2019-10-15 17:28:00 -07:00
Robert Widmann
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
Slava Pestov
044204a5d5 Sema: Don't synthesize null bodies for invalid accessors
We don't want hasBody() == true and getBody() == nullptr.
2019-10-03 17:11:44 -04:00
Slava Pestov
bbce38409c Sema: Decouple availability checking from the TypeChecker 2019-09-24 22:51:23 -04:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Robert Widmann
e0a41b19cb Break some cycles
Computing the generic signature changes the way that cycles appear in the compiler.  For now, break these cycles.  We should investigate each place where hasComputedGenericSignature() is used in service of breaking cycles.  See rdar://55263708
2019-09-16 12:50:24 -07:00
Jordan Rose
dc59cd2043 [Sema] Stop visiting existential exprs an extra time checking for uses (#27150)
This was causing an exponential amount of time traversing the AST with
deeply chained protocol extension methods, such as in the
TestCodableRouter.swift test in Kitura.

If the OpaqueValueExpr is referenced more than once within the
OpenExistentialExpr it'll still get visited more than once, but that
doesn't seem to happen in practice. If it turns out to be a problem,
we can weaken the assertion I'm adding here.

https://bugs.swift.org/browse/SR-11012
2019-09-12 20:21:22 -07:00
Slava Pestov
4668def6b3 Sema: Split addImplicitConstructors() into separate functions for structs and classes 2019-09-03 22:39:35 -04:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Slava Pestov
2ef101c815 Sema: Don't add local functions to TC.definedFunctions
Instead, check them and their error handling right away.

In addition to fixing the crash in the radar, this also causes
us to emit unused variable warnings in functions containing
local functions.

Eventually, TC.definedFunctions should go away altogether.

Fixes <rdar://problem/53956342>.
2019-08-07 00:37:21 -04:00