Commit Graph

3561 Commits

Author SHA1 Message Date
Slava Pestov
cece98b2ed AST: Generalize ClassDecl::checkObjCAncestry() to ClassDecl::checkAncestry()
This replaces ClassDecl::hasObjCMembers() and some hand-coded walks.
2019-03-26 18:42:59 -04:00
Slava Pestov
a2049972ca AST: Add ModuleDecl::isResilient()
This cleans up some code. I'm keeping the ResilienceStrategy enum around
though, in case we want to use it to version the ABI in the future.
2019-03-26 18:42:59 -04:00
Xi Ge
bc9a7dd821 AST: fix a null pointer error found by performing module API checking 2019-03-26 13:03:10 -07:00
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
swift-ci
35f5c7afb3 Merge pull request #23538 from davezarzycki/diag_qoi_SelfAccessKind 2019-03-25 14:23:42 -07:00
David Zarzycki
f99124569b [Diag] Formalize SelfAccessKind printing 2019-03-25 15:40:26 -04:00
Michael Gottesman
b50d878f5d [parse/sema] Give all case bodies their own var decls without using those var decls for anything.
This is a step in the direction of fixing the fallthrough bug. Specifically, in
this commit I give case stmts a set of var decls for the bodies of the case
statement. I have not wired them up to anything except the var decl
list/typechecking.

rdar://47467128
2019-03-25 10:30:57 -07:00
Azoy
dcedba73f0 fix lazy vars
clean up lazy vars

