Commit Graph

3561 Commits

Author SHA1 Message Date
Graydon Hoare
fe6b5b0051 [AST] Mark implicit destructor as @objc 2017-11-09 22:32:42 -08:00
Alex Hoppen
746bfc6d59 [Refactoring] Add refactoring action to move type members to extension (#12795)
This implements SR-6297.
2017-11-09 11:08:34 -08:00
Graydon Hoare
798f1e19b0 [AST] Address review comments. 2017-11-06 15:50:50 -08:00
Graydon Hoare
cf2c753616 [AST] Do type/attr setup in ClassDecl::addImplicitDestructor. 2017-11-06 14:42:52 -08:00
Graydon Hoare
6d46fb144f [AST] Move copyFormalAccess to ValueDecl. 2017-11-06 14:31:21 -08:00
Slava Pestov
e805100f96 Sema: Fix source compatibility break with default initialization of optional properties
In Swift 4, properties declared with a sugared Optional type,
like Int?, have a default value of nil. This can be observed
in two ways:

- Classes and structs get an implicit no-argument initializer
- Designated initializers don't have to initialize this property

Note that this did not apply in general to properties where
the type was spelled explicitly as Optional<Int>, etc, mostly
because of implementation restrictions -- when we check if a
type has implicit initializers, we have not realized types for
all stored property members yet, and doing so is not really
possible without the iterative decl checker.

However, in some cases, we *did* perform default initialization
for Optional<Int>, because of some code duplication and
divergent code paths.

A recent refactoring cleaned up some of the mess in this area,
but accidentally broke source compatibility with code that
relied on the broken Optional<Int> case.

Fix this by simulating the old behavior in -swift-version 4,
and preserving the more correct behavior in -swift-version 5.

Fixes <rdar://problem/35319847>.
2017-11-04 23:40:24 -07:00
Graydon Hoare
7e363ff97a [AST] Add implicit dtors outside typechecking, rdar://35198678 2017-11-04 02:59:52 -07:00
Doug Gregor
3a3e96cf66 Set the outer generic parameters of a protocol extension properly.
Fixes two compiler crashers.
2017-10-27 23:41:08 -07:00
Slava Pestov
363904e3dd AST: Ensure various computeType() methods are only called once 2017-10-22 20:05:00 -07:00
Slava Pestov
15fa6c8955 AST: Call setValidationStarted() on synthesized declarations
This avoids doing unnecessary work in validateDecl().
2017-10-22 20:05:00 -07:00
Doug Gregor
0d42fbf691 [GSB] Delay realization of potential archetypes for conformance requirements.
While here, consolidate PotentialArchetype::addConformance() into
EquivalenceClass::recordConformanceConstraint().
2017-10-17 21:00:24 -07:00
Slava Pestov
065cbd8015 AST: Struct initializers that assign to self can now be resilient
Initializers for non-fixed-layout structs that are inlinable or
are defined in a different module are treated as delegating
initializers.

Previously, only initializers containing a 'self.init' call were
delegating; initializers that assigned to 'self' were not, which
resulted in DI treating them as a root initializer where the
stored 'self' value was exploded into a series of stores to each
stored property member.

They were not resilient as a result.

Fixes <https://bugs.swift.org/browse/SR-5649>,
<rdar://problem/33767516>.
2017-10-13 23:51:15 -07:00
Slava Pestov
b5eeae7446 DI: All enum initializers should be delegating
Again, since there's no distinction between an enum initializer that
delegates to 'self.init' from one that assigns to 'self', we can remove
the special handling of enum initializers in the 'root self' case.

Now, 'root self' is only used for designated initializers in classes
with no superclass, and struct initializers that perform memberwise
initialization of stored properties.

This regresses some diagnostics, because the logic for delegating
init diagnostics is missing some heuristics present in the root self
case. I will fix this in a subsequent patch.
2017-10-13 23:51:15 -07:00
Slava Pestov
0c16aedb60 DI: All protocol extension initializers should be delegating
Previously protocol extension initializers which called 'self.init' were
considered 'delegating', and ones that assign to 'self' were considered
'root'.

Both have the same SIL lowering so the distinction is not useful, and
removing it simplifies some code.
2017-10-13 23:51:14 -07:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Slava Pestov
124251cf2c Merge pull request #9619 from allevato/synthesize-equatable-hashable
Synthesize Equatable/Hashable for complex enums, structs
2017-10-10 18:22:40 -07:00
Graydon Hoare
ea1307cbeb Merge pull request #12190 from graydon/objc-protocols-can-always-be-existential
[ProtocolDecl] Avoid getMembers(), imported ObjC protocols can always be existential.
2017-10-10 17:54:12 -07:00
Tony Allevato
ddaa390a62 Merge branch 'master' into synthesize-equatable-hashable 2017-10-10 01:39:48 -07:00
swift-ci
7aa9839b68 Merge pull request #12351 from adrian-prantl/18296829 2017-10-09 17:07:09 -07:00
Tony Allevato
715ba632dd Merge branch 'master' into synthesize-equatable-hashable 2017-10-09 15:57:36 -07:00
Adrian Prantl
44aa4822e0 Debug Info: Represent private discriminators in DWARF.
... using an inline namespace as the parent of the outermost
declaration(s) that have private or fileprivate accessability. Once
LLDB supports this we can retire the existing hack of storing it as a
fake command line argument.

rdar://problem/18296829
2017-10-09 15:32:06 -07:00
Mishal Shah
08a404c014 Merge pull request #12346 from adrian-prantl/18296829
Revert
2017-10-09 13:44:27 -07:00
Doug Gregor
d3de4f2321 Merge pull request #12321 from DougGregor/assoc-type-overrides
Track "overrides" of associated types
2017-10-09 12:59:21 -07:00
Adrian Prantl
dd3ac0e043 Revert "Debug Info: Represent private discriminators in DWARF."
This reverts commit 0aea1c0528 while investigating bot breakage.
2017-10-09 12:55:37 -07:00
adrian-prantl
53ca3b78e2 Merge pull request #12280 from adrian-prantl/18296829
Debug Info: Represent private discriminators in DWARF.
2017-10-09 09:13:15 -07:00
Doug Gregor
ea1396c364 [GSB] Only build potential archetypes for associated type "anchors".
Use the "override" information in associated type declarations to provide
AST-level access to the associated type "anchor", i.e., the canonical
associated type that will be used in generic signatures, mangling,
etc.

In the Generic Signature Builder, only build potential archetypes for
associated types that are anchors, which reduces the number of
potential archetypes we build when type-checking the standard library
by 14% and type-checking time for the standard library by 16%.

There's a minor regression here in some generic signatures that were
accidentally getting (correct) same-type constraints. There were
existing bugs in this area already (Huon found some of them), while
will be addressed as a follow-up.

Fies SR-5726, where we were failing to type-check due to missed
associated type constraints.
2017-10-07 21:52:40 -07:00
Doug Gregor
15386fa0bf [AST] Track overriding relationship among associated types.
When an associated type declaration “overrides” (restates) an associated
type from a protocol it inherits, note that it overrides that declaration.
SourceKit now reports overrides of associated types.
2017-10-07 21:52:40 -07:00
Adrian Prantl
0aea1c0528 Debug Info: Represent private discriminators in DWARF.
... using an inline namespace as the parent of the outermost
declaration(s) that have private or fileprivate accessability. Once
LLDB supports this we can retire the existing hack of storing it as a
fake command line argument.

rdar://problem/18296829
2017-10-06 15:17:25 -07:00
Graydon Hoare
b156fbe354 Merge pull request #12305 from graydon/clang-importees-have-no-associated-type-members
[AST] Avoid getMembers() calls in contexts that only need associated types.
2017-10-06 10:07:10 -07:00
Graydon Hoare
51d759e0f1 [AST] Add dedicated lazier-path to getting protocol associated types. 2017-10-06 01:55:47 -04:00
Graydon Hoare
880c1b8566 [ProtocolDecl] Avoid getMembers(), imported ObjC protocols can always be existential. 2017-10-05 15:31:43 -04:00
Roman Levenstein
692575ffb1 Remove ResilientStrategy::Fragile 2017-10-04 14:50:16 -07:00
Doug Gregor
0609785b64 [AST] Strip InOutType when cloning a parameter.
Fixes rdar://problem/34789779, where initializer inheritance was breaking
in the presence of 'inout' parameters.
2017-10-04 10:59:16 -07:00
Doug Gregor
2f9c18639d [GSB] Kill off resolveArchetype().
This is somewhat of a pyrrhic victory, because it was just a shell over
resolvePotentialArchetype() anyway, but we now have fewer entry points that
produce potential archetypes.
2017-09-28 15:47:57 -07:00
Doug Gregor
0a1583fb87 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-28 14:27:15 -07:00
Doug Gregor
8f5d8aa7f9 Revert "[GSB] Centralize, clean up, and cache nested type name lookup" 2017-09-25 13:43:10 -07:00
Doug Gregor
a048194041 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-25 08:47:40 -07:00
Doug Gregor
9fa2a8bdca Don’t create a new generic signature builder for non-generic members.
When type-checking a function or subscript that itself does not have generic
parameters (but is within a generic context), we were creating a generic
signature builder which will always produce the same generic signature as
the enclosing context. Stop creating that generic signature builder.

Instead, teach the CompleteGenericTypeResolver to use the generic signature
+ the canonical generic signature builder for that signature to resolve
types, which also eliminates some extraneous re-type-checking.

Improves type-checking performance of the standard library by 36%.
2017-09-24 22:23:00 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
Doug Gregor
eccdedaf97 Merge pull request #12062 from DougGregor/make-fewer-gsbs
Create fewer generic signature builders
2017-09-22 18:38:27 -07:00
Doug Gregor
76a532b3af [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-22 17:11:05 -07:00
Doug Gregor
115d81a327 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-22 11:32:26 -07:00
Doug Gregor
98a255994d Don’t create a new generic signature builder for non-generic members.
When type-checking a function or subscript that itself does not have generic
parameters (but is within a generic context), we were creating a generic
signature builder which will always produce the same generic signature as
the enclosing context. Stop creating that generic signature builder.

Instead, teach the CompleteGenericTypeResolver to use the generic signature
+ the canonical generic signature builder for that signature to resolve
types, which also eliminates some extraneous re-type-checking.

Improves type-checking performance of the standard library by 36%.
2017-09-22 11:32:25 -07:00
Tony Allevato
f2c434a038 Merge branch 'master' into synthesize-equatable-hashable 2017-09-21 22:54:36 -07:00
swift-ci
abe34f804b Merge pull request #11902 from itaiferber/factor-out-isdefaultinitializable 2017-09-20 11:32:39 -07:00
Itai Ferber
cda3bf19aa Factor isDefaultInitializable logic for reuse
Factors isDefaultInitializable logic from
TypeChecker::addImplicitConstructors (and others) so it can be reused
for Codable synthesis.
2017-09-20 09:45:25 -07:00
Slava Pestov
379c15842a AST: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:28 -07:00
Jordan Rose
8685141d7d 'open' classes within 'public' structs should be considered open. (#11925)
Without this, our hack to give all open class vtable members public
linkage at the LLVM level wasn't kicking in, and subclasses from
other modules were getting link errors.

rdar://problem/32885384
2017-09-19 11:12:09 -07:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04:00
Tony Allevato
3731382bf6 Merge branch 'master' into synthesize-equatable-hashable 2017-09-09 14:23:13 -07:00