Commit Graph

755 Commits

Author SHA1 Message Date
Doug Gregor
93435d17d6 [Substitution Map] Handle substitutions of generic parameters made concrete.
If SubstitutionMap is asked to form a substitution for a generic
parameter that has been made concrete by the generic signature,
substitute into the concrete type. This allows us to better deal with
non-canonical types.
2017-04-28 16:22:07 -07:00
Erik Eckstein
76eca003bb ArrayElementValuePropagation: explicitly reserve space for new elements when doing the array-content-of optimization
When Array.append(contentOf:) is replaced by individual Array.append(element) calls, an explicit reserveCapacityForAppend is inserted.
2017-04-27 09:06:56 -07:00
Max Moiseev
42703c9978 Making compiler recognize Substring and allow _ObjectiveCBridgeable conformance 2017-04-25 15:02:51 -07:00
Arnold Schwaighofer
8979fcc4d9 Merge pull request #8868 from aschwaighofer/fix_repl_for_late_import_Foundation_and_cgfloat
ASTContext: Add CGFloat as a trivial representable kind even if we loaded CoreGraphics later
2017-04-21 12:24:07 -07:00
Arnold Schwaighofer
599cca2f1b ASTContext: Add trivially representable types even if we loaded their library later
Add CGFloat (and other types that this applies to) as a trivial type even after
the one-time initialization of the ForeignRepresentableCache.

This allows

  let str = ""
  import Foundation
  let pt = CGPoint(x: 1.0, y: 2.0)

to work.

Before we would populate the cache the first time on the first line "let str =
..." and because the CoreGraphics module was not loaded we would not add CGFloat
as a trivial type. When we come to query for CGFloat on the third line we would
return NSNumber instead of CGFloat as a type and that would crash IRGen.

rdar://31610342
2017-04-20 09:35:06 -07:00
practicalswift
a596961187 [gardening] Make parameter name comments match actual parameter names 2017-04-20 13:47:10 +02:00
Doug Gregor
d9af96ffe4 [AST] Remove more interface-type redundancy from ProtocolConformance. 2017-04-18 17:15:15 -07:00
Doug Gregor
4da11aab58 [AST] Teach SpecializedProtocolConformance to profile its substitutions.
Otherwise, we could theoretically get collisions, although they are
quite unlikely to matter in practice.
2017-04-18 17:15:15 -07:00
Roman Levenstein
07d779058a Address review comments
- Avoid unnecessary memory allocation
- Fix spelling errors
- Some further minor fixes
2017-04-17 11:44:57 -07:00
Roman Levenstein
7933b4fab0 Fix a bug with SILBoxType’s generic arguments
The set of SILBoxType’s generic arguments should be canonical, otherwise getCanonicalType() produces wrong results.

It does not contain a reduced test-case, because the actual bug happens when compiling the stdlib on one of the experimental branches and requires a rather complex setup. I'll try to provide a test-case later.

Resolves one of the issues in rdar://31603112
2017-04-14 19:58:29 -07:00
Slava Pestov
db58e02cb2 Sema: Hook up layout constraints to the solver
There were various problems with layout constraints either
being ignored or handled incorrectly. Now that I've exercised
this support with an upcoming patch, there are some fixes
here.

Also, introduce a new ExistentialLayout::getLayoutConstriant()
which returns a value for existentials which are class-constrained
but don't have a superclass or any class-constrained protocols;
an example would be AnyObject, or AnyObject & P for some
non-class protocol P.

NFC for now, since these layout-constrained existentials cannot
be constructed yet.
2017-04-13 21:17:05 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.

Serialize this bit and take it into account when building
ExistentialLayouts.

Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.

For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
2017-04-13 21:17:05 -07:00
Doug Gregor
5b4f2e64d6 [GSB] More detailed debug dump for GSB idempotency failures. 2017-04-11 14:15:46 -07:00
Slava Pestov
32a7505847 AST: Update ProtocolCompositionType::get() for subclass existentials
Don't assume all members are existential types; we could have
a class (or a class-constrained existential) also, and this
needs to be handled.

