Commit Graph

9332 Commits

Author SHA1 Message Date
Chris Lattner
087d4c8430 Implement the parsing logic for SIL types (the SILType specific attributes).
All of it is still dropped on the floor.


Swift SVN r5195
2013-05-17 01:02:02 +00:00
Chris Lattner
babc1ea148 change printing of SILType to make it more regular and parsable. As usual,
the hard part is updating the testsuite.


Swift SVN r5194
2013-05-17 00:26:27 +00:00
Joe Groff
c4317411b6 IRGen: Use SILType in functions used for existential container insts.
Swift SVN r5191
2013-05-16 22:47:49 +00:00
Chris Lattner
63e2a60585 rename Module:: and Function::getContext to ::getASTContext()
This matches SILType and is more explicit about which context
we're talking about.


Swift SVN r5185
2013-05-16 20:14:13 +00:00
Chris Lattner
21a3b9d246 remove two helper forwarding methods from SILFunction
one is dead, the other isn't helpful enough to persist.


Swift SVN r5184
2013-05-16 20:07:53 +00:00
Chris Lattner
3facf741fa move SILFunction implementation goop out into SILFunction.cpp
and make the SILFunction ctor public since SIL is an optimization
IR, not just a transient by product of IRGen. :)


Swift SVN r5183
2013-05-16 19:59:01 +00:00
Chris Lattner
2e7a6c015a switch the specialize instruction to print its substitution list after
a comma, and restore testcases to check the list.


Swift SVN r5182
2013-05-16 19:48:42 +00:00
Joe Groff
8303addde0 IRGen: Get ObjC thunks from SIL.
Use the SIL-generated ObjC thunk symbols instead of generating them in IRGen. Kill all the now-dead IRGen OwnershipConventions stuff. Teach IRGenSILFunction how to emit a C-calling-convention function, and getFunctionType how to map a C-calling-convention function type. Fix a bug in SILGen where ObjC thunks for methods and properties from extensions weren't getting emitted.

Swift SVN r5180
2013-05-16 19:03:37 +00:00
Chris Lattner
1f2eb7e77b switch the SIL printer to use // as its comment character instead of using ;
Swift SVN r5178
2013-05-16 18:44:16 +00:00
Joe Groff
d5eb080ca5 Revert r5035 force_inline implementation.
We're going to do this in the SIL optimizer instead.

Swift SVN r5171
2013-05-15 18:36:10 +00:00
Doug Gregor
ce3fe3ae92 Implement Ruby-inspired closure syntax.
This commit implements closure syntax that places the (optional)
parameter list in pipes within the curly braces of a closure. This
syntax "slides" well from very simple closures with anonymous
arguments, e.g.,

  sort(array, {$1 > $0})

to naming the arguments

  sort(array, {|x, y| x > y})

to adding a return type and/or parameter types

  sort(array, {|x : String, y : String| -> Bool x > y})

and with multiple statements in the body:

  sort(array, {|x, y|
    print("Comparing \(x) and \(y)\n")
    return x > y
  })

When the body contains only a single expression, that expression
participates in type inference with its enclosing expression, which
allows one to type-check, e.g.,

  map(strings, {|x| x.toUpper()})

without context. If one has multiple statements, however, one will
need to provide additional type information either with context

  strings = map(strings, {
    return $0.toUpper()
  })

