Commit Graph

3502 Commits

Author SHA1 Message Date
Mark Lacey
2008674495 Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
Also remove the decl from the known decls and remove a
bunch of code referencing that decl as well as a bunch of other
random things including deserialization support.

This includes removing some specialized diagnostics code that
matched the identifier ImplicitlyUnwrappedOptional, and tweaking
diagnostics for various modes and various issues.

Fixes most of rdar://problem/37121121, among other things.
2018-02-02 08:35:53 -08:00
David Zarzycki
3da6fe9c0d [AST] NFC: Do not reinterpret_cast pointers into CanTypeWrappers
This also introduces 'TypeArrayView' for when a 'Type' is statically
known to be a given TypeBase subclass.
2018-01-31 11:20:05 -05:00
Davide Italiano
caa4ab3b70 Merge pull request #14262 from graydon/reduce-layering-violation-in-stats-tracer
[Stats] Reduce layering violations in FrontendStatsTracer.
2018-01-30 08:23:34 -08:00
Graydon Hoare
9334779f33 [Stats] Reduce layering violations in FrontendStatsTracer. 2018-01-30 01:54:07 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Mark Lacey
99229582ee Merge pull request #14053 from rudkx/refactor-type-match
Remove unused argument to type matcher.
2018-01-22 01:09:30 -08:00
Mark Lacey
cad0722305 Remove unused argument to type matcher. 2018-01-21 23:43:09 -08:00
Slava Pestov
8f9f7afc55 AST: Static properties of fixed-layout types are resilient
We don't want @_fixed_layout to apply to static properties, or you
get fun consequences like not being able to change static stored
properties defined in extensions of imported types to computed.
2018-01-21 01:31:44 -08:00
David Zarzycki
f0c08a3010 [AST] NFC: Add Decl::getAsGenericContext()
Adding getAsGenericContext() cleans up some code, and improves the
Swift.swiftmodule build time by almost half a percent on LLVM
top-of-tree and with a simulated fix for LLVM PR35909.
2018-01-14 09:34:27 -05:00
Slava Pestov
2584a4878e Sema: Disallow inlinable initializers on non-fixed-layout types even in non-resilient builds
This is technically a source break, but the @_fixed_layout attribute
is not official yet. If anyone really cares, we can make this
conditional on -swift-version 5 later, but I'd rather not.

This change is necessary so that we can give property initializers
non-public linkage. Currently they are public, because they can be
referenced from inlinable initializers.

Now that property initializers inside a @_fixed_layout type can
only reference public symbols, they no longer have to be public,
but making that change requires a bit more work.
2018-01-12 19:03:49 -08:00
John McCall
52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Slava Pestov
ca80bf4d38 Merge pull request #13897 from slavapestov/fixed-layout-property-initializer-restriction
Fixed layout property initializer restriction
2018-01-12 01:42:01 -08:00
Mark Lacey
d30a0f95dc Merge pull request #13896 from rudkx/clone-IUO-attribute
Make sure we copy the ImplicitlyUnwrappedOptionalAttr when cloning Pa…
2018-01-12 01:34:05 -08:00
Slava Pestov
99bc440c50 AST: Add NominalTypeDecl::isFormallyResilient()
We don't want -enable-resilience to change type checker behavior,
so in a few places we will need to check if a declaration is
"formally fixed-layout", which will be false if the declaration
was not explicitly marked as @_fixed_layout, even when the module
was not built with resilience.
2018-01-12 00:06:02 -08:00
Mark Lacey
1818911102 Make sure we copy the ImplicitlyUnwrappedOptionalAttr when cloning ParamDecls.
We should have a more general fix that clones the attribute list here,
but it looks like some attributes have parameters and that it could be
a bit more involved than I can tackle at the moment, so I created
https://bugs.swift.org/browse/SR-6741.
2018-01-11 23:45:01 -08:00
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Slava Pestov
8f2d309a14 Fix a couple of unused variable warnings 2018-01-11 14:54:50 -08: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
Slava Pestov
d1f1c682bc AST: Remove AbstractStorageDecl::{has,requires}ForeignGetterAndSetter() 2018-01-04 21:53:34 -08:00
Slava Pestov
5e1dfaa15f AST: Clean up isPolymorphic() 2018-01-04 21:53:34 -08:00
Mark Lacey
13859647f7 Merge pull request #13680 from rudkx/map-signature-looking-through-inout
Sema: Look through inout when mapping IUOs to Optionals.
2018-01-03 14:38:11 -08:00
Mark Lacey
314d705f41 Sema: Look through inout when mapping IUOs to Optionals.
We translate IUOs to Optionals when generating signatures, but were
failing to look through inout in the process, so we were allowing
functions to be overloaded by Optional vs. IUO when the parameter was
inout.