When building a canonical protocol composition, the subclass
requirement always comes first in the list of types. This is
an important invariant allowing ExistentialLayout to be
calculated quickly.

Also, calculate the recursive properties of the composition
type from the recursive properties of its members, since they're
no longer trivial if the composition contains a class member
with generic parameters.
2017-04-10 17:05:42 -07:00
Slava Pestov
9c3b514c7e AST: New getExistentialLayout() method on TypeBase and CanType
This consolidates calculations which need to look at every
protocol in an existential type. Soon we will also have to
deal with superclass constrained existentials, so start
updating call sites that look at all protocols to use the
new ExistentialLayout and correctly handle a class constraint
as well.

Also, eventually I will kill off the AnyObject protocol and
model it as a protocol composition with no protocols or
superclass, but the requiresClass() flag set.

This is not quite modeled this way yet and AnyObject still
exists, but the new abstraction is a step in the right
direction.
2017-04-10 17:04:37 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Erik Eckstein
f07ed5a78f Helper function in ASTContext to get the Array’s append element function.
Based on the semantics attribute.
2017-03-31 15:31:57 -07:00
Doug Gregor
e2ca174090 [AST] Fail more descriptively when GenericSignatureBuilder is not idempotent 2017-03-24 13:16:17 -07:00
Slava Pestov
237131cbbe AST: Add assertion to catch improper generic signature canonicalization
We expect that feeding a signature into a new GenericSignatureBuilder
and returns the same signature back.
2017-03-24 11:36:44 -07:00
Roman Levenstein
4e2262944d Extend the representation of layout constraints
- Add support for _Class and _NativeClass layout constraints, which are supposed to represent T: Superclass and P: class constraints in the future.
- Use the re-factoring to also reduce the number of dynamic allocations when creating layout constraints. Simple non-parametrized layout constraints are now represented as statically allocated singletons (static members of LayoutConstraintInfo).
2017-03-22 16:37:38 -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
Alex Hoppen
4f0ab96626 Change the backing base name type of DeclName to DeclBaseName
The new DeclBaseName type will later be able to hold either normal
identifiers (as they exist now) or special names that don't have an
identifier (like subscripts)
2017-03-10 21:44:17 +00:00
Xi Ge
555e52206a Sema: fill-protocol-stub fixits should include those missing witnesses that are handled by delayed diagnostics. (#8011) 2017-03-10 11:54:25 -08:00
Slava Pestov
2777c9b478 AST: Remove TypeBase::gatherAllSubstitutions() 2017-03-08 13:54:31 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -08:00
Jordan Rose
e58d02b88b Make sure ErrorTypes containing type variables are marked as such. (#7963)
In some cases, the type checker will produce error types with the
"original type" intact for recovery purposes. Like other types, when
the original type contains a type variable, the ErrorType instance
will be allocated in the "temporary" memory arena associated with the
active constraint solver, because there's no way that particular error
will come up again once the constraint system containing that type
variable has been destroyed.

However, we weren't propagating that "contains a type variable"
information to the newly-created ErrorType, which meant that any type
/containing/ that ErrorType would be allocated in the "permanent"
arena. In practice, this would always be a DependentMemberType; not
too many types are created without looking at their base types at all.
The arena containing the ErrorType would then be deallocated, and its
memory reused later on for a /different/ type. If we ever tried to
make a DependentMemberType whose base was this new type, we'd find the
old DependentMemberType instance in our cache and return that. The
result was that we'd have a DependentMemberType whose "HasError" bit
was set even though the base type was not an error type, and which was
considered canonical whether or not the base type was. This would then
either hit an assertion later on or result in nonsensical errors like
"'C.Iterator' is not the same type as 'C.Iterator'".

Because the reused address always referred to a valid type, none of
the usual dynamic analysis tools could catch the problem. It really
comes down to using a pointer address as a key in a map---but even
without that, we were allocating types in the permanent arena that
really should be temporary, which is a waste of memory.

Likely fixes rdar://problem/30382791, a nondeterministic failure we've
been seeing for weeks on the bots and on developer machines.
2017-03-07 15:18:01 -08:00
Doug Gregor
ec4bf005af [AST] Eliminate unnecessary #includes of AST/ProtocolConformance.h. 2017-03-01 08:22:39 -08:00
Slava Pestov
b319a3aa32 AST: Clean up some more duplication using the new GenericContext 2017-02-19 21:00:00 -08:00
Argyrios Kyrtzidis
ca906d1e99 Add '-Fsystem' framework search option to indicate path for frameworks that should be treated as 'system'
This has the effect of propagating the search path to the clang importer as '-iframework'.
It doesn't affect whether a swift module is treated as system or not, this can be done as follow-up enhancement.
2017-02-14 16:13:25 -08:00
practicalswift
6daa23fa8e [gardening] Fix a vs an typos 2017-02-13 14:45:16 +01:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Doug Gregor
579af863c5 Rename ArchetypeBuilder -> GenericSignatureBuilder 2017-02-10 12:46:34 -08:00
Slava Pestov
a16faae73b AST: Move ProtocolConformance::getTypeWitnessByName() to ProtocolConformanceRef
I need to move some #includes around ("include what you use") to
break circularities for an upcoming refactoring.
2017-02-08 15:33:46 -08:00
Roman Levenstein
e5d5d7d5fd Some LayoutConstraint improvements.
This biggest change is:
- LayoutConstraintInfo is now a FoldingSetNode, which allows for proper canonicalization of LayoutConstraints. This is important for the correctness of type comparisons if types contain layout constraints.

No functionality changes from the client's point of view.
2017-02-07 17:03:11 -08:00
swift-ci
ec274a1bbd Merge pull request #7298 from DougGregor/early-recursive-constraints 2017-02-06 23:28:51 -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
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Doug Gregor
fee89fe7c8 Merge pull request #7266 from DougGregor/generic-signature-create-env
Introduce `GenericSignature::createGenericEnvironment()`
2017-02-06 16:24:47 -08:00
Graydon Hoare
9cb1c52fd8 Count constraint-solving memory more precisely, rdar://29684330 2017-02-06 13:04:19 -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
Doug Gregor
2b9260cdb5 [AST] Add GenericSignature::createGenericEnvironment().
This will eventually be the canonical way to create new generic environments. For now, it’s mainly aspirational.
2017-02-05 21:23:44 -08:00
Doug Gregor
faf659d16b [Archetype builder] Make sure the archetype builder is always "finalized".
ArchetypeBuilder::finalize() is needed to tie up any loose ends before
requesting a generic signature or generic environment. Make sure it
gets called consistently.
2017-02-05 21:23:44 -08:00
Slava Pestov
45a19ddf2d Sema: Fix assertion failures with UnresolvedType in diagnostics
We sometimes construct DependentMemberTypes with an UnresolvedType
base. These are not "real" interface types and can end up in
places where we don't expect interface types, triggering an
assertion. Make sure such types don't respond true to hasTypeParameter().
2017-01-28 18:35:23 -08:00
Slava Pestov
0efa3fb849 AST: Better assertions to catch ErrorTypes in bad places 2017-01-26 21:20:05 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Hugh Bellamy
201ad5d594 Prefix COMPILER_IS_MSVC with SWIFT_ 2017-01-16 22:09:53 +00:00
Hugh Bellamy
cf777d04f5 Introduce and use COMPILER_IS_MSVC 2017-01-15 15:17:18 +00:00
Doug Gregor
0b2a263688 Actually preserve the uniqueness of canonical generic environments. 2017-01-12 11:07:06 -08:00
Roman Levenstein
29180ca1a0 Add support for layout requirements with layout constraints.
This commit introduces new kind of requirements: layout requirements.

This kind of requirements allows to expose that a type should satisfy certain layout properties, e.g. it should be a trivial type, have a given size and alignment, etc.
2017-01-11 19:21:45 -08:00