Commit Graph

1018 Commits

Author SHA1 Message Date
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
7f2b135bcd Assertion: Avoid endless loop in case of circular class inheritance.
This commit does not solve the root cause (incomplete circularity detection), see FIXME.
2015-12-31 15:03:52 +01:00
practicalswift
81e7439a9a Fix typos. 2015-12-23 11:16:34 +01:00
Ben Langmuir
47026609b8 Fix leak of std::function in NominalTypeDecl::DelayedMembers
We were memcopying a std::function into the the AST context memory,
which leaks memory incidentally used by the std::function
implementation.  Fix by using a std::unique_ptr and registering a
destructor cleanup.  Incidentally, I turned the array of functions into
a single function, since we never have more than one anyway.

rdar://problem/22387897

Swift SVN r31600
2015-09-01 16:31:21 +00:00
Doug Gregor
dd93c6390b Teach name lookup to cope with missing archetypes on associated types.
Name lookup shouldn't even depend on such semantic information, but
this fixes 13 crashers.

Swift SVN r31331
2015-08-19 06:42:23 +00:00
Devin Coughlin
9dc0c8a173 Importer: Prefer more available convenience factory initializers over less available convenience initializers
Update the importer and name lookup to prefer a factory initializer that is more available
over a convenience initializer that is less available even though we generally prefer
convenience initializers over convenience factory initializers. The motivation for this
change is CIColor, which has added a new convenience initializer:

- (instancetype)initWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b NS_AVAILABLE(10_11, 9_0);

but already has existing convenience factory initializer:

+ (instancetype)colorWithRed:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b;

Without this change we prefer -initWithRed:green:blue, so instantiating CIColor with:

let colorChannelValue: CGFloat = …
let ciColor = CIColor(red: colorChannelValue, green: colorChannelValue, blue: colorChannelValue)

results in an availability error even though there is a perfectly available convenience
factory initializer. With this change, we choose the convenience factory initializer
when importing, so there is no availability error.

rdar://problem/20617581

Swift SVN r30946
2015-08-03 17:21:21 +00:00
Slava Pestov
6256158eb7 Sema: Fixes for stored let property access from constructor
isSettable() returns true for these, but they don't have a setter.
Tread carefully around them.

Fixes <rdar://problem/21877598> and <rdar://problem/21933630>.

Swift SVN r30631
2015-07-25 19:55:00 +00:00
Doug Gregor
8592d9008f Don't apply module-shadowing rules to protocol members.
It's common for a requirement in a protocol and an implementation of that
requirement in a protocol extension to have the same
signature. Overload resolution prefers the requirement (which
dispatches dynamically), but that was being subverted by the shadowing
rules when the protocol came from an imported module and the extension
was in the current module. Fixes rdar://problem/21739333.

Swift SVN r30598
2015-07-24 22:55:20 +00:00
Ted Kremenek
953ad5350b Revert "Revert "Unify FindLocalVal across UnqualifiedLookup and lookupVisibleDecls.""
This reverts commit r30528.

This is not the source of our project regressions.

Swift SVN r30537
2015-07-23 15:01:15 +00:00
Ted Kremenek
685f2e3800 Revert "Unify FindLocalVal across UnqualifiedLookup and lookupVisibleDecls."
This reverts commit r30525.

This appears likely to be causing build regressions with guard statements on our test projects.

Swift SVN r30528
2015-07-23 05:39:20 +00:00
Jordan Rose
8a2e338e5a Unify FindLocalVal across UnqualifiedLookup and lookupVisibleDecls.
They had already diverged even before my last commit. Let's not have that
happen again!

This re-fixes code completion for bindings declared in top-level guard
statements.

More rdar://problem/21928533

Swift SVN r30525
2015-07-23 04:42:09 +00:00
Jordan Rose
4cdac3fc4c Don't add variables declared in 'guard let' to a SourceFile's Decls.
These variables really are local variables -- they have have a
TopLevelCodeDecl as their DeclContext rather than the SourceFile.
Treating them as global variables caused crashes in serialization.

