Commit Graph

87 Commits

Author SHA1 Message Date
Devin Coughlin
9cdff5fe00 [Exclusivity] Improve static enforcement diagnostics
Static diagnostics now refer to the identifier for the variable requiring
exclusive diagnostics. Additionally, when two accesses conflict we now always
emit the main diagnostic on the first modifying access and the note on either
the second modifying access or the read.

The diagnostics also now highlight the source range for the expression
beginning the access.
2017-04-23 11:39:25 -07:00
Devin Coughlin
4cb51f77fd [SILDiagnostics] Demote exclusivity violation error to warning.
Change the error emitted when diagnosing an exclusivity violation to an warning.
This will make it easier to evaluate on large projects while staging. The
intent it to turn it back into an error before the diagnosis is turned on
by default.
2017-04-14 16:26:50 -07:00
Devin Coughlin
bee17f7838 [SILDiagnostics] Add static enforcement of Law of Exclusivity (#8560)
Add a diagnostic pass that emits errors when a violation of the "Law of
Exclusivity" is detected at compile time. The Law of Exclusivity requires
that the access duration of any access to an address not overlap
with an access to the same address unless both accesses are reads.

This pass relies on 'begin_access' and 'end_access' SIL instruction
markers inserted by SILGen to determine when an access to an address begins and
ends. It models the in-progress accesses with a map from storage locations to
the counts of read and write-like accesses in progress for that location.
2017-04-09 21:41:13 -07:00
Xi Ge
b4cf37bf7d Sema: several improvements on missing switch cases diagnostics. (#8026)
1. Make sure the actions taken by fixits are reflected in diagnostics messages.
2. Issue missing cases diagnostics at the start of the switch statement instead of its end.
3. Use <#code#> instead of <#Code#> in the stub.
2017-03-10 19:32:37 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
David Farler
d5f4ef7fc0 Don't suggest 'break' for empty guard bodies
That's not valid code.

rdar://problem/28944787
2016-10-25 14:51:36 -07:00
Tim Bodeit
9ce9dced91 [SILOptimizer] Fix let constant of non-class protocol being mutable
Extend the checks in `LifetimeChecker` in
`SILOptimizer/Mandatory/DefiniteInitialization.cpp`
to catch when the memory object corresponding to a let constant is used
as an inout parameter in a protocol witness method.

Initializing a let constant separate from its declaration requires write
access. Therefore it is treated as `@lvalue TestProtocol` in the AST for
a certain scope.
Checking that the constant is not written to after being initialized is
supposed to happen in the Mandatory SILOptimizer phase instead.

On loads, the Optimizer checks, that a variable is fully initialized,
but perviously did not validate what happens to it after it is loaded.
This allowed loading the memory object through an open_existential_addr
instruction and applying the result as an Operand to a mutating witness
method.
2016-09-01 22:01:23 +02:00
Robert Widmann
5a2479cb2a Expand the no-return diagnostic
Turn on the noreturn diagnostic for cases where a reachable unreachable
could be encountered.  Previously, the diagnostic would not fire if the
function was marked noreturn and any of its reachable unreachable calls
were around.  While this makes sense from a SILGen perspective (it Just
Crashes tm), it is still wrong.  We need to diagnose *everything* that
has reachable unreachables.
2016-08-18 20:39:24 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
practicalswift
b704ff612a [gardening] Remove unused diagnostic: bridging_objcbridgeable_missing_conformance 2016-03-12 09:57:27 +01:00
Doug Gregor
725c610714 [SILGen] Use _ObjectiveCBridgeable._bridgeToObjectiveC for String -> NSString bridging.
Provide a general mechanism for bridging from a Swift value type to
its corresponding Objective-C class type through the
_bridgeToObjectiveC witness of the appropriate _ObjectiveCBridgeable
protocol conformance. Only enable this new code for bridging String ->
NSString and work through the issues that crop up.

We cannot actually *delete* the _convertStringtoNSString entrypoint
yet, because there is some code that is depending on it indirectly;
I'll address that separately as part of the continued generalization
of the _ObjectiveCBridgeable mechanism.
2016-03-11 20:04:34 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Daniel Duan
5242b67476 [Sema] implement better type circularity check
Certain type circularities weren't being checked until this point. Such as

```
struct X<T> { let a: X<X> }
struct Y<T> { let a: (Int, Y<Y>) }
enum Z<T> { case A(Optional<Z<Z>>) }
```

We introduce a more comprehensive approach to detect these in type checker.
After name lookup, exam each value field in declared structs and enums for
self-reference types that creates inifinite sizes.
2016-02-07 22:10:42 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Doug Gregor
f7407f6a4d [SILGen] SE-0022: emit SIL for #selector expressions.
This completes the core of the #selector feature, which can now be
used to reference the selectors of @objc methods and initializers.
2016-01-27 13:57:40 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Chris Lattner
7c247f2096 Further improve the error message when self escapes in a root class before
its fields are initialized.  Before:

   t.swift:18:24: error: variable 'self.B' captured by a closure before being initialized

after:

t.swift:19:24: error: 'self' captured by a closure before all members were initialized
    self.A.withCString {  cString -> () in
                       ^
t.swift:14:7: note: 'self.B' not initialized
  var B: Int
      ^

This drives home the fact that 'self' is being captured here, not the individual
properties.
2016-01-16 22:54:27 -08:00
Michael Ilseman
de0062e437 [Diagnostics] Remove all categories
Diagnostic categories are entirely unused and arguably useless as
implemented, as they merely denote the sub-component of the
compiler.

As far as categorizing warnings are concerned, I'm abandoning the
effort for now, as the utility is marginal and Swift and the Swift
compiler are probalby not ready for these to be nailed down. For the
sake of cleanliness, the CATEGORY field is also stripped from
WARNINGS.

If there's a need for automatic identifying of compiler sub-components
for diagnstics in the future, there are better ways to do this.

NFC
2016-01-14 14:39:18 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Max Moiseev
2f7b64e475 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-21 12:02:13 -08:00
practicalswift
cd7d8dfaff Fix alignment as requested by @gribozavr in #692 2015-12-21 08:54:24 +01:00
practicalswift
176f487d76 Fix incorrect filenames in headers. 2015-12-20 23:59:05 +01:00
Dmitri Gribenko
3d0ad16094 Unsafe[Mutable]Pointer.memory => .pointee 2015-12-16 15:50:31 -08:00
Joe Groff
6b55e87d2f SILGen: Emit mark_function_escape when capturing variable boxes.
There's no longer a direct use of the variable's address when we invoke the closure, but we have a handy mark_function_escape instruction to mark the use without requiring merging analysis of the box and its contents. This also gives us a slightly more accurate error message when a variable is prematurely captured, noting the variable was captured by a closure instead of just generically used.
2015-12-08 14:35:47 -08:00
Slava Pestov
4a11785144 DI: Fix [derivedselfonly] initializers and clean up diagnostics
Designated initializers in NSManagedObject subclasses, or other
classes with @requires_stored_property_inits cannot assign to
stored properties before doing a super.init() delegation.
Assignments after are OK.

DI did the wrong thing by creating a bitmap with only one bit,
but proceeding down the usual designated initializer path.

Now, handle [derivedselfonly] more like a convenience initializer,
with no stored property access allowed prior to delegation.

Also clean up duplicated diagnostics between designated and
convenience initializers, and make convenience initializers
diagnose method calls or property accesses on self in the same
manner as designated initializers.

Fixes <rdar://problem/22110837>.

Swift SVN r32858
2015-10-24 03:55:56 +00:00
Slava Pestov
f7481acc99 DI: Only emit 'self consumed' error once
Swift SVN r32689
2015-10-14 22:50:13 +00:00
Slava Pestov
f524802e12 DI: Add support for early return from designated initializers
Fixes <rdar://problem/18216578>.

Swift SVN r32678
2015-10-14 06:36:56 +00:00
Slava Pestov
f74a3c96d1 Re-apply "Use the 'self consumed' analysis to diagnose some invalid usages of self"
The problem was an uninitialized memory access. Callers were passing
the address of a local variable to isInitializedAtUse(), but this
function only stored to the pointer conditionally. Serendipitously
(or not), in the debug build the initial value was always zero.

Swift SVN r32599
2015-10-10 06:38:19 +00:00
Erik Eckstein
5447d08241 Revert "Use the 'self consumed' analysis to diagnose some invalid usages of self"
It broke some regression tests.



Swift SVN r32593
2015-10-10 05:06:04 +00:00
Slava Pestov
194c4b1c74 Use the 'self consumed' analysis to diagnose some invalid usages of self
Since a delegation consumes the self value, there's no self value available
in a catch block. Previously we would crash at runtime.

The diagnostics suck right now, so this is mostly for testing and
completeness.

Fixes <rdar://problem/22946400>.

Swift SVN r32583
2015-10-09 22:18:10 +00:00
Slava Pestov
d466d9b3aa SILGen: Re-work C function pointer conversion diagnostics
This removes the partially-correct ABI check in Sema and diagnoses
unsupported conversions in SILGen instead. The new check is more
accurate and correctly diagnoses conversions of DeclRef's to
ABI-incompatible @convention(c) types.

This also fixes two cases where we used to crash but could instead
emit a trivial cast:

- Conversions between ABI-compatible (but not identical)
  @convention(c) types
- Conversions of a DeclRef to an ABI-compatible (but not identical)
  @convention(c) type

Fixes <rdar://problem/22470105>.

Swift SVN r32163
2015-09-22 21:08:31 +00:00
Chris Lattner
b9ef0c40e1 fix <rdar://problem/20065892> Diagnostic for an uninitialized constant calls it a variable
Swift SVN r31691
2015-09-04 21:06:15 +00:00
Chris Lattner
e1ef96221a improve the DI diagnostic for uses of self in a non-delegating protocol initializer,
which is most likely because someone forgot to chain to self.init completely.



Swift SVN r30187
2015-07-14 17:50:59 +00:00
Chris Lattner
35d0b01420 improve QoI for enums that need to be marked indirect, but suggesting a fixit and having
a more specific diagnostic.


Swift SVN r29878
2015-07-02 00:53:13 +00:00
Chris Lattner
4602d51231 Improve the diagnostic for an init in a protocol extension that doesn't
chain to another self.init, hopefully resolving confusion about what
has to be done here.

This fixes <rdar://problem/21295093> Swift protocol cannot implement default initializer


Swift SVN r29571
2015-06-23 16:40:26 +00:00
Chris Lattner
f3a03aeaf2 Make the diagnostic for a guard whose 'else' clause falls through more
explicit to nudge people in the right direction of how to use it.
Fixes <rdar://problem/21355414> Error on forgetting to return on a guard



Swift SVN r29552
2015-06-22 21:38:55 +00:00
Chris Lattner
05bf79404a missed a file :-(
Swift SVN r28836
2015-05-20 18:22:46 +00:00
Slava Pestov
42d7c7251c SILGen: better diagnostic for code after break and throw
Swift SVN r28689
2015-05-18 00:26:19 +00:00
Slava Pestov
cbbde4739e SILGen: remove dead diagnostics for error handling
Looks like Sema is checking all of this stuff now. NFC

Swift SVN r28571
2015-05-14 17:22:44 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Chris Lattner
ba4186befb remove parser support for let/else. I left in a cheesy fixit to help
migrate code, but it isn't great.  It needs to be removed before wwdc
(tracked by 20794825)


Swift SVN r28099
2015-05-03 21:46:05 +00:00
Chris Lattner
0011b3ae21 rename "unless" to "require" and give it an 'else' keyword.
Swift SVN r28059
2015-05-02 00:16:44 +00:00
Chris Lattner
e1e83eb8ce Reject 'unless' blocks that fall through.
Unless is now done, we just need to decide what color to paint it.


Swift SVN r27996
2015-04-30 21:12:39 +00:00
Chris Lattner
16522c3758 fix <rdar://problem/19623566> Obscure diagnostic for assigning negative numbers to unsigned
We now produce:
t.swift:1:15: error: negative integer '-9223372036854775808' overflows when stored into unsigned type 'UInt'
var x: UInt = -0x8000_0000_0000_0000
              ^



Swift SVN r27797
2015-04-27 01:18:47 +00:00
Chris Lattner
fa4f1d86ee Recommit r27756 with an update to diagnostic_constant_propagation_int.swift, which is iOS only.
Swift SVN r27761
2015-04-26 15:56:41 +00:00