Commit Graph

3502 Commits

Author SHA1 Message Date
Jordan Rose
3cf00637fa AST-verify that 'open' is only used on classes and overridable members (#15996)
...and fix places where it was being used inappropriately.

- Don't use 'open' on non-class members in the importer.
- Use the existing 'copyFormalAccessFrom' instead of an ad hoc version
  for synthesized typealiases for protocol conformances. (This can
  change 'internal' down to 'fileprivate', but only where the
  enclosing type was already 'private' or 'fileprivate'.)
- Fix 'copyFormalAccessFrom' to not copy '@usableFromInline' onto
  declarations that don't support it (namely, the above typealiases).

This should have no visible effect in practice.
2018-04-18 16:47:54 -07:00
Jordan Rose
28a1dc7770 Use 'fileprivate' for synthesized members of 'private' decls (#15980)
Since 'private' means "limit to the enclosing scope (and extensions
thereof)", putting it on a member means that the member can't be
accessed everywhere the type might show up. That's normally a good
thing, but it's not the desired effect for synthesized members used
for derived conformances, and when it comes to class initializers this
actually violates AST invariants.

rdar://problem/39478298
2018-04-17 15:19:35 -07:00
Slava Pestov
b4e145dc34 SE-0193: @inlinable implies @usableFromInline 2018-04-06 00:02:29 -07:00
Slava Pestov
05ea885465 AST: More renaming of 'versioned' things 2018-04-05 16:09:44 -07:00
Slava Pestov
ff56a074af AST: Clean up the terminology around @usableFromInline in a couple of places 2018-04-05 14:31:32 -07:00
Huon Wilson
a23808f5d2 [AST] Introduce 'resolveExtensionForConformanceConstruction' for lazier conformance searching.
We need to be able to find which conformances need to be
declared/constructed without forcing extensions to be completely
validated. This is important for both SR-6569 and
rdar://problem/36499373. The former due to the source-level recursion,
and the latter because implied conformances weren't always
constructed (but are needed for good diagnostics).

They weren't always constructed because:

1. ConformanceLookupTable's updateLookupTable on an early stage (before
   implied conformances are found) triggers extension
   validation *before* constructing any conformances, but *after*
   updating the stage state
2. extension validation validates the conditional requirements
3. validating the conditional requirements requires setting up generic
   signatures
4. setting up generic signatures forces the types conformances and so
   ends up in updateLookupTable on the same nominal again, skipping over
   the earlier stages that are complete/in progress
5. we expand the conformances that are implied by all the conformances we
   know about... But we don't know any, because we haven't finished the
   first updateLookupTable.

This breaks the loop at step 2: we instead do the minimal work needed to
know what conformances an extension (might) declare, which is connect
the extension to a type, and then resolve the inherited TypeReprs to
Types.
2018-04-04 10:34:33 +10:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Xi Ge
7224ef84bb Merge pull request #15595 from johnfairh/whither-where
[SourceKit] Include trailing where clause in SourceRange
2018-03-29 10:58:55 -07:00
John Fairhurst
f99321a092 [SourceKit] Include trailing where clause in SourceRange 2018-03-29 11:38:21 +01:00
Doug Gregor
a506f602ea Merge branch 'master' into redeclaration-fixes 2018-03-27 21:59:50 -07:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Doug Gregor
69099a8f8b Merge pull request #15527 from DougGregor/typealias-from-debugger
[AST] Skip verification of typealiases marked as "debugger aliases".
2018-03-26 16:50:31 -07:00
Doug Gregor
9aaa1f146a [AST] Skip verification of typealiases marked as "debugger aliases".
LLDB creates global typealiases that have archetypes in them, which
violates AST invariants and trips up the AST verifier. Introduce a specific
bit that LLDB can set to indicate that a given typealias is such an alias.
We'll skip AST verification for such typealiases.

As a way to stage in this change without requiring synchronization
across the Swift and LLDB repos, also match typealiases with the names
$.*lldb in the AST verifier and skip verification. Once LLDB is
setting the bit appropriately, we'll remove this hack.
2018-03-26 15:47:54 -07:00
Jordan Rose
9d72a2b9dc Merge pull request #15280 from hamishknight/didset-recursion
[Sema] Only directly access members within didSet if accessed on 'self'
2018-03-26 15:33:46 -07:00
Doug Gregor
b2b69e8abf Rename BoundNameAliasType to NameAliasType.
NameAliasType is dead! Long live NameAliasType!
2018-03-25 21:35:17 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Hamish
4b0cbc0f35 [Sema] Limit #15280 to Swift 5 mode 2018-03-25 17:58:19 +01:00
Hamish
5f43627235 [Sema] Revise #15280 in response to feedback
Instead of passing the base expression of a member access to `getAccessSemanticsFromContext`, we now just pass a bool flag for whether this is a member access on the implicit 'self' declaration.
2018-03-24 21:13:47 +00:00
Hamish
8a78e15a0f [Sema] Only directly access members within didSet if accessed on 'self'
Currently we always directly access a member when mutating it in its own didSet/willSet observer (in order to prevent infinite recursion). However we also do this even when accessing the same member on a *different* instance.

