Commit Graph

849 Commits

Author SHA1 Message Date
Erik Eckstein
1f8a9eb5c3 Optimize the generated == function for enums.
Before it was done with a big switch statement, which remained a switch until the final code.
Now it's done by getting an integer index for both enums and just doing an integer compare.
This results in a simple compare in the final code.

Note that the == function is only generated for enums without payload. Getting the integer
index of such enums is a cheap operation.




Swift SVN r23129
2014-11-06 16:04:50 +00:00
Joe Groff
24570fecc9 De-intrinsify and remove the _does*OptionalHaveValue functions.
Swift SVN r22955
2014-10-26 22:34:31 +00:00
Joe Groff
5a2f48e3be Add a Builtin.BridgeObject type.
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:

- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
  Builtin.BridgeObject

  Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
  "ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
  interfere with the reference identity of the resulting value. In other words,
  it is undefined behavior unless:

    castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref

  This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
  object pointer, "bits" must not have any non-spare bits set (unless they're
  already set in the pointer value). The native discriminator bit may only be set
  if the object is Swift-refcounted.

- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T

  Extracts the reference from a BridgeObject.

- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word

  Presents the bit pattern of a BridgeObject as a Word.

BridgeObject's bits are set up as follows on the various platforms:

i386, armv7:

  No ObjC tagged pointers
  Swift native refcounting flag bit: 0x0000_0001
  Other available spare bits:        0x0000_0002

x86_64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
  Swift native refcounting flag bit: 0x0000_0000_0000_0002
  Other available spare bits:        0x7F00_0000_0000_0004

arm64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
  Swift native refcounting flag bit: 0x4000_0000_0000_0000
  Other available spare bits:        0x3F00_0000_0000_0007

TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.

Swift SVN r22880
2014-10-23 00:09:23 +00:00
Dave Abrahams
8b9772d64e Revert "De-intrinsify and remove the _does*OptionalHaveValue functions."
This reverts commit r22829, because reverting r22828 depends on it.
Reverting r22828 because it
was apparently causing an assertion on the bot:

Swift SVN r22830
2014-10-19 19:54:34 +00:00
Joe Groff
7a24c85ed8 De-intrinsify and remove the _does*OptionalHaveValue functions.
Swift SVN r22829
2014-10-19 00:08:30 +00:00
Joe Groff
dc4d3818e0 De-intrinsify the _injectValueInto functions.
The runtime still invokes them, so we can't quite extricate them from the stdlib yet, but the compiler no longer needs them.

