Commit Graph

3502 Commits

Author SHA1 Message Date
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
Xi Ge
560b08c171 SyntaxModel: simplify the collecting of contextual keywords in PrecedenceGroup.NFC (#11819) 2017-09-08 12:38:44 -07:00
Jordan Rose
f8b7db4e76 Excise the terms "blacklist" and "whitelist" from Swift source. (#11687)
The etymology of these terms isn't about race, but "black" = "blocked"
and "white" = "allowed" isn't really a good look these days. In most
cases we weren't using these terms particularly precisely anyway, so
the rephrasing is actually an improvement.
2017-08-30 09:28:00 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
David Ungar
5662c4b5dc Remove redundant getMembers
Also make LazyMemberLoader abstract
Add "final" to (Class|Protocol|Enum|Struct)Decl classes
2017-08-18 20:09:20 -07:00
Slava Pestov
ef87a5bbfb Sema: Fix crash with invalid 'let' property in protocol
Fixes <rdar://problem/25185722>.
2017-08-16 18:17:38 -04:00
Tony Allevato
a3db968057 Move derivesProtocolConformances from AST to Sema 2017-08-08 18:30:22 -07:00
Tony Allevato
425de49454 [Sema] Synthesize Eq/Hash for enums with payloads, structs 2017-08-08 18:20:58 -07:00