more docs
2019-03-20 23:01:38 -05:00
Suyash Srijan
25e0a9f749 [Typechecker] Fix an issue with redeclaration checking (#23227)
* [typechecker] fix an issue with redeclaration checking

* [typechecker] use mapSignatureFunctionType in getOverloadSignatureType() to compute the type for the enum element decl, etc

* [typechecker] allow matching enums to functions as well, not just functions to enums

* [typechecker] fix the check for two enums

* [typechecker] check for nominal types as well when comparing enum elements

* [test] add more tests

* [typechecker] check for typealias as well
2019-03-20 00:25:42 -04:00
swift-ci
611534cc77 Merge pull request #23378 from gottesmm/pr-5d07f093c8b0891046d822d507c526e7ec6cfc1d 2019-03-18 16:23:24 -07:00
Michael Gottesman
b1a7b488fd [sema] Wire up VarDecl parent pointers for case stmt related Var Decls
This is in preparation for fixing issues around SILGenPattern fallthrough
emission and bad rename/edit all in scope of case stmt var decls. Specifically,
I am going to ensure that we can get from any VarDecl in the following to any
other VarDecl:

switch x {
case .a(let v1, let v2), .b(let v1, let v2):
  ...
  fallthrough
case .c(let v1, let v2), .d(let v1, let v2):
  ...
}

This will be done by:

1. Pointing the var decls in .d at the corresponding var decls in .c.
2. Pointing the var decls in .c at the corresponding var decls in .b.
3. Pointing the var decls in .b at the corresponding var decls in .a.
4. Pointing the var decls in .a at the case stmt. Recognizing that we are asking
for the next VarDecl, but have a case stmt, we check if we have a fallthrough
case stmt. If so, follow down the fallthrough case stmts until you find a
fallthrough case stmt that doesn't fallthrough itself and then return the
corresponding var decl in the last case label item in that var decl (in the
above .d).

In a subsequent commit I am going to add case body var decls. The only change as
a result of that is that I will insert them into the VarDecl double linked list
after the last case var decl of each case stmt.
2019-03-18 14:13:10 -07:00
Arnold Schwaighofer
a2c651504c Merge pull request #23337 from aschwaighofer/support_dynamic_replacement_of_stored_with_observer
Add support for dynamic replacement of didSet/willSet
2019-03-18 11:18:21 -07:00
Arnold Schwaighofer
35ca0e3423 Add support for dynamic replacement of didSet/willSet
The observer in a dynamic replacement of variables with a observer will
provide the dynamic replacement for the original.

var original : Int = 0 {
  didSet {
    print("original")
  }
}

@_dynamicReplacement(for: original)
var replacement : Int = 0 {
  didSet {
    print("replacement")
  }
}

rdar://48518788
2019-03-15 16:30:03 -07:00
Pavel Yaskevich
d8d5190518 [AST] Allow access-scope based access check inside inaccessible members
This aids expression diagnostics to pinpoint problems related to
chaining of inaccessible members  e.g.

```swift
struct A {
  struct B {}
}

_ = A.B()
```

Here both `B` and its synthesized constructor are inaccessible.
2019-03-15 15:58:11 -07:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Arnold Schwaighofer
1719f0cdf1 Serialization: Also serialize the filename for internal storage decls with private accessors
If a value decl is internal hasTestableOrPrivateImport will succeed (or
fail) without looking at the filename. However this breaks when we query
an internal storage decl with private formal access for a private
setter: the query would fail because no filename was serialized for the
decl (we only serialize filenames for private decls). So in the special
case of a internal storage with private accessor also serialize the
filename.

rdar://48516545
2019-03-04 13:12:39 -08:00
Slava Pestov
b9bda84e28 SIL: Fix calls of @_weakLinked functions from serialized SIL
We have to set the SILFunction's 'weakLinked' flag in the defining
module too, so that it can be serialized. Otherwise when we
deserialize it we are not weak linking calls to the function.
2019-02-22 21:10:18 -05:00
Slava Pestov
3bf5a175a3 AST: Check the availability context from Decl::isWeakImported()
Fixes <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Slava Pestov
69d1cafd1c AST: Add AvailabilityContext parameter to Decl::isWeakImported()
For now, it's not used, but we do try to pass the right value down from
our various call sites.

Progress on <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Arnold Schwaighofer
17e64f5e9c Merge pull request #22691 from aschwaighofer/allow_dynamic_replacement_init_non_delegating
Allow dynamic replacement initializers to be non delegating
2019-02-19 08:38:08 -08:00
Arnold Schwaighofer
d5b33ba303 Only allow non resilient non-delegating initializers for now 2019-02-18 15:01:03 -08:00
Slava Pestov
bd6490b391 SIL: Introduce '@_alwaysEmitIntoClient' attribute for use by standard library
This is like '@inlinable', except that the symbol does not have a public
entry point in the generated binary at all; it is deserialized and a copy
is always emitted into the client binary, with shared linkage.

Just like '@inlinable', if you apply this to an internal declaration it
becomes '@usableFromInline' automatically.

This uses the same mechanism as default arguments ever since Swift 4, so
it should work reasonably well, but there are rough edges with diagnostics
and such. Don't use this if you are not the standard library.

Fixes <rdar://problem/33767512>, <https://bugs.swift.org/browse/SR-5646>.
2019-02-18 17:10:57 -05:00
Arnold Schwaighofer
8f0fbd2c75 Allow dynamic replacement initializers to be non delegating
rdar://48125765
2019-02-18 10:26:59 -08:00
Davide Italiano
4d7a4b5d16 Merge pull request #22477 from dcci/not_lldb_fault_anymore_maybe
[Decl] Remove a workaround introduced to appease lldb.
2019-02-12 11:01:40 -08:00
Davide Italiano
8bbb26eb56 [Decl] Remove a workaround introduced to appease lldb.
Probably at some point this was true, but it's not the case
anymore.
2019-02-08 09:51:51 -08:00
Slava Pestov
dffa29fd0d AST: Remove a few uses of FunctionType::Param::getOldType() 2019-02-07 23:46:31 -05:00
Rintaro Ishizaki
6e44205c2f Merge pull request #22411 from johnfairh/assoctype-default-loc
[IDE] Fix sourcerange for assoc types with default values
2019-02-06 12:29:46 -08:00
John Fairhurst
f841d45185 [IDE] Fix sourcerange for assoc types with default values 2019-02-06 18:10:41 +00:00
Doug Gregor
d19d2f2490 [AST] Lazily compute ProtocolDecl::getKnownProtocolKind()
Rather than eagerly doing a bunch of name lookups to establish the known
protocol kind, lazily match the ProtocolDecl to the list of known
protocols as-needed. This eliminates a bunch of up-front unqualified
name lookups when spinning up a type checker.
2019-02-04 21:25:48 -08:00
Rintaro Ishizaki
32ebfa4761 [AST] Comment tweak 2019-01-22 15:38:13 -08:00
Slava Pestov
eef3efbe42 AST: Cache ProtocolDecl::getInheritedProtocols()
Fixes <rdar://problem/47371754>.
2019-01-18 15:36:27 -05:00
Slava Pestov
acb37b2b55 AST: Set ClassDecl's HasDestructor bit in one place 2019-01-18 00:15:41 -05:00
Slava Pestov
a8d1910552 AST: Cache SuperclassDeclRequest
This fixes a significant build time regression since 4.2.

Fixes <rdar://problem/47305605>.
2019-01-15 23:24:36 -05:00
Pavel Yaskevich
b78ffa77e8 [AST] If access control is disabled adjust declaration access to maximum openness
This is a follow-up to https://github.com/apple/swift/pull/21783
which made `is{Setter}AccessibleFrom` respect `-disable-access-control`
flag. Now it's `getAdjustedFormalAccess` turn to do the same.
2019-01-14 21:26:11 -08:00
Pavel Yaskevich
69c622fc06 Merge pull request #21783 from xedin/rdar-30933988
[AST] `Decl::is*AccessibleFrom` methods should respect access control…
2019-01-14 14:06:44 -08:00
Rintaro Ishizaki
b446d6b051 Merge pull request #21377 from rintaro/ide-contextinfo
[SourceKit][IDE] New SourceKit request to retrieve context type information
2019-01-15 01:54:16 +09:00
Pavel Yaskevich
da8f384b22 [AST] Move get{Setter}FormalAccess' calls into checkAccess from is*AccessibleFrom` 2019-01-11 17:51:15 -08:00
Pavel Yaskevich
ddc2fa415e [AST] NFC: introduce ASTContext::isAccessControlDisabled 2019-01-11 17:30:10 -08:00
Pavel Yaskevich
5426e0df9e [AST] Decl::is*AccessibleFrom methods should respect access control flag
Otherwise integrated REPL and other tools like LLDB would produce
incorrect results or crash.

Resolves: rdar://problem/30933988
2019-01-11 17:30:10 -08:00
Rintaro Ishizaki
d17bb78a0b [AST] Add shouldHideFromEditor() method
This replaces shouldHideDeclFromCompletionResults() in IDE.
2019-01-10 17:52:36 +09:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Slava Pestov
716ac81b3e AST: Cache protocol generic signature in GenericContext::getGenericSignature()
The generic signature of a protocol is simple enough that we can
build it directly when asked. However, be sure to cache it for
future use.
2019-01-08 22:58:12 -05:00
Nathan Hawes
c3723fd4d7 [sourcekitd][AST] Fix CursorInfo crash on method with unresolved default value
When printing its annotated decl, we would would assume the param's default
value is present if the default value kind was "Normal". The type checker
explicitly sets the default value to nullptr if it doesn't type check though, so
we were crashing for that case. Added the check.

Resolves rdar://problem/46694149
2018-12-21 18:13:53 -08:00
Slava Pestov
bfcf24ee4e AST: Rework @objcMembers inheritance to not depend on validation order
Sema would directly check for the presence of the @objcMembers attribute,
and inherit it from the immediate superclass in validateDecl().

We don't want validateDecl() to have side effects like this and this was
already a problem, because it would not inherit the attribute transitively
in some cases.

Instead, add a ClassDecl::hasObjCMembers() method that walks over all
ancestors and caches the result.

<rdar://problem/46420252>
2018-12-12 15:12:38 -05:00
Slava Pestov
bc4aa75b35 AST: Simplify GenericSignatureBuilder::computeRequirementSignature() 2018-12-11 23:55:41 -05:00
Slava Pestov
544e0a02d5 AST: Don't link together GenericParamLists of nested generic types
GenericParamList::OuterParameters would mirror the nesting structure
of generic DeclContexts. This resulted in redundant code and caused
unnecessary complications for extensions and protocols, whose
GenericParamLists are constructed after parse time.

Instead, lets only use OuterParameters to link together the multiple
parameter lists of a single extension, or parameter lists in SIL
functions.
2018-12-11 23:55:41 -05:00
Slava Pestov
c0bfaaf30f AST: Merge ProtocolDecl::createGenericParams() into createGenericParamsIfMissing() 2018-12-11 23:55:41 -05:00
Slava Pestov
7a038ff817 AST: Refactor ExtensionDecl::createGenericParamsIfMissing()
Let's use the same code path for protocol and non-protocol extensions;
we still have to do something special for protocol extensions though.
2018-12-11 23:22:18 -05:00
Slava Pestov
78e56079ed AST: Introduce ExtensionDecl::createGenericParamsIfMissing()
For now Sema still calls it manually, but soon we could make
getGenericParams() lazy, calling this automatically, since
there's really no reason to create the generic parameters
upfront when binding the extension.
2018-12-11 17:48:52 -05:00
Slava Pestov
1ca81c42b4 AST: Factor out GenericParamList::configureGenericParamDepth() 2018-12-11 17:48:52 -05:00