Commit Graph

641 Commits

Author SHA1 Message Date
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
Michael Gottesman
00840a6b0e AST: adjust for SVN r275575 (#3597)
The intrinsics table is now split sorted, with the generic arguments being
lexicographically sorted prior to the target specific intrinsics.  Adjust the
search accordingly, as otherwise the builtins are not found as the basis for the
search no longer holds.
2016-08-30 23:23:38 -07:00
Michael Gottesman
fa1bb95923 Merge remote-tracking branch 'origin/master' into master-next 2016-08-30 19:50:12 -07:00
Slava Pestov
4bfaa47890 AST: Nuke GenericParamList::AllArchetypes
Now that SILFunctions no longer reference a GenericParamList, we
don't need to de-serialize cross-module references to archetypes
anymore.

This was the last remaining usage of AllArchetypes, so we can
finally rip it out.
2016-08-28 13:51:38 -07:00
Slava Pestov
1c1ab0b83a AST: Introduce new GenericEnvironment class
A GenericEnvironment stores the mapping between GenericTypeParamTypes
and context archetypes (or eventually, concrete types, once we allow
extensions to constrain a generic parameter to a concrete type).

The goals here are two-fold:

- Eliminate the GenericTypeParamDecl::getArchetype() method, and
  always use mapTypeIntoContext() instead

- Replace SILFunction::ContextGenericParams with a GenericEnvironment

This patch adds the new data type as well as serializer and AST
verifier support. but nothing else uses it yet.

Note that GenericSignature::get() now asserts if there are no
generic parameters, instead of returning null. This requires a
few tweaks here and there.
2016-08-28 13:51:36 -07:00
Slava Pestov
57c58176bc AST: Remove noreturn bit from function types 2016-07-24 00:15:34 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00
Saleem Abdulrasool
3c8eca195a AST: adjust for SVN r275575
The intrinsics table is now split sorted, with the generic arguments being
lexicographically sorted prior to the target specific intrinsics.  Adjust the
search accordingly, as otherwise the builtins are not found as the basis for the
search no longer holds.
2016-07-18 17:27:50 -07:00
Andrew Trick
2b732d0af5 Introduce Builtin.bindMemory and SIL bind_memory. (#3573)
Required for SE-0107: UnsafeRawPointer.
2016-07-18 13:18:03 -07:00
Mark Lacey
1c00ac4c6d Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	lib/IRGen/IRGen.cpp
	test/DebugInfo/parent-scope.swift
2016-07-15 19:23:53 -07:00
Andrew Trick
c47687da2c Add an isStrict flag to SIL pointer_to_address. (#3529)
Strict aliasing only applies to memory operations that use strict
addresses. The optimizer needs to be aware of this flag. Uses of raw
addresses should not have their address substituted with a strict
address.

Also add Builtin.LoadRaw which will be used by raw pointer loads.
2016-07-15 15:04:02 -05:00
Slava Pestov
5a902935e8 Sema: Explicitly set interface type on all AbstractFunctionDecls
Previously getInterfaceType() would punt to getType() if no
interface type was set. This patch changes getInterfaceType()
to assert if no interface type is set, and updates various
places to set the interface type explicitly.

This brings us a step closer to removing PolymorphicFunctionType.
2016-07-05 00:24:28 -07:00
Michael Gottesman
8d00a6cb59 Merge remote-tracking branch 'origin/master' into master-next
Conflicts:
	stdlib/public/SDK/GameplayKit/CMakeLists.txt
	test/DebugInfo/bound-namealiastype.swift
	test/DebugInfo/structs.swift
	test/IRGen/c_globals.swift
	test/SourceKit/DocSupport/doc_clang_module.swift
	test/SourceKit/Indexing/index_with_clang_module.swift
	utils/update-checkout
2016-06-25 01:13:50 -07:00
Slava Pestov
170992c39f AST: Add Throws flag and ThrowsLoc to AbstractFunctionDecl
The verifier now asserts that Throws, ThrowsLoc and isBodyThrowing()
match up.

Also, add /*Label=*/ comments where necessary to make the long argument
lists easier to read, and cleaned up some inconsistent naming conventions.

I caught a case where ClangImporter where we were passing in a loc as
StaticLoc instead of FuncLoc, but probably this didn't affect anything.
2016-05-21 12:51:50 -07:00
Michael Gottesman
0c1f6db23b [upstream-update] Add our own LLVM global context now that llvm::getGlobalContext() was removed upstream.
Swift relies on this for now. So create our own. This makes more sense
than trying to add back in the API (which is dead besides the c api) or
use the c api itself. We should probably consider not using a global
context like this.
2016-04-18 07:29:58 -07:00
Doug Gregor
c16e4ffa88 More llvm::AtomicOrdering fixes. 2016-04-14 10:13:01 -07:00
Doug Gregor
57bba50d7e Update our use of AtomicOrdering harder. 2016-04-13 09:01:46 -07:00
Doug Gregor
439ce2039b Update our use of AtomicOrdering for LLVM r265602 and r265685. 2016-04-12 17:29:55 -07:00
John McCall
21e9f5949a Merge remote-tracking branch 'origin/master' into master-next 2016-04-08 13:29:39 -07:00
Mark Lacey
b4787ffe79 Merge remote-tracking branch 'origin/master' into master-next 2016-03-31 16:15:11 -07:00
Erik Eckstein
a47a62d644 A new onFastPath built-in.
It is a hint to the optimizer that the code, where this builtin is called, is on the fast path.
Specifically, the inliner takes it into account and increases the assumed benefit for code where the builtin is located.

Compared to the fastPath/slowPath builtins, this builtin can be placed into plain linear code and doesn't need to be used in conditions.
Compared to the @inline(__always) attribute, this builtin has also an effect on the caller function. Let's assume
	foo() calls bar() contains onFastPath
and both foo and bar are small functions. Then if bar gets inlined into foo, the builtin also increases the chances that foo gets inlined.
This would not be the case if @inline(__always) is used just for bar.
2016-03-31 12:53:44 -07:00
Arnold Schwaighofer
bdaea9be27 Add Builtin.unsafeGuaranteed and Builtin.unsafeGuaranteedEnd
These builtins can be used to denote a scope over which the parameter passed to
unsafeGuaranteed can be assume to be @guaranteed: That is there is another
reference that keeps the value alive.

  // Scope begin
  strong_retain %0 : $Foo
  %2 = builtin "unsafeGuaranteed"<Foo>(%0 : $Foo) : $(Foo, Builtin.Int8)
  %3 = tuple_extract %2 : $(Foo, Builtin.Int8), 0
  %4 = tuple_extract %2 : $(Foo, Builtin.Int8), 1
  %5 = class_method %3 : $Foo, #Foo.beep!1 : (Foo) -> () -> ()
  %6 = apply %5(%3) : $@convention(method) (@guaranteed Foo) -> ()
  strong_release %3 : $Foo
  %8 = builtin "unsafeGuaranteedEnd"(%4 : $Builtin.Int8) : $(
  // Scope end

is semantically equivalent to:

  sil @guaranteed_lifetime : $@convention(method) (@guaranteed Foo) -> () {
  bb(%3: $Foo):
    %5 = class_method %3 : $Foo, #Foo.beep!1 : (Foo) -> () -> ()
    %6 = apply %5(%3) : $@convention(method) (@guaranteed Foo) -> ()
  }

  ...

  // Scope begin
  apply @guaranteed_lifetime(%0)
  // Scope end
2016-03-27 06:47:16 -07:00
Michael Gottesman
acf4c48b55 [upstream-update] Update how we lookup intrinsic names given upstream changes in llvm 258875. 2016-03-26 02:01:19 -07:00