We need an overhaul of top-level variables in script files anyway
(see rdar://problem/20992489&21628526), but this fixes the immediate
issue.

rdar://problem/21928533

Swift SVN r30519
2015-07-23 00:55:36 +00:00
Slava Pestov
d1c33b9fd0 AST: Tighten up AbstractStorageDecl::isSettable()
'let' properties are settable inside certain initializers, but the
logic was wrong -- in most cases we would fall through and return
true from ::isSettable().

This came up when deserialization (correctly) didn't set the setter
accessibility on a 'let' property, and a read of that property from
a constructor in another struct incorrectly decided the property
was settable, causing a crash.

Fixes <rdar://problem/21559246>.

Swift SVN r30484
2015-07-22 01:14:32 +00:00
Jordan Rose
2441ab0c1e Dependencies: Break out member lookups by the name of the member being looked up.
Right now we just have one notion of providing or using a type (as opposed to a
name). It doesn't matter if you're doing lookups, or checking conformance, or
inheriting from a superclass or protocol -- they're all in the same bucket. I'd
like to split these out so that extending a commonly-used type (like, say, Array)
doesn't cause every file in your target to depend on your extension.

This commit doesn't do anything but start tracking which member names are looked
up. For the other things you can do with a type, it's using a dummy empty name.

Swift SVN r30284
2015-07-16 23:36:31 +00:00
Slava Pestov
6992dfc5d1 AST: Start unifying UnqualifiedLookup and lookupVisibleDecl()
For now, just update NameLookup's FindLocalVal to use a
VisibleDeclConsumer just like lookupVisibleDecl().

A subsequent patch will continue removing duplicated code
now that this is place.

This fixes compiler crashers where we were not handling
declarations with duplicate names (which of course is an
error, diagnosed elsewhere).

Swift SVN r29913
2015-07-04 01:53:38 +00:00
Chris Lattner
9a65afff8d Two changes:
- In name lookup, if we find a decl that is already being type checked 
   (which only occurs on illegal code) just assume it is acceptable instead
   of blowing up with an assertion checking access control that hasn't been
   evaluated yet.
 - In checkInheritanceClause, make sure that the we mark the decl being
   resolved as being type checked when resolving the types involved.  That way,
   cyclic references are detected as invalid, instead of causing assertions and
   other explosions.

This fixes some compiler crashers.



Swift SVN r29538
2015-06-20 23:50:31 +00:00
Jordan Rose
2f83732a5a Static lets are never mutable.
Also, assert that we're not misusing isSetterAccessibleFrom, which was masking
this issue.

rdar://problem/20193168

Swift SVN r29461
2015-06-17 22:36:02 +00:00
Slava Pestov
fee95a3c06 AST: Fix a compiler_crash
Swift SVN r29341
2015-06-08 04:00:22 +00:00
Doug Gregor
ca29fd9ea3 Start cleaning up member name lookup.
Fold the witness-mapping code and deduplication logic into the main
lookup path, so we don't end up performing redundant lookups. Delay
the removal of overridden and shadowed declarations until after we've
done witness mapping, so we're not wasting effort the first time
around. NFC except for a small performance optimization.

Swift SVN r29060
2015-05-27 05:51:43 +00:00
Chris Lattner
e517ad9182 Fix unreachable code handling to properly diagnose things like:
throw x 
whatever()  

as being unreachable after the throw.



Swift SVN r28680
2015-05-17 15:13:35 +00:00
Dmitri Hrybenko
0a1f7c09df Revert "Fix unreachable code handling to properly diagnose things like:"
This reverts commit 28678.  It broke the IDE/complete_exception.swift
test.

Swift SVN r28679
2015-05-17 12:27:57 +00:00
Chris Lattner
5ead9764bd Fix unreachable code handling to properly diagnose things like:
throw x
  whatever()

as being unreachable after the throw.



Swift SVN r28678
2015-05-17 05:56:02 +00:00
Doug Gregor
2f0c1b151e Use the archetype for unqualified lookup within protocols and extensions thereof.
When performing unqualified lookup within a type context (or method
thereof) that is a protocol or a protocol extension, use the Self
archetype of the protocol or extension so we look in types implied by
the requirements as well. Part of rdar://problem/20509152, fixing the
example provided in rdar://problem/20694545.

Swift SVN r28363
2015-05-09 03:42:16 +00:00
Doug Gregor
0749486302 Let unqualified lookup find members of protocols and extensions thereof.
Members of protocols found via unqualified name lookup are mapped to
their corresponding witnesses, as we do for qualified name
lookup. This is the bulk of the compiler changes for
rdar://problem/20509152. Performing this mapping for unqualified name
lookup of types will follow.

Swift SVN r28333
2015-05-08 23:22:13 +00:00
Doug Gregor
5c2d1232ee Stop classifying results in UnqualifiedLookupResult.
We're still doing too much work to form these unqualified lookup
results that should really move into semantic analysis, but this is
the NFC part we need now.

Swift SVN r28331
2015-05-08 23:22:05 +00:00
Doug Gregor
edbb75eef8 Eliminate the 'Module' variant from UnqualifiedLookupResult.
Make unqualified lookup always provide a declaration for the things it
finds, rather than providing either a module or a declaration. Unify
various code paths in our type checker now that module declarations
come in with the other declarations.

Swift SVN r28286
2015-05-07 21:10:55 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Doug Gregor
f2e66d1cd7 Break recursion when deserializing constrained protocol extensions.
When reading the generic parameters of a constrained protocol
extension, cross-refencing an associated type would perform name
lookup into the protocol extension itself, causing fatal recursion
during deserialization. Fixed by avoiding additional deserialization
when looking for an associated type. Fixes rdar://problem/20812303.

Swift SVN r28228
2015-05-06 23:56:58 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Chris Lattner
0011b3ae21 rename "unless" to "require" and give it an 'else' keyword.
Swift SVN r28059
2015-05-02 00:16:44 +00:00
Doug Gregor
cf1bb3a8ce Remove the old "delayed protocol conformances" code.
It's in the way of progress; a better solution is coming.

Swift SVN r27970
2015-04-30 16:13:39 +00:00
Doug Gregor
a3541643ec Switch name lookup over to the protocol conformance table.
More of rdar://problem/18448811.

Swift SVN r27969
2015-04-30 16:13:38 +00:00
Chris Lattner
c6aa041fb9 Add parser/ast/sema/sourcekit/etc support for 'unless' statement.
SILGen support still missing.



Swift SVN r27961
2015-04-30 05:55:11 +00:00
Chris Lattner
82ef514f99 Reimplement the AST, Sema, and SILGen of defer to be closure based.
Now we bind the defer body into a ClosureExpr and emit it at the point of
the defer.  At any exit points out of the controlled region, we emit a call 
to the closure.

This should cover any problems where expressions cannot be emitted multiple times.
However, this is dramatically more complex than the obvious implementation, so I 
hope this patch can be reverted.



Swift SVN r27767
2015-04-26 17:58:06 +00:00
Chris Lattner
ee96164996 implement parsing, AST, and basic Sema support for 'defer'.
SILGen support and diagnosing jumps out of a defer aren't done
yet.



Swift SVN r27759
2015-04-26 15:16:37 +00:00
Doug Gregor
2217e38cdf Compare the boolean results of isProtocolOrProtocolExtensionContext().
We were getting some bogus shadowing involving properties in protocols
vs. protocol extensions. Fixes rdar://problem/20608438.

Swift SVN r27683
2015-04-24 06:15:06 +00:00
Doug Gregor
f2e894ba4b Remove useless shadowing code for erroneous redeclarations. NFC
Swift SVN r27682
2015-04-24 06:14:57 +00:00
Chris Willmore
c7c7388cf2 Change do-while to repeat-while.
Change all uses of "do { ... } while <cond>" to use "repeat" instead.
Rename DoWhileStmt to RepeatWhileStmt. Add diagnostic suggesting change
of 'do' to 'repeat' if a condition is found afterwards.

<rdar://problem/20336424> rename do/while loops to repeat/while & introduce "repeat <count> {}" loops

Swift SVN r27650
2015-04-23 22:48:31 +00:00
Chris Lattner
fb87132f72 significantly simplify the BoolPattern AST representation and logic surrounding it.
The SILGen code could be further simplified, but this is progress at least.  NFC.


Swift SVN r27011
2015-04-05 04:52:38 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Doug Gregor
21765eb38d Allow name lookup to find initializers defined in protocol extensions.
For structs/enums, this was already the case. For classes, we simply
need to ensure that we always look at the extensions of protocols to
which the class conforms.

Swift SVN r26773
2015-03-31 18:56:08 +00:00
Roman Levenstein
941e5b6a58 [patternmatch-silgen] Improve silken and diagnostics for switches on bools and tuples of bools.
This patch introduces a new kind of pattern for matching bool literals, i.e. true and false. Essentially, it is very similar to a pattern for matching enum elements, but simpler. Most of the code is just a boiler plate code copy/pasted from the code for enum element patterns. The only different thing is the emitBoolDispatch function, which emits a SIL code for matching bools.

With this patch, we don't get any false non-exhaustive switch diagnostics for switches on bools anymore. And we have a lot of radars complaining about it. For example rdar://16514545 and rdar://20130240.

Note, that this patch fixes the non-exhaustive switch diagnostics without changing the internal representation of bools. Implementing bool as an enum would have the same effect when it comes to these diagnostics and we would get this diagnostics fix for free, i.e. without any code committed here. But implementing bools-as-enums is an ongoing work and I'm investigating its performance implications. If we become confident that bool-as-enum does not have a negative impact on performance and decide to merge it, then we can revert this patch as it would not be necessary anymore. But if we decide to skip the enum-as-bool approach to its performance issues, then we would have at least fixed the false non-exhaustive diagnostics for bools by means of this patch.

Swift SVN r26650
2015-03-27 22:43:47 +00:00
Doug Gregor
d0ab6890f8 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 (without associated types, IRGen crashes, etc.)
with methods that can call protocol requirements, generic free
functions, and other methods within the same protocol extension.

This is identical to r26579; the prior commit addressed the underlying
conformance substitution problem that caused rdar://problem/20320393
and subsequent reversion of r26579.

Swift SVN r26639
2015-03-27 18:30:23 +00:00
Jordan Rose
eb4ade4462 Honor @testable import for internal decls in ValueDecl::isAccessibleFrom.
We can now use internal declarations safely and correctly in source files!
The remaining work is to make sure testable imports work reliably through
modules, which is important for debugging unit tests.

It's also possible this work will affect compile time, but for the most
part we don't have large quantities of internal declarations that are
being ignored, and some day we will strip them out of non-testable modules
altogether.

Part of rdar://problem/17732115

Swift SVN r26633
2015-03-27 16:36:46 +00:00
Arnold Schwaighofer
a4ecf9c5a6 Revert "Teach normal name lookup to find members of protocol extensions."
It is breaking the bots.

This reverts commit r26617.

Swift SVN r26620
2015-03-27 02:27:13 +00:00
Doug Gregor
1e6b445cae Teach normal name lookup to find members of protocol extensions.
We do a silly little dance here of finding all of the members of
protocols and their extensions, then deleting the protocol members. In
the future, this is the place where we should handle the protocol
requirement -> witness mapping, including handling derived
conformances.

Basic protocol extensions seem to be working now:

  extension SequenceType {
    var myCount: Int {
      var result = 0
      for x in self {
        ++result
      }
      return result
    }
  }

  println(["a", "b", "c", "d"].myCount) // 4, duh

Swift SVN r26617
2015-03-27 00:10:21 +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
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00