Commit Graph

557 Commits

Author SHA1 Message Date
Doug Gregor
834b1f0bab Remove code I didn't mean to commit in r28167.
Swift SVN r28169
2015-05-05 17:12:30 +00:00
Doug Gregor
6e114e3cfe Reinstate r26814: Allow 'var' parameters in @objc methods.
'var' parameters affect the definition of the method itself, not its
signature. Fixes rdar://problem/20543054.

Swift SVN r28167
2015-05-05 16:34:09 +00:00
Joe Groff
d0473756ec ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types.
The design we landed on for SIMD is to define the vector types as nested types of their element, e.g. Float.Vector4, Int32.Vector2, etc. Update the Clang importer and other mapping facilities to match.

Swift SVN r28087
2015-05-02 15:04:43 +00:00
John McCall
5c171fd448 Parsing, type-checking, SILGen, and IRGen for try!.
Swift SVN r28085
2015-05-02 08:03:15 +00:00
Doug Gregor
514ef30943 (De-)serialization for foreign error conventions.
Printing a module as Objective-C turns out to be a fantastic way to
verify the (de-)serialization of foreign error conventions, so
collapse the parsing-driving Objective-C printing test of throwing
methods into the general test for methods.

Swift SVN r27880
2015-04-28 20:59:32 +00:00
Doug Gregor
7dafdf873c Revert "(De-)serialization for foreign error conventions."
This reverts r27870. It's causing inexplicable SourceKit failures.

Swift SVN r27875
2015-04-28 17:50:59 +00:00
Doug Gregor
a487a9e345 (De-)serialization for foreign error conventions.
Printing a module as Objective-C turns out to be a fantastic way to
verify the (de-)serialization of foreign error conventions, so
collapse the parsing-driving Objective-C printing test of throwing
methods into the general test for methods.

Swift SVN r27870
2015-04-28 16:00:47 +00:00
Doug Gregor
2fdd8ed6e1 Delay protocol-conformance diagnostics until the conformance is fully checked.
When we're checking for a particular witness in a protocol conformance
because the result is needed elsewhere, capture the diagnostic we
would emit and then store it in the ASTContext. We will emit these
diagnostics when doing the full check of the conformance. Addresses
the rest of rdar://problem/20564378.

Swift SVN r27449
2015-04-18 05:03:31 +00:00
Argyrios Kyrtzidis
707394aea8 [AST] Refactor implementation for ValueDecl::getSatisfiedProtocolRequirements().
Move the map that keeps track of conforming decl -> requirement from ASTContext
to a nominal type's ConformanceLookupTable, and populate it lazily.

This allows getSatisfiedProtocolRequirements() to work with declarations from module files.
Test on the SourceKit side.

Part of rdar://20526240.

Swift SVN r27353
2015-04-16 06:23:56 +00:00
John McCall
a67452c72c SILGen for throwing foreign errors out of @objc thunks.
Also, create a new file specifically for the foreign-error
code.

Swift SVN r27347
2015-04-16 05:16:54 +00:00
Argyrios Kyrtzidis
92ec232e0c [AST] Rename ValueDecl::getConformances() -> getSatisfiedProtocolRequirements(), NFC.
Swift SVN r27321
2015-04-15 17:19:19 +00:00
Argyrios Kyrtzidis
bc6277aacb [AST] Add const-ness for ValueDecl::getConformances().
Swift SVN r27317
2015-04-15 14:47:03 +00:00
John McCall
d62a154e29 Import ObjC method error-handling conventions. WIP.
Swift SVN r27193
2015-04-10 00:32:54 +00:00
Doug Gregor
22179164aa Type utilities for working with opened existential types.
Swift SVN r27188
2015-04-09 23:58:53 +00:00
Jordan Rose
cbe78a5793 Use a proper enum in the implementation of search path deduplication (r27087)
No functionality change. Fix-up for rdar://problem/20291720

Swift SVN r27093
2015-04-07 21:39:12 +00:00
Jordan Rose
f0d529719c Deduplicate search paths.
Now that we can pick up search paths from frameworks (necessary to debug
them properly), we can end up with exponential explosions leading to the
same search path coming up thousands of times, which destroys compilation
time /and/ debugger responsiveness. This is already hitting people with
frameworks compiled for app extensions (due to a mistaken approximation
of whether or not something is a framework), but we're turning this on for
all frameworks in the immediate future.

rdar://problem/20291720

Swift SVN r27087
2015-04-07 18:24:12 +00:00
Jordan Rose
c5e46b524d Add Module::failedToLoad(), mainly for REPL and debugging purposes.
LLDB asked for this to differentiate between modules loaded successfully and
modules that are correctly found but can't be loaded for some reason.

rdar://problem/19750055

