Commit Graph

603 Commits

Author SHA1 Message Date
Slava Pestov
732b215b88 Merge pull request #9413 from rintaro/ast-eliminate-ifconfigstmt
[AST] Eliminate IfConfigStmt
2017-06-16 15:39:47 -07:00
Joe Groff
f262ced6e6 Sema: Track writes through WritableKeyPaths for mutation warnings.
Previously we would erroneously flag a `var` as not being mutated if the only mutations were through WritableKeyPaths. Fixes SR-5214 | rdar://problem/32599483.
2017-06-16 12:44:52 -07:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
Robert Widmann
3af359cb44 Merge pull request #10242 from CodaFi/in-through-the-out-door
[NFC] Move HasInOut bit out of recursive type properties
2017-06-14 13:11:19 -07:00
Robert Widmann
a4bf57f9d1 Move HasInOut bit out of recursive type properties
In anticipation of removing this bit, move it from the
recursive type property into TupleType - its only real
user.  This necessitates uglifying a bit of logic in the
short term that used to speak broadly of materializability
to instead speak about LValues and Tuples of InOut values
independently.
2017-06-14 09:54:19 -07:00
Alex Hoppen
d922944af0 Merge pull request #9976 from ahoppen/pdm-diagnostics2
Migration to DeclBaseName in diagnostic definitions
2017-06-13 12:55:16 +02:00
Pavel Yaskevich
6180ecef73 [QoI] Don't suggest var to let when binding inside for-statement
Instead of doing that, suggest removing 'var' altogether because
'let' cannot be used directly in an implicitly immutable context.

Resolves: rdar://problem/32390726
2017-06-09 01:10:40 -07:00
Pavel Yaskevich
c94fe94d5d [Diagnostics] Add a fix-it for optional to raw representable type conversion
Situations where there is a contextual RawRepresentable type is
used incorrectly would produce `<Type>(rawValue: )` fix-it only
in cases where neither or both sides of the expression are optional.
Let's fix that by adding a fix-it for optional to contextual raw
value type conversion.

Resolves: rdar://problem/32431736
2017-05-31 13:58:17 -07:00
Alex Hoppen
faa1720c48 [Diagnostics] Adjustments for DeclBaseName
Adjust the definition of some diagnostics that are already called with
DeclBaseNames so that the implicit conversion from DeclBaseName to
Identifier is no longer needed.

