Commit Graph

4518 Commits

Author SHA1 Message Date
Jordan Rose
cee28189a2 Add a BodyKind for implicitly-synthesized memberwise initializers.
...rather than just assuming any initializer without a body that makes it
to SILGen is a memberwise initializer.

In the long term we want SILGen to stop handling these initializers, at
which point we can see if it makes sense to remove this body kind.

No intended functionality change.

Swift SVN r25723
2015-03-03 23:22:21 +00:00
Doug Gregor
8859b565bf Create trivial accessors for static stored properties when conformance checking needs them.
This is the propagation of the hack to declare getters/setters when we
need them. It really should be centralized, but this fixes a recent
regression (rdar://problem/19941580).

Swift SVN r25721
2015-03-03 22:25:48 +00:00
Devin Coughlin
1e5daf7557 [Sema] Suppress deprecation warnings inside implicit functions
This commit suppresses deprecation warnings for references to deprecated symbols
by climbing the DeclContext hierarchy to determine if the warning location is
inside an implicit function.

This is a quick fix to get rid of spurious warnings for deprecated enums whose
nil literal conformance is synthesized by the importer. These warnings would
occur even when user code made no apparent reference to the enum in question and
instead only referred to an imported class that itself referred to the enum in a
method signature. This quick fix intentionally drops some valid warnings
(for example, for a synthesized call to a deprecated initializer in a super
class). rdar://problem/20024980 tracks adding these special purpose warnings
back.

rdar://problem/20007266

Swift SVN r25720
2015-03-03 21:16:01 +00:00
Jordan Rose
511f19c6de Mark inherited required initializers as required.
rdar://problem/19793782 (and its dups)

Swift SVN r25704
2015-03-03 03:28:40 +00:00
Joe Groff
5fa20867e9 SILGen: Implement thunking for C function pointer conversions.
If we have a C function pointer conversion, generate a thunk using the same logic we use for ObjC method thunks, and emit a pointer to that thunk as the C function pointer value. (This works for nongeneric, nonmember functions; generics will additionally need to apply generic parameters within the thunks. Static functions would need to gather the metatype as well.)

Swift SVN r25653
2015-03-01 06:18:58 +00:00
Dmitri Hrybenko
3890d64e49 Fix a crash in the type checker when trying to find an ObjC bridge
intrinsic when ObjC interop is absent

Investigated and fixed together with Graham.

Swift SVN r25621
2015-02-27 22:09:15 +00:00
Doug Gregor
09efc9d78e Allow to one to define zero-parameter initializers with Objective-C names longer than "init".
There are a handful of Objective-C initializers with names like
"initForMemory" that take no parameters. The Clang importer has long
been importing them with a single parameter of type (), e.g.,

  init(forMemory: ())

At some point, our @objc checking got stricter and started rejecting
parameters of type (), making it impossible to define such an
initializer in Swift. Codify this case in @objc checking, fixing
rdar://problem/19973250.

Swift SVN r25611
2015-02-27 21:50:04 +00:00
Doug Gregor
2a385c4feb Minor tweaks to our handling of generic parameters from our outer context. NFC
Swift SVN r25609
2015-02-27 21:50:00 +00:00
Joe Groff
f985df8f84 Sema: Don't unwrap vararg tuple subpatterns in enum patterns.
Review feedback from Doug. We don't allow vararg tuple values anymore, but if we did, we would need additional pattern-matching logic anyway.

Swift SVN r25602
2015-02-27 17:49:51 +00:00
Chris Willmore
9910c75c67 Don't offer incorrect fixit for NSString? -> String? conversion.
Update the locator when matching optional types in parallel fashion.
This causes the simplifyLocator() call to fail to simplify the locator
completely, and avoids the bogus diagnostic.

<rdar://problem/19836341> Incorrect fixit for NSString? to String? conversions

Swift SVN r25596
2015-02-27 05:30:11 +00:00
Jordan Rose
1d03915dfc Make sure static vars in protocols don't get mutating setters.
Static members are never mutating, and having them be mutating in protocols
resulted in requirement mismatches.

rdar://problem/19887250

Swift SVN r25593
2015-02-27 04:54:01 +00:00
Devin Coughlin
7b0a050e1e [Sema] Add test for declaration more available than containing extension
At Jordan's request, add a test to ensure that we emit an error when a declaration
inside an extension is more available than the extension itself. Also change a
getContextKind() comparison + cast<> to a dyn_cast<>.

Swift SVN r25592
2015-02-27 03:16:30 +00:00
Devin Coughlin
3fc110e0b8 [Sema]Allow @availability attributes on extensions
This commit allows @availability attributes on extensions.

Unlike other declarations, extensions can be used without referring to them
by name (they don't have one) in the source. For this reason, when checking
the available version range of a declaration we also need to check to see if it is
immediately contained in an extension and use the extension's availability if
the declaration does not have an explicit @availability attribute itself.

This commit also moves building the primary file type refinement context hierarchy
in performTypeChecking() to before we resolve extensions.  Resolving extensions checks for
availability of the extended declaration, so the TRC for the extension must be constructed
before then.

Swift SVN r25589
2015-02-27 02:42:42 +00:00
Chris Lattner
129562b79e fix <rdar://problem/19780343> Default constructor for a struct with optional doesn't compile
We suppress the default initializer in cases where we'd just have a constant initialized
to nil, just like we suppress it when we have an uninitialized member.



Swift SVN r25566
2015-02-26 23:32:15 +00:00
Chris Lattner
da1dfcd55c implement <rdar://problem/19150249> Allow labeled "break" from an "if" statement
This doesn't allow 'continue' out of an if statement for the same reason we don't
allow it on switch: we'd prefer people to write loops more explicitly.



Swift SVN r25565
2015-02-26 22:32:30 +00:00
Xi Ge
7f668e7b49 Add isUserAccessible() in Decl to show whether swift users should know such decl exists. For instance, a.storage for lazy var a is a inaccessible decl. An implicit decl is not necessarily inaccessible, for instance, self.
Fixing rdar://18760063

Swift SVN r25556
2015-02-26 19:16:54 +00:00
Chris Lattner
accfcaa80f revert r25545, a different approach will be needed.
Swift SVN r25554
2015-02-26 18:18:30 +00:00
Chris Lattner
98adbb7277 add a comment about some magic.
Swift SVN r25553
2015-02-26 18:17:28 +00:00
Chris Lattner
60e9b9dbbb Revert r25551, more investigation is required.
Swift SVN r25552
2015-02-26 18:04:08 +00:00
Chris Lattner
5cfc38f13d there is no need to validate stored properties when synthesizing a memberwise
initializer, it has already been done now.


Swift SVN r25551
2015-02-26 17:50:51 +00:00
Chris Lattner
c74848cf30 Rework how synthesis of initializers is performed. Before, we would do it before
type checking any of the members of the type being analyzed, which leads to the
really exciting task of generating (e.g.) a memberwise initializer when you don't
know what the types of the members are.

Instead, synthesize these after the members are checked, which makes the code flow
much more like the other code synthesis stuff we do, and paves the way for future
improvements. NFC except one diagnostic in an error case (due to an order-of-checking 
change).

This resolves <rdar://problem/16921173> implicit constructor synthesization works without validating the members of the type


Swift SVN r25545
2015-02-26 07:10:17 +00:00
Chris Lattner
dce52beab6 remove a pointlessly escaped newline, NFC.
Swift SVN r25544
2015-02-26 06:59:19 +00:00
Joe Groff
dbd1956d1a Sema: Don't bind the tuple label of labeled scalar enum payloads in subpatterns.
In a situation like::

  enum Foo {
    case Bar(bar: Int)
  }
  
  switch foo {
  case let .Bar(bar):
    use(bar)
  }

It's extremely unlikely anyone expects 'bar' to have type '(bar: Int)' rather than 'Int', especially because we try to eliminate single-element tuple types pretty much everywhere else. Put in a hack so that, when we see a paren pattern as the payload subpattern of an enum case pattern, and the payload has a single-element tuple type, we transform the paren pattern into a tuple pattern, which semantically matches off the label. Fixes rdar://problem/18923473, and a lot of dupes.

Swift SVN r25541
2015-02-26 03:37:10 +00:00
Devin Coughlin
b906a54fbd [Sema] Remove unnecessary check for potentially unavailable inferred type parameter actuals
This commit removes an unnecessary check that ensured that inferred type
parameter actuals are available. This check is unnecessary because the
declaration for any inferred actual type parameter (i.e., a generic type
argument at the callsite) must be referred to in an enclosing type refinement
context. If the inferred type is not available, this reference will cause a
diagnostic to be emitted, so we don't need to emit another diagnostic for the
inferred actual. Further, this diagnostic was potentially confusing because the
point at which we emitted the diagnostic did not directly mention the type
name (because it was inferred).

This commit also beefs up testing of diagnostics for potentially unavailable
type parameters.

Swift SVN r25540
2015-02-26 02:39:16 +00:00
Chris Lattner
1f91a63399 remove dead out parameter and newly dead result value, NFC.
Swift SVN r25538
2015-02-26 01:27:01 +00:00
Chris Lattner
99aa4352b2 remove upgrading support for the old @class_protocol attribute.
Swift SVN r25526
2015-02-25 02:04:06 +00:00
Chris Lattner
a9e69c0c36 Take a bozooka out to fix <rdar://problem/19932544> refine error for using @autoclosure and @noescape on the same decl
We didn't have a consistent way to utter attributes in diagnostics, sometimes saying the

'foo' attribute is not allowed
@foo attribute is not allowed
'foo' is not allowed
@foo is not allowed

etc.  Standardize on the last one, since it is clear (with the @ sign, with no quotes, with no
'attribute' word in the diagnostic) that we're talking about an attribute.  Move a bunch of
diagnostics inline with this.



Swift SVN r25524
2015-02-25 01:19:04 +00:00
Jordan Rose
746d835ab9 Don't require "self." in local functions.
(unless the local functions are themselves within closures not inferred
@noescape)

Swift SVN r25513
2015-02-24 21:51:13 +00:00
Chris Lattner
3357ee21f3 Revert r25417, r25408, and r25370. This adds back back the warning for
un-type-annotated AnyObject binding in "if let", and allows general 
patterns in if-let.

This also reverts some unrelated QoI improvements that went in with those
patches, but I'll add those back next.


Swift SVN r25507
2015-02-24 18:55:54 +00:00
Chris Willmore
df706b04b5 Don't reuse ostream for multiple strings when generating result names.
<rdar://problem/19919467> Interpreter/repl.swift regressed under ASan

Swift SVN r25495
2015-02-24 01:09:51 +00:00
Chris Willmore
fc561cd7ea Fix errant fixit "as!" -> "as?!"
"let x: Int? = 5 as Any as! Int" now suggests changing "as!" to "as?"
instead of "as?!".

rdar://problem/19883819

Swift SVN r25490
2015-02-23 22:59:46 +00:00
Jordan Rose
c411348f61 When chaining to a non-designated initializer, warn about the superclass.
...i.e. the immediate superclass, rather than the class that declared the
initializer.

Test also contains Doug's suggested test fix-up for r25410.

Swift SVN r25487
2015-02-23 22:52:39 +00:00
Chris Lattner
eba7aade70 fix <rdar://problem/19763732> False positive in @noescape analysis triggered by default arguments
This was a bug in miscdiagnostics not handling parenexprs inside of scalartotuple expr.


Swift SVN r25455
2015-02-21 01:38:06 +00:00
Chris Lattner
b0db122925 fix rdar://19763676 - False positive in @noescape analysis triggered by parameter label
This changes CSApply to propagate the noescape (and noreturn) bits into a closureexpr even
when the closure type is undergoing some sort of conversion, since the conversion doesn't
affect the semantics of these bits.



Swift SVN r25454
2015-02-21 01:36:19 +00:00
Devin Coughlin
7ea8aa82ea [Sema] Validate declaration version range availability within lexical scope
This commit validates @availability() attribute version ranges to ensure that
a declaration is not more available than its lexically containing scope. To do so,
we find the inner-most declaration containing an @availability attribute that itself
has an @availability attribute and check that first attribute's available
version range is contained in the enclosing declaration's available range. If not,
we emit a diagnostic.

This commit removes a FIXME for checking @availability and overrides. It appears that
the FIXME is a copy/paste to/from AttributeOverrideChecker, where it still resides.

Swift SVN r25453
2015-02-21 01:34:38 +00:00
Chris Lattner
56bf85cc5f fix <rdar://problem/19874152> Swift 1.2 struct memberwise initializer violates new sanctity of previously set let property
If a non-static 'let' field in a struct has an initializer, its implicitly generated
memberwise initializer should not override that.  Handle this by having the memberwise initializer
and default initializer use the initial value of the property instead of an argument to the init.

This would have been a lot easier if sema was synthesizing the ctor bodies instead of SILGen,
but here it is.  The missing case is narrow (let (x,y) = (1,2)) and for now we just disable
implicit synthesization of the incorrect case.



Swift SVN r25424
2015-02-20 07:26:57 +00:00
Chris Willmore
72814a8c13 Use llvm::SaveAndRestore instead of reinventing it.
Swift SVN r25423
2015-02-20 07:22:53 +00:00
Doug Gregor
b1959c93dc Stop allowing archetype-based substitutions in TypeBase::getTypeOfMember().
Swift SVN r25395
2015-02-19 18:13:58 +00:00
Doug Gregor
ecdd30330d Eliminate another case where we were performing substitutions via archetypes.
Interface types are better. Use them.

Swift SVN r25394
2015-02-19 18:13:57 +00:00
Doug Gregor
7ef5ba9ff9 Perform override checking prior to (and independent of) @objc computation.
Always perform override checking based on the Swift type
signatures, rather than alternately relying on the Objective-C
selectors. This ensures that we get consistent override behavior for
@objc vs. non-@objc declarations throughout, and we separately make
sure that the Objective-C names line up.

This also allows us to inherit @objc'ness correctly (which didn't
quite work before), including inferring the Objective-C selector/name
(the actual subject of rdar://problem/18998564).

Fixes rdar://problem/18998564.

Swift SVN r25392
2015-02-19 06:29:34 +00:00
Doug Gregor
a3b4b0903b Teach TypeChecker::resolveTypeInContext to use interface types more often.
When referring to a type declaration that is a member of some nominal
type, we were relying on substitution into the non-interface type,
which is silly. Use the interface type here.

Other than some type-printing differences, this should be NFC.

Slight regression in two compiler crashes that had been fixed in the
previous commit; I'll look into these shortly.

Swift SVN r25385
2015-02-19 00:58:44 +00:00
Doug Gregor
2b9308dbcb Update ConstraintLocator profiling for witnesses and associated types.
Use an exhaustive switch rather than a cascading "if", so we don't
make similar mistakes in the future.

Swift SVN r25382
2015-02-18 23:36:43 +00:00
Doug Gregor
3638f78723 Fix the Fix-It location for insertion of @objc (rdar://problem/19879598).
This is a band-aid; all declarations should consider attributes in
their source range calculations.

Swift SVN r25379
2015-02-18 23:00:20 +00:00
Chris Willmore
4cf775f37a For class C and protocol P, C.Type is not convertible to P.Protocol.
Swift SVN r25376
2015-02-18 19:58:28 +00:00
Doug Gregor
3805e18090 Explicitly track the mapping from dependent types to their opened type variables.
Previously, we were reconstructing this mapping from the "full" opened
type produced by declaration references. However, when dealing with
same-type constraints between associated types and type parameters, we
could end up with an incomplete mapping, which let archetypes slip
through. Most of the churn here is sorting out the locators we need to
use to find the opened-type information. Fixes rdar://problem/18208283
and at least 3 dupes of it that I've found so far.

Swift SVN r25375
2015-02-18 19:41:40 +00:00
Doug Gregor
476c65c180 Add a locator path element for candidate protocol witnesses. NFC
Swift SVN r25374
2015-02-18 19:41:37 +00:00
Chris Lattner
079173ce5b Dial back the warning about "type inferred to AnyObject may be unexpected" in an if/let
conditional context.  There is no point diagnosing it here (just like a foreach loop) because
the if/let is just unwrapping the optional in the initializer expression.

Removing this requirement eliminates a bunch of extraneous type annotations in the testsuite.



Swift SVN r25370
2015-02-18 06:13:11 +00:00
Joe Groff
c660b539f7 ClangImporter: Don't try to provide an elementwise initializer for partially-imported structs.
It doesn't make sense to try to construct a partially-imported struct elementwise in Swift. We don't know what all the fields are yet. Part of rdar://problem/19807099.

Swift SVN r25366
2015-02-18 02:40:13 +00:00
Nadav Rotem
f5910bbe62 Fix a warning.
Swift SVN r25354
2015-02-17 18:43:17 +00:00
Chris Willmore
fdf4c035e9 Only suggest appending 'as! T' if there's a chance that the conversion would succeed.
<rdar://problem/19831919> Fixit offers as! conversions that are known to always fail

Swift SVN r25346
2015-02-17 03:42:52 +00:00