Commit Graph

9268 Commits

Author SHA1 Message Date
Slava Pestov
a14ecfbaef IRGen: Fix calls to default witnesses for static protocol requirements and factor out some duplication
We were checking for a @convention(witness_method) callee with an
abstract Self type in several places. Factor this out into a new
pair of methods on SILFunctionType, and fix the logic for static
methods, where the Self archetype is wrapped in a metatype.
2016-02-23 18:11:26 -08:00
Michael Gottesman
a5be2fff01 [sil] Use FullApplySite instead of ApplyInst in SILInstruction::getMemoryBehavior().
We were giving special handling to ApplyInst when we were attempting to use
getMemoryBehavior(). This commit changes the special handling to work on all
full apply sites instead of just AI. Additionally, we look through partial
applies and thin to thick functions.

I also added a dumper called BasicInstructionPropertyDumper that just dumps the
results of SILInstruction::get{Memory,Releasing}Behavior() for all instructions
in order to verify this behavior.
2016-02-23 15:00:43 -08:00
Max Moiseev
42d5f30d3a Merge remote-tracking branch 'origin/swift-3-api-guidelines' into swift-3-api-guidelines 2016-02-23 14:45:21 -08:00
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Dmitri Gribenko
f0633ce5a9 stdlib: Sequence.iterator() => .makeIterator() 2016-02-23 13:52:30 -08:00
David Farler
eabf6eee0c Add header guard to RelativePointer.h 2016-02-23 13:17:47 -08:00
Erik Eckstein
5b4c73ed3b Revert "GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result."
This reverts commit 4187959e66.

There is a crash in StdlibUnittests on i386 (Release-Assert build)
2016-02-23 08:29:41 -08:00
Todd Fiala
ceb58eac1e Merge branch 'master' of ssh://github.com/apple/swift 2016-02-22 22:00:10 -08:00
Todd Fiala
8ff40a3a22 Revert "Move pre-specializations of popular types away from the standard library."
This reverts commit 4d4c2cdba9.
2016-02-22 21:18:32 -08:00
Xi Ge
dd74e1c0ef [Serialization] Add a new front-end argument to specify the path of the group info file. NFC 2016-02-22 20:28:39 -08:00
Dmitri Gribenko
9aab5ef66e Merge pull request #1400 from practicalswift/typo-fixes-20160222
[gardening] Fix recently introduced typos: "the the" → "the", "paramters" → "parameters", "calle" → "callee", "a unconditional" → "an unconditional"
2016-02-22 18:54:18 -08:00
Dmitri Gribenko
7235595264 Merge pull request #1108 from tinysun212/porting-to-cygwin
Porting to cygwin
2016-02-22 18:53:30 -08:00
swiftix
c978092bec Merge pull request #1392 from swiftix/wip-prespecializations-module
Move pre-specializations of popular types away from the stdlib to reduce the stdlib code size.
2016-02-22 18:17:57 -08:00
Dmitri Gribenko
3085c4937f stdlib: add argument labels to _didEnterMain 2016-02-22 18:16:38 -08:00
Dmitri Gribenko
8c3fbc51a4 stdlib: rename Optional and IUO intrinsics 2016-02-22 18:16:37 -08:00
practicalswift
86e3986303 [gardening] Fix recently introduced typo: "calle" → "callee" 2016-02-22 23:29:19 +01:00
practicalswift
107057f529 [gardening] Fix recently introduced typo: "paramters" → "parameters" 2016-02-22 23:27:57 +01:00
practicalswift
dad1325c24 [gardening] Fix recently introduced typo: "the the" → "the" 2016-02-22 23:27:25 +01:00
Erik Eckstein
4187959e66 GenericSpecializer: When specializing a generic function, convert indirect parameters/result to direct parameters/result.
With this re-abstraction a specialized function has the same calling convention as if it would have been written with the specialized types in the first place.
In general this results in less alloc_stacks and load/stores.
It also can eliminate some re-abstraction thunks, e.g. if a generic closure is used in a non-generic context.
It some (hopefully rare) cases it may require to add re-abstraction thunks.

