Commit Graph

665 Commits

Author SHA1 Message Date
swift-ci
8932679fa1 Merge remote-tracking branch 'origin/master' into master-next 2017-04-20 13:08:31 -07:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
swift-ci
49e3cfb16f Merge remote-tracking branch 'origin/master' into master-next 2017-04-13 23:48:31 -07:00
Slava Pestov
5993b63944 AST: Introduce Builtin.AnyObject
Soon, Swift.AnyObject will become a protocol composition type
with no protocols and a class constraint. Since there's no
way to write this in the language, cons up an AnyObject type
in the Builtin module, so that the standard library can define
'typealias AnyObject = Builtin.AnyObject'.
2017-04-13 21:17:07 -07:00
Joe Groff
d42f2049f7 KeyPaths: Implement in-place instantiation of invariant key paths.
For key paths without generic or subscript parameterization, we can turn the compiler-generated key path pattern into a global object in-place.
2017-04-05 08:46:45 -07:00
swift-ci
9607aa1829 Merge remote-tracking branch 'origin/master' into master-next 2017-03-31 22:48:31 -07:00
Doug Gregor
5b3fe49cd0 [SE-0160] Log uses of @objc thunks emitted due to deprecated @objc inference.
Introduce a new runtime entry point,
`swift_objc_swift3ImplicitObjCEntrypoint`, which is called from any
Objective-C method that was generated due to `@objc` inference rules
that were removed by SE-0160. Aside from being a central place where
users can set a breakpoint to catch when this occurs, this operation
provides logging capabilities that can be enabled by setting the
environment variable SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT:

  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=0 (default): do not log
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=1: log failed messages
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=2: log failed messages with
  backtrace
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=3: log failed messages with
  backtrace and abort the process.

The log messages look something like:

    ***Swift runtime: entrypoint -[t.MyClass foo] generated by
       implicit @objc inference is deprecated and will be removed in
       Swift 4
2017-03-31 21:22:16 -07:00
Saleem Abdulrasool
15565c116a Adjust for SVN r298393 2017-03-22 07:44:03 -07:00
Michael Gottesman
6d7b11c8eb [stdlib] Cleanup usage of Builtin.castToNativeObject(...).
Previously often times when casting a value, we would just pass along the
cleanup of the uncasted value. With semantic SIL this is no longer correct since
the cleanup now needs to be on the cast result.

This caused problems for certain usages of Builtin.castToNativeObject(...) by
the stdlib. Specifically, the stdlib was using this on AnyObject values that
were not necessarily native. Since we were recreating the cleanup on the native
value, a swift native release was being used =><=.

In this commit I solve this problem by:

1. Adding an assert in Builtin.castToNativeObject(...) that ensures that any value
passed to Builtin.castToNativeObject() is known conservatively to use swift
native reference counting.

2. I changed all uses where we do not have a precondition of a native ref
counting type to use Builtin.castToUnknownObject(...).

3. I added a new Builtin called Builtin.unsafeCastToNativeObject(...) that does
not have the compile time check. I used this to rewrite callsites in the stdlib
where we know via preconditions that an AnyObject will dynamically always be
native.

rdar://29791263
2017-03-14 00:10:16 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Joe Groff
39ecc53a25 Add a loadInvariant builtin.
Lowers to an invariant load in LLVM; probably useful for SIL too at some point too, but NFC at that level yet.
2017-03-08 21:02:03 -08:00
Devin Coughlin
6ac36df1e7 SIL: Add SIL builtin for Thread Sanitizer inout accesses
...and IRGen it into a call to __tsan_write1 in compiler-rt. This is
preparatory work for a later patch that will add an experimental
option to treat Swift inout accesses as TSan writes.
2017-03-06 19:13:50 -08:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Doug Gregor
def14bfb70 [Archetype builder] Move checking for recursive constraints to finalize().
Rather than waiting until we try to form a contextual type to diagnose
recursion, perform the check while finalizing the archetype builder
itself.
2017-02-06 22:58:44 -08:00
Doug Gregor
4d7d40c14c Switch some clients over to GenericSignature::createGenericEnvironment().
These are the known-to-be-well-formed clients.
2017-02-05 21:23:44 -08:00
Bob Wilson
c765d5e3a5 Merge remote-tracking branch 'origin/master' into master-next 2017-01-12 15:58:19 -08:00
Doug Gregor
ac5e74601b [Archetype builder] Use a LookupConformanceFn to resolve protocol conformances.
Instead of creating an archetype builder with a module---which was
only used for protocol conformance lookups of concrete types
anyway---create it with a LookupConformanceFn. This is NFC for now,
but moves us closer to making archetype builders more canonicalizable
and reusable.
2017-01-10 16:40:38 -08:00
Bob Wilson
cf3a0458f2 Merge remote-tracking branch 'origin/master' into master-next 2017-01-10 09:05:23 -08:00
Hugh Bellamy
7a5ef4bdd1 Support building swift/AST with MSVC on Windows 2017-01-09 09:05:06 +00:00
Saleem Abdulrasool
3b9608338a Adjust for SVN r290708
The introduction of `llvm.memcpy.element.atomic` would cause an
ambiguity when we did the lookup with the trailing `.` for the type
parameters.  The intrinsic itself is not necessarily suffixed with the
type in the identifier.  Look up the identifier by explicit name.
2017-01-08 17:18:52 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
fb0f372e94 AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- The DeclContext versions of these methods have equivalents
  on the DeclContext class; use them instead.

