Commit Graph

641 Commits

Author SHA1 Message Date
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Arnold Schwaighofer
989d554a45 Add support for an assert_configuration builtin function
This patch adds support for a builtin function assert_configuration that is
replaced by constant progpagation by an appropriate value dependent on a compile
time setting. This replacement can also be disabled when serializing sil for a
library.

Using this mechanism we implement assertions that can  be disabled (or whose
behavior changes) depending on compile time build settings (Debug, Release,
DisableReplacement).

In the standard library we can now write one assert function that uses this
builtin function to provide different compile time selectable runtime behavior.

Example

Assert.swift:

@transparent
func assert<T : LogicValue>(
  condition: @auto_closure () -> T, message: StaticString = StaticString(),

  // Do not supply these parameters explicitly; they will be filled in
  // by the compiler and aren't even present when asserts are disabled
  file: StaticString = __FILE__, line: UWord = __LINE__
) {
  // Only in debug mode.
  if _isDebug() {
    assert(condition().getLogicValue(), message, file, line)
  }
}

AssertCommon.swift:

@transparent
func _isDebug() -> Bool {
  return Int32(Builtin.assert_configuration()) == 0;
}

rdar://16458612

Swift SVN r16472
2014-04-17 22:05:42 +00:00
Doug Gregor
8e597cc695 Eliminate argument parameter patterns.
Swift SVN r16444
2014-04-17 05:20:14 +00:00
Doug Gregor
e12afa2e1d Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound
name with argument names for each of the parameters. 


Swift SVN r16398
2014-04-16 06:05:45 +00:00
Chris Lattner
2b7f6b82b4 rename Builtin.move to Builtin.take. This matches the SIL naming better,
and avoids confusion with the C++'11 notion of "move".  'take' destroys 
source, where std::move leaves it destroyable.


Swift SVN r16316
2014-04-14 14:33:30 +00:00
Joe Groff
71404091d4 Add Builtin.fixLifetime as a way for library code to fix object lifetimes.
Lowers directly to the SIL fix_lifetime instruction.

Swift SVN r15637
2014-03-29 22:59:24 +00:00
Doug Gregor
323b1829b3 Adapt to upstream changes in LLVM and Clang.
Swift SVN r15622
2014-03-29 17:08:09 +00:00
Dave Abrahams
7da624a270 Revert "Fix build failure with instrinsic remaining (Extend|Trunc)VecArgument -> (Extend|Trunc)Argument"
This reverts r15582; these are still ExtendVecArgument/TruncVecArgument
in the LLVM source we're using.

Swift SVN r15610
2014-03-29 10:43:37 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Doug Gregor
48dfa88819 Fix build failure with instrinsic remaining (Extend|Trunc)VecArgument -> (Extend|Trunc)Argument
Swift SVN r15582
2014-03-28 18:12:25 +00:00
Nadav Rotem
a6d2e033f4 handle the unhandled case in the switch.
Swift SVN r15487
2014-03-26 05:45:46 +00:00
Greg Parker
0c44aa4c5e Add a failure ordering to cmpxchg builtin (following llvm r203559).
Swift SVN r14918
2014-03-11 14:44:26 +00:00
Joe Groff
98d6fecc99 '.metatype' -> '.Type'
Also, reserve 'type' as a keyword for ensuing syntax changes.

Swift SVN r14375
2014-02-26 04:23:21 +00:00
Joe Groff
a0874ad8d0 Add a Builtin.canBeObjCClass "type trait" builtin.
This builtin returns true for types that might be ObjC class types. We want to use this builtin to optimize away NSArray handling for non-object Array types, so it needs to persist in SIL long enough for specialization to do its thing, but we never actually want to pay a runtime cost for this check, so always lower it to a constant value at IRGen time. Handle this by having canBeObjCClass return a tri-state "yes/maybe/no" result. In SILGen, we only fold away obviously "yes" or "no" cases, and in IRGen, we fold away "maybe" cases as "yes".

The optimizer will need to learn about this builtin too, but that part isn't done yet.

Swift SVN r13980
2014-02-17 07:25:52 +00:00
Dmitri Hrybenko
571c9b3c5e Split 'type' keyword into 'static' and 'class'
rdar://15911697


Swift SVN r13908
2014-02-14 14:50:32 +00:00
Joe Groff
5c9470b9ca AST: Shun empty GenericSignatures, and remove the ASTContext argument from GenericSignature factories.
GenericSignatures with no params or requirements are a bug, so verify that they don't happen by making GenericSignature::get return null and GenericFunctionType assert that it has a nonnull signature. Hack Sema not to try to produce nongeneric GenericFunctionTypes when a function in a local type in a generic function context is type-checked; there's a deeper modeling issue that needs to be fixed here, but that's beyond the scope of 1.0. Now that GenericSignature always has at least one subtype, its factories no longer need an independent ASTContext argument.