Swift SVN r22550
2014-10-06 20:45:37 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Devin Coughlin
15eb15598a Add SILGen for API availability query expression.
This patch adds SILGen for the API availability (#os(...)) construct. To do so,
it (1) adds version range information to the AvailabilityQueryExpr AST in Sema,
during type refinement context construction; and (2) uses that version range,
during SILGen, to emit a call to the standard library's
_stdlib_isOSVersionAtLeast function.


Swift SVN r22348
2014-09-29 01:24:36 +00:00
Joe Groff
9eb4f5b512 SILGen: Use Array._allocateUninitialized to form array literals.
This avoids a pointless copy every time an array literal is written, and will let us retire the horrible "alloc_array" instruction and globs of broken IRGen code. Implements rdar://problem/16386862, and probably fixes a bunch of bugs related to alloc_array brokenness.

Swift SVN r22289
2014-09-25 22:26:20 +00:00
Jordan Rose
9aed764daa Re-apply "Verify deserialized Swift decls as well as imported Clang decls."
Swift SVN r22248
2014-09-24 00:53:36 +00:00
Dmitri Hrybenko
fec622de0a Revert "Verify deserialized Swift decls as well as imported Clang decls."
This reverts commit 22200.  It broke building PerfTestSuite:
<rdar://problem/18423171> crash in type checking

Swift SVN r22209
2014-09-23 10:13:03 +00:00
Jordan Rose
a49874afb5 Verify deserialized Swift decls as well as imported Clang decls.
Like the Clang decls, this happens at the end of the type-checking, just as
a simple walk through the loaded decls of the loaded modules. This caught
all of the issues in this commit series and will hopefully keep us honest in
the future.

(By the way, we don't verify right when we return a deserialized decl for the
same reason we don't verify right when we return an imported decl: parts of
the decl may be delayed, and (a) we don't want to force things to be imported
or deserialized sooner than necessary, yet (b) we want to verify as much as
possible.)

rdar://problem/16968891

Swift SVN r22200
2014-09-23 02:06:27 +00:00
Doug Gregor
3119e6d345 Remove the tables that track the types that conform to "known" protocols.
The type checker no longer needs them.


Swift SVN r22137
2014-09-19 16:41:26 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Dmitri Hrybenko
d812966d32 stdlib: remove Optional.hasValue property
rdar://17931456


Swift SVN r21172
2014-08-13 10:51:26 +00:00
Joe Pamer
71cf758055 Mitigate exponential solver behavior (rdar://problem/17162690)
While we work out the remaining performance improvements in the type checker, we can improve the user experience for some "runaway solver" bugs by setting a limit on the amount of temporary memory allocated for type variables when solving over a single expression.

Exponential behavior usually manifests itself while recursively attempting bindings over opened type variables in an expression. Each one of these bindings may result in one or more fresh type variables being created. On average, memory consumption by type variables is fairly light, but in some exponential cases it can quickly grow to many hundreds of megabytes or even gigabytes. (This memory is managed by a distinct arena in the AST context, so it's easy to track.) This problem is the source of many of the "freezing" compiler and SourceKit bugs we've been seeing.

These changes set a limit on the amount of memory that can be allocated for type variables while solving for a single expression. If the memory threshold is exceeded, we can surface a type error and suggest that the user decompose the expression into distinct, less-complex sub-expressions.

I've set the current threshold to 15MB which, experimentally, avoids false positives but doesn't let things carry on so long that the user feels compelled to kill the process before they can see an error message. (As a point of comparison, the largest allocation of type variable data while solving for a single expression in the standard library is 592,472 bytes.) I've also added a new hidden front-end flag, "solver-memory-threshold", that will allow users to set their own limit, in bytes.

Swift SVN r20986
2014-08-03 23:10:42 +00:00
Jordan Rose
4eebcb9853 Change ASTContext's LoadedModules map to be keyed by Identifiers, not strings.
No intended functionality change, but there's no reason to be performing
string lookups here.

Swift SVN r20902
2014-08-01 18:03:47 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Joe Groff
c556d92ccd SILGen: Implement codegen for lvalue ForceValueExprs.
Add a set of _preconditionOptionalHasValue intrinsics that merely test that an optional has a case. Emit an lvalue ForceValueExpr as a physical lvalue, first asserting the precondition then projecting out the Some payload.

Swift SVN r20188
2014-07-18 22:49:49 +00:00
Joe Groff
09cfd4a43f CFunctionPointer is representable in @objc entry points if the function type argument is.
Swift SVN r20047
2014-07-16 22:13:26 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Joe Groff
954f746b92 SILGen: Implement pointer-to-pointer conversions.
Perform pointer-to-pointer argument conversions with the help of the _convertPointerToPointerArgument stdlib helper function.

Swift SVN r19105
2014-06-23 23:22:02 +00:00
John McCall
a2d5ad4c87 Add methods to easily fetch Some and None for a
particular optional type.

Swift SVN r19040
2014-06-20 07:46:59 +00:00
Joe Groff
dba8a23d64 AST: Refactor get*UnsafePointerDecl() lookups onto the AST context.
These types are needed by enough of the stack now that it makes sense to centralize their lookup and caching onto the AST context like other core types.

Swift SVN r19029
2014-06-20 03:02:29 +00:00
John McCall
7effec113c Change ImplicitlyUnwrappedOptional to be an enum type itself,
not a struct wrapping an Optional.

Among other things, this means you can now pattern-match on
an IUO.  It also makes it more convenient to build and destroy
them.

SILGen's type lowering should probably canonicalize one kind
of optional to the other so that we don't get silly abstraction
costs from conversion.

Swift SVN r18991
2014-06-18 23:27:08 +00:00
Doug Gregor
7eb090ab3a Macro-metaprogram array and dictionary up/downcast declaration accessors. NFC
Swift SVN r18962
2014-06-17 22:41:46 +00:00
Doug Gregor
2ccbcccc0a Rename Dictionary downcast entry points to include "Conditional".
s/_dictionaryCheckedDownCast/_dictionaryDownCastConditional/g
s/_dictionaryBridgeFromObjectiveC/_dictionaryBridgeFromObjectiveCConditional/g


Swift SVN r18931
2014-06-16 15:35:18 +00:00
Doug Gregor
c19b92e4b3 Rename array downcast entry points to have "conditional" in the name.
s/_arrayCheckedDownCast/_arrayDownCastConditional/g
s/_arrayBridgeFromObjectiveC/_arrayBridgeFromObjectiveCConditional/g



Swift SVN r18930
2014-06-16 15:06:04 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Doug Gregor
aac9b3c7e2 Implement SILGem support for dictionary downcasting.
Finishes <rdar://problem/16847470>.


Swift SVN r18901
2014-06-14 19:01:05 +00:00
Doug Gregor
b75093b367 Add SILGen support for dictionary upcasts <rdar://problem/17289296>.
This allows us to perform upcasts (including bridging upcasts) for dictionaries end-to-end.

Swift SVN r18889
2014-06-14 04:34:49 +00:00
Jordan Rose
79b45268e2 Allow ASTContext::getStdlibModule to load the stdlib if it isn't present.
This is better than requiring people to go through Ctx.getModule() using
Ctx.StdlibModuleName. There aren't that many cases of this, but they
shouldn't be using a completely different API.

The default behavior remains the same: if the standard library has not been
loaded, null will be returned.

Refinement of r18796, which modified the behavior of SourceFiles to assume
that the standard library had already been loaded.

Swift SVN r18813
2014-06-11 23:34:41 +00:00
Doug Gregor
2da304d05e Start using the _arrayBridgeFromObjectiveC entry point for checked downcasts.
This allows us to perform a checked downcast from an Object[] to a String[].

Swift SVN r18371
2014-05-19 00:04:41 +00:00
Argyrios Kyrtzidis
65e15380b1 [AST] Introduce ASTContext::getTotalMemory().
This is used to report the memory cost when caching an AST.

Swift SVN r18367
2014-05-18 23:38:23 +00:00
Doug Gregor
5783d0b313 Revert r19185: Add T* syntactic sugar type for UnsafePointer<T>.
Swift SVN r18255
2014-05-17 16:43:46 +00:00
Doug Gregor
806daf3a87 Add T* syntactic sugar type for UnsafePointer<T>.
This is the basic plumbing for <rdar://problem/16912508>.


Swift SVN r18195
2014-05-16 15:30:26 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Doug Gregor
8c41b1d6a2 Under -objc-bridge-dictionary, allow Dictionary<K, V> in an @objc entry point.
This is currently allowed when K is a subclass of NSObject and V works
with AnyObject. The easy part of <rdar://problem/16870606>.

Swift SVN r17805
2014-05-09 21:37:02 +00:00
Joe Pamer
709da29301 Implement checks for conditionally bridged types when performing a bridged conversion between array types. (rdar://problem/16540403)
Swift SVN r17660
2014-05-08 00:58:30 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +00:00
Joe Pamer
edb4946f66 Begin updating type checking of array upcasts to conform with the new spec.
Also, call through DaveA's new entry point for upcasts on Array<T>.

Swift SVN r17564
2014-05-06 21:32:22 +00:00
Chris Lattner
d230228cdd store the capture list of a ClosureExpr in the AST and print it out
in the AST dumper.


Swift SVN r17451
2014-05-05 16:25:33 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Chris Lattner
a7012f23ef Remove swift::ArrayType. It is dead and vestigial code for supporting fixed size
arrays, which never got baked.  Remove it until we have time to do things right.


Swift SVN r16995
2014-04-28 21:18:27 +00:00
Jordan Rose
0e7bb07b26 Make module loaders owned by the AST context instead of ref-counted.
Also, create the Clang module loader directly rather than indirecting through
a "get constructor" function. It's no longer a valid configuration to not
have a Clang importer.

Swift SVN r16862
2014-04-26 00:57:09 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Dmitri Hrybenko
fd25c253b2 Add constness to APIs
Swift SVN r16816
2014-04-25 12:01:17 +00:00
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