Commit Graph

155 Commits

Author SHA1 Message Date
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
e36b52c25d Resolve some compiler crashers
Crashers fixed are minor logic errors:

Patterns: Crash occurred when requesting the range of a created
Pattern.  Validity of the range should be checked before returning it
to keep the entire range valid or invalid but never both.

ParseExpr/ParsePattern: The same fixes as the ones provided in #6319

CSDiag: The generic visitor needn’t look through TypeVarTypes either.
2017-01-03 18:53:06 -07:00
practicalswift
16d6dce62e [gardening] Fix recently introduced typos. 2016-12-16 21:42:09 +01:00
Doug Gregor
d4fca2cc8b [Serialization] Lazily form context types for deserialized patterns.
When a pattern within a type context is serialized, serialize its
interface type (not its contextual type). When deserializing, record
the interface type and keep a side table of the associated
DeclContext, so that we can lazily map to the contextual type on first
access. This is designed to break recursion when we change the way
archetypes and generic environments are serialized.
2016-12-09 20:48:41 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Chris Lattner
62e4811dac Remove support for nominal type patterns, which have never been supported in an
official swift release and have bitrotted.
2016-07-31 18:44:08 -07:00
Xi Ge
26b71a7d05 [AST] Correct set implicit for enum element patterns. 2016-04-06 18:27:52 -07:00
Michael Ilseman
b6904d76e3 [Type Checker] Check subpattern storage instead of whole pattern.
Fixes SR-1050, where @NSManaged subpatterns were not yet visited, and
thus still were deemed 'stored', by the time getStorage() was called
on the whole pattern. Change this to check the subpattern storage as
we go. Test case added.
2016-03-30 10:25:25 -07:00
Jordan Rose
d9d49f72a3 Adopt llvm::TrailingObjects as much as possible in AST.
This class formalizes the common case of the "trailing allocation" idiom we use
frequently. I didn't spot any true bugs while making this change, but I did see
places where we were using the wrong pointer type or casting through void* for
no good reason. This will keep us honest.

I'll get to the other libraries soon.
2016-02-08 19:40:47 -08:00
Adrian Prantl
aa102c16a7 Document Pattern's implicit flag. 2016-02-01 14:12:54 -08:00
Chris Lattner
fe3250ea71 Constify Pattern::operator new and remove Pattern::clone completely,
it is dead now.  NFC.
2015-12-31 21:12:39 -08:00
Chris Lattner
cc3f173040 remove variadics, default args etc, from tuple patterns, and simplify
the Pattern::clone interface now that the complexity isn't needed.
This also removes support for serializing this state.
2015-12-31 20:12:12 -08:00
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
Slava Pestov
0269e0291e Sema: Fix assertion failure if EnumElementPattern is re-typechecked
We weren't actually successfully mutating ParentType,
so fix that, and also ensure we set ParentType together
with the rest of the state.

Discovered while writing resilient enum tests.
2015-12-11 08:58:51 -08:00
Xi Ge
c8ab2b6999 Re-apply "[CodeComplete] Make sure the lookup API can find closure parameters. rdar://17968255"
This also fixes an ASAN issue when TuplePattern tries to retrieve its associated element buffer whose
size is 0.

