Commit Graph

1195 Commits

Author SHA1 Message Date
Stephan Tolksdorf
79cef77ce0 [AST] Remove unused LazyResolver parameter from ObjC-selector-related Decl methods 2018-02-27 01:11:35 +01:00
Joe Groff
d4e03f2ba3 SIL: Add an 'external' KeyPathPatternComponent kind.
This will allow key paths to resiliently reference public properties from other binaries by referencing a descriptor vended by the originating binary. NFC yet, this just provides printing/parsing/verification of the new component.
2018-02-14 10:48:24 -08:00
Doug Gregor
fd5d3afb61 [Type checker] Tolerate missing generic environments better.
Before matching witnesses, ensure that we have a valid signature, and be
more tolerant of null generic environments by using the
mapTypeIntoContext entry point meant to handle null.

We haven't managed to get a decent reproducer for this, but it's
happening often enough, and this change hardens the affected code
paths.

Should fix rdar://problem/37255982.
2018-02-12 14:31:11 -08:00
Mark Lacey
7f805ba2bc Replace classifyAsOptionalType with isOptionalDecl. 2018-02-05 23:59:00 -08:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05: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
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
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
6d670c89c3 [AST] NFC: Find Optional enum elements semantically, not nominally 2018-01-14 19:01:28 -05: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
David Zarzycki
11666de1cd [AST] NFC: Reorder Decl nodes to make isa/dyn_cast faster
Please note that %target-swift-ide-test implicitly leaks the
DeclNode.def order in its output. See SR-6755.
2018-01-14 09:34:27 -05: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
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
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
David Zarzycki
dc43a4a51f [AST] NFC: Feedback from Jordan 2018-01-08 21:01:01 -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
Slava Pestov
d1f1c682bc AST: Remove AbstractStorageDecl::{has,requires}ForeignGetterAndSetter() 2018-01-04 21:53:34 -08:00
Doug Gregor
b11d5447c6 Merge pull request #13643 from DougGregor/redecl-fewer-validations
[Type checker] Make redeclaration checking validate fewer declarations.
2017-12-31 20:20:53 -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
David Zarzycki
da238539f5 [Basic] NFC: Inline bitfield cleanup
1) Remove SWIFT_INLINE_BITS boilerplate. Now that we're not using anonymous/transparent unions, we don't need the
SWIFT_BITFIELD_BITS macro.
2) Refine the the bitfield size check to better support templated bitfields.
3) Refine the SIL templated bitfields to not be prematurely "full".
2017-12-28 09:20:31 -05:00
David Zarzycki
54ea315586 [Basic] NFC: Stop using transparent unions 2017-12-16 10:43:49 -05:00
David Zarzycki
68a846e761 [AST] NFC: Do not hard code bit size of 'Kind' field
Also, give each class hierarchy at least 8 bits for the 'Kind' field.
In practice, no class hierarchy has more than 256 nodes, so this
optimizees code generation to make isa/dyn_cast faster.
2017-12-15 14:45:38 -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
Slava Pestov
1f1fa3b91d AST: Remove NominalTypeDecl::hasDelayedMembers() 2017-12-12 14:01:55 -08:00
David Zarzycki
4d56dfcc31 [AST] NFC: Repack misc EnumCaseDecl bits 2017-12-10 20:38:02 -05: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
82e08ed3b7 [AST] NFC: Repack misc AbstractFunctionDecl 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
91f9f9d741 [AST] NFC: Pack FuncDecl bits into intrusive bitfield 2017-12-05 16:12:37 -05:00
David Zarzycki
9b9d1733d4 [AST] NFC: Pack Ctor bits into intrusive bitfield 2017-12-05 16:12:37 -05:00
David Zarzycki
392e33637a [AST] NFC: Make Decl bitfield be 64 bit 2017-12-05 16:12:37 -05:00
swift-ci
6285582c13 Merge pull request #13074 from gottesmm/pr-bae9d9e30d40c9211864b978ff3400b9b01034c9 2017-11-26 21:55:50 -08:00
Michael Gottesman
7be1815d3f [ast] Add support for dumping a decl to a file from the debugger.
This is often times useful when one has a wall of AST dump and one wants to
winnow the lines down in a text editor.
2017-11-26 20:16:27 -08:00
Joe Groff
39dfe07354 IRGen: Treat class layout for classes from other modules a bit more opaquely.
We would miscompile in mixed-language-version projects when a Swift class was compiled for one language version, while using Objective-C-imported types that are only available to that version, and then imported into a Swift module with a different language version that wasn't able to see all of the properties because of incompatible imported types. This manifested in a number of ways:

- We assumed we could re-derive the constant field offsets of the class's ivars from the layout, which is wrong if properties are missing, causing accesses to final properties or subclass properties to go to the wrong offsets.
- We assumed we could re-derive the instance size and alignment of a class instance in total, causing code to allocate the wrong amount of memory.
- We neglected to account for the space that stored properties take up in the field offset vector of the class object, causing us to load vtable entries for following subclass methods from the wrong offsets.

Eventually, resilience should reduce our exposure to these kinds of problems. As an incremental step in the right direction, when we look at a class from another module in IRGen, treat it as always variably-sized, so we don't try to hardcode offsets, size, or alignment of its instances. When we import a class, and we're unable to import a stored property, leave behind a new kind of MissingMemberDecl that records the number of field offset vector slots it will take up, so that we lay out subclass objects and compute vtable offsets correctly. Fixes rdar://problem/35330067.

A side effect of this is that the RemoteAST library is no longer able to provide fixed field offsets for class ivars. This doesn't appear to impact the lldb test suite, and they will ultimately need to use more abstract access patterns to get ivar offsets from resilient classes (if they aren't already), so I just removed the RemoteAST test cases that tested for class field offsets for now.
2017-11-17 14:38:08 -08:00
Nathan Hawes
fcc27f04ee Merge pull request #12981 from nathawes/rdar34859742-protocol-rename-failure-in-generic-requirement-of-subscript
[ASTWalker|Refactoring] Walk generic params and requirements in source order for subscript decls
2017-11-16 18:20:39 -08:00
Nathan Hawes
7403e779ad [ASTWalker|Refactoring] Walk generic params and requirements in source order for subscript decls
Also handle requirements in non-trailing where clauses (for -swift-version 3)
Resolves rdar://problem/34859742
2017-11-16 16:02:12 -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
Slava Pestov
ed0ef94d91 Sema: Use a flag to short-circuit the requestClassLayout() check 2017-11-12 19:47:33 -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
6d46fb144f [AST] Move copyFormalAccess to ValueDecl. 2017-11-06 14:31:21 -08:00
Graydon Hoare
7e363ff97a [AST] Add implicit dtors outside typechecking, rdar://35198678 2017-11-04 02:59:52 -07:00
Graydon Hoare
924948419a [NamedLazyMemberLoading] Serialize ProtocolDeclBits.ExistentialTypeSupported. 2017-11-02 15:55:22 -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
Doug Gregor
a92d8d5760 [Cleanup] Reduce dependencies on swift/AST/LazyResolver.h. 2017-10-10 10:01:39 -07:00