Swift SVN r27041
2015-04-06 21:23:57 +00:00
Joe Groff
56de5fb95e SIL: Drop unnecessary bits from SILFunctionType::ExtInfo.
"Autoclosure" is uninteresting to SIL. "noescape" isn't currently used by SIL and we shouldn't have it until it has a meaningful effect on SIL. "throws" should be adequately represented by a SIL function type having an error result.

Swift SVN r27023
2015-04-05 17:35:28 +00:00
Joe Groff
4821f594bb SIL: Separate SILFunctionType::Representation and ExtInfo from AST FunctionTypes.
The set of attributes that make sense at the AST level is increasingly divergent from those at the SIL level, so it doesn't really make sense for these to be the same. It'll also help prevent us from accidental unwanted propagation of attributes from the AST to SIL, which has caused bugs in the past. For staging purposes, start off with SILFunctionType's versions exactly the same as the FunctionType versions, which necessitates some ugly glue code but minimizes the potential disruption.

Swift SVN r27022
2015-04-05 17:04:55 +00:00
Doug Gregor
aa0e763940 Imbue ASTContext with a lazy resolver.
Have TypeChecker's constructor register itself as the lazy resolver,
and its destructor unregister itself. This introduces the
completely-sensible restriction that there can only be one type
checker active for an ASTContext at a time, which is the case already.

Use ASTContext's lazy resolver in a single place that's been causing
trouble (rdar://problem/20363958, rdar://problem/19773096), where
deserializing a protocol conformance can cause us to pass a null lazy
resolver into the protocol conformance table, which doesn't handle it
well. This commit fixes those issues, which I'm unable to reduce down
to a sane-enough test case to commit.

This commit implies a ton of cleanup work to eliminate LazyResolver
parameters from *everywhere*, deriving them from the ASTContext in the
few places they're needed as well. It's a good direction, but that
cleanup can be evolutionary.

Swift SVN r26824
2015-04-01 21:31:47 +00:00
Xi Ge
fb2c8aa103 [SDKAnalyzer] The initial commit of swift sdk digester.
This tool takes the input of two versions of the same sdk and outputs
their diff to facilicate the auto-migration of sdk clients.
In this initial commit, we take the path of one sdk and generate
a tree describing its API content. Next, we will diff trees generated
from different versions of the sdk.

In addition, this commit also refactored out part of swift-sdk-analyzer
to the common utils shared with swift-sdk-digester.

Swift SVN r26656
2015-03-28 00:05:28 +00:00
Doug Gregor
3d77855b31 Start allowing extensions of protocol types.
Remove the semantic restrictions that prohibited extensions of
protocol types, and start making some systematic changes so that
protocol extensions start to make sense:
  - Replace a lot of occurrences of isa<ProtocolDecl> and
    dyn_cast<ProtocolDecl> on DeclContexts to use the new
    DeclContext::isProtocolOrProtocolExtensionContext(), where we want
    that behavior to apply equally to protocols and protocol extensions.
  - Eliminate ProtocolDecl::getSelf() in favor of
    DeclContext::getProtocolSelf(), which produces the appropriate
    generic type parameter for the 'Self' of a protocol or protocol
    extension. Update all of the callers of ProtocolDecl::getSelf()
    appropriately.
  - Update extension validation to appropriately form generic
    parameter lists for protocol extensions.
  - Methods in protocol extensions always use the witnesscc calling
  convention.

At this point, we can type check and SILGen very basic definitions of
protocol extensions with methods that can call protocol requirements,
generic free functions, and other methods within the same protocol
extension.

Regresses four compiler crashers but improves three compiler
crashers... we'll call that "progress"; the four regressions all hit
the same assertion in the constraint system that will likely be
addressed as protocol extensions starts working.

Swift SVN r26579
2015-03-26 04:50:51 +00:00
John McCall
35b7db3ae1 Parsing support for error results from SILFunctionType.
Swift SVN r26566
2015-03-26 00:01:32 +00:00
Doug Gregor
04e9c9892e Start threading a DeclContext through substitution computation.
The context in which the substitution occurs matters because it determines which generic parameters we compute. NFC for now.

Swift SVN r26441
2015-03-23 19:00:54 +00:00
Doug Gregor
479660b54b When !NDEBUG, track the contexts of archetype types.
Helps with debugging when archetypes get tangled together. NFC

Swift SVN r26439
2015-03-23 19:00:51 +00:00
John McCall
08d3460a19 Implement throw expressions. Untested.
Tests tomorrow for this and 'catch', I promise. :)

Swift SVN r26432
2015-03-23 08:10:15 +00:00
Doug Gregor
9bd774fd57 Eliminate ExtensionDecl::(get|set|)Conformances.
Stop storing a conformances array on ExtensionDecls. Instead, always use the conformance lookup table to retrieve conformances (which is lazy and supports multi-file, among other benefits).

