Commit Graph

1694 Commits

Author SHA1 Message Date
Joe Groff
5b4519d12b Mangle operator fixity and tuple variadicity.
Tweak the mangling rules to fix some collisions I found:

- Mangle variadic tuples with a lowercase 't' to distinguish them from nonvariadic tuples with a slice as their final element.
- Mangle the fixity of operators using 'op' for prefix, 'oP' for postfix, and 'oi' for infix, so that operator declarations that differ only in fixity can coexist.

While we're here, 'Slice' seems worthy of a standard substitution, so mangle it to 'Sa'.

This fixes <rdar://problem/13757744> and <rdar://problem/13757750>.

Swift SVN r4965
2013-04-28 15:48:18 +00:00
John McCall
268eb42f46 Fix a bug with the SIL-generation of generic tuples.
Reviewed by Joe.

Swift SVN r4928
2013-04-26 23:47:45 +00:00
Joe Groff
f3b6f9cb4f SILGen: Don't emit super_method for non-dynamic super calls.
We won't be able to easily lower super_method to a static call in IRGen when we pre-mangle symbols, so move the logic to determine whether a super call requires dynamic dispatch up to SILGen.

Swift SVN r4913
2013-04-25 22:32:04 +00:00
Doug Gregor
a91941b635 Introduce assignments into the implicitly-defined default constructor body.
Add assignment statements into the implicitly-defined default
constructor body to initialize all of the members appropriately, e.g.,
by calling the default constructor. For builtin types and class types,
introduce ZeroValueInitExpr to produce a "zero" value.

ZeroValueInitExpr still needs a representation in SIL. Until then,
actual generation of this AST is suppressed.



Swift SVN r4895
2013-04-25 00:00:28 +00:00
Joe Groff
11109a9376 SILGen: Implement switch statements.
This should bring SILGen up to feature parity with the old backend. This implementation also now supports fallthrough.

Swift SVN r4858
2013-04-22 01:10:06 +00:00
Joe Groff
e5068920bb SILGen: Handle ObjC ownership conventions of calls
Port IRGen's calculation of consumed arguments and return value semantics to SILGen, and use it to handle the ownership semantics of calls. Refactor the handling of properties and other clients of emitApply so they can properly hand ownership semantics down to it.

This should let all the moribund cleanup management code in IRGen die. Unfortunately Scope appears to be tied into scoped calculated metadata caching so it's not quite ready to die.

Swift SVN r4834
2013-04-20 23:13:42 +00:00
Joe Groff
45acdfad78 Clean up IRGen tests for SIL-IRGen.
Remove tests that test things that are now mostly SILGen's job, and strip down and tweak the remaining tests to test IRish things in a way that matches SIL-IRGen's output. XFAIL a few tests that trigger SIL-IRGen crashes for further investigation.

Swift SVN r4759
2013-04-17 00:48:34 +00:00
Joe Groff
88d5192a69 SILGen: Don't crash if FuncDecls lack bodies.
FuncDecls for builtins don't have bodies. Deal with this when determining function natural uncurry levels and captures for SILGen.

Swift SVN r4734
2013-04-14 19:45:02 +00:00
Joe Groff
9ff03ec06d SILGen: Stub out support for oneof elements.
Add a OneOfElement kind to SILConstant so we can at least reference Bool's element constructors.

Swift SVN r4733
2013-04-14 16:43:13 +00:00
Joe Groff
1fcf2237af SILGen: Emit global variable initializers.
Emit global initializers into the 'toplevel' function in a library TU, which IRGen will then wire up to a global constructor.

Swift SVN r4732
2013-04-14 15:31:35 +00:00
Joe Groff
4cdcdba22e SIL: Add BridgeToBlockInst.
And in SILGen, lower BridgeToBlockExprs to BridgeToBlockInsts.

Swift SVN r4723
2013-04-13 17:05:38 +00:00
Joe Groff
217eb22756 SILGen: Visit extension decls.
Swift SVN r4611
2013-04-05 18:03:43 +00:00
Chris Lattner
85c7c494ae Wire up the most trivial support for sil parsing, which allows us to write
a (trivial, empty) sil parser testcase.  The parser is still not SIL aware
though.


Swift SVN r4585
2013-04-03 05:57:42 +00:00
Joe Groff
bc7afbae3a SILGen: Visit ClangImporter external definitions.
Emit SIL for definitions synthesized by the Clang importer.

Swift SVN r4552
2013-03-30 17:41:33 +00:00
Joe Groff
73de77cc34 SILGen: Remove bad assert from Condition.
It's valid to fold away the continuation BB if it's not reachable, such as in a loop that breaks or continues in every execution path.

Swift SVN r4474
2013-03-22 16:30:46 +00:00
Joe Groff
e07609c3e7 SIL: Add ClassMetatypeInst.
Represents getting the dynamic metatype from a class instance.

Swift SVN r4459
2013-03-20 23:27:18 +00:00
Joe Groff
b53d7a2344 SILGen: Catch up with new Expr nodes.
Add SILGen support for recently-added super.constructor and collection literal expr nodes. Remove the default visitExpr hack and add stubs for the handful of expr nodes remaining to implement.

