Commit Graph

3502 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
944e20949a [AST/IDE] Use TypeReprs to keep track of the type components in an ExtensionDecl.
This allows preserving type info and proper annotation of the extension's type components.

Swift SVN r25309
2015-02-16 08:36:16 +00:00
Roman Levenstein
7ced3da7e1 @transparent on declarations of vars with getters/setters inside extensions should not be ignored.
Swift SVN r25270
2015-02-13 15:31:44 +00:00
Doug Gregor
38a4f0c9fe Revert "Match Objective-C names in overrides as part of validation, not override checking."
This reverts r25243, per rdar://problem/19816977.

Swift SVN r25253
2015-02-12 22:01:19 +00:00
Doug Gregor
b25eda36fa Match Objective-C names in overrides as part of validation, not override checking.
Previously, we were using the Objective-C names to help determine
whether a declaration is an override or not. This is broken, because
we should determine overrides based on the Swift rules for
overriding, then (later) check that the Objective-C runtime will see
the same override behavior that the Swift runtime does. Address this
problem, both by taking the Objective-C selector out of the equation
when matching overrides (except for diagnostic purposes) and by
performing better validation of the Objective-C names for the
overriding vs. overridden methods/properties.

The motivating case here (from rdar://problem/18998564) is an
Objective-C initializer:

  -(instancetype)initString:(NSString *)string;

When trying to override this in a Swift subclass, one naturally
writes:

  override init(string: String)

which implicitly has the selector initWithString:. We ended up in an
unfortunate place where we rejected the override (because the
selectors didn't match) with a crummy diagnostic, but omitting the
"override" would result in a different conflict with the superclass.

Now, we'll treat this as an override and complain that one needs to
rename the method by adding "@objc(initString:)" (with a Fix-It, of
course). This fixes rdar://problem/18998564, but it is not ideal: the
complete solution (covered by rdar://problem/19812955) involves
reworking the dance between override and @objc so that we compute
'override' first (ignoring @objc-ness entirely), and let the
@objc'ness of the overridden declaration both imply @objc for the
overriding declaration and implicitly fix the selector. However, such
a change is too risky right now, hence the radar clone.

Swift SVN r25243
2015-02-12 17:46:56 +00:00
Joe Pamer
4d86ddc692 When checking if a decl with trivial accessors is settable, make sure it actually has a setter. Not doing so can lead to improper projections from rvalue to lvalue, and cause crashes during SIL generation. (rdar://problem/19781739)
Swift SVN r25215
2015-02-12 01:17:09 +00:00
Denis Vnukov
ec839a691f Fix for rdar://19773050, Swift 1.2b1: Compiler crash with errant curly brace
Handle error type in enum value declaration



Swift SVN r25193
2015-02-11 21:08:30 +00:00
Chris Lattner
38dbd74ccf fix <rdar://problem/19770775> Deferred initialization of let bindings rejected at top level in playground
by looking through TopLevelCode decls.


Swift SVN r25169
2015-02-11 07:10:00 +00:00
Doug Gregor
20bc247494 Use unified logic for determining whether a subscript index is bridged to an object type.
Fixes rdar://problem/19772357.

Swift SVN r25145
2015-02-10 23:56:07 +00:00
Doug Gregor
fc3a5a726a Make sure we don't add bogus same-type requirements to a generic signature.
Fixes rdar://problem/19137463.

Swift SVN r24972
2015-02-04 21:07:43 +00:00
John McCall
9e26ecf2af Make ArchetypeType::NestedType its own proper type
with more explicit/semantic conversions in and out.

Using a PointerUnion with overlapping pointer types
is both error-prone and pretty close to illegible.

Swift SVN r24707
2015-01-24 13:05:38 +00:00
Denis Vnukov
45c2d9741f Fix for rdar://problem/19539259, Fuzzing Swift: AST validation failed in getSignatureSourceRange(...)
Handle cases in AbstractFunctionDecl::getSignatureSourceRange() when param pattern elements do 
not have valid start/end locations.



Swift SVN r24688
2015-01-23 18:27:02 +00:00
Jordan Rose
66d0eccad2 Refactor the handling of *ApplicationMain classes.
Rather than keeping just a "main class" in every module, track the "main file"
that's responsible for producing the module's entry point. This covers both
main source files and files containing classes marked @UIApplicationMain or
@NSApplicationMain.

This should have no functionality change, but is preparation for the next
commit, where we will preserve some of this information in serialization.

Swift SVN r24529
2015-01-19 23:08:54 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
Doug Gregor
fea55d98f2 Eliminate dependent types from within archetypes.
When dealing with multiple levels of generic parameters, the mapping
from potential archetypes down to actual archetypes did not have
access to the archetypes for outer generic parameters. When same-type
requirements equated a type from the inner generic parameter list with
one from the outer generic parameter list, the reference to the outer
generic parameter list's type would remain dependent. For example,
given:

  struct S<A: P> {
    init<Q: P where Q.T == A>(_ q: Q) {}
  }

we would end up with the dependent type for A (τ_0_0) in the same-type
constraint in the initializer requirement.

Now, notify the ArchetypeBuilder of outer generic signatures (and,
therefore, outer generic parameters), so that it has knowledge of the
mapping from those generic parameters to the corresponding
archetypes. Use that mapping when translating potential archetypes to
real archetypes. Additionally, when a potential archetype is mapped to
a concrete type (via a same-type constraint to a concrete type),
substitute archetypes for any dependent types within the concrete
type.

Remove a bunch of hacks in the compiler that identified dependent
types in "strange" places and tried to map them back to
archetypes. Those hacks handled some narrow cases we saw in the
standard library and some external code, but papered over the
underlying issue and left major gaps.

Sadly, introduce one hack into the type checker to help with the
matching of generic witnesses to generic requirements that follow the
pattern described above. See ConstraintSystem::SelfTypeVar; the proper
implementation for this matching involves substituting the adoptee
type in for Self within the requirement, and synthesizing new
archetypes from the result.

Fixes rdar://18435371, rdar://18803556, rdar://19082500,
rdar://19245317, rdar://19371678 and a half dozen compiler crashers
from the crash suite. There are a few other radars that I suspect this
fixes, but which require more steps to reproduce.

Swift SVN r24460
2015-01-16 00:27:18 +00:00
David Farler
cad9f99929 Revert "Serialize local types and provide a lookup API"
Changing the design of this to maintain more local context
information and changing the lookup API.

This reverts commit 4f2ff1819064dc61c20e31c7c308ae6b3e6615d0.

Swift SVN r24432
2015-01-15 00:33:10 +00:00
David Farler
fab3d491d9 Serialize local types and provide a lookup API
rdar://problem/18295292

Locally scoped type declarations were previously not serialized into the
module, which meant that the debugger couldn't reason about the
structure of instances of those types.

Introduce a new mangling for local types:
[file basename MD5][counter][identifier]
This allows the demangle node's data to be used directly for lookup
without having to backtrack in the debugger.

Local decls are now serialized into a LOCAL_TYPE_DECLS table in the
module, which acts as the backing hash table for looking up
[file basename MD5][counter][identifier] -> DeclID mappings.

New tests:
* swift-ide-test mode for testing the demangle/lookup/mangle lifecycle
of a module that contains local decls
* mangling
* module merging with local decls

Swift SVN r24426
2015-01-14 22:08:47 +00:00
David Farler
87c3d7421f Refine static func and var syntax
rdar://problem/17198298

- Allow 'static' in protocol property and func requirements, but not 'class'.
- Allow 'static' methods in classes - they are 'class final'.
- Only allow 'class' methods in classes (or extensions of classes)
- Remove now unneeded diagnostics related to finding 'static' in previously banned places.
- Update relevant diagnostics to make the new rules clear.

Swift SVN r24260
2015-01-08 03:03:29 +00:00
John McCall
44eec49842 Change the signature of materializeForSet to return an
optional callback; retrofit existing implementations.

There's a lot of unpleasant traffic in raw pointers here
which I'm going to try to clean up.

Swift SVN r24123
2014-12-23 22:14:38 +00:00
Connor Wakamo
3c555ac19b Made Decl's ClangNode storage support 32-bit platforms.
Previously, this storage required that alignof(void *) >= alignof(Decl). This is
true on 64-bit platforms, where these are both 8, but on 32-bit platforms
alignof(void *) is only 4.

This now allocates enough bytes to match the alignment of the Decl in question.
This does mean that a void * must fit in that alignment, but this is true on 32-
and 64-bit platforms, and a static_assert ensures that this is true at compile
time.

As part of this change, the logic for allocating memory for a Decl has been
refactored into a separate function, so that the logic for allocating space for
a ClangNode can be centralized.

Swift SVN r23990
2014-12-17 21:23:16 +00:00
Chris Lattner
9414378210 change maintenance of "ParentPattern" in VarDecl to be implicitly handled by PatternBindingDecl itself, instead of having all clients do it.
Swift SVN r23918
2014-12-13 07:35:34 +00:00
Chris Lattner
a048b078e3 Implement: <rdar://problem/16181314> don't require immediate initialization of 'let' values
... now that we have an exquisitely shaved yak.

This provides a simple and uniform model for "let" constants: they are always either
immediately initialized in their declaration, or they are initialized dynamically
exactly once before any use.  

This is a simple generalization of our current model for initializers, but enables
the use of let constants in more cases in local context, e.g. patterns like this:

   let x : SomeThing

   if condition {
     x = foo()
   } else {
     x = bar()
   }
   use(x)

Previously this would have to be declared a "var" for no good reason: the value is
only ever initialized, never actually mutated.

The implementation of this is reasonably straight-forward now that the infrastructure
is in place: Sema treats 'let' constants as "settable" if they lack an initializer
(either in the declaration or in a non-PBD binding).  This exposes them as an lvalue
at the AST level.  SILGen then lowers these things to an alloc_stack, and DI enforces
the "initialization only" requirement that it already enforces for uninitialized 'let'
properties in structs/classes.



Swift SVN r23916
2014-12-13 07:17:44 +00:00
Chris Lattner
d844671de5 Revise our AST to represent the self argument of a non-mutating protocol method
as passing self by value, not by inout.  This is the correct representation at
the AST level, and we now lower self references as the new @in_guaranteed
parameter convention.  This allows SIL clients (like DI) to know that a nonmutating
protocol method does not mutate the pointee passed into the method.

This fixes:
<rdar://problem/19215313> let properties don't work with protocol method dispatch
<rdar://problem/15821762> Self argument of generic curried nonmutating instance methods is inout



Swift SVN r23864
2014-12-11 20:41:37 +00:00
Argyrios Kyrtzidis
b11d990818 Avoid APIs that return a new ASTContext-allocated array every time you call them.
Have them fill out a vector provided by the caller instead.

It is very easy to have callers just go through the array, thus wasting memory, as
the clang importer ended up doing.
The caller should be the one deciding if the array must be copied in ASTContext or not.

Swift SVN r23472
2014-11-20 06:33:27 +00:00
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Doug Gregor
89e5e5b6fa Diagnose redeclarations of Objective-C methods.
@objc methods, initializers, deinitializers, properties, and
subscripts all produce Objective-C methods. Diagnose cases where two
such entities (which may be of different kinds) produce the same
Objective-C method in the same class.

As a special exception, one can have an Objective-C method in an
extension that conflicts with an Objective-C method in the original
class definition, so long as the original class definition is from a
different model. This reflects the reality in Objective-C that the
category definition wins over the original definition, and is used in
at least one overlay (SpriteKit).

This is the first part of rdar://problem/18391046; the second part
involves checking that overrides are sane.

Swift SVN r23147
2014-11-07 01:15:14 +00:00
Doug Gregor
caca3ea2d1 Include outer generic parameters in the generic signatures for nominal types.
Generic function signatures were including outer generic parameters,
but generic type signatures were not. This is a small part of the
problem with nested generics (in general), but also a useful cleanup
for generic signatures.

Swift SVN r23011
2014-10-29 22:27:38 +00:00
Chris Lattner
691225337c teach DI that value_metatype doesn't require its argument to be fully initialized,
allowing some cases of "self.dynamicType" in initializers before self is fully
initialized.  There is still more to do.

This is part of:
<rdar://problem/17207456> Unable to access dynamicType of an object in a class initializer that isn't done



Swift SVN r22732
2014-10-14 20:51:21 +00:00
Doug Gregor
02808fb733 Remove resolvePotentialArchetypeToType() in favor of PotentialArchetype::getDependentType()
The latter uses information that is maintained by the potential
archetype, which makes it more efficient and simpler. NFC

Swift SVN r22645
2014-10-09 22:43:55 +00:00
Manman Ren
c0c5ef8158 [SILParser] parse address and mutableAddress without a body.
The result type of addressor or mutableAddressor can have invalid
location when it is created without a source location.


Swift SVN r22588
2014-10-08 00:21:39 +00:00
Roman Levenstein
6cabeeec02 Add a few helper methods for finding method implementations or overrides inside a given class or its superclasses. This can be used e.g. by the upcoming devirtualizer changes.
Swift SVN r22520
2014-10-04 09:49:43 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
John McCall
88b8254057 Lift the restrictions on addressors so that you can
define properties and subscripts with the
get+mutableAddress combination of accessors.

Fix a couple of simple problems this exposes.

rdar://17270560

Swift SVN r22419
2014-10-01 02:05:23 +00:00
John McCall
8c303ef7a6 Representational changes towards get-and-mutableAddress
properties.

The main design change here is that, rather than having
purportedly orthogonal storage kinds and has-addressor
bits, I've merged them into an exhaustive enum of the
possibilities.  I've also split the observing storage kind
into stored-observing and inherited-observing cases, which
is possible to do in the parser because the latter are
always marked 'override' and the former aren't.  This
should lead to much better consideration for inheriting
observers, which were otherwise very easy to forget about.
It also gives us much better recovery when override checking
fails before we can identify the overridden declaration;
previously, we would end up spuriously considering the
override to be a stored property despite the user's
clearly expressed intent.

Swift SVN r22381
2014-09-30 08:39:38 +00:00
Dmitri Hrybenko
d225e496e6 Fix warnings about && nested in ||
Swift SVN r22326
2014-09-28 01:55:18 +00:00
Dmitri Hrybenko
8fdd6aca87 Fix warnings about falling off the end of a function without a return
Swift SVN r22317
2014-09-27 23:34:22 +00:00
John McCall
f20225a34b Access properties and subscripts in the most efficient
semantically valid way.

Previously, this decision algorithm was repeated in a
bunch of different places, and it was usually expressed
in terms of whether the decl declared any accessor
functions.  There are, however, multiple reasons why a
decl might provide accessor functions that don't require
it to be accessed through them; for example, we
generate trivial accessors for a stored property that
satisfies a protocol requirement, but non-protocol
uses of the property do not need to use them.

As part of this, and in preparation for allowing
get/mutableAddressor combinations, I've gone ahead and
made l-value emission use-sensitive.  This happens to
also optimize loads from observing properties backed
by storage.

rdar://18465527

Swift SVN r22298
2014-09-26 06:35:51 +00:00
John McCall
6923101341 Rename "AccessKind" to "AccessSemantics". NFC.
There are a lot of different ways to interpret the
"kind" of an access.  This enum specifically dictates
the semantic rules for an access:  direct-to-storage
and direct-to-accessor accesses may be semantically
different from ordinary accesses, e.g. if there are
observers or overrides.

Swift SVN r22290
2014-09-25 23:12:39 +00:00
John McCall
a7c65273d5 Parsing and Sema support for addressors.
Swift SVN r22229
2014-09-23 20:34:21 +00:00
John McCall
16cb523c3a AST support for accessors.
Swift SVN r22228
2014-09-23 20:34:19 +00:00
Doug Gregor
44c1709505 Add EnumElementDecl::getArgumentInterfaceType().
Use this in calls to TypeBase::getTypeOfMember() that were relying on
archetypes solely because they were using EnumElementDecl::getArgumentType().

Swift SVN r22205
2014-09-23 03:44:00 +00:00
Doug Gregor
da32b678a1 Allow class/static properties to overload instance properties rdar://problem/18409106.
Swift SVN r22166
2014-09-22 06:14:07 +00:00
John McCall
8cae5ba1d0 Generalize 'isDirectPropertyAccess' to allow for
direct (i.e. non-polymorphic) access to accessor
functions, and use this in materializeForSet for
computed properties.

Swift SVN r22059
2014-09-18 05:51:32 +00:00
John McCall
cfc47fe882 Introduce a hack to ensure that we don't type-check the
body of a function twice.

This is almost taken care of by careful ordering, but it gets
all screwed up by synthesized accessor functions.  Just give
up and keep a bit.

Swift SVN r22019
2014-09-17 08:08:15 +00:00
John McCall
75050f8166 Generate an implicit 'materializeForSet' accessor
along with getters and setters.

Just generate it for now.

Swift SVN r22011
2014-09-17 08:08:03 +00:00
Manman Ren
1b60e87c28 [SILParser] reconstruct requirements in the same way as how type checker
generates them.

Modify getAsCanonicalGenericSignature to dump same-type requirements last.
Also mix the conformance requirements on assocaited archetypes with the witness
markers.

SILParser used to put witness markers for all assocaited archetypes, then
add same-type requirements, and finally the conformance requirements on
associated archetypes. This causes mismatch types between deserialized
SILFunctionTypes and parsed SILFunctionTypes.

rdar://17998988


Swift SVN r21423
2014-08-22 21:44:00 +00:00
Doug Gregor
7cae0cfc8e Remove -enable-dynamic and its language option; it's always on anyway.
Swift SVN r21354
2014-08-21 15:15:12 +00:00
Doug Gregor
42dc448e7e Reflect failability of an initializer in the optionality of its result type.
Don't verify this for the Optional and ImplicitlyUnwrappedOptional types.


Swift SVN r21293
2014-08-19 20:42:06 +00:00
Doug Gregor
c06e22d406 Revert r21291; it's breaking the standard library build.
Swift SVN r21292
2014-08-19 20:37:05 +00:00
Doug Gregor
e6f051fcd2 Reflect failability of an initializer in the optionality of its result type.
Swift SVN r21291
2014-08-19 20:22:25 +00:00
Doug Gregor
64bd844e0e Parse failable initializers.
Parsing, representation, (de-)serialization, printing, and dumping for
failable initializers.


Swift SVN r21290
2014-08-19 18:41:30 +00:00