Swift SVN r13837
2014-02-12 19:17:27 +00:00
Joe Groff
68db63b45d AST: Have GenericFunctionType use GenericSignature.
Change GenericFunctionType to reference a GenericSignature instead of containing its generic parameters and requirements in-line, and clean up some interface type APIs that awkwardly returned ArrayRef pairs to instead return GenericSignatures instead.

Swift SVN r13807
2014-02-12 03:44:28 +00:00
Chris Lattner
bc005219d1 Implement most of support for properties in function scope, part of rdar://15922884.
Most of the complexity here is teaching SILGen how to handle closed-over direct 
accesses to observing properties, since all of the getter/setter/willSet/didSet
members of the property are actually full closures when in a function body.

We generate correct but really terrible code here, since the setter captures the
willset/didset members themselves.  I'm not worrying about the performance of 
this construct though, functionality is what matters.


Swift SVN r13778
2014-02-11 06:23:14 +00:00
John McCall
5757f732b0 We don't handle these LLVM intrinsic kinds yet either.
Swift SVN r13753
2014-02-10 18:46:59 +00:00
Chris Lattner
70d547c1da remove a bunch of code that is manually monkeying around with DeclContexts,
now that they are implicitly updated.  This exposes two things:
1) we're unncessarily serializing selfdecls in ctors and dtors.
2) The index pattern of a SubscriptDecl has no sensible DeclContext that 
   owns variables in it.

I'll deal with the first tomorrow, I'm not sure what to do with
the second one.


Swift SVN r13703
2014-02-09 07:36:18 +00:00
Chris Lattner
929ad99f08 Clean up and generalize the code pertaining to how a FuncDecl accessor
knows about the AbstractStorageDecl it works on.  NFC.



Swift SVN r12994
2014-01-27 17:57:38 +00:00
Michael Gottesman
5a4ae66944 Handle unhandled enum case IITDescriptor::HalfVecArgument as unsupported in DecodeIntrinsicType to get rid of a -Wswitch warning.
Swift SVN r12980
2014-01-27 03:22:36 +00:00
Dave Abrahams
d58caea0cd Revert "Zap accumlated warnings in non-assert builds"
This reverts r12850, which broke the build for me.

Swift SVN r12856
2014-01-23 06:47:29 +00:00
Dave Zarzycki
17eb84d9c6 Zap accumlated warnings in non-assert builds
Swift SVN r12850
2014-01-23 05:45:24 +00:00
Joe Groff
6478d75911 AST: Contextualize the generic parameter decls of builtins.
Fixes a transparent serialization bug related to <rdar://problem/15869614>.

Swift SVN r12833
2014-01-23 01:10:18 +00:00
Joe Groff
197a1653fd SIL: Start on a StripRuntimeChecks pass.
In the long term we want more detailed configurability of runtime checks, but for our short-term performance work we just want a blanket on/off switch. Add a StripRuntimeChecks SIL pass that, as a start, converts invocations of checked overflow builtins to the equivalent unchecked builtins and kills cond_fails. Expose it through the compiler with a -disable-all-runtime-checks switch.

NB: I haven't tested building the stdlib or running the tests with the switch thrown yet.

Swift SVN r12379
2014-01-16 02:35:16 +00:00
Joe Groff
8bebb084e6 Rename 'RequirementKind::ValueWitnessMarker' to 'WitnessMarker'.
It's witnessing protocol requirements, not values, and "value witness" has a particular meaning in IRGen.

Swift SVN r11814
2014-01-02 17:47:40 +00:00
Chris Lattner
9ae289de46 Drive the semantic wedge harder into lvalues. Now, instead of having one LValueType
with qualifiers on it, we have two distinct types:
 - LValueType(T) aka @lvalue T, which is used for mutable values on the LHS of an
   assignment in the typechecker.
 - InOutType(T) aka @inout T, which is used for @inout arguments, and the implicit
   @inout self argument of mutable methods on value types.  This type is also used
   at the SIL level for address types.

While I detangled a number of cases that were checking for LValueType (without checking
qualifiers) and only meant @inout or @lvalue, there is more to be done here.  Notably,
getRValueType() still strips @inout, which is totally and unbearably wrong.



