Commit Graph

1316 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
Jordan Rose
30b2f05466 Handle 'import struct Foo' where Foo is a non-nominal typealias (#14797)
Previously this just crashed. Now it suggests `import typealias Foo`,
a syntax that works back to Swift 1.

rdar://problem/36756349
2018-02-26 11:50:04 -08:00
Graydon Hoare
76b82accbc [Stats] Simplify FrontendStatsTracer uses and formatter-definitions. 2018-02-21 14:49:24 -08:00
Graydon Hoare
6f46362f38 [Stats] Improve stats tracing readability a little. 2018-02-21 14:49:24 -08:00
Jordan Rose
1785855934 Merge pull request #14660 from jrose-apple/one-weak-since-you-looked-at-me
Add @_weakSymbol and a corresponding SIL attribute
2018-02-21 11:22:26 -08:00
Jordan Rose
aa85e4512f Don't force inlinable constructors to delegate in non-resilient code (#14721)
This restriction came from wanting to make resilient and non-resilient
code follow the same rules whenever possible, but after thinking about
it a bit more we realized there was no reason why you /wouldn't/ just
mark your structs @_fixed_layout in non-resilient libraries anyway.
Since that (currently?) doesn't affect what you can do with the struct
across module boundaries, and since the layout of the struct is
available anyway in a non-resilient library, there's no real downside,
which means it's a meaningless restriction.

The same logic doesn't /quite/ apply to classes, since classes are
normally much more flexible than structs. (For example, you could add
a stored property to a class without recompiling clients, as long as
no initializers are inlined.) But it's close enough that we don't want
to put in the restriction at this time.

All of this is about attributes that haven't been finalized yet anyway
(hence the leading underscore), but it's still useful information.

rdar://problem/37408668
2018-02-21 10:15:58 -08:00
Jordan Rose
bb339778b4 Add @_weakLinked and a corresponding SIL attribute
This is mostly intended to be used for testing at this point; in the
long run, we want to be using availability information to decide
whether to weak-link something or not. You'll notice a bunch of FIXMEs
in the test case that we may not need now, but will probably need to
handle in the future.

Groundwork for doing backward-deployment execution tests.
2018-02-20 17:55:31 -08:00
Huon Wilson
c6ab136112 Merge pull request #14628 from huonw/no-conditional-objc-generics
[Sema] Disallow conditional conformances on objective-c generics.
2018-02-16 09:14:50 +11:00
Huon Wilson
50b6d10a4e [NFC] Move TypeOrExtensionDecl out of PrintOptions.h. 2018-02-15 16:58:24 +11: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
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 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
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08:00
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