- The GenericEnvironment versions of these methods are now
  static methods on the GenericEnvironment class. Note that
  these are not made redundant by the instance methods on
  GenericEnvironment, since the static methods can also be
  called with a null GenericEnvironment, in which case they
  just assert that the type is fully concrete.

- Remove some unnecessary #includes of ArchetypeBuilder.h
  and GenericEnvironment.h. Now changes to these files
  result in a lot less recompilation.
2016-12-18 19:55:41 -08:00
Slava Pestov
a384b2a677 Don't call VarDecl::getType() on deserialized VarDecls 2016-12-15 22:46:15 -08:00
Doug Gregor
84a88b067e [AST] Rename GenericSignatureBuilder -> BuiltinGenericSignatureBuilder.
Since I'm in the area, make it clear that this is building a signature
for builtins. Also, I plan to steal the name "GenericSignatureBuilder"
for what is currently the "ArchetypeBuilder" in the near future.
2016-12-07 16:42:11 -08:00
Doug Gregor
bacebb9505 [AST] Use ArchetypeBuilder to construct generic environments for builtins. 2016-12-07 16:42:11 -08:00
Michael Gottesman
59c6a64f5a [gardening] 0 => nullptr. Fixed with clang-tidy. 2016-12-06 23:14:13 -08:00
Michael Gottesman
1af1cbfb76 [gardening] Add a bunch of end namespace comments found by clang-tidy. 2016-12-06 19:22:52 -08:00
Slava Pestov
2d83a79c2c AST: Remove TypeDecl::getDeclaredType()
A pointless use of polymorphism -- the result values are not
interchangeable in any practical sense:

- For GenericTypeParamDecls, this returned getDeclaredInterfaceType(),
  which is an interface type.

- For AssociatedTypeDecls, this returned the sugared AssociatedTypeType,
  which desugars to an archetype.

- For TypeAliasDecls, this returned TypeAliasDecl::getAliasType(),
  which desugars to a type containing archetypes.

- For NominalTypeDecls, this returned NominalTypeDecl::getDeclaredType(),
  which is the unbound generic type, a special case used for inferring
  generic arguments when they're not written in source.
2016-12-01 13:00:18 -08:00
Doug Gregor
6f64658346 [AST] Stash an archetype builder in an "incomplete" generic environment.
This eliminates the really gross registration of archetype builders
within the ASTContext, and is another little step toward lazily
constructing archetypes.
2016-12-01 10:35:17 -08:00
Doug Gregor
95f1aaf4d1 [Archetype builder] Separate potential archetypes from *specific* archetypes.
Stop recording specific archetypes anywhere in
PotentialArchetype. Instead, use a GenericEnvironment to record/query
the archetype that corresponds to that PotentialArchetype, making it
possible to use the same archetype builder (and its potential
archetypes) to build multiple generic environments.
2016-11-30 15:44:13 -08:00
Slava Pestov
0f7a455d7d AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls 2016-11-29 03:05:33 -07:00
Doug Gregor
e656ca1dbc [AST] Compress ArchetypeType's storage slightly.
The "associated type" and "name" fields are mutually independent,
because one can recover the name from the associated type.
2016-11-28 11:25:45 -08:00
Doug Gregor
e7eeeb43ac [AST] Drop the 'isRecursive' bit from ArchetypeType. NFC 2016-11-28 09:55:31 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
85ba4fe40f [AST] Narrow TypeSubstitutionMap to SubstitutableType keys.
Type substitution works on a fairly narrow set of types: generic type
parameters (to, e.g., use a generic) and archetypes (to map out of a
generic context). Historically, it was also used with
DependentMemberTypes, but recent refactoring to eliminate witness
markers eliminate that code path.