or via annotations

  map(strings, {|x| -> String 
    return x.toUpper()
  }

because we don't perform inter-statement type inference.

The new closure expressions are only available with the new type
checker, where they completely displace the existing { $0 + $1 }
anonymous closures. 'func' expressions remain unchanged.

The tiny test changes (in SIL output and the constraint-checker test)
are due to the PipeClosureExpr AST storing anonymous closure arguments
($0, $1, etc.) within a pattern in the AST. It's far cleaner to
implement this way.

The testing here is still fairly light. In particular, we need better
testing of parser recovery, name lookup for closures with local types,
more deduction scenarios, and multi-statement closures (which don't
get exercised beyond the unit tests).



Swift SVN r5169
2013-05-14 05:17:10 +00:00
Joe Groff
d5784307d2 SILGen: Emit objc_msgSend-able thunks in SIL.
Emit thunks for [objc] class methods and properties as SILFunctions, using SILGen's OwnershipConventions. This will help kill some redundant ownership code in IRGen, and will allow msgSend thunks to handle string and block bridging. IRGen doesn't actually codegen the thunks yet; that will require teaching IRGenSILFunction how to be AbstractCC-aware, so for now, we just reemit the thunks using the old IRGen code.

Swift SVN r5168
2013-05-14 01:22:12 +00:00
Joe Groff
d2e18f74c8 SIL: ArchetypeMethodInst doesn't need a value operand.
Archetype methods can be looked up from the local witness tables for the archetype independent of an object.

Swift SVN r5152
2013-05-10 22:26:22 +00:00
Joe Groff
f5eaf12011 SIL: Print function types with SIL representation.
SIL mangles function types enough that the Swift function type is unhelpful and potentially misleading, especially if we start bridging types in SILGen.

Swift SVN r5135
2013-05-09 22:59:37 +00:00
Joe Groff
e1c838962e Revert "Remove [objc_block] attribute from Swift type system."
Implementing SIL bridging is going to take more IRGen work than I anticipated.

Swift SVN r5113
2013-05-09 16:32:18 +00:00
Jordan Rose
77ce3f31cb Add a DeclContextKind for Swift modules.
Swift SVN r5095
2013-05-08 18:33:34 +00:00
Joe Groff
bcf510e30b SIL: Remove 'getPreLoweredType' from SILType.
We don't need this hole to bypass SIL TypeLowering anymore.

Swift SVN r5094
2013-05-08 18:26:38 +00:00
Joe Groff
38f13e56f5 Remove [objc_block] attribute from Swift type system.
We will handle Swift-function-to-ObjC-block bridging in SILGen as part of general Cocoa-to-Swift type bridging. Temporarily disable building swiftAppKit and tests that exercise block bridging until the new implementation lands.

Swift SVN r5090
2013-05-08 16:52:12 +00:00
Joe Groff
26b6be85f7 SILGen: Calculate ownership for specialized types.
Specializing on a tuple type changes the SIL function signature, so we need to recalculate the ownership conventions bitvector for a callee when it gets specialized. Fixes <rdar://problem/13822463>.

Swift SVN r5079
2013-05-07 15:33:26 +00:00
Joe Groff
fecf19cc1a SILGen: Fix dominance bug in ternary codegen.
Wrap the branches of the ternary in their own scopes so that their temporaries don't get cleaned up outside of the conditional.

Swift SVN r5061
2013-05-06 20:52:59 +00:00
Joe Groff
35993a9e2c SIL: Actually verify instruction dominance.
We weren't actually calling into Verifier::checkSILInstruction, so we were missing the dominance and other basic validity checks for instructions, causing us to miss a dominance bug in SILGen for the ternary.

Swift SVN r5059
2013-05-06 20:23:50 +00:00
Joe Groff
f79e939460 SIL: Sever load-bearing links to the AST.
Make IntegerLiteral, FloatLiteral, and StringLiteral own their own copies of their values so they don't depend on the AST. Remove the now-redundant IntegerValueInst, which only existed to be a non-AST-dependent variant of IntegerLiteral.

Swift SVN r5045
2013-05-06 03:08:58 +00:00
Joe Groff
63e73bfd47 SILGen: Dumb typos.
No functionality change, just a badly-named variable.

Swift SVN r5044
2013-05-06 00:35:09 +00:00
Joe Groff
b818405034 Replace direct use of [[clang::fallthrough]] with a macro.
Add a SWIFT_FALLTHROUGH macro that expands to [[clang::fallthrough]] for Clang and nothing for other compilers. No functionality change.

Swift SVN r5043
2013-05-05 18:54:03 +00:00
Joe Groff
daa971dc2e SILGen: Detangle 'makeConstantType'.
Switch on the SILConstant's kind instead of working through a tangled mess of nested if-else conditions. No functionality change.

Swift SVN r5042
2013-05-05 18:32:05 +00:00
Joe Groff
253e24bb50 SILGen: Factor out return expr evaluation.
Factor the return expr evaluation code out of visitReturnStmt so it can be shared by emitClosure for ClosureExprs, and closure exprs that return address-only types can work.

Swift SVN r5040
2013-05-05 17:09:52 +00:00
Joe Groff
3d0616dca6 SILGen: Don't emit cleanups if block is terminated.
Don't shoot instructions off into space if the current block has already been terminated.

Swift SVN r5038
2013-05-04 01:06:32 +00:00
Joe Groff
e40d2f6769 SILGen: Implement basic force-inlining.
Set things up in SILGenFunction so that there can be nested return scopes, and emit force_inline functions inline in SILGenApply.

Swift SVN r5037
2013-05-04 00:46:51 +00:00
Doug Gregor
0f6b7a9d22 Rework our handling of "external" definitions created by the Clang importer.
Keep track of external definitions as they are created by broadcasting
them through a mutation listener interface. At name binding time, we
just cache them. When a type checker is alive, it immediately performs
any additional operations necessary on those types (e.g., declaring
implicit constructors).

This also eliminates some O(N^2) behavior in the type checker as well,
because we don't have to walk through all of the module imports to
find the external definitions. We just keep a single list in the
ASTContext along with our place in the list.

Fixes <rdar://problem/13769497>.


Swift SVN r5032
2013-05-03 00:24:34 +00:00
Joe Groff
e6b2598f9c SILGen: Fix SIL emission for protocol static methods.
Fix typeof(p).staticMethod() for a protocol value p, by allowing ProtocolMethodInst to operate on an existential metatype operand, and fixing the type of static methods accessed by ProtocolMethod so that they can be called using the same metatype value.

Swift SVN r5029
2013-05-02 23:19:28 +00:00
Joe Groff
24d44b051e Have destroying destructors return 'this' back to the deallocator.
This saves the deallocating destructor having to keep 'this' alive across the destructor call.

Swift SVN r5026
2013-05-02 16:36:50 +00:00
Joe Groff
16a640e939 runtime: Guard against recursive destruction in swift_release.
Retain heap objects before invoking their destructor so that retains and releases of the object during its destructor don't trigger recursive destruction. In destructor SILGen, eliminate the goofy double-retain guard that was getting emitted into every destroying destructor. If we count on release fixing the retain count and enforce fixed-lifetime capture of 'this' within a destructor body, we don't need to mess with 'this' at all in a destructor prolog or epilog—it's just a +0 argument.

Swift SVN r5022
2013-05-02 00:52:54 +00:00
Joe Groff
a2341a4cde Add Unicode symbol characters to operator charset.
Remove '@' from the operator character set, but add the math, symbol, punctuation, arrow, and line- and box-drawing characters. Also allow operators to contain (but not start with) combining characters--this should be safe, because identifiers can't start with combining characters either, and we don't allow them anywhere else.

Swift SVN r5019
2013-05-01 23:13:48 +00:00
Joe Groff
6133119f8d Add a Builtin.typeof function.
This performs the operation 'x.metatype' performs now. SILGen lowers it using the same logic as for MetatypeExpr--emit a static metatype for value types, or look up a dynamic metatype for class, archetype, and existential types.

Swift SVN r5007
2013-05-01 02:47:56 +00:00
Doug Gregor
80b7001cea Implement support for member initializers.
One can now attach an initializer to a member variable. That value
will used as the default initialization for the member variable(s) it
initializes. Fixes <rdar://problem/12597404>.


Swift SVN r4989
2013-04-30 00:32:12 +00:00
Joe Groff
1013781bcc Parse: Allow Unicode identifier characters.
Extend the character set for identifiers according to WG14 N1518, which recommends an extended character set for identifier start and continuation characters in C. Mangle identifiers containing non-ASCII characters by borrowing the Punycode encoding used for international domain names.

No Unicode operators just yet.

Swift SVN r4968
2013-04-28 21:39:02 +00:00
Joe Groff
7b305c785f SILGen: Fix crash when taking an address-only tuple argument.
Fix the argument visitor to use RValue's tuple restructuring logic instead of naively trying to cast a TupleInst over destructured arguments, which doesn't work for address-only tuples.

Swift SVN r4967
2013-04-28 16:37:18 +00:00
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
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00
Joe Groff
b5c42d9876 SILGen: Consume address-only arguments in-place.
If an address-only argument doesn't need a box, we can just bind the address we were passed to the argument variable directly. We only need to destroy_addr the value when it goes out of scope.

Swift SVN r4929
2013-04-27 03:45:26 +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
John McCall
5cd2af74ae Add a newline after the pretty stack trace for a SILFunction.
Swift SVN r4921
2013-04-26 18:48:35 +00:00
Joe Groff
54e101c517 SIL: Give BuiltinFunctionRef its own instruction.
We don't want to have to recover from a mangled name whether a function call is to an IRGen-lowered builtin, so add an instruction for referencing builtins.

Swift SVN r4919
2013-04-26 18:36:47 +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
Joe Groff
0f0dd62d52 SILGen: Hook up emission of ZeroValueExprs.
Turn ZeroValueExprs that were created for implicit constructors into SIL BuiltinZeroInsts. Fixes <rdar://problem/13733107>.

Swift SVN r4912
2013-04-25 21:39:12 +00:00
Joe Groff
8bdccdd418 IRGen: Clear up dtor special cases in SIL-IRGen.
Change the destroying destructor entry point ABI to take 'this' as the appropriate type instead of as %swift.refcounted. Emit the deallocating destructor in IRGen when we see the ClassDecl, not when we see the SILFunction for the destructor. This frees us from having to worry about whether a SILFunction came from a destructor decl. We won't be able to reconstruct that once SILFunctions are pre-mangled.

While we're here, repaint some bikesheds so it's clearer that SIL and SILGen work with the destroying destructor.

Swift SVN r4908
2013-04-25 19:50:58 +00:00
Joe Groff
d0e0911ecf SIL: Add builtin_zero instruction.
To represent the zero value of builtin types.

Swift SVN r4907
2013-04-25 19:50:56 +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
ee9ca634a5 SIL: Add linkage and calling conv to SILFunctions.
Move AbstractCC into SILType and make it an attribute of SILTypes for functions. Add a ConvertCCInst to represent calling convention conversions. Give SILFunctions a linkage attribute. Add logic to SILGen to calculate these attributes for SILConstants based on their attached decls.

IRGen doesn't use these new attributes yet. I'll hook that up when I move mangling over.

Swift SVN r4886
2013-04-24 18:09:44 +00:00
Joe Groff
36b02ac22b SILGen: Stub out implicit default ctor codegen.
Emit a zero-initialization for now, just so SILGen doesn't crash when it sees an implicit default ctor.

Swift SVN r4878
2013-04-24 16:02:37 +00:00