Commit Graph

797 Commits

Author SHA1 Message Date
Anna Zaks
ccc1dae7fd Reimplement integer arithmetic overflow checking to use special, error on overflow builtins
After talking to John, Joe, and Dave Z, we've decided that it's best to
specialize each arithmetic builtin that could overflow, instead of calling
a separate generic "staticReport" builtin and passing it enough info to
produce the message. The main advantage of this approach is that it
would be possible for the compiler to customize the message and better
link it to the builtin that overflows. For example, the constants that
participated in the computation could be printed. In addition, less code
will be generated and the compiler could, in the future, automatically
emit the overflow diagnostics/trap at runtime.

This patch introduces new versions of op_with_overflow swift builtins.
Which are lowered to llvm.op_with_overflow builtins in IRGen after the
static diagnostics. If the last argument to the builtins evaluates to true,
the overflow is unintentional. CCP uses the builtins to diagnose the overflow
detectable at compile time. FixedPoint is changed to rely on these in
implementation of primitive arithmetic operations.

Swift SVN r9034
2013-10-08 23:07:56 +00:00
Greg Parker
be12f30395 Move MaxScalarsForDirectResult to SwiftTargetInfo.
Swift SVN r8935
2013-10-04 22:11:46 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Doug Gregor
d110451430 Uncurried parameters are already backwards; we don't need to reverse again.
Swift SVN r8616
2013-09-25 01:05:30 +00:00
Doug Gregor
153630dffe Handle multiple levels of currying for Objective-C methods.
Test to follow.


Swift SVN r8611
2013-09-24 22:28:13 +00:00
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00
Joe Groff
cc37187c53 SIL: Remove 'UncurryDirection' and uncurry all methods right-to-left.
ObjC methods are already tagged with a special calling convention and have special IRGen handling to keep the _cmd argument abstracted away from SIL. We can use the CC to also abstract away the detail that Swift methods pass 'self' last but ObjC methods pass 'self' first. This eliminates a weird special case from SIL's perspective, and also means that 'partial_apply' can work on objc methods correctly without becoming significantly more complex.

Swift SVN r8091
2013-09-11 17:05:44 +00:00
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Joe Groff
b86203f021 IRGen: Emit partial applications of indirect function calls.
Add support to partial_apply lowering to handle partial applications of indirect functions, including ones that already have context.

Swift SVN r8074
2013-09-10 18:59:08 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +00:00
Joe Groff
32b9066abf IRGen: Resurrect 'copy' with a dual 'consume' LoadableTypeInfo method.
These will be useful to implement nontrivial union value semantics.

Swift SVN r7497
2013-08-23 01:16:10 +00:00
Anna Zaks
21ce68188d [SIL] Add attributes to swift builtins, specifically, the readnone attribute.
Use the attribute when deciding if a call to a builtin can be eliminated as dead.

Swift SVN r7391
2013-08-21 00:02:25 +00:00
Anna Zaks
2f05d5c4df [SIL] Move GenFunc to use getBuiltinInfo and getIntrinsicInfo.
Make the functions support a wider range of builtins and store types to make
it possible.

This is an optimization - the cached ID will be used for builtin identification,
instead of retrieval of the string name and using it as the key.

Swift SVN r7390
2013-08-21 00:02:22 +00:00
Joe Groff
1ca346d6c4 IRGen: Fix up union payload packing for aggregates.
SequentialTypeInfo types need to recursively packUnionPayload/unpackUnionPayload their elements, so have packUnionPayload/unpackUnionPayload take a starting offset and fix up the implementations so they pass down proper offsets for aggregate types.

Swift SVN r7362
2013-08-20 17:01:13 +00:00
John McCall
0f9328c0f4 Remove LoadableTypeInfo::copy, which has become dead.
Swift SVN r7351
2013-08-20 00:59:00 +00:00
John McCall
1a8e5740cb Rename load -> loadAsCopy and fix a test case that
was accidentally causing a double retain (in a suspicious
case, but still).

Swift SVN r7350
2013-08-20 00:55:08 +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
John McCall
eaa6228124 getFragileTypeInfo -> getTypeInfo
I didn't end up going the same way with fragility that I
thought I would at start, and this method name has become a
legacy.

Swift SVN r7340
2013-08-19 23:01:44 +00:00
Joe Groff
0e41a7e581 IRGen: Teach LoadableTypeInfos how to make union payloads.
Add packUnionPayload and unpackUnionPayload methods to LoadableTypeInfo that pack an explosion into a union payload and unpack an explosion from a union payload.

Swift SVN r7321
2013-08-18 19:48:02 +00:00
John McCall
7ec0f84e33 Demote most of the Explosion routines on TypeInfo to
the new LoadableTypeInfo refinement interface.

This protects against bugs which would introduce unbalanced
allocations of temporary memory.

Swift SVN r7227
2013-08-14 07:19:52 +00:00
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +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
Adrian Prantl
5e98accde4 Debug info: Rename createFunction -> emitFunction for consistency.
Swift SVN r7054
2013-08-08 21:20:07 +00:00
John McCall
3f4dcf455a dealloc_stack is not a no-op.
Swift SVN r6975
2013-08-07 03:21:14 +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
e3584068e8 Distinguish the allocation cases in IR-gen.
This gives us a more convenient type for allocateStack
and eliminates some unnecessary redundancy.

Swift SVN r6935
2013-08-06 07:31:36 +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
00a940ac1b Rename weak_retain to unowned_retain and change it to
require the correct [unowned] type as an argument.

