Commit Graph

7976 Commits

Author SHA1 Message Date
swift-ci
808c48401f Merge pull request #6743 from swiftix/wip-partial-pre-specializations-wip-layout-constraints 2017-01-12 10:12:44 -08:00
Slava Pestov
386d93e130 Merge pull request #6753 from xedin/if-expr-recheck
[Diagnostics] Improve diagnostics for expressions involving ternary operators
2017-01-11 22:44:04 -08:00
Slava Pestov
21272c178b Merge pull request #6732 from xedin/diag-generic-requirements
[Diagnostics] Improve diagnostics for generic types with unfulfilled requirements
2017-01-11 22:32:25 -08:00
Pavel Yaskevich
f142568eaa [Diagnostics] Improve diagnostics for expressions involving ternary operators
FailureDiagnosis::visitApplyExpr is going to attempt to type-check
argument expression multiple times - with and without allowing free
type variables, since first type-check might mutate AST if (sub-expression
type-checks correctly) it's required to fix up ternary operations
represented as IfExpr to it's original condition form, because IfExpr
is going to convert Bool into implicit call `(Bool) -> () -> Int1`
upon successful type-check, which is not handled by either
ConstraintGenerator nor ExprRewriter because they don't expect
well-formed type-checked IfExpr is input.

Resolves: <rdar://problem/29850459>.
2017-01-11 21:25:45 -08:00
Slava Pestov
5d8bfb09e7 Re-apply "Playground Transform: Fix assertion failure in generic code" (#6747)
This regression was introduced in the following commit:
<6cbb494ad2>

Fixes <rdar://problem/29935266>.
2017-01-11 19:47:20 -08:00
Roman Levenstein
29180ca1a0 Add support for layout requirements with layout constraints.
This commit introduces new kind of requirements: layout requirements.

This kind of requirements allows to expose that a type should satisfy certain layout properties, e.g. it should be a trivial type, have a given size and alignment, etc.
2017-01-11 19:21:45 -08:00
Doug Gregor
408eb0fd8a Merge pull request #6703 from jtbandes/literally-not-even-used
[QoI] Add diagnostic for unused literal values
2017-01-11 16:37:10 -08:00
Pavel Yaskevich
c158f49417 [Diagnostics] Improve diagnostics for generic types with unfulfilled requirements 2017-01-11 15:25:16 -08:00
Matthew Carroll
0e09bbbb83 [DiagnosticsQoI] SR-3359: Add a fix-it to remove @discardableResult on functions that return Void or Never (#6681)
This commit adds a fix-it to remove @discardableResult on functions that return Void or Never. The fix-it is at the warning level. A test was added to verify that the fix-it removes the @discardableResult. This issue was reported in SR-3359:
https://bugs.swift.org/browse/SR-3359

Changes:
TypeCheckAttr.cpp: implemented AttributeChecker::visitDiscardableResultAttr to add a fix-it to remove @discardableResult on functions returning Void or Never.

DiagnosticsSema.def: Added a warning with a diagnostic message.

LoggingWrappers.swift.gyb, HashedCollections.swift.gyb: Removed @discardableResult on functions returning Void.

fixits-apply-all.swift, fixits-apply-all.swift.result: Added tests to verify that @discardableResult is removed from functions returning Void or Never.
2017-01-11 15:12:36 -08:00
Arnold Schwaighofer
dbab7257bf Revert "Playground Transform: Fix assertion failure in generic code" 2017-01-11 09:02:38 -08:00
swift-ci
115b9b8a14 Merge pull request #6729 from rudkx/time-expression-type-checking 2017-01-11 00:37:05 -08:00
Mark Lacey
3903a43f97 Add a command-line option to time expression type-checking. 2017-01-11 00:15:38 -08:00
swift-ci
a6419f27f2 Merge pull request #6726 from rudkx/fix-release-build-warning 2017-01-10 23:43:30 -08:00
swift-ci
aa2402c200 Merge pull request #6725 from rudkx/expression-too-complex 2017-01-10 23:15:25 -08:00
Mark Lacey
75c8afce2a Fix release build warning. 2017-01-10 23:01:21 -08:00
Mark Lacey
5f2aeec434 Implement a new "expression too complex" metric for Swift 4 mode.
Rather than waiting until we've used a huge amount of memory, attempt to
make the choice to bail out based on the number of type bindings /
disjunction choices we visit.

I expect this will generally fail faster than the Swift 3 metric, but
will still only fail when we've got clearly exponential type checking
behvior.

Since we have multiple sources of exponential behavior today, I don't
want to make the bounds too tight. Once we fix some/most of that
behavior we can look at further tightening up the metric.
2017-01-10 22:09:11 -08:00
Jacob Bandes-Storch
4a16880103 [QoI] Add diagnostic for unused literal values
Fixes SR-3522.
2017-01-10 20:42:36 -08:00
Mark Lacey
1a4795e2a1 Report "expression was too complex" more consistently.
We were only reporting it in cases where we found no solutions before
deciding the expression was too complex. Had we found some solution, we
would go ahead and use that solution before bailing out due to
complexity, which means e.g. we might have been allowing otherwise
ambiguous expression to type check.
2017-01-10 20:12:11 -08:00
swift-ci
6acd2610a7 Merge pull request #6716 from gottesmm/eliminate_deallocating_convention 2017-01-10 20:02:51 -08:00
Doug Gregor
2a3817f434 Merge pull request #6722 from DougGregor/archetype-builder-without-module
[Archetype builder] Use a LookupConformanceFn to resolve protocol conformances
2017-01-10 19:44:28 -08:00
Michael Gottesman
d944930591 Remove the deallocating convention.
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
2017-01-10 17:32:17 -08:00
Doug Gregor
ac5e74601b [Archetype builder] Use a LookupConformanceFn to resolve protocol conformances.
Instead of creating an archetype builder with a module---which was
only used for protocol conformance lookups of concrete types
anyway---create it with a LookupConformanceFn. This is NFC for now,
but moves us closer to making archetype builders more canonicalizable
and reusable.
2017-01-10 16:40:38 -08:00
Slava Pestov
d38c65dff5 Playground Transform: Fix assertion failure in generic code
This regression was introduced in the following commit:
<6cbb494ad2>

Fixes <rdar://problem/29935266>.
2017-01-10 16:23:12 -08:00
Jordan Rose
1f2121377e Infer selectors from protocols for property accessors too. (#6634)
Most property accessors have selectors matching their protocols, but
not all. Don't force the user to write '@objc' explicitly on an
accessor, which isn't even possible for stored properties.

More groundwork for rdar://problem/28543037.
2017-01-10 13:36:45 -08:00
Jordan Rose
f2fb1e9d93 [Sema] Record invalid protocol witnesses to avoid re-diagnosis. (#6698)
This is a /little/ risky because previously a recorded witness would
only be empty if the requirement was optional, but it's a relatively
non-intrusive way to improve diagnostics. The conformance is still
marked invalid, which is the important part.

Groundwork for rdar://problem/28543037.
2017-01-10 13:36:24 -08:00
Doug Gregor
ffa901cb9f [Type checker] Don't infer type variable bindings from checked casts (as?/as!).
Checked casts are dependent on run-time queries; we should not attempt
to infer type variable bindings from them, because doing so produces
unreasonable bindings. Fixes rdar://problem/29894174.
2017-01-10 11:03:54 -08:00
Slava Pestov
d65d1d25f9 Sema: Diagnostics for @_inlineable, @_versioned and Swift 4 default arguments model
Piggybacks some resilience diagnostics onto the availability
checking code.

Public and versioned functions with inlineable bodies can only
reference other public and internal entities, since the SIL code
for the function body is serialized and stored as part of the
module.

This includes @_transparent functions, @_inlineable functions,
accessors for @_inlineable storage, @inline(__always) functions,
and in Swift 4 mode, default argument expressions.

The new checks are a source-breaking change, however we don't
guarantee source compatibility for underscored attributes.

The new ABI and tests for the default argument model will come in
subsequent commits.
2017-01-09 16:59:13 -08:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
Slava Pestov
e0ed4a1e97 Sema: Diagnose types nested inside closures in generic context
Neither of the following is supported:

func g<T>(_: T) {
  _ = {
    struct S {}
  }
}

struct G<T> {
  let fn = {
    struct S {}
  }
}

Even though nested generic types are supported, the second example
is more like a type inside a function than a type inside a type,
because 'S' has no parent type.

Technically this is source-breaking but since neither SILGen nor
IRGen knew how to generate code for these I doubt anything worked.
2017-01-09 16:46:31 -08:00
Slava Pestov
c04c6c9c61 Merge pull request #6586 from xedin/SR_3520
Generic function taking closure with inout parameter returns erroneous results
2017-01-09 12:25:20 -08:00
Pavel Yaskevich
0f716e643b [QoI] Fix inference of inout closure parameters in generic contexts
Convert subtype constraints with inout on one side and type variable
on the other into fixed binding. Constriants like `inout T0 subtype T1`
where (T0 must be materializable) are created when closures are part
of the generic function parameters e.g. `func foo<T>(_ t: T, (inout T) -> Void) {}`
so when such function gets called e.g.
```
  var x = 42
  foo(x) { $0 = 0 }
```
it's going to try and map closure parameters type (inout T0) - where
is opened generic parameter T - to argument type (T1), which can
be 'inout' but it's uncertain at this stage, but since closure
'declaration' `{ $0 = 0 }` is wrapped inside of a function call,
it has to 'map' parameters to arguments instead of converting them,
see `ConstraintSystem::matchFunctionTypes`.

Resolves: SR-3520, SR-1976, SR-3073, SR-3479.
2017-01-09 00:23:00 -08:00
Slava Pestov
02185c30ee Sema: When validating members for layout, skip certain members
For all types, we can safely skip nested nominal types and
typealiases.

For a struct, we only have to look at VarDecls; methods never
affect layout.

Similarly for an enum, only EnumElementDecls matter.

For a class, we still have to look at all methods and properties.
Ideally, in non-optimized builds we would invoke virtual methods
by calling thunks, and only emit the thunks from the translation
unit containing the class. Then the layout of a class will
only be necessary if you subclass the class.

This should improve compiler scalability in multiple-frontend
mode.
2017-01-08 21:01:14 -08:00
Slava Pestov
208dec74d0 Sema: Validate addressors when an AbstractStorageDecl is validated
Previously we were relying on the 'validate for layout' path
validating these, but that's going to change.
2017-01-08 21:01:13 -08:00
Slava Pestov
7731d4c6cb Sema: Remove some unnecessary calls to getCanonicalType() 2017-01-08 21:01:13 -08:00
Slava Pestov
95ddef57df Fix JSON serialization of ConstraintSolver statistics 2017-01-08 18:12:47 -08:00
Pavel Yaskevich
dd7360e821 [Diagnostics] Improve diagnostics for closures with erroneous implicit return types 2017-01-07 22:07:15 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
adc75d6806 [gardening] Add "// end anonymous namespace" where appropriate 2017-01-07 20:18:21 +01:00
practicalswift
83f250312b [gardening] Add override where appropriate 2017-01-07 20:17:16 +01:00
practicalswift
6417606f5f [gardening] Make sure parameter comments match actual parameter names 2017-01-07 20:06:28 +01:00
Slava Pestov
6b72345682 Merge pull request #6636 from slavapestov/move-some-code-around
Sema: Extract availability code into TypeCheckAvailability.cpp
2017-01-06 20:20:16 -08:00
Robert Widmann
cd8360c97c Merge pull request #6547 from CodaFi/i-have-a-little-shadow-that-goes-in-and-out-with-me
Simplify Condition Resolution
2017-01-06 20:01:20 -07:00
Slava Pestov
aa63f83f51 Sema: Extract availability code into TypeCheckAvailability.cpp 2017-01-06 18:59:34 -08:00
Mark Lacey
bd5f05cbda Merge pull request #6629 from rudkx/fix-iuo-collections
Fix one source of exponential behavior in the type checker.
2017-01-06 18:56:58 -08:00
Mark Lacey
1efafbcd9b Fix one source of exponential behavior in the type checker.
For collection literals that contained implicitly unwrapped optionals,
we were attempting three different conversions per element of the
collection, resulting in exponential type checking time.

We should only ever attempt one of these conversions for any pair of
types where one or both is optional.

We had several reports of this as it seems quite common for people to
write expressions that create a collection of IUOs from class/struct
elements, and then either return the collection or some variation that
has been filtered and mapped.

I am looking at adding the appropriate instrumentation to the type
checker so that I can add a scale-test for this and other type checker
test cases related to slow type checking so that we can avoid regressing
in the future.
2017-01-06 16:04:38 -08:00
Robert Widmann
0febbf0b72 Effectively revert #5778
This reverts the contents of #5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in #6279 we get the best of both worlds
with a performance win and a simpler implementation.
2017-01-06 16:16:39 -07:00
practicalswift
30a88d38e6 [gardening] Fix recently introduced typos 2017-01-06 21:16:02 +01:00
practicalswift
94091980b3 [gardening] Remove dupe word 2017-01-06 20:43:48 +01:00
practicalswift
6af21f7b05 [gardening] "a" vs. "an" 2017-01-06 20:34:41 +01:00
practicalswift
153730d3a1 [gardening] Fix header consistency 2017-01-06 20:33:03 +01:00