Commit Graph

831 Commits

Author SHA1 Message Date
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
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
Doug Gregor
76a532b3af [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-22 17:11:05 -07:00
Doug Gregor
115d81a327 [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-22 11:32:26 -07:00
Tony Allevato
f2c434a038 Merge branch 'master' into synthesize-equatable-hashable 2017-09-21 22:54:36 -07:00
Kacper Harasim
80698a04b0 [IDE] SR-5745 Refactoring: converting strings concatenation expression to strings interpolation (#11944) 2017-09-19 13:37:42 -07:00
David Ungar
3d2484af28 git-clang-format
# Conflicts:
#	lib/Frontend/Frontend.cpp
2017-09-18 14:02:50 -07:00
David Ungar
26e90a624c Removed performTypeChecking timer
To maintain coverage added timers:
performWholeModuleTypeChecking, and
verifyAllLoadedModules
2017-09-18 14:01:12 -07:00
Xi Ge
73e5d66c7d ASTContext: Add a utility to retrieve the '+' function decl for RangeReplaceableCollection in the stdlib. NFC (#11964) 2017-09-15 18:47:25 -07:00
Tony Allevato
3731382bf6 Merge branch 'master' into synthesize-equatable-hashable 2017-09-09 14:23:13 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Slava Pestov
c522b49342 AST: Introduce ASTContext::getExistentialSignature()
Given an existential type E, this creates a new canonical
generic signature <T : E>.

If E is a protocol composition containing members of protocol,
class or AnyObject type, the resulting generic signature will
split up the T : E requirement into a canonical and minimal
set of conformance, superclass and layout requirements.

If/when we implement generalized existentials, existential
types will be defined in terms of an arbitrary set of
generic requirements applied to a single generic parameter;
at that point, this method will be replaced with a generic
signature stored inside the type itself.

For now, this will be used to simplify some logic in the
SILOptimizer.
2017-09-01 00:46:18 -07:00
Robert Widmann
75a83da03e Implement SE-0075: CanImport
This implementation required a compromise between parser
performance and AST structuring.  On the one hand, Parse
must be fast in order to keep things in the IDE zippy, on
the other we must hit the disk to properly resolve 'canImport'
conditions and inject members of the active clause into the AST.
Additionally, a Parse-only pass may not provide platform-specific
information to the compiler invocation and so may mistakenly
activate or de-activate branches in the if-configuration decl.

The compromise is to perform condition evaluation only when
continuing on to semantic analysis.  This keeps the parser quick
and avoids the unpacking that parse does for active conditions
while still retaining the ability to see through to an active
condition when we know we're moving on to semantic analysis anyways.
2017-08-28 18:35:06 -04:00
Slava Pestov
6f6974654a Sema: Fix type safety hole with convenience initializers which delegate to protocol extension initializers
A protocol extension initializer creates a new instance of the
static type of Self at the call site.

However a convenience initializer in a class is expected to
initialize an instance of the dynamic type of the 'self' value,
because convenience initializers can be inherited by subclasses.

This means that when a convenience initializer delegates to a
protocol extension initializer, we have to substitute the
'Self' type in the protocol extension generic signature with
the DynamicSelfType, and not the static type.

Since the substitution is formed from the type of the 'self'
parameter in the class convenience initializer, the solution is
to change the type of 'self' in a class convenience initializer
to DynamicSelfType, just like we do for methods that return
'Self'.

This fixes cases where we allowed code to type check that
should not type check (if the protocol extension initializer
has 'Self' in contravariant position, and we pass in an
instance of the static type).

It also fixes a miscompile with valid code -- if the protocol
extension initializer was implemented by calling 'Self()',
it would again use the static type and not the dynamic type.

Note that the SILGen change is necessary because Sema now creates
CovariantReturnExprs that convert a static class type to
DynamicSelfType, but the latter lowers to the former at the
SIL level, so we have to peephole away unnecessary unchecked_ref_cast
instructions in this case.

Because this change breaks source compatibility, it is guarded
by a '-swift-version 5' check.
2017-08-26 01:18:35 -07:00
Tony Allevato
8419f10883 Fix typo in _mixInt comment 2017-08-09 15:59:04 -07:00
Tony Allevato
1e1bed3334 [AST] Factor out common code in operator/func lookups 2017-08-08 18:30:22 -07:00
Tony Allevato
aa93ee52e1 Formatting and other cleanup. 2017-08-08 18:30:22 -07:00
Tony Allevato
eda0e38069 [AST] Accessors for ^= and _mixInt 2017-08-08 18:20:57 -07:00