In case a function has multiple indirect results, only the first is converted to a direct result. This is an open TODO.
2016-02-22 13:58:10 -08:00
Erik Eckstein
682c1cb5a1 refactoring: move static function isPartialApplyOfReabstractionThunk from SILCombiner to Local.
Because it will be needed by the generic specializer, too.
NFC
2016-02-22 13:58:10 -08:00
Erik Eckstein
27929cba2a Support for mangling of generic specializations with different reabstraction.
This will be needed when the generic specializer will be able to change indirect arguments/results to direct arguments/results.
2016-02-22 13:58:10 -08:00
Erik Eckstein
3b6a4d8231 Handle array.get_element semantics calls with direct results in SIL optimizations.
Currently the array.get_element calls return the element as indirect result.
The generic specializer will change so that the element can be returned as direct result.
2016-02-22 13:58:10 -08:00
Erik Eckstein
666e20381f Refactor some ArraySemanticsCall code. NFC. 2016-02-22 13:58:10 -08:00
Jordan Rose
0ab43e125b Merge pull request #1282 from dduan/SR771_stmt_in_type_body_2
[Parser][SR-711] Couple "expected declaration" Diagnose With A Note
2016-02-22 13:39:55 -08:00
Max Moiseev
fcad164e18 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-22 12:59:57 -08:00
Xi Ge
bf1436a367 ASTPrinter: Move the logic for collecting all module groups from SourceKit to an IDE API, NFC. 2016-02-22 11:50:34 -08:00
Joe Groff
c6bfac7281 Handle initial value requirements in property behaviors.
If a behavior protocol requires an `initialValue` static property, satisfy the requirement using the initial value expression from the property declaration. This lets us implement `lazy` as a property behavior.
2016-02-22 08:43:17 -08:00
Roman Levenstein
4d4c2cdba9 Move pre-specializations of popular types away from the standard library.
Pre-specializations were only used by Onone builds, but were kept inside the standard library dylyb anyways. This commit moves all the pre-specializations into a dedicated Swift module and a dynamic library, which are only used by Onone builds.

This reduces the code size of libswiftCore.dylib by 5%.
2016-02-22 07:54:44 -08:00
John McCall
12b8a92e9d In generic functions, derive local type data for associated types
from the witness tables for their associations rather than passing
them separately.

This drastically reduces the number of physical arguments required
to invoke a generic function with a complex protocol hierarchy.  It's
also an important step towards allowing recursive protocol
constraints.  However, it may cause some performance problems in
generic code that we'll have to figure out ways to remediate.

There are still a few places in IRGen that rely on recursive eager
expansion of associated types and protocol witnesses.  For example,
passing generic arguments requires us to map from a dependent type
back to an index into the all-dependent-types list in order to
find the right Substitution; that's something we'll need to fix
more generally.  Specific to IRGen, there are still a few abstractions
like NecessaryBindings that use recursive expansion and are therefore
probably extremely expensive under this patch; I intend to fix those
up in follow-ups to the greatest extent possible.

There are also still a few things that could be made lazier about
type fulfillment; for example, we eagerly project the dynamic type
metadata of class parameters rather than waiting for the first place
we actually need to do so.  We should be able to be lazier about
that, at least when the parameter is @guaranteed.

Technical notes follow.  Most of the basic infrastructure I set up
for this over the last few months stood up, although there were
some unanticipated complexities:

The first is that the all-dependent-types list still does not
reliably contain all the dependent types in the minimized signature,
even with my last patch, because the primary type parameters aren't
necessarily representatives.  It is, unfortunately, important to
give the witness marker to the primary type parameter because
otherwise substitution won't be able to replace that parameter at all.
There are better representations for all of that, but it's not
something I wanted to condition this patch on; therefore, we have to
do a significantly more expensive check in order to figure out a
dependent type's index in the all-dependent-types list.

