Commit Graph

1001 Commits

Author SHA1 Message Date
Doug Gregor
3df2c11c8a Diagnose Objective-C method overrides not reflected as Swift overrides.
Diagnose cases where the use of @objc will produce Objective-C methods
that end up overriding an Objective-C method in a superclass, when
that override is not properly represented as an override in the Swift
type system. This can happen when the Objective-C methods are produced
by different kinds of entities. For example:

  class Super {
    @objc var property: Int
  }

  class Sub : Super {
    @objc func setProperty(property: Int) { }
  }

In Swift, Sub.setProperty and Super.property are completely
unrelated. However, both produce an Objective-C instance method with
the selector "setProperty:", so we end up with unexpected overriding
behavior. Diagnose this whenever it occurs, regardless of the kind of
@objc entity that produced the Objective-C methods: initializers,
deinitializers, methods, properties, or subscripts.

Implements the rest of the intended functionality of
rdar://problem/18391046, with the caveat that there are two remaining
classes of bugs:
  1) Superclasses defined in a module (or imported from a Clang
  module) aren't handled properly yet; we might not see those methods.
  2) We won't properly detect all of these failures when the methods
  are scattered across different source files in the same module.

Swift SVN r23170
2014-11-08 00:55:45 +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
Jordan Rose
ca6639cf97 Track types that we perform qualified lookup on from the primary file.
We need to do this mainly to figure out when extensions can affect this file.
This is part of the intra-module dependency tracking work to implement
incremental rebuilds.

Part of rdar://problem/15353101

Swift SVN r22927
2014-10-24 22:23:05 +00:00
Jordan Rose
fc09bd4585 Add basic reference tracking based on name lookups.
This tracks top-level qualified and unqualified lookups in the primary
source file, meaning we see all top-level names used in the file. This
is part of the intra-module dependency tracking work that can enable
incremental rebuilds.

This doesn't quite cover all of a file's dependencies. In particular, it
misses cases involving extensions  defined in terms of typealiases, and
it doesn't yet track operator lookups. The whole scheme is also very
dependent on being used to track file-level dependencies; if C is a subclass
of B and B is a subclass of A, C doesn't appear to depend on A. It only
works because changing A will mark B as dirty.

Part of rdar://problem/15353101

