Commit Graph

847 Commits

Author SHA1 Message Date
Stephan Tolksdorf
79cef77ce0 [AST] Remove unused LazyResolver parameter from ObjC-selector-related Decl methods 2018-02-27 01:11:35 +01:00
Graydon Hoare
dd85e946e7 [Stats] Replace nonstandard SharedTimers with FrontendStatsTracers. 2018-02-21 14:49:24 -08:00
troughton
457ac78dc9 Correctly import C int types on Windows x64 2018-02-14 19:36:59 +13:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
fdd86fe069 Remove ImplicitlyUnwrappedOptionalType.
We haven't been creating these since
https://github.com/apple/swift/pull/14299 but there was more
groundwork before we could actually remove the type definition.
2018-02-05 23:59:01 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
2008674495 Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
Also remove the decl from the known decls and remove a
bunch of code referencing that decl as well as a bunch of other
random things including deserialization support.

This includes removing some specialized diagnostics code that
matched the identifier ImplicitlyUnwrappedOptional, and tweaking
diagnostics for various modes and various issues.

Fixes most of rdar://problem/37121121, among other things.
2018-02-02 08:35:53 -08:00
Rintaro Ishizaki
057254dbc1 [Syntax] Bump allocate and cache/reuse RawSyntax
Introduced SyntaxArena for managing memory and cache.

SyntaxArena holds BumpPtrAllocator as a allocation storage.
RawSyntax is now able to be constructed with normal heap allocation, or
by SyntaxArena. RawSyntax has ManualMemory flag which indicates it's managed by
SyntaxArena. If the flag is true, its Retain()/Release() is no-op thus it's
never destructed by IntrusiveRefCntPtr.
This speedups the memory allocation for RawSyntax.

Also, in Syntax parsing, "token" RawSyntax is reused if:
a) It's not string literal with >16 length; and
b) It doesn't contain random text trivia (e.g. comment).
This reduces the overall allocation cost.
2018-02-02 01:27:06 +09:00
David Zarzycki
3da6fe9c0d [AST] NFC: Do not reinterpret_cast pointers into CanTypeWrappers
This also introduces 'TypeArrayView' for when a 'Type' is statically
known to be a given TypeBase subclass.
2018-01-31 11:20:05 -05:00
David Zarzycki
7c096c9f26 [AST] NFC: Misc tiny fixes
1) Don't assume that the alignment of a random Type is equal to the
   alignment of Type itself.
2) Compute the bit count of RecursiveTypeProperties.
2018-01-30 09:28:22 -05:00
David Zarzycki
6d670c89c3 [AST] NFC: Find Optional enum elements semantically, not nominally 2018-01-14 19:01:28 -05:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Arnold Schwaighofer
498f30bf0c Default argument generators of functions must return 'noescaping' function types
A default argument generator must not return a @noescape function type.
Returning a @noescape function is nonsense. That means the function escapes.

* Assert that we don't return @noescape function types
* Fix for throwing default arguments
* Add more test cases
* Adapt to mangling changes

Part of:
SR-5441
rdar://36116691
2018-01-08 07:53:06 -08:00
David Zarzycki
2882e16c3f [AST] Perf: Make generic decl types share field offsets and fast casting logic 2018-01-01 13:52:15 -05:00
Karoy Lorentey
f481530a92 Merge pull request #13056 from xwu/much-of-a-muchness
[stdlib/Sema/AST] Adopt a commonly used implementation for combining hashes
2017-12-21 18:27:56 +01:00
David Zarzycki
3c128f3892 [AST] NFC: Minor performance tuning
1) Make AnyFunctionType::getParams() inline friendly (it compiles down
   to just a few instructions).
2) Byte align/size the embedded number of AnyFunctionType parameters.
   This was set to 10 bits back when the inline bitfields were 32 bits
   in size. Now with 64 bits to play with, we have room to spare.
2017-12-20 09:35:15 -05:00
David Zarzycki
54ea315586 [Basic] NFC: Stop using transparent unions 2017-12-16 10:43:49 -05:00
David Zarzycki
97541e0d1e [Basic] NFC: Standardize and simplify inline bitfields
Inline bitfields are a common design pattern in LLVM and derived
projects, but the associated boilerplate can be demotivating and
brittle. This new header makes it easier to define and use inline
bitfields in Swift.

