Commit Graph

399 Commits

Author SHA1 Message Date
Slava Pestov
6ac2dde97e Sema: Enforce inlinable restrictions for stored property initializers in fixed layout types
We want stored property initializers of fixed layout structs to be
inlinable, so that inlinable initializers can be fully eliminated
by the optimizer.

This is the first step in fixing <rdar://problem/36454839>.
2018-01-12 00:06:03 -08:00
David Zarzycki
13cafad3a7 [AST] NFC: Avoid nullptr comparisons
There is some worry in GitHub PR #13795 that future compilers might
optimize away the whole assert because of the nullptr comparison.
2018-01-08 21:52:38 -05:00
David Zarzycki
dc43a4a51f [AST] NFC: Feedback from Jordan 2018-01-08 21:01:01 -05:00
David Zarzycki
887471d613 [AST] NFC: Feedback from Jordan; plus micro-optimizations 2018-01-08 17:01:52 -05:00
David Zarzycki
0e1251648c [AST] NFC: DeclContext micro-optimizations 2018-01-08 13:33:49 -05:00
David Zarzycki
e9b643026b [AST] NFC: Stop over aligning DeclContexts
DeclContexts as they exist today are "over aligned" when compared to
their natural alignment boundary and therefore they can easily cause
adjacent padding when dropped into the middle of objects via C++
inheritance, or when the clang importer prefaces Swift AST allocations
with a pointer to the corresponding clang AST node.

With this change, we move DeclContexts to the front of the memory layout
of AST nodes. This allows us to restore natural alignment, save memory,
and as a side effect: more easily avoid "over alignment" in the future
because DeclContexts now only need to directly track which AST node
hierarchy they're associated with, not specific AST nodes within each
hierarchy.