Swift SVN r22925
2014-10-24 22:23:03 +00:00
Denis Vnukov
448822b1c4 Fixed an issue in IfConfigStmt parsing leading to source ranges verification assertions (rdar://problem/18251200).
The change also includes replacing BraceStmt* reference in IfConfigStmtClause structure with a simple list of clause elements.




Swift SVN r22868
2014-10-21 22:48:20 +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
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
Joe Pamer
a474d86305 When checking for shadowed values, account for the fact that we may be checking the rhs of a recursive binding.
This addresses crash suite scenarios 016 and 034. (rdar://problem/17837823)

Swift SVN r22125
2014-09-19 06:12:32 +00:00
Argyrios Kyrtzidis
856c6b6807 [TypeChecker] Refactor the accessibility calculations for declarations into a separate TypeChecker::validateAccessibility() function.
This is so that AccessFilteringDeclConsumer can filter without validating decls, thus avoiding unnecessary typechecking for
private declarations across the module during code-completion.

Test case on the SourceKit side.

Swift SVN r22052
2014-09-18 00:30:02 +00:00
Sean Callanan
d98e9aaf07 Use the DebuggerClient to find file-local names.
This is Jordan's fix, and he said he's going to
look into making a Swift-side test.  LLDB will be
using this very shortly.


Swift SVN r22034
2014-09-17 20:21:26 +00:00
Jordan Rose
cacec395db Drop the separate "LookupName" type for discriminated lookup.
Now that there's just one entry point for discriminated lookup, there's not
really a need for this extra abstraction.

One thing still up in the air is unqualified lookup support for discriminator
preferences (for, say, breakpoint conditions), but we'll cross that bridge
when we come to it.

Part of rdar://problem/17632175

Swift SVN r21755
2014-09-06 00:18:05 +00:00
Jordan Rose
1f5d81d5dc Teach swift-ide-test to look up entities by mangled name.
Currently this only handles top-level nominal types. We're just trying to
emulate what the debugger does when it needs to go from a mangled name to
an AST node, so it's okay that the cases handled here are very restricted.
We just want to make sure that the debugger is /able/ to do what it needs
to do.

This does not yet handle nested (non-top-level) values; that will require
changes to DeclContext::lookupQualified.

Part of rdar://problem/17632175

Swift SVN r21690
2014-09-03 23:42:13 +00:00
Jordan Rose
bbfedf989d Change qualified lookup to take a (DeclName, discriminator) pair.
This is in preparation for allowing demangling to match up with a particular
AST node, even if there are two private decls with the same name in the same
module. This commit doesn't actually change anything about the lookup; the
next commits will start adding support for the various lookups-with-
discriminators. (This is mostly only useful for the debugger.)

Part of rdar://problem/17632175

Swift SVN r21689
2014-09-03 23:42:11 +00:00
Doug Gregor
344ecfd3f9 Add a new 'fail' statement to the AST for failing from an initializer.
The spelling of the 'fail' statement is simply 'return nil', but
distinguishing it in the AST clarifies intent for SILGen.

Swift SVN r21310
2014-08-20 17:22:36 +00:00
Chris Lattner
4cc4039be1 remove an unnecessary #include in the middle of a file.
Swift SVN r21217
2014-08-14 20:24:18 +00:00
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +00:00
Jordan Rose
4eebcb9853 Change ASTContext's LoadedModules map to be keyed by Identifiers, not strings.
No intended functionality change, but there's no reason to be performing
string lookups here.

Swift SVN r20902
2014-08-01 18:03:47 +00:00
Jordan Rose
bf366de647 Don't find submodules via name lookup.
Previously, importing "ctypes.bits" would expose "bits" as a module name,
but that module would be empty and useless. We may want to revisit this
when we design submodules for Swift.

Swift SVN r20901
2014-08-01 18:03:44 +00:00
Doug Gregor
7c97642bf3 Don't check the inheritance clauses of extensions as part of validating the type they extend.
This makes the type checking slightly lazier for declarations, but is
otherwise NFC.

Swift SVN r20686
2014-07-29 19:49:02 +00:00
Doug Gregor
ac332429d9 Give extensions generic parameters and signatures within the AST.
This adds generic parameters and generic signatures to extension
declarations. The actual generic parameters just mirror what is
available on the extended type; however, it is filled in via extension
validation, which is handled lazily.

This is a NFC step toward decoupling the archetypes of extensions from
the archetypes of the extended types <rdar://problem/16974298>.

Swift SVN r20675
2014-07-29 16:20:56 +00:00
Jordan Rose
5c1e9d7d36 [Accessibility] Store setter accessibility explicitly.
Previously, we were just storing setter accessibility via the accessibility
level on the setter function. However, some Stored properties never actually
have a setter synthesized, which led to the compiler dropping the setter
accessibility at serialization time. Rather than try to hack up something
clever, just store the setter accessibility explicitly in every
AbstractStorageDecl. (We still only serialize it for VarDecls, because
settable SubscriptDecls always have setter functions.)

<rdar://problem/17816530>

Swift SVN r20598
2014-07-26 22:43:54 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Jordan Rose
4b5ce8703f Fix r19963 to /not/ respect access control when it's disabled.
<rdar://problem/17684933>

Swift SVN r20223
2014-07-20 17:26:22 +00:00
Jordan Rose
67536dbb8a Respect access control in visible decl lookup (and code completion).
<rdar://problem/17648922>

Swift SVN r19963
2014-07-14 23:02:41 +00:00
Jordan Rose
5b80dc3d44 Respect accessibility for scoped imports.
"import var Foo.bar" should error if "Foo.bar" is not public.

Swift SVN r19747
2014-07-09 22:10:20 +00:00
Jordan Rose
132a29eb67 Remove unnecessary wrapper type GenericParam.
This always wrapped a single GenericTypeParamDecl *, and provided no benefit
over just using the decl directly.

No (intended) functionality change.

Swift SVN r19628
2014-07-07 20:51:50 +00:00
Jordan Rose
f18dc4101f [Accessibility] Honor private(set) with -enable-access-control.
...for both variables and subscripts.

Swift SVN r19549
2014-07-04 01:53:49 +00:00
Jordan Rose
11742821c1 Respect access control for member lookups as well.
(when -enable-access-control is used)

Note that this is currently circumvented when looking up requirements in a
protocol. We're not currently set up to pass along the DeclContext where a
protocol's requirements are requested /from/, so we're just relying on the
fact that the requirements have the same visibility as the protocol in 1.0.

Swift SVN r19355
2014-06-30 18:50:53 +00:00
Jim Ingham
f685f4d8b7 Change how the DebugClient supplies names to the Name lookup (for lldb REPL and expression parser.) We used to be
only a fallback if no names are found.  But that meant the repl couldn't add overloaded versions of functions that
have any versions not provided by the debugger.  Now we augment the result of lookupInModule, and the rest of the
resolution mechanism can pick the right variant.

<rdar://problem/17025292>


Swift SVN r19301
2014-06-27 18:56:35 +00:00
Doug Gregor
b2224ca649 Remove another non-deterministic sort/unique.
Swift SVN r19219
2014-06-26 04:28:15 +00:00
Jordan Rose
a7b563855e Add a mode in which access control is respected for module-scope lookups.
This applies to both qualified and unqualified lookups, and is controlled
by the -enable-access-control and -disable-access-control flags. I've
included both so that -disable-access-control can be put into specific tests
that will eventually need to bypass access control (e.g. stdlib unit tests).
The default is still -disable-access-control.

Swift SVN r19146
2014-06-24 21:32:21 +00:00
Doug Gregor
afe7688b33 Allow inheritance of convenenience initializers for Objective-C classes.
Eliminates a weird special case for imported Objective-C classes,
fixing <rdar://problem/17032934>.

Swift SVN r18752
2014-06-09 20:18:58 +00:00
Joe Pamer
c81e822ef5 Add some logic to the type checking process to prevent stack overflows while type checking certain kinds of self-referential declarations. This addresses rdar://problem/1641865, rdar://problem/16994520 and host of other radars that have been filed over the past several months.
Post-WWDC, we need to update the type checking process to make these kinds of infinite loops impossible without checking special flags.

Swift SVN r18598
2014-05-23 18:19:29 +00:00
Joe Groff
05c80a8fe9 AST: Avoid instantiating all members when implicit destructors are inserted into classes.
We were accidentally forcing all members of a class to be instantiated in two places:

- by trying to look up an existing destructor decl in the class, and
- by adding the implicit destructor to the class, because addMember needlessly called loadAllMembers.

Fix the former problem by adding a 'has destructor' bit to ClassDecl so we can track whether the implicit destructor needs to be added without querying its members. Fix the latter by making IterableDeclContext::addMember not call loadAllMembers, and making loadAllMembers not barf when it sees existing members in the context.

Together with Jordan and JoeP's changes, this makes many interpreter tests now compile 3-20x faster.

Swift SVN r17562
2014-05-06 20:30:08 +00:00
Doug Gregor
bf4967958a When overriding a method or initializer, require the full names to match.
Do some QoI heroics here so that we get good diagnostics and Fix-Its
when we attempt to override but fail to do so because one picked
different argument names.

Swift SVN r16784
2014-04-25 00:32:42 +00:00
Doug Gregor
82a7f1f87b Improve de-duplication logic for imported Objective-C class initializers.
Before we create a new initializer, check whether it would collide
with existing initializers. If it's better than the existing
initializer, mark the existing one as unavailable; if it's not better,
don't build it.

In support of this, we tweak a few things w.r.t. unavailble
declarations:
  - An unavailable declaration is shadowed by an available one,
  - Don't emit SIL unavailable, imported initializers

This fixes the last problem with <rdar://problem/16509024>.



Swift SVN r16611
2014-04-21 06:26:52 +00:00
Doug Gregor
d35a2f5c94 Allow declarations to be made visible to name lookup before they are added.
NFC so far: the Clang importer will use this to suppress duplicates.


Swift SVN r16600
2014-04-20 20:24:05 +00:00
Doug Gregor
6b3ef547ec Replace "Members" arrays with an intrusive linked list.
The use of ASTContext-allocated arrays to store the members of nominal
type declarations and the extensions thereof is an
abomination. Instead, introduce the notion of an "iterable"
declaration context, which keeps track of the declarations within that
context (stored as a singly-linked list) and allows iteration over
them. When a member is added, it will also make sure that the member
goes into the lookup table for its context immediately.

This eliminates a ton of wasted memory when we have to reallocate the
members arrays for types and extensions, and moves us toward a much
more sane model. The only functionality change here is that the Clang
importer no longer puts subscript declarations into the wrong class,
nor does it nested a C struct within another C struct.



Swift SVN r16572
2014-04-19 23:37:06 +00:00
Doug Gregor
36889a2b1a Introduce DeclIterator and DeclRange for iterating over decl members.
NFC. DeclRange is a range over DeclIterators, and is used rather than
ArrayRef<Decl*> to retrieve the members of a nominal type declaration
or extension thereof. The intent is to change the representation of
DeclRange next.


Swift SVN r16571
2014-04-19 18:53:20 +00:00
Joe Pamer
7245e40825 The type checker collects all overloads for a given function application during the pre-type check phase, but equality conformances (and their associated '==' overloads) may be added to a type lazily during type resolution. This can lead to inconsistent behavior during type checking equality comparisons on imported enumeration types. (rdar://problem/16526249)
Basically, if an imported enumeration case is referenced without qualification as an argument to a '==' application (E.g., "foo.bar == .Baz"), and the enumeration type had not previously been resolved, overloads to '==' will be added to the global scope while performing overload resolution. This means the overloads will be ignored while solving for that application, but will be available for subsequent applications. (So you'll get an "expression does not type check" error the first time around, but not for subsequent applications of '==' to that enumeration type.)

The Equatable protocol is rather lightweight, however, and adding it to imported types directly results in no meaningful overhead to type check performance; we should just add it outright. As things evolve, though, it'll be worth considering how to make the type checker more amenable to lazy declarations.

Swift SVN r16557
2014-04-19 00:12:08 +00:00
Doug Gregor
d80b689c51 Introduce "convenience factory" initializers.
Convenience factory initializers are convenience initializers produced
by importing an Objective-C factory method as a convenience
initializer. The distinction is currently only used to eliminate the
awful layering violation I recently introduced in name lookup, which
was consulting Clang AST nodes directly. It will also be useful in
SILGen.

Swift SVN r16527
2014-04-18 15:34:26 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Doug Gregor
8676ae267a Teach name lookup to shadow factory-method-imported constructors with init-method-imported ones.
There is no way to avoid having both the factory-method-imported
constructor and the init-method-imported constructor show up in the
AST (which could happen in the REPL when subsequent modules are
loaded), so cope with the problem directly. Still, we can do somewhat
better here if we can suppress redundant declarations in the general
case and use "available" in the uncommon case.


Swift SVN r16495
2014-04-18 05:13:09 +00:00
Doug Gregor
b09fbf73b8 Centralize our addition of @objc attributes in the Clang importer.
Swift SVN r16348
2014-04-15 00:35:40 +00:00
Doug Gregor
3b6109e016 Add a member lookup table for classes keyed off an Objective-C selector.
Swift SVN r16346
2014-04-15 00:35:36 +00:00
Jordan Rose
22645d7f97 Add a wrapper type for the union of ArrayRef and LazyMemberLoader+context.
This requires some careful handling since the base of an ArrayRef and the
lazy loading "context data" both have no free bits, but it now works.
(It's essentially a TwoPointerUnion type, just specialized for a particular
pair of two-pointer types.)

No functionality change, except that NominalTypeDecl and ExtensionDecl
are two words smaller.

Swift SVN r15910
2014-04-04 01:17:54 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Joe Pamer
bcab632730 When requesting members or protocols from a type declaration, force any delayed members by default. This allows us to pretty-print otherwise unresolved implicit members of imported enums. (rdar://problem/16430343)
Swift SVN r15534
2014-03-26 22:31:02 +00:00