As part of this, space-optimize ExtensionDecl's handling of conformance loaders. When one registers a conformance loader, it goes into a DenseMap on ASTContext and gets erased once we've loaded that data, so we get two words worth of space back in each ExtensionDecl.

Swift SVN r26353
2015-03-20 16:32:21 +00:00
Doug Gregor
1511d7a15a Start building conformances when requested in the AST.
Previously, we would require the type checker to be able to build a
conformance, which meant we would actually have to lie in the AST
about having a conformance (or crash; we did the form). Now, we can
form the conformance in the AST and it will be checked in the type
checker when needed. The intent here is to push conformance creation
into the conformance lookup table.

To get here, we had to stop relying on the broken, awful,
ASTContext-wide conformance "cache". A proper cache can come back once
the model is sorted out.

Swift SVN r26250
2015-03-18 04:31:22 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Doug Gregor
2f4aee5ce6 Don't profile the conforming type for a normal protocol conformance.
Normal protocol conformances are uniquely determined by protocol and
DeclContext; the type is unnecessary. NFC

Swift SVN r26128
2015-03-14 06:18:12 +00:00
Doug Gregor
9271a24a92 Introduce a protocol conformance registry for nominal types.
(Note that this registry isn't fully enabled yet; it's built so that
we can test it, but has not yet taken over the primary task of
managing conformances from the existing system).

The conformance registry tracks all of the protocols to which a
particular nominal type conforms, including those for which
conformance was explicitly specified, implied by other explicit
conformances, inherited from a superclass, or synthesized by the
implementation.

The conformance registry is a lazily-built data structure designed for
multi-file support (which has been a problematic area for protocol
conformances). It allows one to query for the conformances of a type
to a particular protocol, enumerate all protocols to which a type
conforms, and enumerate all of the conformances that are associated
with a particular declaration context (important to eliminate
duplicated witness tables).

The conformance registry diagnoses conflicts and ambiguities among
different conformances of the same type to the same protocol. There
are three common cases where we'll see a diagnostic:

1) Redundant explicit conformance of a type to a protocol:

    protocol P { }
    struct X : P {  }
    extension X : P { } // error: redundant explicit conformance

2) Explicit conformance to a protocol that collides with an inherited
  conformance:

    protocol P { }
    class Super : P { }
    class Sub : Super, P { } // error: redundant explicit conformance

3) Ambiguous placement of an implied conformance:

    protocol P1 { }
    protocol P2 : P1 { }
    protocol P3 : P1 { }

    struct Y { }
    extension Y : P2 { }
    extension Y : P3 { } // error: ambiguous implied conformance to 'P1'

  This happens when two different explicit conformances (here, P2 and
  P3) placed on different declarations (e.g., two extensions, or the
  original definition and other extension) both imply the same
  conformance (P1), and neither of the explicit conformances imply
  each other. We require the user to explicitly specify the ambiguous
  conformance to break the ambiguity and associate the witness table
  with a specific context.

Swift SVN r26067
2015-03-12 21:11:23 +00:00
Jordan Rose
c91952130f Wordsmith the errors for Objective-C selector conflicts.
Also, if warning about an accessor that comes from a stored property,
point to the property rather than the (implicit, source-location-less)
accessor decl.

Both of these changes are aimed at improving the presentation in Xcode.

rdar://problem/19927828

Swift SVN r25725
2015-03-03 23:25:46 +00:00
Doug Gregor
7ef5ba9ff9 Perform override checking prior to (and independent of) @objc computation.
Always perform override checking based on the Swift type
signatures, rather than alternately relying on the Objective-C
selectors. This ensures that we get consistent override behavior for
@objc vs. non-@objc declarations throughout, and we separately make
sure that the Objective-C names line up.