Adjust the call side of diagnostics which don't have to deal with
special names to pass an Identifier to the diagnostic.
2017-05-31 15:58:46 +02:00
Jordan Rose
4468ad2028 [Sema] Preparations for removal of getName on ValueDecl (#9972)
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 22:36:39 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00
Alex Hoppen
f302afc97f Unify approach to printing declaration names (#9320)
Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:25:20 -07:00
Slava Pestov
ec12e974ee Sema: More consistent enforcement of '.self' on metatype values in Swift 4 mode
In Swift 3, we required that '.self' be specified on TypeExprs
and DeclRefExprs that reference types.

However, types referenced as member lookups, such as 'Foo.Bar',
did not get this treatment, and '.self' was not required.

Fix this by emitting warnings in the cases that Swift 3 did not
diagnose, and producing errors in Swift 4 mode where we want
strict enforcement.
2017-05-21 18:14:55 -07:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Slava Pestov
214c7f8e5a Sema: Update getDefaultGenericArgumentsString() for primitive AnyObject 2017-05-01 19:30:43 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
practicalswift
65bcc8ff84 [gardening] Use o && isa<T>(o) instead of dyn_cast_or_null<T>(o) when result is unused 2017-04-14 17:33:24 +02:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
David Hart
13edc600f0 [SR-2421] Remove variable_never_used fixit to work with two-stage let initialization
The variable_never_used fixit transforms into invalid code in the case of two-stage let initialization. I introduced a new diagnostic that does not fixit and suggests removing the value.
2017-03-18 00:21:18 +01:00
Doug Gregor
a9daae2fea [Type checker] Don’t print an erroneous superclass in a diagnostic. 2017-02-07 15:22:50 -08:00
Jordan Rose
37774eb97e Fix the TypeChecker's omitNeedlessWords to use interface types. (#7193)
...avoiding a crash when trying to detect near misses of protocol
requirements. Unfortunately I can't come up with a test case for the
VarDecl changes; everything I try seems to already work. But using
interface types is more correct anyway.

https://bugs.swift.org/browse/SR-3812
2017-02-02 14:26:29 -08:00
Slava Pestov
71cf245701 Merge pull request #7023 from KingOfBrian/bugfix/SR-2115
Generate unused variable warnings in top level statements
2017-01-29 20:25:46 -08:00
Slava Pestov
974e2e1e9e Sema: Fix @warn_unqualified_access crash 2017-01-28 18:35:24 -08:00
Brian King
e9e237871c Fix a crash with a nil pattern returned from StmtConditionElement 2017-01-27 15:37:19 -05:00
Brian King
3c4fec8d87 Make sure braces are consistently cuddled 2017-01-26 21:52:19 -05:00
Brian King
b389fc3ef5 Code review feedback 2017-01-26 18:00:00 -05:00
Brian King
d835167485 Flag global variables declared in guard constructs 2017-01-26 09:59:51 -05:00
Brian King
36e36a1551 Align TLCD checking better with existing approach 2017-01-26 09:59:27 -05:00
Brian King
6091cda408 Run the VarDeclUsageChecker on top level declarations 2017-01-24 22:50:28 -05:00
Slava Pestov
10e292bfdf Sema: Make it explicit that the 'tuple splat' diagnostic is only for Swift 3 compatibility mode 2017-01-19 20:07:06 -08:00
Rintaro Ishizaki
3952e0043c [Diag] Don't attempt 'fixOverrideDeclarationTypes' when indices count doesn't match for subscript
Fixes a crasher
2017-01-16 22:51:35 +09:00
Slava Pestov
aa63f83f51 Sema: Extract availability code into TypeCheckAvailability.cpp 2017-01-06 18:59:34 -08:00
Joe Groff
720f496b2e Merge pull request #6605 from jckarter/unsafe-bitcast-warnings
Sema: Warn about some common classes of `unsafeBitCast` misuse.
2017-01-06 09:13:56 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Groff
d0787fb6b5 Sema: Warn about some common classes of unsafeBitCast misuse.
- Most immediately, we now have `withoutActuallyEscaping` as a supported way to temporarily reference a nonescaping closure as if it were escapable, and we plan to break the ABI for escaping and nonescaping closures so that the old `unsafeBitCast` workaround no longer works.
- `unsafeBitCast` is also commonly used to kludge pointers into different types, but we have more semantically meaningful APIs for type punning now. Guide users towards those APIs.
- Suggest more specific and type-safe operations, like `bitPattern:` initializers or `unsafeDowncast`, for the situations where `unsafeBitCast` is being used to avoid dynamic type checks or reinterpret numerical bits.
2017-01-05 21:19:02 -08:00
Slava Pestov
87e9b1b34e Sema: Fix a warning 2017-01-04 15:48:38 -08:00
Slava Pestov
18adb53226 Sema: Tighten up name lookup routines to not look through metatypes/lvalues/etc
Previously all of the following would strip off varying amounts of
MetatypeType, LValueType, InOutType, DynamicSelfType, etc:

- ConstraintSystem::performMemberLookup()
- ConstraintSystem::lookupMember()
- TypeChecker::lookupMember()
- DeclContext::lookupQualified()
- Type::getContextSubstitutions()

The problem is that the higher level methods that took a lookup type
would call the lower level methods, and post-process the result using
the given lookup type. Since different levels of sugar were stripped,
it made the code hard to reason about and opened up edge cases, eg
if a DynamicSelfType or InOutType appears where we didn't expect it.

Since filtering out static/instance and mutating/nonmutating members
is done at higher levels, there's no reason for these name lookup
operations to accept anything other than nominal types, existentials
and archetypes.

Make this so with assertions, and deal with the fallout.
2017-01-04 01:40:19 -08:00
Slava Pestov
7258861d73 Merge pull request #6515 from xedin/crasher-28588
[QoI] While merging equivalence classes don't forget to merge fixed types (if any).
2017-01-03 19:35:47 -08:00
Joe Groff
796df2dc44 Merge pull request #6429 from jckarter/type-of-by-overload-resolution
`withoutActuallyEscaping`
2017-01-03 18:47:29 -08:00
Robert Widmann
3a4eb3f8ac Validate an assumption in 'lookupConstructors'
Invalid ASTs like the one in 28625 cause Parse to generate an AST that
looks a heck of a lot like a constructor call, however this makes no
sense as the type in question is a TupleType and lookup asserts in such
cases.  Guard against this so we don't crash diagnosing.
2017-01-03 19:03:23 -07:00
Robert Widmann
51dc142fca [28419] Extend nested init-chaining diagnostics to defer statements
This used to cause SILGen to capture and subsequently load `self` as a
constant.  Then, when the super call was SILGen’d, it assumed that
`self` would be loaded Boxed.  Diagnose before hitting SILGen so we
don’t have to pollute Lowering with code that handles `self` in this
odd position.
2017-01-03 18:53:06 -07:00
Pavel Yaskevich
fac59ce4ee [Diagnostics] Improve diagnostics of self assignment of the anonymous closure parameters 2016-12-31 19:00:30 -08:00
Joe Groff
0c9297862f Sema: Handle type-checking for withoutActuallyEscaping.
withoutActuallyEscaping has a signature like `<T..., U, V, W> (@nonescaping (T...) throws<U> -> V, (@escaping (T...) throws<U> -> V) -> W) -> W, but our type system for functions unfortunately isn't quite that expressive yet, so we need to special-case it. Set up the necessary type system when resolving an overload set to reference withoutActuallyEscaping, and if a type check succeeds, build a MakeTemporarilyEscapableExpr to represent it in the type-checked AST.
2016-12-22 17:51:26 -08:00
Joe Groff
1889fde228 Resolve type(of:) by overload resolution rather than parse hackery.
`type(of:)` has behavior whose type isn't directly representable in Swift's type system, since it produces both concrete and existential metatypes. In Swift 3 we put in a parser hack to turn `type(of: <expr>)` into a DynamicTypeExpr, but this effectively made `type(of:)` a reserved name. It's a bit more principled to put `Swift.type(of:)` on the same level as other declarations, even with its special-case type system behavior, and we can do this by special-casing the type system we produce during overload resolution if `Swift.type(of:)` shows up in an overload set. This also lays groundwork for handling other declarations we want to ostensibly behave like normal declarations but with otherwise inexpressible types, viz. `withoutActuallyEscaping` from SE-0110.
2016-12-22 16:28:31 -08:00
practicalswift
ce7a10474f [gardening] Fix accidental double and triple spaces. 2016-12-21 22:13:56 +01:00
Slava Pestov
fb0f372e94 AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- The DeclContext versions of these methods have equivalents
  on the DeclContext class; use them instead.

- The GenericEnvironment versions of these methods are now
  static methods on the GenericEnvironment class. Note that
  these are not made redundant by the instance methods on
  GenericEnvironment, since the static methods can also be
  called with a null GenericEnvironment, in which case they
  just assert that the type is fully concrete.

- Remove some unnecessary #includes of ArchetypeBuilder.h
  and GenericEnvironment.h. Now changes to these files
  result in a lot less recompilation.
2016-12-18 19:55:41 -08:00
Michael Gottesman
96c63e9e76 Merge pull request #6324 from practicalswift/cpp-gardening
[gardening] C++ gardening: Terminate namespaces, fix argument names, …
2016-12-16 23:30:33 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Doug Gregor
0c0517f997 [Type checker] Don't drop "delayed" conformance diagnostics after a source file.
The protocol conformance checker tries to delay the emission of
diagnostics related to the failure of a type to conform to a protocol
until the source file that contains the conformance is encountered, to
provide redundant diagnostics. However, if a file produced only such
delayed diagnostics, such that all diagnostics were suppressed,
invalid ASTs could slip through to later stages in the pipeline where
they would cause verification errors and crashes. This happens
generally with whole-module-optimization builds, where we are re-using
an ASTContext when typing multiple source files.

This is a narrow-ish fix to stop dropping diagnostics from one source
file to the next in whole-module-optimization builds. Part of
rdar://problem/29689007.
2016-12-16 15:15:17 -08:00