Commit Graph

292 Commits

Author SHA1 Message Date
Doug Gregor
24f4706056 SIL: Introduce the dynamic_method_br instruction.
The dynamic_method_br instruction branches depending on whether a
particular object can accept a given message, as determined at
runtime. If the object can accept the message, it branches to the
first basic block, providing the uncurried method as the BB
argument. If the object cannot accept the message, it branches to the
second basic block. Either way, the result is packaged up into an
optional type and passed along to the continuation block, which
provides the optional result.

Note that this instruction is restricted to lookup of Objective-C
methods.

Documentation and IR generation (via -respondsToSelector) to
follow. Review greatly appreciated!



Swift SVN r8065
2013-09-09 23:46:10 +00:00
Anna Zaks
c06bd83358 [SIL] Remove the last few uses of SILLocation constructor.
This also removes the constructor itself, which forces future users of
SILLocation to construct a valid location.

Swift SVN r8056
2013-09-09 22:34:05 +00:00
Doug Gregor
c5557a624c SIL: Introduce the 'dynamic_method' instruction for dynamic method dispatch.
The dynamic_method instruction handles method lookup on an existential
of type DynamicLookup based on the selector of an [objc] method of a
class or protocol. It is only introduced in the narrow case where we
are forcing a use of the method with '!', e.g.,

class X {
  func [objc] f() { println("Dynamic lookup") }
}

var x : DynamicLookup = X()
x.f!()



Swift SVN r8037
2013-09-09 16:12:50 +00:00
John McCall
b9dea7f458 Remove the emitSemantic* methods from TypeLowering and
move the corresponding functionality into SILGen.

I've switched around 'assign' so that it's no longer a
semantic assignment --- that is, so that it expects a properly
lowered value as its operand, not an r-value of the semantic
type.  This actually simplifies quite a lot of code and removes
some ugly special-casing from MemoryPromotion.

Swift SVN r7942
2013-09-05 06:44:50 +00:00
Anna Zaks
8208bf63b6 [SIL Loc] Replace calls to SILLocation() with more specific locations.
(Ideally, I’d like to get rid of SILLocation() to force the API user to always provide a non-null location.)

Swift SVN r7818
2013-08-30 23:41:38 +00:00
Chris Lattner
fc04d57bd0 Rework the assign instruction in two major ways:
1. Change assign to follow SILGen's model for a semantic assignment,
   which (in the case of unowned pointers) doesn't require the left
   and right hand sides to be the same.
2. Change assign to consume/take the refcount from the LHS, following
   SILGen's design (which I completely misunderstood before).



Swift SVN r7787
2013-08-30 17:59:56 +00:00
Dmitri Hrybenko
ceffc29bc9 Make 'constructor' a normal keyword.
Swift SVN r7773
2013-08-30 01:34:29 +00:00
John McCall
02ce2fe199 Make is_nonnull produce a primitive Builtin.Int1 instead
of Bool, and use swift._getBool to turn that into a Bool
as necessary.

Swift SVN r7720
2013-08-29 06:47:15 +00:00
Anna Zaks
440631f86a [SIL] Add the SILLocation hierarchy.
Now we should be ready to start using these.

Swift SVN r7632
2013-08-27 22:16:18 +00:00
Doug Gregor
330f5fe1e7 For nested archetypes, track the corresponding associated type.
Each nested archetype X.Y corresponds to an associated type named 'Y'
within one of the protocols to which X conforms. Record the associated
type within the archetype itself. When performing type substitutions,
use that associated type to extract the corresponding type witness
rather than looking for the type itself. This is technically more
correct (since we used the type witness for type checking), and a step
toward pulling type substitutions into the AST.



Swift SVN r7624
2013-08-27 17:05:11 +00:00
Michael Gottesman
d41b871b3a At Joe's suggestion added the prefix strong to instructions Retain,Release,RetainAutoreleased,RetainUnowned to prevent confusion in between RetainUnowned and UnownedRetain.
This is was a very mechanical patch where I basically first renamed SILNodes.def
and then just kept fixing things until everything compiled, so even though it is
large patch I feel ok(ish) with committing it.

If anyone has any concerns/etc, please email me and I will revert in 1 second.

Swift SVN r7604
2013-08-26 23:32:16 +00:00
Joe Groff
c74dc79610 SIL: Add instructions to implement address-only unions.
Because union layout may interleave tag bits with payload data, we need to be able to efficiently inject and remove tag bits from an address-only union in-place. To do this, we'll model address-only union initialization by projecting out the data address (union_data_addr) and storing to it, then overlaying the tag bits (inject_union_addr). To dispatch and project out the data, we'll use a destructive_switch_union_addr instruction that clears any tag bits in-place necessary to give a valid data address.