The second is that the ability to add requirements to associated
types in protocol refinements means that we have to find the *right*
associatedtype declaration in order to find the associated witness
table.  There seems to be relatively poor AST support for this
operation; maybe I just missed it.

The third complexity (so far) is that the association between an
archetype and its parent isn't particularly more important than
any other association it has.  We need to be able to recover
witness tables linked with *all* of the associations that lead
to an archetype.  This is, again, not particularly well-supported
by the AST, and we may run into problems here when we eliminate
recursive associated type expansion in signatures.

Finally, it's a known fault that this potentially leaves debug
info in a bit of a mess, since we won't have any informaton for
a type parameter unless we actually needed it somewhere.
2016-02-22 01:02:31 -08:00
Han Sangjin
e06c7136cb Porting to Cygwin. rebased and squashed 2016-02-22 13:20:21 +09:00
Xin Tong
a48584ccbc Create a fast path for not-final release instruction.
For a release on a guaranteed function paramater, we know right away
that its not the final release and therefore does not call deinit.

Therefore we know it does not read or write memory other than the reference
count.

This reduces the compilation time of dead store and redundant load elim. As
we need to go over alias analysis to make sure tracked locations do not alias
with it.
2016-02-20 22:00:36 -08:00
Joe Groff
d4fdc1e7a8 Conditionally enable behaviors by a frontend flag.
Since the feature is incomplete and yet to be accepted or implemented as proposed, hide it behind an -enable-experimental-property-behaviors frontend flag.
2016-02-20 15:01:06 -08:00
Joe Groff
a1ef412815 Sema/SILGen: Get property behavior implementations to codegen.
Fix some interface type/context type confusion in the AST synthesis from the previous patch, add a unique private mangling for behavior protocol conformances, and set up SILGen to emit the conformances when property declarations with behaviors are visited. Disable synthesis of the struct memberwise initializer if any instance properties use behaviors; codegen will need to be redesigned here.
2016-02-20 15:01:06 -08:00
Joe Groff
26e55ce465 Sema: Initial parsing and synthesis for properties with behaviors.
Parse 'var [behavior] x: T', and when we see it, try to instantiate the property's
implementation in terms of the given behavior. To start out, behaviors are modeled
as protocols. If the protocol follows this pattern:

  ```
  protocol behavior {
    associatedtype Value
  }
  extension behavior {
    var value: Value { ... }
  }
  ```

then the property is instantiated by forming a conformance to `behavior` where
`Self` is bound to the enclosing type and `Value` is bound to the property's
declared type, and invoking the accessors of the `value` implementation:

  ```
  struct Foo {
    var [behavior] foo: Int
  }

  /* behaves like */

  extension Foo: private behavior {
    @implements(behavior.Value)
    private typealias `[behavior].Value` = Int

    var foo: Int {
      get { return value }
      set { value = newValue }
    }
  }
  ```

If the protocol requires a `storage` member, and provides an `initStorage` method
to provide an initial value to the storage:

  ```
  protocol storageBehavior {
    associatedtype Value

    var storage: Something<Value> { ... }
  }
  extension storageBehavior {
    var value: Value { ... }

    static func initStorage() -> Something<Value> { ... }
  }
  ```

then a stored property of the appropriate type is instantiated to witness the
requirement, using `initStorage` to initialize:

  ```
  struct Foo {
    var [storageBehavior] foo: Int
  }

  /* behaves like */

  extension Foo: private storageBehavior {
    @implements(storageBehavior.Value)
    private typealias `[storageBehavior].Value` = Int
    @implements(storageBehavior.storage)
    private var `[storageBehavior].storage`: Something<Int> = initStorage()

    var foo: Int {
      get { return value }
      set { value = newValue }
    }
  }
  ```

