Commit Graph

696 Commits

Author SHA1 Message Date
Doug Gregor
b4acc38730 [Type checker] Drop parameter 'inout' types in a few more places.
Follow-up to my earlier changes to drop 'inout' types when cloning parameter
lists, we also need to deal with substitutions into those parameter types.
This is an artifact of us having mostly---but not entirely---removed
InOutType from the AST. Fixes rdar://problem/34818336.
2017-10-04 21:18:05 -07:00
Slava Pestov
02204f08c3 Sema: Synthesized delegating initializers inherit the @_inlineable attribute
Also add a test that deinits can be declared @_inlineable, but this is not
 a new feature, it was just previously untested.
2017-09-25 16:23:07 -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
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
Slava Pestov
55916fa128 Sema: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Slava Pestov
731a2f26aa Sema: Fix unused variable warning 2017-09-19 00:04:26 -07:00
Slava Pestov
f3e9aa35a7 Sema: Inherited initializers inherit the @_versioned attribute
Fixes <rdar://problem/34398148>.
2017-09-16 00:23:14 -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
Slava Pestov
194b80049c Sema: Lazy property setters should not be transparent
A lazy property setter stores a value to the underlying storage
of the lazy property. The underlying storage is private, and it
is not proper for a public transparent function body to reference
a private member.

In practice, this only failed if the private member had a
non-constant offset, which only occurs with subclasses of @objc
classes, and resilient classes.

For @objc classes we already had a workaround where no accessors
for stored properties are ever transparent. I put this in to fix
this very issue with lazy properties, but now I realize it was
the wrong workaround, because we still had this problem with
resilient classes.

Note that I'm keeping the logic which made @objc accessors
non-transparent in place, because there's a good chance we will
decide that field offset globals should always be private.

Also, to make this issue reproducible in the test, I changed the
resilience execution tests to build the resilient library as a
dylib and link against that instead of just linking .o files
together. This is because .o files can see each other's internal
symbols, so I was not able to reproduce the original failure
this way. I went ahead and updated the other resilient tests to
do this as well. Also, each test now builds in WMO and non-WMO
mode, to exercise different SIL linking behavior. Again, the
WMO variant was needed to reproduce the issue fixed by this
commit, because without WMO we currently discard serialized SIL,
so no cross-module inlining of the lazy property setter was
taking place.
2017-08-29 01:22:11 -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
Robert Widmann
76a4935d16 Staging for __consuming
Pushes __consuming through the frontend and extends existing
attribute-based diagnsotics to cover it.  Unlike `nonmutating`,
__consuming is allowed in class methods, though it makes little
sense to put it there.
2017-08-23 12:19:00 -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
Robert Widmann
d019485e36 Address review comments 2017-07-19 12:38:23 -07:00
Robert Widmann
8cdddef2f8 Refactor Params to use flags
Also, begin to pass around base types instead of raw InOutType types.  Ideally, only Sema needs to deal with them, but this means that a bunch of callers need to unwrap any inouts that might still be lying around before forming these types.

Multiple parts of the compiler were slicing, dicing, or just dropping these flags.  Because I intend to use them for the new function type representation, I need them to be preserved all across the compiler.  As a first pass, this stubs in what will eventually be structural rules as asserts and tracks down all callers of consequence to conform to the new invariants.