Fixes https://bugs.swift.org/browse/SR-6685 / rdar://problem/36255630.
2018-01-02 11:36:38 -08:00
Doug Gregor
8b58b0dbb4 [Type checker] Make redeclaration checking validate fewer declarations.
Redeclaration checking was validating all declarations with the same
base name as the given declaration (and in the same general nominal
type), even when it was trivial to determine that the declarations
could not be conflicting. Separate out the easy structural checks
(based on kind, full name, instance vs. non-instance member, etc.) and
perform those first, before validation.

Fixes SR-6558, a case where redeclaration checking caused some
unnecessary recursion in the type checker.
2017-12-30 23:27:04 -08:00
Joe Groff
f7fc74332c AST: Property requirements in @objc protocols should return true for requiresForeignGetterAndSetter.
We need to use ObjC dispatch to get to the witness of an ObjC protocol requirement. The wrong answer here was causing us to do the wrong thing when producing identifiers for key paths that refer to ObjC protocol requirements.
2017-12-18 12:29:14 -08:00
David Zarzycki
54ea315586 [Basic] NFC: Stop using transparent unions 2017-12-16 10:43:49 -05:00
David Zarzycki
97541e0d1e [Basic] NFC: Standardize and simplify inline bitfields
Inline bitfields are a common design pattern in LLVM and derived
projects, but the associated boilerplate can be demotivating and
brittle. This new header makes it easier to define and use inline
bitfields in Swift.

This also reorders some fields for better code generation.
2017-12-15 14:14:59 -05:00
Ben Langmuir
68a454556f Merge pull request #13348 from benlangmuir/cc-generic-subscript
[parse] Recover better from malformed subscript decls for code-completion
2017-12-13 15:45:03 -08:00
Ben Langmuir
dc5888d887 [parse] Recover better from malformed subscript decls for code-completion
Code-completion of generic types expects to get a DeclContext for the
subscript, so make sure we recover well enough to produce a
SubscriptDecl.

rdar://35619175
2017-12-13 13:37:41 -08:00
David Zarzycki
045d996127 [AST] NFC: Repack misc ClassDecl bits 2017-12-10 20:38:01 -05:00
David Zarzycki
f3a8023059 [AST] NFC: Repack misc ProtocolDecl bits 2017-12-10 20:38:01 -05:00
David Zarzycki
67f30ac3ea [AST] NFC: Repack misc GenericTypeParamDecl bits 2017-12-10 20:38:01 -05:00
David Zarzycki
dd617aafa5 [AST] NFC: Repack misc ImportDecl bits 2017-12-10 20:38:01 -05:00
David Zarzycki
8de981d2a9 [NFC] AST: Pack ParamDecl bits into intrusive bitfield 2017-12-05 16:41:58 -05:00
David Zarzycki
9b9d1733d4 [AST] NFC: Pack Ctor bits into intrusive bitfield 2017-12-05 16:12:37 -05:00
Jordan Rose
8f8f00012a Merge pull request #12834 from jrose-apple/restrict-cross-module-struct-initializers-2
Implementation of SE-0189 "Restrict cross-module struct initializers to be delegating"

rdar://problem/34777878
2017-11-30 13:32:45 -08:00
Slava Pestov
be1512c89f Serialization: Don't serialize the 'self' parameter 2017-11-18 20:02:50 -05:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Graydon Hoare
97ac580384 Merge pull request #12782 from graydon/fix-35198678-a-little-better
Fix 35198678 a little better
2017-11-15 00:21:47 -08:00
Jordan Rose
14198a360c Treat cross-module struct initializers as delegating in Swift 5
(and when the struct in question is non-fixed-layout, which was
already implemented)

This ensures that these initializers are never fieldwise in Swift 5
mode, which makes it safe for library authors to add new fields.
2017-11-10 10:59:24 -08:00
Graydon Hoare
3d4c8db140 [AST] Mark implicit dtors as having started validation. 2017-11-09 22:33:04 -08:00
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