Swift SVN r4406
2013-03-16 20:28:49 +00:00
Joe Groff
b2c1a83433 SILGen: Uncurry function applications.
Reference and call uncurried function applications when appropriate to the call site, following the same logic implemented in CallEmission/CalleeSource in IRGen. Add ClassMethodInst and SuperMethodInst instructions to represent method and super dispatch. Change how closures and ClosureInst are represented in SIL so that closures are functions with an extra implicit uncurry level and so that ClosureInst applies the outer uncurries of an uncurried function type to give a curried type as a result. This breaks...pretty much everything else SIL-dependent; I'll clean it up next.

Swift SVN r4368
2013-03-14 01:27:54 +00:00
Joe Groff
2a74aa7b44 Move test/SIL/IRGen to test/Interpreter/SIL.
They're all really interpreter tests.

Swift SVN r4306
2013-03-06 18:36:52 +00:00
Joe Groff
e822b95861 IRGen: Lowering for SIL UpcastInst.
Swift SVN r3873
2013-01-26 00:49:49 +00:00
Joe Groff
7a7e14a9c5 IRGen: Emit SIL destructors.
Emit the SIL destructor as a destroying destructor, then emit a deallocating destructor shim that calls into it and then returns the heap size. (The actual deallocation still happens in swift_release--I talked to John about that and I'll fix it later.) This gets the broken SIL/IRGen class tests passing again.

Swift SVN r3838
2013-01-22 23:36:37 +00:00
Joe Groff
5852448152 IRGen: Generate SIL ctor and property decls.
Remove the filter that only irgenned SIL functions for FuncDecls so that we emit functions for all SIL decls, and disable the old paths for properties, constructors, and destructors when a SIL module is present. Unfortunately this breaks class constructors because SIL and IRGen don't agree on how initializing constructors should work. I need to sync with John to figure out how to fix that.

Swift SVN r3827
2013-01-22 02:45:27 +00:00
Joe Groff
c9d6a351f5 IRGen: SIL ClosureInsts (almost).
Implement lowering of SIL ClosureInsts by packing the partial arguments into a heap allocation and emitting a thunk to unpack them and apply the closure function, similar to curried entry points. The test doesn't work quite yet because nested FuncDecls don't get visited anymore. I need to replace my hacked SIL path with a proper walk of the SIL module to generate functions and the AST to generate types.

Swift SVN r3817
2013-01-20 19:50:10 +00:00
Joe Groff
5674cfd0b1 IRGen: SIL literals and zero initialization.
Pick up the remaining low-hanging fruit by implementing irgen for FloatLiteralInst, ZeroValueInst, and ZeroAddrInst.

Swift SVN r3801
2013-01-18 18:02:10 +00:00
Joe Groff
d2c91a2323 IRGen: SIL protocol type value support.
Factor out the witness table initialization and projection logic from GenProto so that IRGenSIL can use it to implement the ProjectExistential and InitExistential instructions. Also map the CopyAddr and DestroyAddr instructions to value witness table calls so that value semantics on protocol values (and other address-only values) work. The added test compiles but doesn't run yet because invoking methods on a protocol value still requires implementing the ProtocolMethod instruction.

Swift SVN r3787
2013-01-17 23:20:59 +00:00
Joe Groff
1459512901 IRGen: SIL tuple helper instructions.
Implement ElementAddrInst for lvalue tuples, and implement the AllocArray, IndexAddr, and IntegerValue insts used to lower variadic tuples. (Actually compiling code that uses variadic tuples still requires support for SpecializeInst and generic functions.)

Swift SVN r3781
2013-01-17 18:17:39 +00:00
Joe Groff
312e4872e9 IRGen: SIL class accessors.
Implement IRGen for RefElementAddr so that class accessors work. Add a loadUnmanaged method to TypeInfo classes so that we can populate Explosions without accruing unwanted cleanups.

Swift SVN r3779
2013-01-16 22:12:21 +00:00
Joe Groff
7e57041393 IRGen: SIL struct manipulation.
Implement ElementRefInst so that struct accessors work. Also extend SILConstant lowering to support constant_refs to constructors, destructors, and property accessors so that constructor and property accessor references work. (Constructors don't yet get visited by IRGenSIL, though.)

Swift SVN r3776
2013-01-16 19:04:08 +00:00
Joe Groff
afa65ef3f4 IRGen: SIL function arguments and return values.
Lower arguments and value returns instead of assuming all functions are () -> ().

Swift SVN r3769
2013-01-16 01:20:15 +00:00
Joe Groff
8320df8b9d IRGen: SIL branching and variable allocation.
Implement SIL-to-IR lowering for allocation, deallocation, load, store, and branching instructions so that local variables and branching control flow can be used. Add a Fibonacci loop test to exercise the new instructions.

Swift SVN r3767
2013-01-15 22:32:49 +00:00
Joe Groff
0970a18e7d IRGen: Compile the toplevel through SIL.
If IRGenModule has a SILModule, use its toplevel Function to emit the top-level code instead of re-walking TopLevelCodeDecls itself.

Swift SVN r3761
2013-01-14 18:33:08 +00:00
Joe Groff
9259c0d912 IRGen: Get "hello world" to compile through SIL.
Add a path through IRGenModule to optionally codegen FuncDecls using their corresponding SIL Functions when constructed with a SILModule. Jury-rig an IRGenSILFunction subclass of IRGenFunction that does the bare minimum necessary to compile "hello world" from SIL. There are some impedance mismatches between irgen and SIL that need to be smoothed out, particularly the AST-dependent way irgen currently handles function calls. Nonetheless, `swift -sil-i hello.swift` works!

Swift SVN r3759
2013-01-14 02:57:11 +00:00
Joe Groff
b4c1ea890b SILGen: Recursively destructure tuple arguments.
Fully and consistently destructure tuples when in a function argument context, and require that ApplyInst always take destructured arguments corresponding to the lowered argument types as its inputs. This eliminates a ton of finicky special-case code all over the place and also has the nice fringe benefit of avoiding a bunch of useless TupleInsts that were being emitted before. Currently this breaks variadic tuple fields and argument writeback. I'll fix variadic tuple fields soon. The argument writeback sucked anyway and I'll do it right later.

Swift SVN r3730
2013-01-10 03:45:45 +00:00
Joe Groff
7d8f04ac45 SIL: Make SILType independent of Type.
Move SILType to its own header, and make it its own container type consisting of a Type with an "isAddress" bit for representing address types. Move the "isAddressOnly" information from SILGen's TypeInfo onto SILType as a second bit, because address-only-ness is extremely useful for verification outside of SILGen. Instead of mangling function types during type lowering, rely on the fact that SILType is no longer a Type to force us to mangle argument and return types when we see them. (We may eventually need SILFunctionType and SILTupleType things to represent lowered SIL function and tuple types containing addresses, but for now we can lower function and tuple components as needed.)

Swift SVN r3551
2012-12-19 21:51:39 +00:00
Joe Groff
0d34838a79 SILGen: Handle address-only arguments and returns.
Use copy_addr to copy argument addresses into local boxes and to store to the return value address when working with address-only types. Add a bit to ManagedValue so that it knows when it's referencing an address-only value (as opposed to just an address) so it can require that forwarded address-only values be forwardInto-ed a memory location.

Swift SVN r3540
2012-12-19 01:30:23 +00:00
Joe Groff
dc1af6ae11 SILGen: Implement address-only type lowering.
Add a getLoweredType() method to SILGen's TypeInfo and logic to convert function signatures and address-only types to their SIL-level representations. Drive a (currently weak) type wedge between lowered and unlowered types by making a SILType subclass of CanType. Make SILConstants take on their lowered function types. This breaks a bunch of SIL test cases, which I've temporarily XFAILed until proper address-only type support can propagate through the rest of SILGen.

Swift SVN r3528
2012-12-18 02:29:27 +00:00
Joe Groff
eeaa120fa7 SILGen: Visit methods in types.
Generate SIL for methods inside NominalTypeDecls.

Swift SVN r3449
2012-12-12 17:42:17 +00:00
Joe Groff
374aff6632 SILGen: Use ElementAddr for lvalue TupleElements.
If the operand of a TupleElementExpr is an lvalue, derive the address of the element from the operand rather than try to extract a value from it as the code was doing before.

Swift SVN r3392
2012-12-07 00:37:31 +00:00
Joe Groff
909f8db12e SILGen: Emit local function decls.
Generate local functions with captured variables as arguments to the entry block. Still need to implement the closure construction sequence when local functions are referenced.

Swift SVN r3357
2012-12-05 00:18:25 +00:00
Joe Groff
814229fce7 SILGen: Generate top-level code.
Add a toplevel Function object to SILModule. When SILGenModule encounters TopLevelCodeDecls, pass their bodies on to SILGenFunction to emit SIL into the toplevel function

Swift SVN r3336
2012-12-03 20:38:14 +00:00
Joe Groff
9967769d25 SILGen: Steal stupid cleanup support from IRGen
Port over the basic machinery to push and pop cleanups from IRGen, and implement simple straight-line cleanup emission. Add a basic cleanup for VarDecls as a proof of concept. More sophisticated handling of outflows, dormant/alive/dead states, etc. still needs to be carried over. Breaks test/SIL/statements.swift due to lack of support for cleanups through branches.

Swift SVN r3196
2012-11-15 22:24:10 +00:00
Joe Groff
cb6d12d52d Revert "WIP"
Not ready for prime time, sorry.

This reverts commit 3185.

Swift SVN r3189
2012-11-15 00:11:40 +00:00
Joe Groff
9d08711627 WIP
Swift SVN r3187
2012-11-15 00:04:23 +00:00
Chris Lattner
9db8f970e2 rename test/CFG to test/SIL
Swift SVN r3123
2012-11-07 00:42:01 +00:00