Swift SVN r6825
2013-08-02 00:02:09 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Joe Groff
f866e5af25 Revert "IRGen: Pass existentials as generic parameters by unwrapping the container."
This reverts commit r6350. We don't imminently need this and intend to do it right soon.

Swift SVN r6605
2013-07-25 18:38:14 +00:00
John McCall
e668ff914f Add parsing and IR-gen for weak_retain and weak_release.
Swift SVN r6492
2013-07-23 06:28:51 +00:00
John McCall
69b64a09ce More canonical type preserving.
Swift SVN r6377
2013-07-19 07:08:38 +00:00
John McCall
16063866ed Preserve type canonicality with isa/cast/dyn_cast.
Swift SVN r6362
2013-07-18 23:28:53 +00:00
Joe Groff
5fe164df07 IRGen: Pass existentials as generic parameters by unwrapping the container.
When an existential's contained type is used as a generic parameter, unwrap the existential container and save its metadata and witnesses to be used as polymorphic arguments.

Our AST representation can't quite express the distinction between a type parameter being satisfied by the existential type itself from being satisfied by the existential's contained yet. I use a goofy heuristic where I assume a protocol type bound to a type variable with no requirements is satisfied by the protocol type itself; this covers all of the existing <T> (Slice<T>, T) cases that come up in the library, while enabling the <T:Foo> (T) cases. This hopefully addresses <rdar://problem/14470097> well enough to unblock library work until we get a solid AST representation of this difference.

Swift SVN r6352
2013-07-18 19:09:19 +00:00
John McCall
0d0e0d1939 Abstract out sub-interfaces for [unowned] and [weak] TypeInfos.
Swift SVN r6325
2013-07-17 09:20:30 +00:00
John McCall
7b86817b3c Basic value structure for [weak] and [unowned] references.
Add a bunch of new entrypoints and give them terrible
implementations.

Swift SVN r6322
2013-07-17 09:20:20 +00:00
John McCall
127a0e66a4 Privatize IRGenSILFunction.
Swift SVN r6173
2013-07-11 21:17:50 +00:00
John McCall
0e63c4a0ed Extract a ReferenceTypeInfo subinterface for refcount operations.
Weak stuff will introduce a much broader set of required
operations.

Swift SVN r6143
2013-07-11 00:22:06 +00:00
Adrian Prantl
ae9bd9397b Debug Info: Generate scope information for many more builtin/artificial functions.
Swift SVN r5876
2013-06-28 20:05:41 +00:00
Doug Gregor
9a5c96a8c1 Introduce basic support for LLVM vectors as builtins.
This adds builtin types Builtin.VecNxT, where N is a natural number
and T is a builtin type, which map down to the LLVM type <N x T>. 

Update varous builtins to support vector arguments, e.g., binary
operations, comparisons, negation. Add InsertElement and
ExtractElement builtins for vectors.

On top of these builtins, add Vec4f and Vec4b structs to the standard
library, which provide 4xFloat and 4xBool vectors, respectively, with
basic support for arithmetic. These are mostly straw men, to be burned
down at our leisure.

Some issues as yet unresolved:
  - Comparisons of Vec4f'ss are producing bogus Vec4b's, which I
  haven't tracked down yet.
  - We still don't support the shuffle builtin, although it should be
  easy
  - More testing!



Swift SVN r5820
2013-06-26 21:16:36 +00:00
Joe Groff
a55f246946 Remove the controversial "bounded" from "class-bounded".
Just refer to "class archetypes" and "class protocols". Change 'isClassBounded' methods to 'requiresClass', which is a character shorter.

Swift SVN r5674
2013-06-19 03:58:11 +00:00
Joe Groff
087803f5b0 IRGen: Implement type info for class-bounded archetypes.
Split ArchetypeTypeInfo into ClassBoundedArchetypeTypeInfo, for class-bounded archetypes, and OpaqueArchetypeTypeInfo, for fully generalized archetypes (the existing case). ClassBoundedArchetypeTypeInfo is represented using a single refcounted ObjCPointer. Implement abstraction remapping from class instances to class-bounded archetypes and back, and from class-bounded archetypes to non-class-bounded and back.

Witness tables are still generated only for opaque archetypes, so method calls on class-bounded archetypes won't work just yet.

Swift SVN r5569
2013-06-11 00:19:34 +00:00
Ted Kremenek
8876da8057 Remove essentially unused variable.
Swift SVN r5563
2013-06-11 00:11:18 +00:00
Joe Groff
b22fd22d57 SILGen: Handle Builtin.gep as a SIL builtin.
Add an index_raw_pointer instruction that acts like index_addr but for RawPointers, and use it to lower Builtin.gep into SIL instead of into IR.

Swift SVN r5479
2013-06-05 16:49:50 +00:00
Joe Groff
3e3e5710ec Set proper DeclContext for ImplicitClosureExprs.
Now that SILGen and IRGen can both handle capturing archetypes from generic scopes, we can set the DeclContext of ImplicitClosureExprs correctly, so that SILGen captures their context archetypes. &&, and ||, and assert now work in generic contexts, at least in simple test cases.

Swift SVN r5476
2013-06-05 05:09:59 +00:00
Joe Groff
ae56951d08 IRGen: Emit specialized partial_apply thunks.
If a specialization is partially applied, emit a single thunk bundling the bound polymorphic arguments and the partially-applied argument values into a single context object. This should almost get closures in generic contexts (at least, ones that never cross abstraction boundaries) working.

Swift SVN r5475
2013-06-05 04:51:51 +00:00