In either case, the `value` and `storage` properties should support any combination
of get-only/settable and mutating/nonmutating modifiers. The instantiated property
follows the settability and mutating-ness of the `value` implementation. The
protocol can also impose requirements on the `Self` and `Value` types.

Bells and whistles such as initializer expressions, accessors,
out-of-line initialization, etc. are not implemented. Additionally, behaviors
that instantiate storage are currently only supported on instance properties.
This also hasn't been tested past sema yet; SIL and IRGen will likely expose
additional issues.
2016-02-20 15:01:05 -08:00
Dmitri Gribenko
3d3d4540e1 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-20 14:37:49 -08:00
Slava Pestov
7fdada8ee5 SIL: Add SILFunction::mapTypeOutOfContext(), NFC 2016-02-19 18:53:28 -08:00
Xi Ge
1872214d40 Swif-ide-test: add a parameter to specify the group names to print. 2016-02-19 17:21:28 -08:00
Xin Tong
fcb707b40c Improve epilogue retain matcher.
Instead of only checking the return block, we could potentially check
its predecessors and its predecessors's predecessors, etc.

Alos put in a threshold to throttle this to make sure its cheap.

We are still only being able to find of a small # of epilogue retains.
The bail on MayDecrement is blocking many of the opportunites.

This should bring us closer to being able to handle Walsh.

This is part of rdar://24022375.
2016-02-19 16:22:41 -08:00
Adrian Prantl
8e1d6c013b Make SILDebugLocation a value member of SILInstruction again.
The overhead of uniquing the locations in a Densemap isn't worth any of
the potential memory savings: While this adds an extra pointer and
unsigned to each SILInstruction, any extra memory is completely lost in
the noise (measured on a release -emit-ir build of the x86_64 stdlib).
This is not too surpising as the ratio between SILInstructions and unique
SILLocations is not very high and the DenseMap also needs space.

<rdar://problem/22706994>
2016-02-19 13:41:54 -08:00
Mark Lacey
945065f37d Change where in the pass manager we validate that analyses are unlocked.
Verify just prior to running passes, and after running each pass, that
no analyses are locked from being invalidated.
2016-02-19 13:32:40 -08:00
Adrian Prantl
40c7a1abee Separate underlying storage and location kind in SILLocation and
remove the mixed concept that was SILFileLocation.
Also add support for a third type of underlying storage that will be used
for deserialized debug lcoations from textual SIL.

NFC

<rdar://problem/22706994>
2016-02-19 11:16:48 -08:00
Daniel Duan
2f789859e1 [Parser] Couple "expected declaration" Diagnose With A Note
As reported in SR-711, when an (unexpected) statement appears in a type
declaration, we note the beginning of the declaration in addiction to the
existing diagnostic.
2016-02-19 10:15:21 -08:00
practicalswift
6eefb5f8db [gardening] Fix recently introduced typo: "inteface" → "interface" 2016-02-19 14:19:56 +01:00
practicalswift
47095ac6de [gardening] Fix recently introduced typo: "conveneion" → "convention" 2016-02-19 14:18:29 +01:00
Dmitri Gribenko
f39b443e24 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-19 01:16:19 -08:00
Michael Gottesman
13cc88f694 Revert "[arc] Put back in the RCIdentity cache."
This reverts commit 6c728daa61.

This is a speculative revert to try and fix the ASAN build.
2016-02-18 18:25:01 -08:00
Dmitri Gribenko
0f36bec31f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-18 16:41:35 -08:00
Joe Groff
ae0e855aaf Revert "Runtime: Remove retainCount entry points."
This reverts commit 51e0594e1c. The retainCount
entry points are used by Instruments.
2016-02-18 09:38:23 -08:00
practicalswift
c6c7010dfb [gardening] Remove unused diagnostic: sil_function_multiple_results 2016-02-18 15:32:59 +01:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00