Commit Graph

1030 Commits

Author SHA1 Message Date
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
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Doug Gregor
ff2cb3305d [Type checker] Factor "type check function body until" into a request.
Extend the "type check function body" request to also cover the case
where we have a specific ending source location. Fold all of this
functionality into a single request, so we consistently go through a
request to compute a type-checked function body.
2019-07-12 17:40:53 -07:00
Jordan Rose
e3a6b67c63 Revert "[Diagnostic] Improve diagnostic for trailing closures in statement conditions (#25165)"
This reverts commit 4da49fcfee.
2019-06-28 13:59:07 -07:00
Owen Voorhees
4da49fcfee [Diagnostic] Improve diagnostic for trailing closures in statement conditions (#25165)
This improves the diagnostic for trailing closures in statement conditions to catch cases where one or more trailing closures are used in a chain composed of multiple calls
2019-06-28 09:08:50 -07:00
gregomni
92eb874e0e Insert access level fixits in front of 'override', if it's there, instead of
after. This is so that code produced by this fixit matches the same keyword
order as code produced by autocompleting a method decl in a new subclass.
2019-06-27 06:57:02 -07:00
Slava Pestov
5826db5d56 AST: Add AbstractFunctionDecl::hasDynamicSelfResult() and use it
This calculates a result directly from the function's result type
instead of checking a bit that was previously set by the type
checker. Also, always returns true for constructors to simplify
some callers.
2019-06-26 01:10:12 -04:00
Jordan Rose
9e471e4124 Don't offer a fix-it to convert to a 'some' type (#25619)
There's no way to spell an opaque type in a cast, and that means
there's no way to force the conversion today (even if you know the
types are dynamically the same).

Part of rdar://problem/50346954
2019-06-19 19:17:32 -07:00
Parker Schuh
823ba0bb73 Convert ObjectLiteralExpr to not use tc.callWitness() or generate a SemanticExpr.
For reference, all other literal types except dictionaries and string
interpolation have been converted over to this form.
2019-06-11 02:47:32 -07:00
Suyash Srijan
9ae2c85991 [Typechecker] Use CallArgs for checking duplicate label & add new test cases 2019-05-17 23:38:34 +01:00
Suyash Srijan
92d41ef166 [Typechecker] Fix a crash 2019-05-17 00:57:40 +01:00
Suyash Srijan
b2c86709b1 [Typechecker] Check for CallExpr only, not ApplyExpr. Also, check for EnumElementDecl separately 2019-05-17 00:52:43 +01:00
Suyash Srijan
90d96881bb [Typechecker] Do not check tuple labels for a function call
It's okay to have two function parameters with the same external label, as long as the internal labels are different. If not, we already emit a diagnostic for it, so no need to check
2019-05-17 00:13:42 +01:00
Suyash Srijan
935128cd3b Merge branch 'master' into fix/duplicate-tuple-labels 2019-05-15 22:38:52 +01:00
Suyash Srijan
a332eb6b4d [Typechecker] Don't add empty identifiers to the set 2019-05-15 02:26:04 +01:00
Suyash Srijan
71fee96093 [Typechecker] Ban tuples with duplicate labels 2019-05-14 19:43:46 +01:00
Slava Pestov
b103fed866 Sema: Remove old diagnostics for misplaced InOutExpr 2019-05-07 23:10:49 -04:00
Joe Groff
22793b4567 Fixes for opaque return types on local functions.
- In Sema, don't traverse nested declarations while deducing the opaque return type. This would
  cause returns inside nested functions to clobber the return type of the outer function.
- In IRGen, walk the list of opaque return types we keep in the SourceFile already for type
  reconstruction, instead of trying to visit them ad-hoc as part of walking the AST, since
  IRGen doesn't normally walk the bodies of function decls directly.

Fixes rdar://problem/50459091
2019-05-03 16:53:21 -07:00
Pavel Yaskevich
caad4a817b [MiscDiagnostics] Run opaque return checker only if all of the return expressions are correct 2019-04-29 18:42:28 -07:00
Suyash Srijan
a58db50b4f [Diagnostics] Update diagnostics for T! to Any (#23617)
Add a tailored diagnostic for the case where implicitly unwrapped optional is coerced to `Any`
2019-04-18 15:23:52 -07:00
Joe Groff
0fcc7cdac0 Check the underlying type of get-only computed properties with opaque return types. 2019-04-17 14:46:22 -07:00
Joe Groff
f008019bda Sema: Infer the underlying type for opaque return types from function bodies. 2019-04-17 14:43:32 -07:00
Brent Royal-Gordon
7a41c3874b Permit subscripting types without using .self 2019-04-10 23:17:04 -07:00