Commit Graph

19 Commits

Author SHA1 Message Date
Slava Pestov
40bae8a6c0 SILGen: Simpler mangling for materializeForSet callback
We don't really need to mangle the AST type of the callback, besides
it doesn't have an AST type at all, because it is polymorphic.

Also, mangle the closure as if it were parented by the requirement
and not the witness, for consistency with witness thunks.

The mangling should still be unique since it includes the conformance.

NFC other than updating tests for new mangling.
2016-03-07 17:06:52 -08:00
Slava Pestov
7d55d5a0be SILGen: Factor out TypeConverter::getMaterializeForSetCallbackType(), NFC
I'm planning on changing materializeForSet to return the callback
as a RawPointer, and casting it to the correct polymorphic SILFunctionType
type at the call site.

This will allow us to call it with the right generic signature, which
is currently not possible since it is returned as an optional of an
AST function type, and optionals of SIL function types are not permitted.
2016-03-07 17:05:44 -08:00
Slava Pestov
3e7f2e195c SILGen: Refactoring MaterializeForSet to support default witness thunk emission
Previously we would emit two types of MaterializeForSet implementations
in SILGen:

- materializeForSet for a concrete storage declaration

- materializeForSet witness thunk in a conformance

This refactoring decouples the code from taking a conformance, which is
needed for two new types of materializeForSet that we need:

- materializeForSet witness thunk in a default witness table -- this is
  necessary in order to be able to resiliently add storage requirements
  with default implementations to protocols

- materializeForSet vtable thunk -- this is necessary to fix a missing
  re-abstraction case with overriding storage in a subclass

This patch brings us closer to implementing these two. For default
implementations, we still have an issue in that the materializeForSet
has a different "generic signature abstraction pattern" in concrete
and default witnesses, so default and concrete witnesses for
materializeForSet are currently ABI-incompatible because the type
metadata for the storage is passed differently to the callback.
2016-03-07 17:05:06 -08:00
Slava Pestov
924e4c4e13 SILGen: Clean up lvalue re-abstraction a bit
When we emit calls to getters and setters with emitApply(), the call
emission code ends up re-abstracting the result of a getter or the
parameter to a setter.

As a result, getOrigFormalType() was incorrect for logical path
components. This was worked around by only adding an OrigToSubst
path component to an lvalue if the last path component was physical.

This caused a problem in the following case:

1) There was an abstraction difference between the storage of the
   protocol requirement and the storage of the protocol witness

2) There was an abstraction difference between the storage of the
   protocol witness, and the fully-substituted type of the witness

An example is when the witness is in a protocol extension, and uses
'Self' or some other associated type which is concrete and loadable
in the conformance.

Fix this properly by splitting up getStorageTypeData() into two
functions, one used when adding physical path components and another
one used for logical.

As a result, we can now give the correct abstraction pattern to
logical path components.
2016-03-07 17:05:06 -08:00
Adrian Prantl
310b0433a9 Reapply "Serialize debug scope and location info in the SIL assembler language.""
This ireapplies commit 255c52de9f.

Original commit message:

Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 13:28:57 -08:00
Adrian Prantl
255c52de9f Revert "Serialize debug scope and location info in the SIL assembler language."
Temporarily reverting while updating the validation test suite.

This reverts commit c9927f66f0.
2016-02-26 11:51:57 -08:00
Adrian Prantl
c9927f66f0 Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 10:46:29 -08: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
Daniel Duan
efe230774b [AST] rename some isXXX methods to getAsXXX
There's a group of methods in `DeclContext` with names that start with *is*,
such as `isClassOrClassExtensionContext()`. These names suggests a boolean
return value, while the methods actually return a type declaration. This
patch replaces the *is* prefix with *getAs* to better reflect their interface.
2016-02-11 16:23:40 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Slava Pestov
ac5f44e913 SILGen: Fix materializeForSet for observing accessors
The following patch introduced a regression where materializeForSet
did not invoke didSet/willSet for stored properties with observers:

<249242b08d>

The old SILGen materializeForSet was only used for witness thunks,
where it used Ordinary access semantics for the storage.

When I switched over to using the new materializeForSet implementation
for static thunks too, I added some logic to use DirectToStorage access
semantics where appropriate, however this was wrong for observable
properties, which need DirectToAccessor semantics.

Fixes <rdar://problem/24315392>.
2016-01-23 23:39:30 -08:00
Slava Pestov
0a138c1b1b SILGen: Remove PolymorphicFunctionType usage from materializeForSet emission, NFC
We always passed nullptr to getMaterializeForSetCallbackType(), so
I'm assuming it is safe to just delete this bit of dead code.

Now the only remaining usages of PolymorphicFunctionType in SIL are
assertions ensuring that PolymorphicFunctionType doesn't end up there.

There are still a number of usages of AllArchetypes though, via
SILFunction::ContextGenericParams. Once @rjmccall finishes the
heavy lifting on the IRGen side, it should be pretty easy to rip
these out from SIL, too.
2016-01-22 11:35:03 -08:00
practicalswift
6d0eee9b8c Remove unused variables. 2016-01-21 10:33:17 +01:00
Slava Pestov
7edc5db2c1 SILGen: Fix materializeForSet emission for static computed properties of generic types
The original implementation of SILGenMaterializeForSet.cpp did not
support the case where SelfInterfaceType contained a generic
parameter. Recent changes to switch SILGen to always open-code
materializeForSet, and Sema to always emit accessors, exposed this
in validation-tests.
2016-01-20 14:51:44 -08:00
Slava Pestov
086cfc284b SILGen: Small cleanups, NFC 2016-01-18 20:34:30 -08:00
Slava Pestov
a8d8af4c7a SILGen: Fix materializeForSet emission for static stored properties
Lower the metatype instead of brazenly declaring it @thick.

This was triggering the SIL verifier with the newly-added test case.
2016-01-16 02:23:28 -08:00
Slava Pestov
249242b08d SILGen: Always open-code materializeForSet
This improves MaterializeForSetEmitter to support emission
of static materializeForSet thunks, as well as witnesses.

This is now done by passing in a nullptr as the conformance
and requirement parameters, and adding some conditional code.

Along the way, I fixed a few limitations of the old code,
namely weak/unowned and static stored properties weren't
completely plumbed through. There was also a memory leak in
addressed materializeForSet, the valueBuffer was never freed.

Finally, remove the materializeForSet synthesis in Sema since
it is no longer needed, which fixes at least one known crash
case.
2016-01-11 19:53:16 -08:00
Chris Lattner
41bcdb3854 add newline at end of file to silence warning. 2016-01-11 17:14:27 -08:00
Slava Pestov
b70e4d2aad SILGen: Split off SILGenMaterializeForSet.cpp from SILGenLValue.cpp, NFC
In order to fix some other issues that came up with materializeForSet
and resilience, I had to bite the bullet and finish off John's code
for open-coding materializeForSet emission in SILGen. This patch
makes the subsequent changes easier to review.
2016-01-10 17:06:19 -08:00