Swift SVN r11727
2013-12-29 22:23:11 +00:00
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Jordan Rose
417b5d3982 Merge TranslationUnit into Module, and eliminate the term "translation unit".
This completes the FileUnit refactoring. A module consists of multiple
FileUnits, which provide decls from various file-like sources. I say
"file-like" because the Builtin module is implemented with a single
BuiltinUnit, and imported Clang modules are just a single FileUnit source
within a module.

Most modules, therefore, contain a single file unit; only the main module
will contain multiple source files (and eventually partial AST files).

The term "translation unit" has been scrubbed from the project. To refer
to the context of declarations outside of any other declarations, use
"top-level" or "module scope". To refer to a .swift file or its DeclContext,
use "source file". To refer to a single unit of compilation, use "module",
since the model is that an entire module will be compiled with a single
driver call. (It will still be possible to compile a single source file
through the direct-to-frontend interface, but only in the context of the
whole module.)

Swift SVN r10837
2013-12-05 01:51:15 +00:00
Jordan Rose
eede5ec4f9 Begin refactoring for mixed file kinds within a single module.
The goal of this series of commits is to allow the main module to consist
of both source files and AST files, where the AST files represent files
that were already built and don't need to be rebuilt, or of Swift source
files and imported Clang headers that share a module (because they are in
the same target).

Currently modules are divided into different kinds, and that defines how
decls are looked up, how imports are managed, etc. In order to achieve the
goal above, that polymorphism should be pushed down to the individual units
within a module, so that instead of TranslationUnit, BuiltinModule,
SerializedModule, and ClangModule, we have SourceFile, BuiltinUnit,
SerializedFile, and ClangUnit. (Better names welcome.) At that point we can
hopefully collapse TranslationUnit into Module and make Module non-polymorphic.

This commit makes SourceFile the subclass of an abstract FileUnit, and
makes TranslationUnit hold an array of FileUnits instead of SourceFiles.
To demonstrate that this is actually working, the Builtin module has also
been converted to FileUnit: it is now a TranslationUnit containing a single
BuiltinUnit.

Swift SVN r10830
2013-12-05 01:51:03 +00:00
Chris Lattner
ecfba9fb53 Rename getBuiltinValue -> getBuiltinValueDecl since it doesn't
produce a value, it produces a decl.



Swift SVN r10697
2013-12-01 02:13:45 +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
Joe Groff
19457c12ea Give Builtin.Word an abstract size.
Instead of hardcoding Builtin.Word to be an alias for Builtin.Int64, make it its own type of abstract pointer width.

- Change BuiltinIntegerType's width representation to accommodate abstract widths.

- In the AST and in SIL, store values of the types as the greatest supported size for the abstract width (64 bits for a pointer).

- Add some type safety to the ([sz]ext|trunc)(OrBitCast)? builtins that they're used appropriately given the upper and lower bounds of the abstract sizes they're working with.

- Now that Builtin.Word is a distinct type, give it its own mangling.

- In IRGen, lower pointer-sized BuiltinIntegerType appropriately for the target, and truncate lowered SIL values if necessary.

Fixes <rdar://problem/15367913>.

Swift SVN r10467
2013-11-14 19:56:26 +00:00
Chris Lattner
3830957562 Reenable a case in a switch that joe disabled in r10434. I
think that it was an accident.  If not, lemme know.


Swift SVN r10438
2013-11-13 23:41:20 +00:00
Joe Groff
fdd858dd21 ClangImporter: Import NS_OPTIONS constants as static properties.
Apply the same prefix-chopping logic as for NS_ENUM to produce static property names to put inside the Swift type we create. For now, continue importing NS_OPTIONS as structs with a single integer field; in the short term it's easy to put a C-like interface over them this way.

Swift SVN r10434
2013-11-13 23:19:32 +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
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
Mark Lacey
915209b4f9 Add IITDescriptor::VarArg case to DecodeIntrinsicType().
LLVM rev r193766 adds this new descriptor kind. Update the switch
to squelch the warning about an unhandled enum value.

Swift SVN r9868
2013-11-01 05:46:27 +00:00
Greg Parker
beaa56d8e9 Add Builtin.Word and use it to implement swift.Word.
Swift SVN r9864
2013-11-01 00:11:22 +00:00
Doug Gregor
fcf9f91ae5 Add the value witness marker for generic builtins.
Swift SVN r9618
2013-10-23 14:23:15 +00:00
Joe Groff
db5fe95abb AST: Add a Builtin.condfail function.
Lowered by SILGen into a cond_fail instruction.

Swift SVN r9591
2013-10-22 15:53:11 +00:00
Doug Gregor
c9b30d191e Give the builtin generic functions proper interface types.
Swift SVN r9542
2013-10-21 16:11:02 +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