Commit Graph

479 Commits

Author SHA1 Message Date
Joe Shajrawi
d8289aa3ec Code size: destroy_addr outline 2017-11-17 16:10:27 -08:00
Jordan Rose
ac6fd7214e [Serialization] Recover if a typealias's underlying type is broken (#12979)
We could handle a typealias itself disappearing, but not if the
typealias was okay but the underlying type wasn't. This came up in
real Swift 3/4 mix-and-match code.

rdar://problem/34940079
2017-11-16 19:31:13 -08:00
Arnold Schwaighofer
0971d82f70 SILGen: Remaining fixes for @callee_guaranteed closures and enable it
- Fix block to func reabstraction thunks block argument handling
- Forward cast ownership
- Fix applyPartiallyAppliedSuperMethod ownership for @callee_guaranteed closures
- Avoid a copy in buildBlockToFuncThunkBody
- Update tests for callee_guaranteed closures

SR-5441
rdar://33255593
2017-11-15 19:46:08 -08:00
Erik Eckstein
8033476b64 Function-level optimization attributes.
For now these are underscored attributes, i.e. compiler internal attributes:
@_optimize(speed)
@_optimize(size)
@_optimize(none)

Those attributes override the command-line specified optimization mode for a specific function.
The @_optimize(none) attribute is equivalent to the already existing @_semantics("optimize.sil.never") attribute
2017-11-14 11:25:02 -08:00
John McCall
045998544f Add begin_apply, abort_apply, and end_apply instructions to allow
yield_once coroutines to be executed.
2017-11-13 04:03:54 -05:00
John McCall
7743be30f6 Add a "token" type to SIL to allow dependencies to be expressed without
allowing abstraction.
2017-11-13 04:03:21 -05:00
Huon Wilson
99c4cddfca [SILGen] Store conditional conformances in SILWitnessTables. 2017-11-08 17:02:50 -08:00
Doug Gregor
82e1c98e46 [Serialize] Serialize uniqued generic signatures.
Rather than inlining generic signatures in a half dozen places throughout
the serialization format, serialize (uniqued) generic signatures with their
own GenericSignatureID. Update various layouts (generic function types,
SIL function types, generic environments, extension cross-references) to
use GenericSignatureID.

Shaves ~187k off the size of Swift.swiftmodule.
2017-11-07 13:36:22 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Mark Lacey
d83374449b Add a declaration attribute for implicitly unwrapped optional.
Attach this attribute to VarDecls declared as IUO, and to function decls
that have a result type that is an IUO.

