Commit Graph

815 Commits

Author SHA1 Message Date
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Joe Groff
ab65140a2e Add a 'Builtin.once' builtin.
This lowers to a call to a to-be-written swift_once runtime function and will be used for lazy global initialization. Having this be a builtin seemed appropriate to me given that:

- references to it will be implicitly emitted by SILGen for global initializers.
- there are restrictions on its correct use that are currently impossible to express in the language outside of the stdlib.

Swift SVN r10508
2013-11-16 00:50:12 +00:00
Anna Zaks
0f390c9c54 Add dynamic checking for sign errors(overflows) during signed <-> unsigned conversions for integers of the same type.
Add unsafe alternatives to allow unsafe conversions:
 - asUnsigned()
 - asSigned()

Swift SVN r10476
2013-11-15 00:16:18 +00:00
Anna Zaks
f058c52d81 Cleanup/Fix comments
Swift SVN r10445
2013-11-14 01:35:22 +00:00
Anna Zaks
b687c3ce9c Add runtime integer truncation checking to the conversion constructors
Add new builtins(by generalizing, renaming, and extending the builtins used for compile time integer literal checking). These new builtins truncate integers and check for overflow/truncation errors at runtime. Use these for FixedPoint conversion constructors.

Fix a routine in stdlib's String implementation and a test that relied on bitwise behavior of the constructors (and triggered overflows).

TODO:
- Teach CCP about these to get static checking.
- Add special builtins for same size signed <-> unsigned conversions.

Swift SVN r10432
2013-11-13 21:54:34 +00:00
Anna Zaks
084bdfd05f Change the signature of the trunc builtins to return a tuple containing teh overflow bit as well as the result.
This is a first step in generalizing the builtin to handle non-constant int to int truncations.

Swift SVN r10341
2013-11-11 21:20:04 +00:00
John McCall
93dfaa6bf4 Make everything getting a TypeInfo declare whether it's
working with a SIL-lowered or SIL-unlowered type.

Swift SVN r10067
2013-11-09 01:41:16 +00:00
Joe Groff
554abf2d7a IRGen/Runtime: Expose extra inhabitants of class types.
Start using null-page values as extra inhabitants when laying out single-payload enums that contain class pointers as their payload type. Don't use inhabitants that set the lowest bit, to avoid trampling potential ObjC tagged pointer representations. This means that 'T?' for class type T now has a null pointer representation. Enums with multiple empty cases, as well as nested enums like 'T??', should now have optimal representations for class type T as well.

Note that we don't yet expose extra inhabitants for aggregates that contain heap object references, such as structs with class fields, Swift function types, or class-bounded existentials (even when the existential has no witness tables).

Swift SVN r10061
2013-11-09 00:43:40 +00:00
Greg Parker
49e1856c13 Add Builtin.[trunc|zext|sext]OrBitCast() instead of hijacking the true casts.
Swift SVN r9985
2013-11-06 03:15:04 +00:00
Adrian Prantl
5bbe0afb9f Debug info: Properly handle the function prologue in the line table.
Introduces a new flag in SILLocation: InPrologue to mark instructions
that setup the stack and allocate storage for local variables/arguments.

Fixes rdar://problem/15290023: Breakpoint set on prologue - crash ensues.

Swift SVN r9686
2013-10-26 00:12:20 +00:00
Anna Zaks
961c2b0219 Use the correct cache to lookup builtin info.
Also, rename the variables to better reflect that they are for builtins and not for intrinsics.

Swift SVN r9371
2013-10-15 20:22:31 +00:00
Anna Zaks
740fc0a9d9 Revert "Revert "Reimplement integer arithmetic overflow checking to use special, error on overflow builtins""
(This only fails under -DSWIFT_OPTIMIZED=NO; most likely due to an llvm bug.)

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 r9328
2013-10-14 21:42:33 +00:00
Dmitri Hrybenko
158ed79f34 Adds overflow checking for floating point literals. The approach is the same
as for integer literals.


Swift SVN r9325
2013-10-14 19:47:38 +00:00
Joe Groff
a818f6f23b IRGen: Steal single-Swift-refcounted partial_apply argument as context.
If a partial application's context consists of a sole Swift-refcounted argument, we don't need an additional box; we can just adopt the argument as the function context. This nicely handles the common case of a class method being partially applied on its "self".

Swift SVN r9298
2013-10-14 00:23:18 +00:00
Anna Zaks
1d646a8ba8 Implement overflow checking on integer literals (1 of 2)
- Added 2 new builtins strunc_with_overflow and utrunc_with_overflow
  that perform truncation and produce a compile time error when truncation
  overflows.

- Used these builtins instead of trunc to implement "_convertFromBuiltinIntegerLiteral".

- Currently, the builtins are converted to trunc in IRGen, but we should
  not be IRGenning code that uses them, since all uses of
  "_convertFromBuiltinIntegerLiteral" should be inlined and the arguments
  constant folded.

- I had to change a test and the implementation of operator '~' in the standard library
  because they assumed that '0xFF' is a valid signed Int8. It is questionable if we should
  allow this and if we should treat signed and unsigned integers differently depending on
  how they are spelled (decimal or hexadecimal).

* This patch will be further improved (Ex: will start finding overflows on Int64, better
  deal with '-128' after the negative integer literal patch is committed.)

Swift SVN r9226
2013-10-11 22:19:14 +00:00
Joe Groff
03c4c436d8 Hey, we actually have a "proper C++11 compiler" now.
Swift SVN r9095
2013-10-09 22:07:59 +00:00
Joe Groff
57ea2025cb Adopt '_TPA.*' as a proper mangling for partial_apply thunks.
Jim wants a less ad-hoc naming convention for these thunks so that LLDB's 'trampoline' logic can recognize and step past these thunks in the process of "stepping into" methods involving closures.

Swift SVN r9086
2013-10-09 20:42:24 +00:00
John McCall
a79cee2c54 Revert "Reimplement integer arithmetic overflow checking to use special, error on overflow builtins"
This was causing massive failures at run-time.

This reverts commit 80081db973ccb7100741fea19ce8e8c116fc410f.

Conflicts:
	lib/SILPasses/ConstantPropagation.cpp
	test/SILPasses/constant_propagation.swift
	test/SILPasses/constant_propagation2.sil

Swift SVN r9050
2013-10-09 01:20:39 +00:00
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