This also allows us to inherit @objc'ness correctly (which didn't
quite work before), including inferring the Objective-C selector/name
(the actual subject of rdar://problem/18998564).

Fixes rdar://problem/18998564.

Swift SVN r25392
2015-02-19 06:29:34 +00:00
Doug Gregor
530835fc6c Ignore initializers that aren't inherited when performing Objective-C override checking.
Fixes the last piece of rdar://problem/19794036, thanks Jordan!

Swift SVN r25357
2015-02-17 21:08:30 +00:00
Chris Lattner
635d46d909 Fix <rdar://problem/19821633> only allow autoclosure on parameters, not on properties and globals
Disallow autoclosure on anything but paramdecls, and provide better QoI when you use them in enums.



Swift SVN r25262
2015-02-13 01:55:56 +00:00
Chris Lattner
9c7417edc2 fix <rdar://problem/19782264> Immutable, optional class members can't have their subproperties read from during init()
The problem here was that the _preconditionImplicitlyUnwrappedOptionalHasValue
compiler intrinsic was taking the optional/IUO argument as inout as a performance
optimization, but DI would reject it (in narrow cases, in inits) because the inout
argument looks like a mutation.  

We could rework this to take it as an @in argument or something, but it is better
to just define this problem away: the precondition doesn't actually care about the
optional, it is just testing its presence, which SILGen does all the time.  Have
SILGen open code the switch_enum and just have the stdlib provide a simpler
_diagnoseUnexpectedNilOptional() to produce the error message.

This avoids the problem completely and produces slightly better -O0 codegen.



Swift SVN r25254
2015-02-12 22:35:51 +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
Doug Gregor
049e58417c Pass declarations, not locations, when diagnosing Objective-C method redeclarations.
Fixes rdar://problem/19726258.

Swift SVN r25182
2015-02-11 17:42:30 +00:00
Doug Gregor
bc1422e9e0 Diagnose attempts to replace Objective-C methods via an extension.
Remove the logic that allowed an extension to provide an Objective-C
method that was already declared in the class itself, relying on the
existing Objective-C method redeclaration logic to detect such
conflicts. Fixes rdar://problem/17687082.

Swift SVN r25175
2015-02-11 08:01:22 +00:00
Jordan Rose
19af8a124c Re-apply "If a function conversion fails, suggest wrapping in a closure."
This re-applies r24987, reverted in r24990, with a fix for a spuriously-
introduced error: don't use a favored constraint in a disjunction to avoid
applying a fix. (Why not? Because favoring bubbles up, i.e. the
/disjunction/ becomes favored even if the particular branch is eventually
rejected.) This doesn't seem to affect the outcome, though: the other
branch of the disjunction doesn't seem to be tried anyway.

Finishes rdar://problem/19600325

Swift SVN r25054
2015-02-06 23:12:54 +00:00
Joe Groff
d523ad07e6 SIL: Don't lower the @noescape attribute from the AST to SILFunctionType.
@noescape may be interesting to passes in the future, but it currently has no effect except to cause symbol collisions in reabstraction thunks and other places. Since it has no effect, just remove it from SIL for now.

Swift SVN r24925
2015-02-03 20:35:05 +00:00
Doug Gregor
9abe8f717c Diagnose Objective-C conflicts due to unsatisfied, optional @objc requirements.
An optional @objc requirement within a protocol can be left
unsatisfied in a well-formed program. However, there may still be a
conflict within the Objective-C runtime if the conforming class
defines a method with the corresponding Objective-C selector(s) for
that requirement, which means that the Swift and Objective-C semantics
will differ. Diagnose such issues.

More steps along the road to fixing rdar://problem/18383574.

Diagnose conflicts between unsatisfied, optional @objc requirements and

Swift SVN r24830
2015-01-29 22:53:46 +00:00
Doug Gregor
f19a320ffe Ban the definition of Objective-C '+load' methods.
They don't work properly, and if we want eager static initialization,
we'll add a Swift feature for it. Fixes rdar://problem/18423731.

Swift SVN r24814
2015-01-29 05:47:36 +00:00
Joe Groff
bf3c92c743 Sema: Move 'getBridgedToObjC' out of the type checker.
It is useful for other code to be able to query whether a type is bridged sharing the same logic as the type checker. NFC yet.

Swift SVN r24758
2015-01-27 21:20:39 +00:00
John McCall
d3a9ebbcb4 Make ArchetypeType's "constructors" return canonical types.
Swift SVN r24708
2015-01-24 13:05:41 +00:00
Graham Batty
057c27f009 Disable existential metatype casting on non-objc.
Also fixes getting the size of an instance of a class to
work without it when objective-c interop is turned off.

Swift SVN r24477
2015-01-16 20:27:54 +00:00
Jordan Rose
1d3bdfae7f Separate dependency tracking from Make-style .d file generation.
This refactoring is groundwork for saving the cross-module dependencies
in the swiftdeps files as well, so that we know to rebuild files if an
outside file changes (such as a bridging header, another framework's
headers, or another framework's swiftmodule).

Part of rdar://problem/19270920

Swift SVN r24258
2015-01-08 03:02:17 +00:00
Chris Lattner
83591f9845 pull NumParameters out of SILFunctionTypeBitfields, and add static
asserts to ensure that SILFunctionTypeBitfields never overflows the
bitfield size.


Swift SVN r24083
2014-12-22 23:02:53 +00:00
Chris Lattner
0ea4b20931 fix several bugs that would cause the nocapture bit to get truncated off (because it is bit 9
and char can't hold it).


Swift SVN r24081
2014-12-22 22:11:02 +00:00