Swift SVN r7589
2013-08-26 20:50:31 +00:00
Joe Groff
fe1ad586e7 SIL: Add a 'union' instruction to construct unions.
The instruction represents constructing a loadable union given a case and the data for that case, which will let us emit union constructor functions in SIL instead of IRGen (rdar://problem/14773182).

Swift SVN r7558
2013-08-24 18:33:24 +00:00
Chris Lattner
d4a0c16baa revert my r7505 patch to 'assign'. It turns out that changing
assign in this way doesn't actually make things simpler, and the
former model for assign is simpler to work with.


Swift SVN r7537
2013-08-23 22:40:56 +00:00
Stephen Lin
51303421b1 Minor refactor to make variable usage fit naming better
Swift SVN r7530
2013-08-23 21:55:07 +00:00
Stephen Lin
d0375e615f SIL Parser: stop incorrectly rejecting partial_apply instructions with fewer arguments than callee input types
Swift SVN r7516
2013-08-23 19:17:38 +00:00
Chris Lattner
f6a5c78df2 Per John's advice (a few weeks ago), rework the 'assign' instruction
to being a semantic assign.  The functional difference here is only
for unowned pointers, where now the conversion from strong to unowned 
is implicit in the assign.

The logic behind this is that 'assign' is really part of SILGen, that
is only moved later to make it easier to make it be flow sensitive.
Since it is part of SILGen and will be using some of the type lowering
functionality used by SILGen, we should play by its rules.

No functionality change.


Swift SVN r7507
2013-08-23 18:15:21 +00:00
John McCall
1ea82afa8e Split ReferenceStorageType into {Weak,Unowned}StorageType.
Swift SVN r7478
2013-08-22 21:36:36 +00:00
Chris Lattner
69d0afb658 rename [force_inlining] to [transparent].
Swift SVN r7448
2013-08-22 16:05:41 +00:00
Dmitri Hrybenko
354c5f4a18 Parser: replace diagnose(Tok.getLoc(), ...) -> diagnose(Tok, ...)
We already had the Parser::diagnose(Token, ...) overload, but it was not used
in all these cases.


Swift SVN r7395
2013-08-21 00:26:30 +00:00
Doug Gregor
6ff6ec9df8 Reduce the reliance of PolymorphicFunctionType on GenericParamList.
This is a baby step toward eliminating GenericParamList from
PolymorphicFunctionType, fixing up the easy callers. No functionality
change.


Swift SVN r7370
2013-08-20 21:18:11 +00:00
Dmitri Hrybenko
b0dd877454 Use ParserResult in type parsing
Swift SVN r7353
2013-08-20 01:19:31 +00:00
Doug Gregor
1ddb34fb71 Factor generic parameters and associated types into their own decl nodes.
Previously, TypeAliasDecl was used for typealiases, generic
parameters, and assocaited types, which is hideous and the source of
much confusion. Factor the latter two out into their own decl nodes,
with a common abstract base for "type parameters", and push these
nodes throughout the frontend.

No real functionality change, but this is a step toward uniquing
polymorphic types, among other things.


Swift SVN r7345
2013-08-19 23:36:58 +00:00
Manman Ren
c851c54ccd SIL Parser: parse switch_int.
Swift SVN r7301
2013-08-16 22:58:39 +00:00
Stephen Lin
4a5c357a10 Change SILBuilder::createRefElementAddr() return type to RefElementAddrInst* to fit common pattern
Swift SVN r7167
2013-08-12 18:50:17 +00:00
Stephen Lin
5fc7966675 Add [force_inline] to SIL apply instruction; kill FunctionInst abstract value type
Swift SVN r7163
2013-08-12 17:33:37 +00:00
Chris Lattner
9b14f753b5 Fix the SIL Parser to parse store_weak into a StoreWeak, not a Store.
Testcase forthcoming.


Swift SVN r7160
2013-08-12 17:15:25 +00:00
Chris Lattner
eae021c7ad add a trivial test for SIL parsing the assign instruction, and fix
the bug exposed by it.  :-/


Swift SVN r7147
2013-08-12 14:38:42 +00:00
Chris Lattner
c8f01a0bf3 Introduce a new SIL "assign" instruction to represent assignments in SIL when
SILGen doesn't know whether they are initializations or stores.


Swift SVN r7146
2013-08-12 14:24:52 +00:00
Manman Ren
538a4c118c SIL Parser: parse specialize.
Modify SILPrinter to print the generic function type for specialize.

TODO: the testing case needs uniquing of PolymorphicFunctionType. Right now,
we will get a type mismatch between two copies of the same
PolymorphicFunctionType.


Swift SVN r7097
2013-08-09 20:27:24 +00:00
Manman Ren
abe1fcbbcf SIL Parser: parse ModuleInst.
Swift SVN r7092
2013-08-09 19:57:09 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Manman Ren
591410ea23 SIL Parser: parse init_existential, init_existential_ref, deinit_existential.
TODO: Conformances are currently not included in SIL.rst for init_existential
or init_existential_ref, but they exist in InitExistentialInst and
InitExistentialRefInst.


Swift SVN r7076
2013-08-09 01:10:10 +00:00
Manman Ren
9628330509 SIL Parser: parse switch_union.
Swift SVN r7071
2013-08-09 00:09:11 +00:00
Stephen Lin
f1842552f8 Do not parse trailing double-quote as part of string literal.
Swift SVN r7049
2013-08-08 18:36:17 +00:00
John McCall
14cb7001b3 Implement basic support for [weak].
Swift SVN r7041
2013-08-08 04:04:51 +00:00
John McCall
204980bdfd Add parsing for some missing SIL instructions.
Swift SVN r7040
2013-08-08 04:04:49 +00:00
Chris Lattner
44d8a942e1 Fix the sil parser to more correctly compute the result type of the partial_apply
instruction.


Swift SVN r7032
2013-08-08 00:58:56 +00:00
Chris Lattner
b478def6b1 Extend the SIL parser to add source locations to all parsed instructions.
Based on this, .sil files can now use -verify mode.  Switch memory_promotion.sil
to use it.


Swift SVN r6990
2013-08-07 18:37:25 +00:00
John McCall
e9b913fb5b Remove LocalStorageType, make it a kind of SILType.
Swift SVN r6968
2013-08-07 00:22:26 +00:00
John McCall
b0084f7204 Prepare SILType for more than just isAddress.
Swift SVN r6946
2013-08-06 20:23:12 +00:00
John McCall
36aa6c2645 alloc_stack needs to return two values like alloc_box.
The current implementation of dealloc_stack in IR-gen is a
no-op, but that's very much wrong for types with non-trivial
local allocation requirements, e.g. archetypes.  So we need
to be able to do non-trivial code here.  However, that means
modeling both the buffer pointer and the allocated address
in SIL.

To make this more type-safe, introduce a SIL-specific
'[local_storage] T' type that represents the required
allocation for locally storing a T.  alloc_stack now returns
one of those in additon to a *T, and dealloc_stack expects
the former.

IR-gen still implements dealloc_stack as a no-op, but
that's now easy to fix.

Swift SVN r6937
2013-08-06 07:31:41 +00:00
John McCall
592732c6b4 Split *one* unimplemented dealloc_ref instruction into
*two* unimplemented instructions!  This is progress.

Swift SVN r6931
2013-08-06 01:23:51 +00:00
Manman Ren
bfe0c39884 SIL Parser: parse builtin_function_ref.
In SILParser, factor out lookupTopDecl and lookupMember.
lookupTopDecl finds the top-level ValueDecl or Module given a name and
lookupMember finds the ValueDecl given a type and a member name.
Update comments for parseSILDeclRef to match SIL.rst.
We now handle the case where the first component of a dotted path is a
module.

In SILPrinter, print the full path for builtin_function_ref, also
"!" is optional when printing SILDeclRef.


Swift SVN r6926
2013-08-06 00:53:07 +00:00
Manman Ren
0d8f8b062c SIL Parser: parse alloc_array.
Swift SVN r6912
2013-08-05 18:41:03 +00:00
Chris Lattner
5a717502e7 merge some common parsing logic together, no functionality change.
Swift SVN r6888
2013-08-05 14:36:52 +00:00
Chris Lattner
e6d197c8f1 SILParser support for dealloc_ref.
Swift SVN r6887
2013-08-05 14:33:50 +00:00
John McCall
b77c430848 Add SIL-gen and some missing runtime support for [unowned].
Swift SVN r6881
2013-08-03 08:46:54 +00:00
John McCall
0fe3bee1e5 Normalize the names of createUnowned{Retain,Release}.
Swift SVN r6878
2013-08-03 05:59:18 +00:00
Joe Groff
5a2128bc77 SIL: Model project_existential using an address.
Have project_existential return $*This instead of $Builtin.OpaquePointer, and have protocol_method do the same for methods of opaque protocols. This makes it easier for passes to reason about the semantics of the projected address, since it's restricted by the semantics of SIL addresses.

Swift SVN r6872
2013-08-03 01:48:15 +00:00