Therefore, narrow TypeSubstitutionMap's keys to SubstitutableType,
which covers archetypes and generic type parameters. NFC
2016-11-15 11:34:09 -08:00
Huon Wilson
fa56e7928d [AST] Remove redundant GenericSignatures.
The GenericSignature is now canonically available through the
GenericEnvironment.
2016-11-11 14:57:04 -08:00
Huon Wilson
1102cf6643 [AST] Store a GenericSignature in GenericEnvironment.
An environment is always associated with a location with a signature, so
having them separate is pointless duplication. This patch also updates
the serialization to round-trip the signature data.
2016-11-11 14:57:03 -08:00
Doug Gregor
84d70a2284 Eliminate witness markers. NFC 2016-11-09 19:22:51 -08:00
Slava Pestov
5ab94a6ef0 AST: Add "re-sugaring" to GenericEnvironment
Sugared GenericTypeParamTypes point to GenericTypeParamDecls,
allowing the name of the parameter as written by the user to be
recovered. Canonical GenericTypeParamTypes on the other hand
only store a depth and index, without referencing the original
declaration.

When printing SIL, we wish to output the original generic parameter
names, even though SIL only uses canonical types. Previously,
we used to accomplish this by mapping the generic parameter to an
archetype and printing the name of the archetype. This was not
adequate if multiple generic parameters mapped to the same
archetype, or if a generic parameter was mapped to a concrete type.

The new approach preserves the original sugared types in the
GenericEnvironment, adding a new GenericEnvironment::getSugaredType()
method.

There are also some other assorted simplifications made possible
by this.

Unfortunately this makes GenericEnvironments use a bit more memory,
however I have more improvements coming that will offset the gains,
in addition to making substitution lists smaller also.
2016-10-12 18:56:16 -07:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
Joe Groff
b318763bb7 Add a builtin to generate the ObjC @encode string for a type.
We need the encode string to be able to construct NSValues using the core valueWithBytes:objCType: API. This builtin only works with concrete, @objc-representable types for now, which should be sufficient for a stdlib-internal API.
2016-09-19 11:14:01 -07:00
Erik Eckstein
d89a21460e Add builtins to generate instructions for tail-allocated arrays in SIL.
Those builtins are: allocWithTailElems_<n>, getTailAddr and projectTailElems
Also rename the "gep" builtin, which indexes raw bytes, to "gepRaw" and add a new "gep" builtin to index in a typed array.
2016-09-16 11:02:19 -07:00
Greg Parker
cd9a8afd5d Revert "SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel." (#4820) 2016-09-15 18:18:07 -07:00
Joe Groff
3441fe8ca4 Merge pull request #4782 from jckarter/bridging-enhancements
SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
2016-09-15 13:06:01 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Joe Groff
cfa9cd9a08 SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
id-as-Any lets you pass Optional to an ObjC API that takes `nonnull id`, and also lets you bridge containers of `Optional` to `NSArray` etc. When this occurs, we can unwrap the value and bridge it so that inhabited optionals still pass into ObjC in the expected way, but we need something to represent `none` other than the `nil` pointer. Cocoa provides `NSNull` as the canonical "null for containers" object, which is the least bad of many possible answers. If we happen to have the rare nested optional `T??`, there is no precedented analog for these in Cocoa, so just generate a unique sentinel object to preserve the `nil`-ness depth so we at least don't lose information round-tripping across the ObjC-Swift bridge.

Making Optional conform to _ObjectiveCBridgeable is more or less enough to make this all work, though there are a few additional edge case things that need to be fixed up. We don't want to accept `AnyObject??` as an @objc-compatible type, so special-case Optional in `getForeignRepresentable`.

Implements SR-0140 (rdar://problem/27905315).
2016-09-14 15:50:13 -07:00
Erik Eckstein
2a92b84b54 Add builtins to generate instructions for tail-allocated arrays in SIL.
Those builtins are: allocWithTailElems_<n>, getTailAddr and projectTailElems
Also rename the "gep" builtin, which indexes raw bytes, to "gepRaw" and add a new "gep" builtin to index in a typed array.
2016-09-14 14:54:18 -07:00
Erik Eckstein
7c374066e6 Remove the strideof_nonzero builtin.
Because now the stride of all types is at least one, anyway.
2016-09-14 13:24:19 -07:00