Commit Graph

635 Commits

Author SHA1 Message Date
Graydon Hoare
ce28efbf5e [NamedLazyMemberLoading] Tolerate mid-flight getMembers() calls better. 2017-12-01 16:52:25 -08:00
Graydon Hoare
3e76aebee1 [NamedLazyMemberLoading] Support named loading from ObjC categories. 2017-12-01 16:52:25 -08:00
Graydon Hoare
464dc1bcc1 [NamedLazyMemberLoading] Use per-IDC recursion-breaking flag, not sentinel.
The empty sentinel in the lookup table caused recursion-breaking to bottom
out in slightly different order than the old eager code, making certain
order-sensitive tests fail.
2017-12-01 16:52:25 -08:00
Graydon Hoare
a6701a8cce [NamedLazyMemberLoading] Give up trying to break recursion on clang-imported init for now. 2017-12-01 16:52:25 -08:00
Arnold Schwaighofer
eba12a7c3e Revert "Finish and default-enable named lazy member loading" 2017-12-01 07:25:54 -08:00
Graydon Hoare
094ee2fd27 [NamedLazyMemberLoading] Tolerate mid-flight getMembers() calls better. 2017-11-30 22:29:12 -08:00
Graydon Hoare
a967f8c6ea [NamedLazyMemberLoading] Support named loading from ObjC categories. 2017-11-30 22:27:58 -08:00
Graydon Hoare
9e1859469c [NamedLazyMemberLoading] Use per-IDC recursion-breaking flag, not sentinel.
The empty sentinel in the lookup table caused recursion-breaking to bottom
out in slightly different order than the old eager code, making certain
order-sensitive tests fail.
2017-11-30 22:18:25 -08:00
Graydon Hoare
dfc67d6b93 [NamedLazyMemberLoading] Give up trying to break recursion on clang-imported init for now. 2017-11-30 22:02:42 -08:00
Graydon Hoare
bfde4f564c [NamedLazyMemberLoading] Don't self-add extn members to partial tables. 2017-11-10 15:55:34 -08:00
Graydon Hoare
bbeec57182 [NamedLazyMemberLoading] Handle case of source extension on deserialized type. 2017-11-03 00:35:03 -07:00
Graydon Hoare
ed0b43cbce [NamedLazyMemberLoading] Move SerialID to IDC, get extensions working. 2017-11-01 17:35:46 -07:00
Graydon Hoare
f96c0d9b63 [NamedLazyMemberLoading] Address review comments. 2017-11-01 17:35:46 -07:00
Graydon Hoare
e9fbd2ce53 [NamedLazyMemberLoading] Add diagram + comment of IDC + MemberLookupTable. 2017-11-01 17:34:56 -07:00
Graydon Hoare
2d36f5cdae [NamedLazyMemberLoading] Use NominalTypeDecl::LookupTable as proper cache. 2017-11-01 17:34:56 -07:00
Graydon Hoare
30b6fdce83 Merge pull request #12429 from graydon/named-lazy-member-loading
Named lazy member loading 1/N
2017-10-24 14:27:04 -07:00
Slava Pestov
28efca5785 AST: Short-circuit isSetterAccessibleFrom() for ParamDecls 2017-10-22 20:05:00 -07:00
Graydon Hoare
cb1c8526c8 [NamedLazyMemberLoading] Address further review comments. 2017-10-20 22:48:45 -07:00
Graydon Hoare
99cbcde518 [NamedLazyMemberLoading] Debug logging. 2017-10-20 22:48:43 -07:00
Graydon Hoare
125c85f9a1 [NamedLazyMemberLoading] Wire into NominalTypeDecl::lookupDirect. 2017-10-20 22:48:42 -07:00
David Ungar
443ab7d950 git-clang-format 2017-09-26 18:02:35 -07:00
David Ungar
90b456b116 Use if (auto for getting Stats 2017-09-26 17:32:38 -07:00
David Ungar
a41a3c9fa5 compiles using movable guards 2017-09-26 17:22:58 -07:00
David Ungar
2af86f5cac First compiling run, WIP 2017-09-26 16:07:07 -07:00
Slava Pestov
a2e7f363f3 AST: Split off LazyConformanceLoader from LazyMemberLoader 2017-09-11 22:34:43 -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
c3e3d45396 Instrument NominalTypeDecl::lookupDirect
Also implement RecursiveSharedTimer
2017-08-23 14:53:53 -07:00
Rintaro Ishizaki
eb6914ccfc Merge pull request #11346 from rintaro/rip-cfor
Eliminate C-style ForStmt
2017-08-08 07:49:42 -07:00
Slava Pestov
8c98b7a306 AST: Fix a crasher with unqualified lookup
If the DeclContext's Self type-in-context is an ErrorType,
we should still resolve generic parameters to interface types.
2017-08-06 00:21:49 -07:00
Rintaro Ishizaki
a375267e5c [ASTScope] Remove ForStmt support. 2017-08-04 23:27:22 +09:00
Slava Pestov
7db4c9075c AST: Change LookupResultEntry to store a DeclContext instead of a base ValueDecl
Storing a DeclContext allows us to distinguish type
members from extension members just by looking at the
lookup result.
2017-07-18 22:09:55 -07:00
Slava Pestov
fb9d410350 AST: Rename UnqualifiedLookupResult => LookupResultEntry
There's a similar LookupResult::Result type in Sema, and I'd like
to combine the two.
2017-07-18 22:09:02 -07:00
Itai Ferber
e86428559a Expose synthesized members in AST lookups
Some types and members are synthesized by derived protocol conformances
(e.g. the CodingKeys member type or init(from:)/encode(to:) members
from Decodable/Encodable conformance) — however, they are not visible
in AST lookup if they have not been synthesized.

Exposes a LazyResolver callback for performing member synthesis where
relevant during qualified lookups to synthesize these members on demand
when needed.
2017-07-13 13:27:08 -07:00
Slava Pestov
d91d811df7 AST: Restore old behavior for name lookup inside 'lazy' in Swift 3 mode
Restore the old Swift 3 behavior for source compatibility reasons:

- Unqualified lookup finds static properties (but not static methods)
  first, then global members.

- Qualified lookup into 'self' is still supported.

There's no change in Swift 4 mode, where the newer more correct
behavior is enabled.

Fixes <rdar://problem/32570766>.
2017-06-05 23:14:33 -07:00
Jordan Rose
325a96983e [AST] Preparations for removal of getName on ValueDecl (#9969)
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:04:19 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

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:55:03 -07:00
Slava Pestov
51aebd2127 AST: Fix name lookup from within lazy property initializers
Allow instance properties and methods to be referenced from
within a lazy property initializer, with or without explicit
'self.' qualification.

The old behavior in Swift 3 was an incredible combination
of odd quirks:

- If the lazy property had an explicitly-written type, it was
  possible to reference instance members from the initializer
  expression by explicitly prefixing 'self.'.

- However, if the lazy property type is inferred, it would
  first be type checked in the initializer context, which
  has no 'self' available.

- Unqualified references to instance members did not work
  at all, because name lookup thought the "location" of the
  lookup was outside of the body of the getter.

- Unqualified references to static properties worked, however
  unqualified references to static methods did not, and
  produced a bogus diagnostic, because one part of the name
  lookup code thought that initializers were "instance
  context" and another thought they were "static context".

This patch improves on the old behavior with the following
fixes:

- Give PatternBindingInitializers associated with lazy
  properties an implicit 'self' declaration for use by
  name lookup.

- In order to allow "re-parenting" the initializer after it
  has been type checked into the body of the getter, "steal"
  the initializer's 'self' when buiding the getter.

- Fix up name lookup and make it aware of the implicit
  'self' decl of a PatternBindingInitializer.

This improves upon an earlier fix for this issue by Doug Gregor
which only worked with ASTScope enabled; the new fix is more
general and shares logic between the two name lookup
implementations.

Fixes <rdar://problem/16888679>, <https://bugs.swift.org/browse/SR-48>,
<https://bugs.swift.org/browse/SR-2203>,
<https://bugs.swift.org/browse/SR-4663>, and the countless other
dupes of this issue.
2017-05-24 18:59:48 -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
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -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
5447443c5b Add support for sharing the private scope between type declaration and extensions in Swift 4 2017-04-28 10:02:49 -04:00
Slava Pestov
9c3b514c7e AST: New getExistentialLayout() method on TypeBase and CanType
This consolidates calculations which need to look at every
protocol in an existential type. Soon we will also have to
deal with superclass constrained existentials, so start
updating call sites that look at all protocols to use the
new ExistentialLayout and correctly handle a class constraint
as well.

Also, eventually I will kill off the AnyObject protocol and
model it as a protocol composition with no protocols or
superclass, but the requiresClass() flag set.

This is not quite modeled this way yet and AnyObject still
exists, but the new abstraction is a step in the right
direction.
2017-04-10 17:04:37 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Slava Pestov
ab74f6b143 AST: Simplify name lookup a little 2017-04-03 23:14:17 -07:00
Jordan Rose
4b0255d5d3 [ClangImporter] Always load a class's members before any categories.
This ensures that any @property redeclarations that appear in class
extensions (a special kind of category in ObjC) do not affect the
primary type of the property as declared in the class itself.

To accomplish this, lookups in importDecl that are checking for
conflicts now no longer pull in new categories/extensions if the
current context is a ClassDecl.

rdar://problem/30785976
2017-03-30 15:21:08 -07:00
Jordan Rose
67f29eb470 Remove default from DeclAttributes::isUnavailableInSwiftVersion. (#8208)
If this had a default, it should be the effective language version,
not the compiler language version. That is, in the Swift 4 compiler's
Swift 3 mode, we want to be acting like Swift 3, not Swift 4.
2017-03-20 12:37:56 -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