This also reorders some fields for better code generation.
2017-12-15 14:14:59 -05:00
David Zarzycki
3af569cad2 [AST] NFC: Use llvm::TrailingObjects for ProtocolCompositionType member types
Also, fix a copy that should have been removed from the previous commit.
2017-12-12 16:29:30 -05:00
David Zarzycki
aa4d53e3dd [AST] NFC: Use llvm::TrailingObjects for BoundGenericType generic args 2017-12-12 15:47:07 -05:00
David Zarzycki
f45b16574d [AST] NFC: Use llvm::TrailingObjects for TupleType elements 2017-12-11 10:31:16 -05:00
Xiaodi Wu
30d5e344b1 Rename the combine hashes function and use a common implementation 2017-12-10 02:13:25 -06:00
David Zarzycki
a52b07faf8 [AST] NFC: Try to static_assert that ExtInfo and TypeBase agree 2017-11-27 07:55:58 -05:00
David Zarzycki
f228e98208 [AST] NFC: Simplify truncation detection 2017-11-22 17:09:49 -05:00
David Zarzycki
882ae3ac65 [AST] NFC: ExtInfo should reserve only needed TypeBase bits
Both AnyFunctionType and SILFunctionType reserve 16 bits in the TypeBase
for their respective "ExtInfo" bits, but then these types use less than
half of the bits they reserve. This patch changes AnyFunctionType and
SILFunctionType to only reserve what they need and then verify at
construction time that ExtInfo bits are not being truncated.

This change is motivated by the need to have more TypeBase bits
available for other uses.

Finally, this change fixes a copy-and-paste error introduced when
AnyFunctionType and SILFunctionType stopped sharing the same ExtInfo
data structure.
2017-11-22 16:31:42 -05:00
Doug Gregor
6dbde269b8 [AST] Collapse redundant specialized conformances.
Sometimes we end up mapping a conformance into and then out of a
particular context, which led to "stacked" specialized conformances
that were basically a no-op. Look through these to collapse them
eagerly.

Collapses 15786 conformances in the standard library.
2017-11-20 14:08:55 -08:00
John McCall
7743be30f6 Add a "token" type to SIL to allow dependencies to be expressed without
allowing abstraction.
2017-11-13 04:03:21 -05:00
Doug Gregor
a49455e3b2 [Clang importer] Move the "all properties" lists into the name importer.
Swift's ASTContext contained all of the logic to find the complete list
of properties for an Objective-C class, which is used by the Clang importer
to influence the mapping of Objective-C names into Swift. Swift's
ASTContext also included a *cache* for this information, indexed by
the Clang `ObjCInterfaceDecl *`. However, this cache was getting
populated/queried from the Clang importer's name importer, such that
the keys would be Clang declarations used to build modules and then
deallocated. If that memory eventually gets reused for a different
`ObjCInterfaceDecl *`, we would get incorrect/stale all-properties
information.

Almost Surely fixes rdar://problem/35347167, which is a
nondeterministic failure where UIView's `addGestureRecognizer(_:)` gets
occasionally imported as `add(_:)`.
2017-11-08 15:25:15 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
David Zarzycki
6d9a8bfb5b [AST] NFC: Simplify BoundGenericType::Profile
BoundGenericType::Profile() is the only Profile method that calculates the
recursive type properties as a side effect. This change makes the method
like all of the others.
2017-11-04 22:14:21 -04:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Doug Gregor
493d4da667 Warn on “near-misses” when defaults are used for protocol witnesses.
When a particular nominal type or extension thereof declares conformance
to a protocol, check whether that type or extension contains any members
that *nearly* match a defaulted requirement (i.e., a requirement that 
is satisfied by something in a protocol extension), but didn’t match
for some reason and weren’t used to satisfy any other requirement of
that protocol. It’s intended to catch subtle mistakes where a default
gets picked instead of the intended member.

This is a generalization of the code we’ve had for @objc optional
requirements for a long time.