Finally, as a word of caution, after this change one can no longer
assume that AST nodes safely convert back and forth with "void*". For
example, WitnessTableEntry needed fixing with this change.
2018-01-08 12:21:14 -05:00
David Zarzycki
7bede89a9b [AST] NFC: Repack misc IterableDeclContext bits 2017-12-10 20:38:01 -05:00
Graydon Hoare
8bcfafe23d Merge pull request #13216 from graydon/force-on-named-lazy-member-loading-retry
Force on named lazy member loading retry
2017-12-04 01:00:15 -08:00
Jordan Rose
ace0f56e9c Be way more conservative about marking dependencies as non-cascading (#13214)
Being part of the type of a private declaration isn't sufficient,
because that could be used for the inferred type of a non-private
variable/constant/property.

Also, introduce a new kind of dependency test that shows both that a
file A changes its interface based on a change in another file B, and
that the swiftdeps output for file A includes the dependency on file B
as cascading.

https://bugs.swift.org/browse/SR-6149
2017-12-01 18:35:18 -08:00
Graydon Hoare
7a9bc26fd9 [NamedLazyMemberLoading] Handle nominals with mix of added/lazy members. 2017-12-01 16:52:26 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
f07cde75e7 AST: Move mapTypeOutOfContext() from GenericEnvironment to TypeBase
It doesn't actually *use* the generic environment.
2017-11-15 22:52:13 -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
ed0b43cbce [NamedLazyMemberLoading] Move SerialID to IDC, get extensions working. 2017-11-01 17:35: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
Doug Gregor
a92d8d5760 [Cleanup] Reduce dependencies on swift/AST/LazyResolver.h. 2017-10-10 10:01:39 -07:00
Tony Allevato
715ba632dd Merge branch 'master' into synthesize-equatable-hashable 2017-10-09 15:57:36 -07:00
David Ungar
90b456b116 Use if (auto for getting Stats 2017-09-26 17:32:38 -07:00
Tony Allevato
f2c434a038 Merge branch 'master' into synthesize-equatable-hashable 2017-09-21 22:54:36 -07:00
Slava Pestov
ab242bd448 AST: Fix some warnings 2017-09-20 12:56:44 -07:00
Slava Pestov
2fe8fea875 AST: Remove DeclContext::getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Slava Pestov
400693b811 AST: Store the default argument resilience expansion in the AbstractFunctionDecl
Previously we stored this inside each default argument
initializer context. This was overkill, because it is
the same for all default arguments in a single function,
and also insufficient, because initializer contexts are
not serialized and thus not available in SILGen when
the function is in a different module.

Instead store it directly inside the function and
serialize it.

NFC for now, since SILGen isn't using this yet.
2017-09-15 16:20:45 -07:00
Tony Allevato
3731382bf6 Merge branch 'master' into synthesize-equatable-hashable 2017-09-09 14:23:13 -07:00
Slava Pestov
9f55deccaa AST: Fix an unused variable warning 2017-09-01 02:04:22 -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
Tony Allevato
6dfa87d0ba [AST] Add DeclContext.getAsStructOrStructExtensionContext 2017-08-08 18:20:58 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Andrew Trick
c312c3737b Fix DeclContext::printContext to emit a single hex prefix "0x".
LLVM's raw_ostream already formats (void*) as a hexadecimal representation using
HexPrintStyle::PrefixLower.
2017-07-17 14:06:27 -07:00
Doug Gregor
623d72db3c [AST] Make the "requirement signature" of a protocol a flat array.
Rather than pretend that the requirement signature of a protocol is a
full, well-formed generic signature that one can meaningfully query,
treat it as a flat set of requirements. Nearly all clients already did
this, but make it official. NFC
2017-06-29 14:01:49 -07:00
Slava Pestov
151f38630b AST: Fix DeclContext::getAsTypeOrTypeExtensionContext() for extensions of typealiases 2017-06-21 00:44:32 -07:00
Slava Pestov
89dc5afa57 Sema: Targeted fix for bad interaction between resilience checks and -enable-testing
The -enable-testing flag makes ValueDecl::getEffectiveAccess()
say that internal declarations are public.

This would lead us to emit spurious diagnostics if a default
argument of an internal function referenced a private symbol,
for example, which is something we actually want to allow.

This is a second revision of the patch -- instead of changing
getEffectiveAccess() to take an extra parameter, this changes
getFormalAccessScope() instead.

Fixes <rdar://problem/32592973>.
2017-06-08 01:35:44 -07:00
Slava Pestov
7cfa34952a Revert "Sema: Targeted fix for bad interaction between resilience checks and -enable-testing"
This reverts commit 66173a9b97.
2017-06-07 22:06:54 -07:00
Slava Pestov
66173a9b97 Sema: Targeted fix for bad interaction between resilience checks and -enable-testing
The -enable-testing flag makes ValueDecl::getEffectiveAccess()
say that internal declarations are public.

This would lead us to emit spurious diagnostics if a default
argument of an internal function referenced a private symbol,
for example, which is something we actually want to allow.

Hack around this by adding a new 'forLinkage' parameter to
getEffectiveAccess(). When this is false, we ignore the
-enable-testing flag, and only look for the @_versioned
attribute.

I'm not very happy with the fix, because it only compliates
the subtle behaviors of getFormalAccess(), getEffectiveAccess()
and getFormalAccessScope() further. But refactoring this is
a bigger change than I'm willing to put into swift-4.0-branch.

Fixes <rdar://problem/32592973>.
2017-06-07 21:43:37 -07:00
Slava Pestov
c49a1d77d2 AST: Stricter DeclContext::getParentForLookup() 2017-06-06 23:56:32 -07:00
Doug Gregor
ea20a1d137 [AST] Add DeclContext::get(Syntactic|Semantic)Depth.
Utilities functions used when comparing declaration contexts. Only the syntactic form is currently used (for the owning DC of a generic environment).
2017-06-01 08:25:42 -07:00
Alex Hoppen
f302afc97f Unify approach to printing declaration names (#9320)
Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:25:20 -07:00
Slava Pestov
5197f38cda AST/Serialization: Some assertions for extensions
These helped me rule out my first theory about another bug, even
though it turned out to be unrelated.
2017-05-22 14:18:23 -07:00
Doug Gregor
f792aeaf1a [AST] Teach the AST verifier not to deserialize generic environments.
The AST verifier was causing deserialization of generic environments,
which slows things down considerably and affects our ability to test
for laziness in deserialization. Prevent it from doing so---and only
do the extra checkig if something else deserialized the generic
environment already.

... except there are some cases where it happens through means that
are harder to control (e.g., the AST walker for patterns) that need
more thought.
2017-05-16 11:03:15 -07:00
Slava Pestov
2fe863266c AST: Fix crashes when name lookup finds declarations outside of a protocol or extension that's nested in another type
When performing a name lookup from inside of a protocol
or extension, skip directly to the source file context
when we are done visiting the protocol or extension.

Otherwise, if we have invalid code where the protocol
or extension is nested inside another type, we might
find a member whose type contains generic parameters
of the outer type; these parameters will not resolve,
since we do not model protocols or extensions nested
inside generic contexts (yet?).

This supercedes an earlier workaround for a similar
issue; the new workaround fixes more crashes.

This is needed to avoid crasher regressions with an
upcoming patch.
2017-05-07 03:01:47 -07:00
ematejska
75a1dcaf28 Merge pull request #9098 from KingOfBrian/feature/SE-0169
SE-0169: Add support for shared private
2017-05-02 16:12:17 -07:00
Brian King
0dce9b7e3d Store the private scope context in the AccessScope constructor to fix equality support 2017-04-28 17:02:04 -04:00
Graydon Hoare
b5292f04f8 Add an assortment of new "always-on" metrics. 2017-04-28 13:56:13 -07:00
Brian King
0a1d52e738 Update the language and method names to avoid the term 'shared private' 2017-04-28 16:37:00 -04:00
Brian King
b3d44e06fa Do not use GNU ternary extension 2017-04-28 15:52:11 -04:00
Brian King
5447443c5b Add support for sharing the private scope between type declaration and extensions in Swift 4 2017-04-28 10:02:49 -04:00
David Hart
ecdcac5aa2 Resolve crasher 28704 (#8158)
This crash happens because shouldAddSelfFixit (a check for the expected_self_before_reference diagnotic) performs name lookup inside the parser, which causes a search for extensions, which triggers the mangler, which can get confused if we are in an unfinished declaration (a PatternBindingInitilizer in this case).

A cleaner fix would be to move that logic inside Sema, but it would require much more refactoring that I don’t feel comfortable doing. Instead, this band-aid checks if the innermost type is inside a local context. If that’s the case, we can ignore the search for extensions.
2017-03-17 18:43:23 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Slava Pestov
880803aaba AST: Initial plumbing for generic subscripts 2017-02-19 21:34:26 -08:00