This commit changes the behaviour such that only member accesses on the implicit 'self' declaration are accessed directly within that member's own willSet/didSet.

Note that this change has the potential to cause recursion in cases where it didn't previously, for example this will now infinitely recurse:

    struct S {
      var i = 0 {
        didSet {
          var s = self
          s.i = 5
        }
      }
    }

    var s = S()
    s.i = 2

I don't know how serious this impact is though.

Resolves SR-419.
2018-03-24 21:13:47 +00:00
Hamish
ae8b125f82 [Sema] Revise #15412 in response to feedback (2)
- Emit a warning in Swift 4 for performing a redeclaration that will be illegal in Swift 5

- Minor fixes
2018-03-24 15:44:27 +00:00
Hamish
d9401d64dc [Sema] Revise #15412 in response to feedback
- Reuse existing logic to curry the signature type with the 'self' of the context (in addition we no longer use a MetatypeType for the 'self' of a static member as they don't have conflicting signatures with instance members anyway)

- Limit the fix for SR-7251 to Swift 5 mode

- Add tests for generic subscripts
2018-03-23 01:09:14 +00:00
Hamish
dee1590ae2 [Sema] Fix several redeclaration checking bugs
Currently we only give subscripts and var decls custom overload types if they're in generic extensions. However, because we give them no custom overload type in any other case, we don't detect for example a conflict with a previous declaration in the body of the extended type.

This commit changes the overload type logic such that properties and subscripts are always given custom overload types, which is determined by:

- The interface type of the decl (for subscripts only; as variables cannot be overloaded by type)
- The 'self' type of the context, if any
- The generic signature of the context, if any

Additionally, this commit adds a new `swift::conflicting` overload to ensure that different declarations always conflict even if their overload types are different.

Resolves SR-7249, SR-7250 & SR-7251.
2018-03-22 11:42:29 +00:00
Jordan Rose
d150f96967 Merge pull request #14945 from jrose-apple/frozen-enums
Implementation for /most/ of SE-0192 (frozen and non-frozen enums)
2018-03-21 11:06:31 -07:00
Jordan Rose
1b1a4cb22e [PrintAsObjC] Use enum_extensibility to represent @_frozen
Previously (a03c40cb2c) we assumed all Swift enums were non-frozen in
ObjC, a weird choice in retrospect. Now that we actually distinguish
frozen and non-frozen enums in Swift, we can use the
'enum_extensibility' attribute to mark them as open or closed in ObjC.

Note that this only matters for Swift libraries compiled with
-enable-resilience, i.e. those that might get a new implementation at
runtime. Everyone else is now declaring a "closed" enum, matching the
behavior in Swift.
2018-03-20 14:49:11 -07:00
Jordan Rose
7e3aaff78d Treat exhaustive enums as "non-resilient", and add a few more tests
"Formally non-resilient" in this new world means "the enum has a fixed
representation", which implies a fixed layout algorithm. We're not
there yet, but non-exhaustive enums should be able to be fixed-layout
as well by picking a general representation that won't need to grow.
Specifically, that's enums with raw types, and possibly also indirect
enums as well.

(It's likely the '_fixed_layout' /attribute/ on enums will go away,
but the concept of a fixed-layout enum is still useful.)
2018-03-20 11:49:23 -07:00
Jordan Rose
7c60f1c895 Diagnose uncovered switches on non-frozen enums
Warn in Swift 4 mode and error in Swift 5 mode when switching on a
non-frozen enum without providing a default case.

Note that this is a preliminary implementation, in order to test the
rest of the feature.
2018-03-20 10:39:02 -07:00
Jordan Rose
8a66d998fa Decide if a class inherits convenience inits alongside implicit inits
We have a predicate in ClassDecl, 'inheritsSuperclassInitializers',
that is used in a few places to decide if we need to do lookups into a
superclass to find all relevant initializers. That's useful, but the
actual work being computed in that function is almost identical to the
work done in figuring out whether the class has provided all its
superclass's /required/ initializers, which is part of the type
checker operation 'resolveImplicitConstructors'. Furthermore,
'inheritsSuperclassInitializers' is /already/ calling
'resolveImplicitConstructors' because those implicit constructors
might affect the result.

Simplify this whole mess and prevent further inconsistencies like the
previous commit by just making 'resolveImplicitConstructors' decide
whether superclass convenience initializers are inherited. It does
make that function more complicated, but with the benefit of not
having duplication anymore.

No intended user-visible change, except that this bit is now
serialized instead of being recomputed, which means the module format
changed.
2018-03-19 18:28:41 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Slava Pestov
615d068d63 Sema: Replace some uses of getBaseIdentifier() with userFacingName() 2018-03-14 22:26:58 -07:00
Robert Widmann
dac06898e9 [SE-0194] Deriving Collections of Enum Cases
Implements the minimum specified by the SE-proposal.

* Add the CaseIterable protocol with AllCases associatedtype and
allCases requirement
* Automatic synthesis occurs for "simple" enums
    - Caveat: Availability attributes suppress synthesis.  This can be
              lifted in the future
    - Caveat: Conformance must be stated on the original type
              declaration (just like synthesizing Equatable/Hashable)
    - Caveat: Synthesis generates an [T].  A more efficient collection
              - possibly even a lazy one - should be put here.
2018-03-09 00:22:55 -05:00
Sho Ikeda
74ba135008 Merge pull request #15040 from ikesyo/gardening-not-empty
[gardening] Use `!empty()` over `size() > 0`
2018-03-08 18:47:12 +09:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Huon Wilson
78bdc95ce3 Merge pull request #14874 from huonw/at-owned-cleanup
Various refactorings for __owned.
2018-03-02 14:20:21 -08:00
Huon Wilson
12871d75bc [AST] Introduce "ValueOwnership" collecting __shared, inout, etc.
This is designed to stop having to n bits to track each of the
mutually exclusive 'shared', 'inout' and eventually 'owned'.
2018-03-02 11:40:20 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Stephan Tolksdorf
79cef77ce0 [AST] Remove unused LazyResolver parameter from ObjC-selector-related Decl methods 2018-02-27 01:11:35 +01:00
Jordan Rose
30b2f05466 Handle 'import struct Foo' where Foo is a non-nominal typealias (#14797)
Previously this just crashed. Now it suggests `import typealias Foo`,
a syntax that works back to Swift 1.

rdar://problem/36756349
2018-02-26 11:50:04 -08:00
Graydon Hoare
76b82accbc [Stats] Simplify FrontendStatsTracer uses and formatter-definitions. 2018-02-21 14:49:24 -08:00
Graydon Hoare
6f46362f38 [Stats] Improve stats tracing readability a little. 2018-02-21 14:49:24 -08:00
Jordan Rose
1785855934 Merge pull request #14660 from jrose-apple/one-weak-since-you-looked-at-me
Add @_weakSymbol and a corresponding SIL attribute
2018-02-21 11:22:26 -08:00
Jordan Rose
aa85e4512f Don't force inlinable constructors to delegate in non-resilient code (#14721)
This restriction came from wanting to make resilient and non-resilient
code follow the same rules whenever possible, but after thinking about
it a bit more we realized there was no reason why you /wouldn't/ just
mark your structs @_fixed_layout in non-resilient libraries anyway.
Since that (currently?) doesn't affect what you can do with the struct
across module boundaries, and since the layout of the struct is
available anyway in a non-resilient library, there's no real downside,
which means it's a meaningless restriction.

The same logic doesn't /quite/ apply to classes, since classes are
normally much more flexible than structs. (For example, you could add
a stored property to a class without recompiling clients, as long as
no initializers are inlined.) But it's close enough that we don't want
to put in the restriction at this time.

All of this is about attributes that haven't been finalized yet anyway
(hence the leading underscore), but it's still useful information.

rdar://problem/37408668
2018-02-21 10:15:58 -08:00
Jordan Rose
bb339778b4 Add @_weakLinked and a corresponding SIL attribute
This is mostly intended to be used for testing at this point; in the
long run, we want to be using availability information to decide
whether to weak-link something or not. You'll notice a bunch of FIXMEs
in the test case that we may not need now, but will probably need to
handle in the future.

Groundwork for doing backward-deployment execution tests.
2018-02-20 17:55:31 -08:00
Huon Wilson
c6ab136112 Merge pull request #14628 from huonw/no-conditional-objc-generics
[Sema] Disallow conditional conformances on objective-c generics.
2018-02-16 09:14:50 +11:00
Huon Wilson
50b6d10a4e [NFC] Move TypeOrExtensionDecl out of PrintOptions.h. 2018-02-15 16:58:24 +11:00
Doug Gregor
fd5d3afb61 [Type checker] Tolerate missing generic environments better.
Before matching witnesses, ensure that we have a valid signature, and be
more tolerant of null generic environments by using the
mapTypeIntoContext entry point meant to handle null.

We haven't managed to get a decent reproducer for this, but it's
happening often enough, and this change hardens the affected code
paths.

Should fix rdar://problem/37255982.
2018-02-12 14:31:11 -08:00
Mark Lacey
7f805ba2bc Replace classifyAsOptionalType with isOptionalDecl. 2018-02-05 23:59:00 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08:00