Fixes rdar://problem/24714887.
2017-10-26 17:04:46 -07:00
Doug Gregor
1892dbd598 Cope with ill-formed recursion in associated type overrides computation.
Fixes some crasher regressions and accounts for some newly-fixed
crashers.
2017-10-17 22:23:14 -07:00
Slava Pestov
124251cf2c Merge pull request #9619 from allevato/synthesize-equatable-hashable
Synthesize Equatable/Hashable for complex enums, structs
2017-10-10 18:22:40 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
Doug Gregor
936a701b15 [AST] Stop uniquing canonical GSBs based on the module.
Now that the GenericSignatureBuilder is no longer sensitive to the input
module, stop uniquing the canonical GSBs based on that module. The main
win here is when deserializing a generic environment: we would end up 
creating a canonical GSB in the module we deserialized and another
canonical GSB in the module in which it is used.
2017-10-10 09:41:23 -07:00
Doug Gregor
ef542ffd8a [GSB] Eliminate the stored LookupConformanceFn to the GSB.
Implement a module-agnostic conformance lookup operation within the GSB
itself, so it does not need to be supplied by the code constructing the
generic signature builder. This makes the generic signature builder
(closer to) being module-agnostic.
2017-10-10 09:41:23 -07:00
Tony Allevato
715ba632dd Merge branch 'master' into synthesize-equatable-hashable 2017-10-09 15:57:36 -07:00
Doug Gregor
d3de4f2321 Merge pull request #12321 from DougGregor/assoc-type-overrides
Track "overrides" of associated types
2017-10-09 12:59:21 -07:00
Doug Gregor
15386fa0bf [AST] Track overriding relationship among associated types.
When an associated type declaration “overrides” (restates) an associated
type from a protocol it inherits, note that it overrides that declaration.
SourceKit now reports overrides of associated types.
2017-10-07 21:52:40 -07:00
Slava Pestov
9c0de31c22 AST: Simpler implementation of mapTypeOutOfContext()
Now that archetypes store an interface type, GenericEnvironments
no longer need to store a reverse mapping.
2017-10-07 05:44:57 -07:00
Doug Gregor
878abb08b3 Track the number of generic signature builders “registered”
The number of generic signature builders “registered” indicates how many
times a generic signature builder (GSB) was moved in to become the canonical
GSB, rather than recreating the GSB. When a GSB is “already registered”, it
means that we’ve constructed a new GSB only to find that there already was
a canonical GSB for that particular generic signature. These latter cases
could potentially benefit from more caching.
2017-09-28 16:19:08 -07:00
Doug Gregor
d93bed5ed1 [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-28 16:19:08 -07:00
Doug Gregor
0a1583fb87 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-28 14:27:15 -07:00
Doug Gregor
8f5d8aa7f9 Revert "[GSB] Centralize, clean up, and cache nested type name lookup" 2017-09-25 13:43:10 -07:00
Doug Gregor
a048194041 [GSB] Tighten up interfaces for computing a generic signature.
Funnel all places where we create a generic signature builder to compute
the generic signature through a single entry point in the GSB
(`computeGenericSignature()`), and make `finalize` and `getGenericSignature`
private so no new uses crop up.

Tighten up the signature of `computeGenericSignature()` so it only works on
GSB rvalues, and ensure that all clients consider the GSB dead after that
point by clearing out the internal representation of the GSB.
2017-09-25 08:47:40 -07:00
Tony Allevato
13ad81a173 Synthed hashValue now calls _mixForSynthesizedHashValue
For enums, we now only call _mixInt on the computed hash value if
it has associated values; for enums without associated values, we
use the ordinal alone, as before.
2017-09-24 10:57:31 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
David Ungar
d4cf2d4a24 Merge pull request #11656 from davidungar/addingTimers
Refactoring performSema in order to add timers
2017-09-22 20:31:06 -07:00
Doug Gregor
70861f64ec Track the number of generic signature builders “registered”
The number of generic signature builders “registered” indicates how many
times a generic signature builder (GSB) was moved in to become the canonical
GSB, rather than recreating the GSB. When a GSB is “already registered”, it
means that we’ve constructed a new GSB only to find that there already was
a canonical GSB for that particular generic signature. These latter cases
could potentially benefit from more caching.
2017-09-22 17:11:06 -07:00