This is temporary.
2017-07-19 09:49:32 -07:00
Slava Pestov
83684eb08a Sema: Remove LookupResult::Entry in favor of AST's LookupResultEntry
Both types store a base declaration and a result declaration;
we can remove one. Soon, it will change to store a base
declaration context, instead.
2017-07-18 22:09:19 -07:00
Robert Widmann
f11779572c Replace setLet with setSpecifier 2017-07-05 14:41:59 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
e423d8c0b2 Remove duplicated conveniences 2017-07-05 14:01:07 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Jordan Rose
77de3dc1f2 [AST] Bring 'mutating' and 'inout self' in sync. (#10375)
- A mutating method or accessor always has 'inout self'.
- A nonmutating method or accessor never has 'inout self'.
- Only instance members can be mutating.
- Addressors are still addressors even when on static members.

Came up after reviewing another patch that confused the two as
possibly distinct concepts.
2017-06-19 16:16:47 -07:00
Slava Pestov
c4df92aef3 Sema: Clean up 'dynamic' inference a bit 2017-06-07 17:55:42 -07:00
Slava Pestov
345a8b7eea Sema: Fix bug where lazy properties could become stored sometimes
If synthesizeWitnessAccessorsForStorage() got called on a lazy
property before maybeAddAccessorsToVariable(), we would build
it as a stored property instead.

This count result in bogus diagnostics, assertions and bad runtime
behavior.

Fixes <https://bugs.swift.org/browse/SR-1825>.
2017-05-26 16:59:23 -07:00
Slava Pestov
ab7d22277c AST: Remove LazyResolver::introduceLazyVarAccessors() 2017-05-24 19:03:50 -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
73976b2134 Sema: Remove TypeChecker::getTypeOfRValue() 2017-05-24 01:56:21 -07:00
Jordan Rose
03b38534a6 Make sure to inherit 'dynamic' when inheriting initializers. (#9400)
Uncovered by Slava's bcbd1d2, which infers 'dynamic' in more places,
but this was always a problem when an initializer was /explicitly/
marked 'dynamic'.

rdar://problem/32026930
2017-05-08 17:38:14 -07:00
Jordan Rose
6c098033de Lift the decision of whether a method needs a vtable slot up to AST.
This lets us serialize that decision, which means we can conceivably
/change/ the decision in later versions of the compiler without
breaking existing code. More immediately, it's groundwork that will
eventually allow us to drop decls from the AST without affecting
vtable layout.

This isn't actually a great answer; what we really want is for SIL
vtables to be serialized consistently and treated as the point of
truth. But that would be more change than we're comfortable taking in
the Swift 4 timeframe.

First part of rdar://problem/31878396.
2017-05-04 17:49:47 -07:00
Jordan Rose
e575d2d5ba [ClangImporter] Error structs from enums are not imported decls.
Enums with the ns_error_domain attribute represent codes for NSError,
which means Swift developers will expect to interact with them in
terms of Error. SE-0112 improved bridging for these enums to generate
a struct with the following form:

    struct MyError: Error {
      @objc enum Code: RawRepresentable {
        case outOfMemory
        case fileNotFound
      }
      var userInfo: [NSObject: AnyObject] { get }
      static var outOfMemory: Code { get }
      static var fileNotFound: Code { get }
    }

where MyError.Code corresponds to the original MyError enum defined in
Objective-C. Until recently, both the enum and the synthesized struct
were marked as having the original enum as their "Clang node", but
that leads to problems: the struct isn't really ObjC-compatible, and
the two decls have the same USR. (The latter had already been worked
around.)

This commit changes the struct to be merely considered a synthesized
"external definition", with no associated Clang node. This meant
auditing everywhere that's looking for a Clang node and seeing which
ones applied to external definitions in general.

There is one regression in quality here: the generated struct is no
longer printed as part of the Swift interface for a header file, since
it's not actually a decl with a corresponding Clang node. The previous
change to AST printing mitigates this a little by at least indicating
that the enum has become a nested "Code" type.
2017-04-24 09:57:41 -07:00
Doug Gregor
d9af96ffe4 [AST] Remove more interface-type redundancy from ProtocolConformance. 2017-04-18 17:15:15 -07:00
Slava Pestov
c1c54d1462 Sema: Fix materializeForSet for members of extensions of imported classes
An assertion I added recently to check property overrides in
the ASTVerifier uncovered some bugs in this area:

- We did not synthesize a materializeForSet for properties
  defined in extensions of imported classes unless they
  witnessed a protocol requirement.

  This triggered an assertion if the property had an
  override that was checked before the protocol conformance,
  since the override's materializeForSet would not be marked
  as an override of the base materializeForSet.

- materializeForSet for properties defined in extensions would
  statically dispatch the getter and setter instead of dynamically
  dispatching. This is incorrect since we statically dispatch
  to the materializeForSet in this case, and we can in fact
  override it in a subclass.

Fixes <rdar://problem/31334272>.
2017-04-02 23:43:41 -07:00
Slava Pestov
e1ad85b082 Sema: Don't synthesize materializeForSet if Optional type is missing
This fixes a regression in one of the SIL crashers.
2017-04-02 23:43:41 -07:00
Slava Pestov
aebf843dda SIL: Addressors don't need vtable entries
In the old vtable emission code, IRGen would skip addressors,
but they had entries in the SILVTable. This is still correct
behavior, so skip addressors explicitly in SILVTableVisitor.

We never call addressors dynamically, only inside a getter,
setter or materializeForSet. When a property with addressors
is overridden we provide new getters and setters (which may
or may not statically dispatch to a peer addressor).
2017-03-23 20:36:12 -07:00
Slava Pestov
38f27c0496 Sema: Always add synthesized accessors in the same spot
We had some non-deterministic behavior where depending on
validation order, synthesized accessors would end up in
different places because we would sometimes just add them
at the end of the member list.

Now add the getter right after the storage, the setter
right after the getter and the materializeForSet right
after the setter.

This changes some test output where the declaration order
did not make sense before but should otherwise have no
functional effect.
2017-03-23 18:17:41 -07:00
practicalswift
3144f4ce1a [gardening] Remove unused variable superclassSig 2017-03-17 08:22:11 +01:00
Slava Pestov
46600b5f1a Sema: Remove gatherAllSubstitutions() usage 2017-03-08 13:54:30 -08:00
Doug Gregor
ec4bf005af [AST] Eliminate unnecessary #includes of AST/ProtocolConformance.h. 2017-03-01 08:22:39 -08:00
Slava Pestov
928a74c47e Parse: Support for generic subscripts 2017-02-23 21:14:02 -08:00
Slava Pestov
32316559f8 AST: Stored property accessors on non-Objective-C derived classes can be transparent
In 74d979f0ac, the policy was changed
so that only value type accessors are ever marked transparent, and
not class accessors.

This was intended to fix a bug where inlining an accessor of an
Objective-C-derived class across module boundaries caused a linker
failure because the accessor referenced a field offset variable,
which has hidden visibility.

However, this also caused a performance regression for Swift native
classes. Bring back the old behavior for Swift native classes in
non-resilient modules.

Fixes <rdar://problem/29884727>.
2017-02-14 22:35:27 -08:00
Slava Pestov
9331d3f5bb AST: Remove unnecessary SubstOptions() parameters to Type::subst() 2017-02-12 00:51:27 -08:00
Slava Pestov
85a8a50bee Merge pull request #7295 from slavapestov/introduce-substitution-list
AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
2017-02-06 22:36:03 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
06de5d70c1 Sema: Use dynamic dispatch for inout access of properties in classes
The problem is that the derived property's materializeForSet was
being synthesized after recordOverride() was called, so the new
accessor never got setOverridenDecl() called on it.

As a result, SIL didn't know that the derived materializeForSet
should replace the vtable entry for the base class materializeForSet.

The more fundamental problem here is that even after some recent
cleanups, accessors are still sometimes type checked before
the AbstractStorageDecla and sometimes after. So things like
inferring final, dynamic and overrides have to be duplicated in
multiple places.

Fixes <https://bugs.swift.org/browse/SR-3840> and
<rdar://problem/30336146>.
2017-02-06 19:34:30 -07:00
Slava Pestov
7ce643a637 Revert "Sema: Fix materializeForSet overrides" 2017-02-03 19:56:18 -08:00
Slava Pestov
293227aaa0 Sema: Use dynamic dispatch for inout access of properties in classes
The problem is that the derived property's materializeForSet was
being synthesized after recordOverride() was called, so the new
accessor never got setOverridenDecl() called on it.

As a result, SIL didn't know that the derived materializeForSet
should replace the vtable entry for the base class materializeForSet.

The more fundamental problem here is that even after some recent
cleanups, accessors are still sometimes type checked before
the AbstractStorageDecla and sometimes after. So things like
inferring final, dynamic and overrides have to be duplicated in
multiple places.

Fixes <https://bugs.swift.org/browse/SR-3840> and
<rdar://problem/30336146>.
2017-02-03 19:13:27 -08:00
Slava Pestov
208dec74d0 Sema: Validate addressors when an AbstractStorageDecl is validated
Previously we were relying on the 'validate for layout' path
validating these, but that's going to change.
2017-01-08 21:01:13 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00