Swift SVN r32303
2015-09-29 19:14:06 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Ben Langmuir
5b2a16f7ad [CodeCompletion] Don't look at null subpattern of "is T.Type"
Fixes a crash in

    switch x.self {
    case T.Type:
      #^COMPLETE_HERE^#

rdar://problem/21174713

Swift SVN r29549
2015-06-22 16:45:41 +00:00
Chris Lattner
16b4ad5ce1 Generalize r29106 to handle all of the different kinds of statements that have patterns
in a more robust way.  Also, add testcases for them all.



Swift SVN r29199
2015-06-01 02:52:30 +00:00
John McCall
71198a2869 Test error-coverage diagnostics more completely.
Fix an assert-on-valid caused by a broken getSourceRange()
implementation and a missing diagnostic caused by a broken
walker implementation.

Swift SVN r28142
2015-05-05 00:30:51 +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
Chris Lattner
f7fe8a5f4a Fix <rdar://problem/20392122> Destructuring tuple with labels doesn't work
This pushes tuple pattern labels forward:
  - Actually record them in TuplePatternElt.
  - Remove the tuple shuffle ban that prevents some cases
    (e.g. the one in the radar) of a tuple with labels being shuffled
    onto a tuple without labels.
  - Remove dead code enabled by removing the restriction.



Swift SVN r26852
2015-04-02 04:23:54 +00:00
Chris Lattner
b02da0ae31 Add tuple element label information to TuplePatterns. Before we had no way
to represent them, and just dropped them on the ground. Now we parse them,
persist them in the AST, and "resolve" them from the expr grammar, but still
drop them on the ground.  This is progress towards fixing: rdar://20135489


Swift SVN r26828
2015-04-01 22:11:32 +00:00
Chris Lattner
1a270136fd move isPatternSyntacticallyIrrefutable into a method on Pattern (and rename it), NFC.
Swift SVN r26707
2015-03-29 22:18:49 +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
Chris Lattner
9ac6c23c1d rename IsaPattern -> IsPattern to follow source syntax, NFC.
Swift SVN r25951
2015-03-10 20:09:02 +00:00
Chris Lattner
db187f2183 Enhance VarPattern to capture a bit indicating whether the pattern was a var or let.
Previously we only used this information in the parser, but Sema needs to know as well.

NFC except in -dump-ast.



Swift SVN r25914
2015-03-10 06:07:56 +00:00
Chris Lattner
de808d1603 Progress on: <rdar://problem/19382878> Introduce new x? pattern
This introduces a new pattern, spelled "x?" which is sugar for
matching ".Some(x)".  It also changes the parser slightly so that
_ (the discard expr) is parsed as a unary expr instead of as an
expr.  This allows it to have postfix ? after it, which is important
in pattern contexts to support "case _?:".



Swift SVN r25907
2015-03-10 01:00:23 +00:00
Denis Vnukov
0d84be65de Fix for rdar://problem/19605567, Fuzzing Swift: abort() in Verifier::checkSourceRanges(...)
Correct start/end locations of constructor arguments and class body in erroneous scenarios.



Swift SVN r24769
2015-01-28 01:05:36 +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
Chris Lattner
11a84793ec Add a new bit to VarDecl to track cases where a vardecl gets an
initializer but has no "parent" PatternBindingDecl or Pattern (i.e.
paramdecls).  This is currently set on decls in the pattern of 
foreach loops and case patterns, but I'll add it to other places I
find as well.

NFC since this bit is only set and not read, just more yak shaving.


Swift SVN r23910
2014-12-13 06:25:14 +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
Jordan Rose
d3a9e58133 Use Nothing instead of {} to initialize Optionals.
In preparation for the switch to llvm::Optional, which has an explicit
default constructor.

Swift SVN r22470
2014-10-02 18:51:33 +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
Jordan Rose
f0bcc5cf2d [Accessibility] Fix existing checks to work with protocol requirements as well.
Going forward, everything will be added to checkAccessibility.

Swift SVN r19494
2014-07-02 23:54:51 +00:00
Joe Groff
0a04cae732 whitespace
Swift SVN r19083
2014-06-22 19:32:17 +00:00
Chris Lattner
97288044c1 Fix some minor internal inconsistencies handling implicitly synthesized constructors. These
don't manifest currently, but do with some other changes I'm working on. NFC.



Swift SVN r18158
2014-05-16 01:15:27 +00:00
Sean Callanan
da5112e7b8 Fixed a crash when dumping an anonymous NamedPattern.
<rdar://problem/16908334>


Swift SVN r18085
2014-05-14 23:26:36 +00:00
Argyrios Kyrtzidis
19aeaf94fc Fully embrace ParamDecls instead of AnyPattern at function creation time, thus removing the need to create param decls at SILGen or Sema.
Swift SVN r17829
2014-05-10 18:23:50 +00:00
Argyrios Kyrtzidis
a5eeb9617a [Parser] Create ParamDecls even for unnamed parameters.
This preserves more of source info (e.g. API name location) and simplifies things since
we don't have to construct ParamDecls for the unnamed parameters later on.

Swift SVN r17828
2014-05-10 18:23:47 +00:00
Argyrios Kyrtzidis
dfa772de8b [AST] Set the source range of ParamDecl as the argument+parameter range and keep track of its parent pattern.
Swift SVN r17441
2014-05-05 15:14:31 +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
db439c1a4a Start introducing declaration names for more function declarations.
Swift SVN r16396
2014-04-16 04:52:07 +00:00
John McCall
f70879c4d9 Fix a weirdly complicated issue with the order of
type-checking and applying attributes.

We should really move to a model where variables are
type-checked in a single pass, including their attributes.
However, given that we don't, attributes which affect the
type must be applied in multiple places and hence multiple
times to the same declaration.

Swift SVN r16339
2014-04-14 22:54:30 +00:00
Joe Groff
4fdc20f739 Allow '<pattern> as T' checked patterns with subpattern bindings.
Allow a form of 'case is T' that matches the cast result to a subpattern, 'case <pattern> as T'. This exposes an issue in switch destructuring with casting into complex class hierarchies <rdar://problem/16401831> but works for common cases.

Swift SVN r15396
2014-03-24 00:02:44 +00:00
Doug Gregor
339a726a72 Allow inheritance of designated initializers with unnamed parameters.
Another small part of <rdar://problem/16318855>.

Swift SVN r15064
2014-03-14 20:16:59 +00:00
Doug Gregor
d32f668fb2 Introduce "inherited" default arguments and use them for inherited initializers.
Previously, we were cloning the default arguments completely, which
meant code duplication (when inheriting within a module) or simply a
failure (when inheriting across modules). Now, we reference the
default arguments where we inherited them, eliminating the
duplication. Part of <rdar://problem/16318855>.

Swift SVN r15062
2014-03-14 18:31:22 +00:00
Doug Gregor
8cf018a1d2 Give Pattern::clone() an OptionSet rather than a bool; it's going to get more interesting.
Swift SVN r15061
2014-03-14 18:31:21 +00:00