NFC at the moment. Eventually we'll use these to determine where to
implicitly unwrap optional values.
2017-11-02 22:44:37 -07:00
Graydon Hoare
924948419a [NamedLazyMemberLoading] Serialize ProtocolDeclBits.ExistentialTypeSupported. 2017-11-02 15:55:22 -07:00
Graydon Hoare
9cd32f3975 [NamedLazyMemberLoading] Fix a couple tests accidentally broken. 2017-11-01 17:35:46 -07:00
Graydon Hoare
c78e04cd4f [NamedLazyMemberLoading] Add initial bits of serialized Decl member tables. 2017-11-01 17:35:46 -07:00
Graydon Hoare
09301cfbb4 [NamedLazyMemberLoading] Remove duplicate defn of DeclID in ModuleFormat.h 2017-11-01 17:34:56 -07:00
Graydon Hoare
7ba241dada [NamedLazyMemberLoading] Rename CLASS_MEMBERS{,_FOR_DYNAMIC_LOOKUP} for clarity 2017-11-01 17:34:56 -07:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Joe Shajrawi
d851abeed8 Merge branch 'master' into outline_copyddr 2017-10-31 17:28:09 -07:00
Joe Shajrawi
f4db36426c Code Size: Outline copy addr instruction 2017-10-31 17:03:48 -07:00
Arnold Schwaighofer
a177bdc6a9 Increase the version number after single payload enum change 2017-10-30 14:02:17 -07:00
Slava Pestov
7d41e79819 Serialization: Serialize FuncDecl::hasForcedStaticDispatch()
Otherwise, a protocol conformance where the witness was a dynamic
property in another module would trigger an assertion while building
the materializeForSet witness, or miscompile and fail at runtime
if asserts are off.
2017-10-24 20:45:48 -07:00
Michael Gottesman
36a8d0d5c0 [sil] Add support for the destructure_{struct,tuple} instructions.
rdar://31521023
2017-10-24 18:36:37 -07:00
Roman Levenstein
d86ef3b7e3 Add [serialized] flag to sil_vtables 2017-10-21 19:18:15 -07:00
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -07:00
Slava Pestov
0acf3ac8d9 SIL: Remove is_nonnull instruction 2017-10-13 17:38:32 -07:00
Doug Gregor
15386fa0bf [AST] Track overriding relationship among associated types.
When an associated type declaration “overrides” (restates) an associated
type from a protocol it inherits, note that it overrides that declaration.
SourceKit now reports overrides of associated types.
2017-10-07 21:52:40 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Slava Pestov
400693b811 AST: Store the default argument resilience expansion in the AbstractFunctionDecl
Previously we stored this inside each default argument
initializer context. This was overkill, because it is
the same for all default arguments in a single function,
and also insufficient, because initializer contexts are
not serialized and thus not available in SILGen when
the function is in a different module.

Instead store it directly inside the function and
serialize it.

NFC for now, since SILGen isn't using this yet.
2017-09-15 16:20:45 -07:00
Joe Groff
78d75428d6 SILGen: Lower key path subscript indexes.
And fill out SIL support for parsing, printing, and serializing key path
patterns with captured indexes.
2017-09-15 10:00:32 -07:00
Arnold Schwaighofer
085c424a7f Bump the module format version for array copy runtime changes 2017-09-13 08:43:48 -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
Doug Gregor
53bfcbc96d [Serialization] Stop serializing “inherited” types of an associated type
The “inherited” types of an associated type are only needed to
type-check an associated type in the context of its protocol.
Once that is complete, the requirement signature of the protocol
is the “truth”, and we no longer rely on the “inherited” types.
Stop serializing them.
2017-09-08 17:07:09 -07:00
Greg Parker
0af574a7be [AST] Rename DefaultArgumentKind::Nil to NilLiteral.
This avoids a conflict with #define Nil in objc/objc.h.
2017-08-31 21:55:45 -07:00
Roman Levenstein
a74c66794b [sil-serialization] Use a variable width integer instead of a fixed width integer for the max number of specialized attributes
It is just to make it more future-proof and avoid overflows we've seen recently.
Thanks Jordan who suggested this change.
2017-08-30 17:09:04 -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
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
Erik Eckstein
9c6fe76927 SIL, IRGen: add instructions "object" and "global_value” to support statically initialized objects.
This commit contains:
-) adding the new instructions + infrastructure, like parsing, printing, etc.
-) support in IRGen to generate global object-variables (i.e. "heap" objects) which are statically initialized in the data section.
-) IRGen for global_value which lazily initializes the object header and returns a reference to the object.

For details see the documentation of the new instructions in SIL.rst.
2017-08-23 09:15:49 -07:00
Roman Levenstein
05d0700c25 Increase the max number of possible @_specialize attributes for a SILFunction
The number was limited to 3 attributes for some reason. Now a SILFunction may have up to 2^16 such attributes, which should be enough for a while ;-)

Fixes rdar://problem/34026325
2017-08-22 20:40:03 -07:00
Andrew Trick
5aac427ee0 SIL Ownership: Remove consumptionKind from SIL unconditional cast and related logic.
Remove the cast consumption kind from all unconditional casts. It
doesn't make sense for unconditional casts, complicates SIL ownership,
and wasn't fully supported for all variants. Copies should be
explicit.
2017-08-18 20:44:54 -07:00
Slava Pestov
556d35d9b1 SIL: Record whether vtable entries are inherited or overridden
Consider a class hierarchy like the following:

class Base {
  func m1() {}
  func m2() {}
}

class Derived : Base {
  override func m2() {}
  func m3() {}
}

The SIL vtable for 'Derived' now records that the entry for m1
is inherited, the entry for m2 is an override, and the entry
for m3 is a new entry:

sil_vtable Derived {
  #Base.m1!1: (Base) -> () -> () : _T01a4BaseC2m1yyF [inherited]
  #Base.m2!1: (Base) -> () -> () : _T01a7DerivedC2m2yyF [override]
  #Derived.m3!1: (Derived) -> () -> () : _T01a7DerivedC2m3yyF
}

This additional information will allow IRGen to emit the vtable
for Derived resiliently, without referencing the symbol for
the inherited method m1() directly.
2017-08-14 19:50:34 -04:00
Jordan Rose
35f8e17e88 [Serialization] Drop extensions whose base type can't be deserialized. (#11323)
This shows up with swift_wrapper typedefs, which get imported into
Swift as structs. If someone makes an extension of a swift_wrapper
type, but the swift_wrapper is only applied in Swift 4 mode, that
extension will break any Swift 3 clients. Recover by just dropping
the extension entirely.

There's still more complexity around extensions---what if a
requirement can't be deserialized? what if something's depending on
the protocol conformance provided by the extension?---but the missing
base type case should be pretty safe. If you can't see the type at
all, things that depend on its conformances are already in trouble.

rdar://problem/33636733
2017-08-03 16:02:16 -07:00
Alex Hoppen
2eb36e41f5 Introduce special name for destructors
This name is not used yet
2017-07-28 10:46:50 +02:00
Doug Gregor
f23ee2341e Merge pull request #11158 from DougGregor/jsexport-redundant-inheritance
[GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
2017-07-25 02:17:18 -04:00
Doug Gregor
1b2a2c9b90 [GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
Inheritance of a protocol from JavaScriptCore's JSExport protocol is
used to indicate that the methods and properties of that protocol
should be exported to JavaScript. The actual check to determine
whether a protocol (directly) inherits JSExport is performed via the
Objective-C runtime. Note that the presence of JSExport in the
protocol hierarchy is not sufficient; the protocol must directly
inherit JSExport.

Swift warns about redundant conformance requirements and eliminates
them from the requirement signature (and, therefore, the Objective-C
metadata). This behavior is incorrect for JSExport, because the
conformance is actually needed for this API to work properly.

Recognize a protocol's inheritance JSExport specifically (by
name) when computing the requirement signature of the protocol. When
we find such a redundancy, suppress the "redundant conformance
constraint" diagnostic and add a new (hidden) attribute
@_restatedObjCConformance(proto). The attribute is used only by Objective-C
protocol metadata emission to ensure that we get the expected metadata
in the Objective-C runtime.

Fixes rdar://problem/32674145.
2017-07-24 17:02:34 -07:00
Jordan Rose
4d26358708 [Serialization] Recover from ObjC protocols changing inheritance. (#11109)
When there's an Objective-C protocol that adopts other protocols, the
other protocols become part of the requirement signature. If that can
change, Swift conformances to that protocol will get very confused
when it comes time to deserialize the conformances that satisfy the
requirement signature.

To recover from this, just deserialize /all/ trailing conformances,
rather than follow the requirement signature, and match them up after
the fact. (This only works for Objective-C protocols where we know all
conformance requirements represent inherited protocols, as opposed to
constraints on associated types.)

rdar://problem/33356098
2017-07-24 16:22:10 -07:00
Robert Widmann
ab093db95e Serialize the __shared type attribute 2017-07-23 21:47:25 -07:00
Andrew Trick
1ab24d8c0f Update SIL VERSION_MINOR for new SIL instruction. 2017-07-18 08:58:57 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -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