Commit Graph

1293 Commits

Author SHA1 Message Date
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -07: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
Michael Ilseman
b4b31908a6 [noescape by default] drop isExplicitlyEscaping bit
The isExplicitlyEscaping bit, though useful for printing,
unfortunately puts us in a position where we have different bit
patterns for the same type, and thus lose much of our type equivalence
checking for overriding, protocol conformance, etc., even if we were
to take subtyping into account. We need to drop it, relying on the
existing noescape bit alone to determine the type's semantics (at
least, as long as we continue to encode this information in the type
system).

This is a partial fix; we will now be excessively printing @escaping,
but the subsequent commits will correct this. For printing, we will
instead need to be more context-aware.
2016-07-29 13:48:07 -07:00
Doug Gregor
202cf2e754 [SE-0111] Track function reference kinds in member references.
Extend the handling of function reference kinds to member references
(e.g., x.f), and therefore the logic for stripping argument labels. We
appear to be stripping argument labels from all of the places where it
is required.
2016-07-28 15:41:59 -07:00
Doug Gregor
a9536906ff [SE-0111] Drop argument labels on references to function values.
When referencing a function in the type checker, drop argument labels
when we don't need them to type-check an immediate call to that
function. This provides the semantic behavior of SE-0111, e.g.,
references to functions as values produce unlabeled function types,
without the representational change of actually dropping argument
labels from the type system.

At the moment, this only works for bare references to functions. It
still needs to be pushed through more of the type checker and more AST
nodes to work in the general case.

Keep this work behind the frontend flag
-suppress-argument-labels-in-types for now.
2016-07-28 15:40:11 -07:00
Doug Gregor
8c7e75afa0 [AST] Eliminate OverloadedMemberRefExpr.
This expression kind was introduced in exactly one place, and only
with one member. That place can use MemberRefExpr instead.
2016-07-28 14:44:23 -07:00
Doug Gregor
d050a213a1 [ASTDumper] Dump argument labels. 2016-07-27 15:51:42 -07:00
Doug Gregor
e4d8f486a8 Simplify AST for string literals to not depend on implicit tuple splat.
String literal expressions, as well as the magic literals #file and
tuple value that is then fed into one or two call expressions. For
string literals, that tuple value was implicitly splatted, breaking
AST invariants.

Instead, keep string literals and these magic literals that produce a
string as a single expression node, but store the declarations that
will be used to transform the raw literal into the complete
literal. SILGen will form the appropriate calls. This representation
is far simpler---the AST no longer has a bunch of implicit nodes---and
doesn't break AST invariants.
2016-07-27 12:30:22 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Doug Gregor
604adff1bd [SE-0111] Capture argument labels directly in CallExpr.
Yet another step on the way to SE-0111, capture the argument labels
(and their locations) directly in CallExpr, rather than depending on
them being part of the tuple argument.
2016-07-25 23:14:41 -07:00
Jordan Rose
508e825ff2 Split 'fileprivate' and 'private', but give them the same behavior.
'fileprivate' is considered a broader level of access than 'private',
but for now both of them are still available to the entire file. This
is intended as a migration aid.

One interesting fallout of the "access scope" model described in
758cf64 is that something declared 'private' at file scope is actually
treated as 'fileprivate' for diagnostic purposes. This is something
we can fix later, once the full model is in place. (It's not really
/wrong/ in that they have identical behavior, but diagnostics still
shouldn't refer to a type explicitly declared 'private' as
'fileprivate'.)

As a note, ValueDecl::getEffectiveAccess will always return 'FilePrivate'
rather than 'Private'; for purposes of optimization and code generation,
we should never try to distinguish these two cases.

This should have essentially no effect on code that's /not/ using
'fileprivate' other than altered diagnostics.

Progress on SE-0025 ('fileprivate' and 'private')
2016-07-25 13:13:35 -07:00
Slava Pestov
57c58176bc AST: Remove noreturn bit from function types 2016-07-24 00:15:34 -07:00
John McCall
f4d7ce84d8 Build arbitrary conversion expressions for collection upcasts.
Not used yet.
2016-07-19 14:35:03 -07:00
Robert Widmann
a77539aa38 Merge pull request #3425 from tanadeau/sr-1952-add-escaping-parsing
[WIP][Parser][SR-1952] Added @escaping attribute parsing
2016-07-15 15:30:14 -07:00
Doug Gregor
5a83c86455 Eliminate default arguments from TupleType.
In Swift, default arguments are associated with a function or
initializer's declaration---not with its type. This was not always the
case, and TupleType's ability to store a default argument kind is a
messy holdover from those dark times.

Eliminate the default argument kind from TupleType, which involves
migrating a few more clients over to declaration-centric handling of
default arguments. Doing so is usually a bug-fix anyway: without the
declaration, one didn't really have

The SILGen test changes are due to a name-mangling fix that fell out
of this change: a tuple type is mangled differently than a non-tuple
type, and having a default argument would make the parameter list of a
single-parameter function into a tuple type. Hence,

  func foo(x: Int = 5)

would get a different mangling from

  func foo(x: Int)

even though we didn't actually allow overloading.

Fixes rdar://problem/24016341, and helps us along the way to SE-0111
(removing the significance of argument labels) because argument labels
are also declaration-centric, and need the same information.
2016-07-15 13:55:53 -07:00
Trent Nadeau
6ef59c09e5 Added @escaping attribute parsing 2016-07-08 21:14:39 -04:00
Slava Pestov
c870052520 Sema: Give capture analysis ability to sniff out uses of dynamic 'Self'
This also adds some tests for the existing generic parameter
capture logic, which was only tested as part of SILGen tests
until now.

Also, move capture analysis into a new TypeCheckCaptures.cpp file.
2016-06-27 18:37:52 -07:00
Joe Groff
3a8520be56 SILGen: Partial codegen for property behaviors with DI initialization.
If a behavior has storage that can be initialized out-of-line, generate code in SILGen that uses stores to mark_uninitialized_behavior for eventual analysis by DI.

This is incomplete, particularly, it's missing code generation of glue thunks for accessors that require reabstraction, but I wanted to make sure the progress here didn't bitrot.
2016-06-14 20:10:22 -07:00
Joe Groff
e72af82f04 Remove the unused isSome Optional intrinsics.
We already have detailed knowledge of Optional's layout in SILGen, so these intrinsics were almost unused. They were only used in a few obscure places by some optional-to-bool conversions, used by 'is [A]' collection tests and the codegen for 'lazy' properties. Change these over to generate an EnumIsCaseExpr that we can directly lower to a 'select_enum' instruction in SILGen, leading to better codegen and obviating the need for these intrinsic functions.
2016-06-08 09:31:47 -07:00
Doug Gregor
9f0cec4984 SE-0062: Implement #keyPath expression.
Implement the Objective-C #keyPath expression, which maps a sequence
of @objc property accesses to a key-path suitable for use with
Cocoa[Touch]. The implementation handles @objc properties of types
that are either @objc or can be bridged to Objective-C, including the
collections that work with key-value coding (Array/NSArray,
Dictionary/NSDictionary, Set/NSSet).

Still to come: code completion support and Fix-Its to migrate string
literal keypaths to #keyPath.

Implements the bulk of SR-1237 / rdar://problem/25710611.
2016-05-18 23:30:15 -07:00
Alex Hoppen
d2e045c8b5 Implement SE-0064 / SR-1239: #selector for property getters and setters
Implements the core functionality of SE-0064 / SR-1239, which
introduces support for accessing the Objective-C selectors of the
getter and setter of an @objc property via #selector(getter:
propertyName) and #selector(setter: propertyName).

Introduce a bunch of QoI around mistakes using #selector to refer to a
property without the "getter:" or "setter:", using Fix-Its to help the
user get it right. There is more to do in this area, still, but we
have an end-to-end feature working.

Much of the implementation and nearly all of the test cases are from
Alex Hoppen (@ahoppen). I've done a bit of refactoring, simplified the
AST representation, and replaced Alex's custom
expression-to-declaration logic with an extension to the constraint
solver. The last bit might be short-lived, based on swift-evolution
PR280, which narrows the syntax of #selector considerably.
2016-05-11 16:51:27 -07:00
Ted Kremenek
942e524285 Revert "SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations" (#2477) 2016-05-11 11:02:37 -07:00
Alex Hoppen
b7abfd2d5c [Gardening] Fixed formatting issue in ASTDumper 2016-05-07 22:39:18 +02:00
Ted Kremenek
b8bbed8c13 [WIP] Implement SE-0039 (Modernizing Playground Literals) (#2215)
* Implement the majority of parsing support for SE-0039.

* Parse old object literals names using new syntax and provide FixIt.

For example, parse "#Image(imageLiteral:...)" and provide a FixIt to
change it to "#imageLiteral(resourceName:...)".  Now we see something like:

test.swift:4:9: error: '#Image' has been renamed to '#imageLiteral
var y = #Image(imageLiteral: "image.jpg")
        ^~~~~~ ~~~~~~~~~~~~
        #imageLiteral resourceName

Handling the old syntax, and providing a FixIt for that, will be handled in a separate
commit.

Needs tests.  Will be provided in later commit once full parsing support is done.

* Add back pieces of syntax map for object literals.

* Add parsing support for old object literal syntax.

... and provide fixits to new syntax.

Full tests to come in later commit.

* Improve parsing of invalid object literals with old syntax.

* Do not include bracket in code completion results.

* Remove defunct code in SyntaxModel.

* Add tests for migration fixits.

* Add literals to code completion overload tests.

@akyrtzi told me this should be fine.

* Clean up response tests not to include full paths.

* Further adjust offsets.

* Mark initializer for _ColorLiteralConvertible in UIKit as @nonobjc.

* Put attribute in the correct place.
2016-04-25 07:19:26 -07:00
Chris Willmore
02a6be6d01 Allow parsing of function types in expr position (#2273)
Previously it was not possible to parse expressions of the form

    [Int -> Int]()

because no Expr could represent the '->' token and be converted later
into a FunctionTypeRepr. This commit introduces ArrowExpr which exists
solely to be converted to FunctionTypeRepr later by simplifyTypeExpr.

https://bugs.swift.org/browse/SR-502
2016-04-22 21:53:26 -07:00
John McCall
b3a2762f59 Improve the dumping of ProtocolConformances, Substitutions,
and ErasureExpr.
2016-04-14 10:33:44 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Chris Lattner
a58d9949bf [ASTDumper] Print generic parameters for an arbitrary GenericTypeDecl, not
just NominalTypeDecls.  NFC
2016-03-06 21:17:43 -08:00
Chris Lattner
868a795566 Introduce a new class between TypeDecl and NominalTypeDecl named GenericTypeDecl.
This factors the DeclContext and generic signature behavior out of NTD, allowing
it to be reused in the future.  NFC.
2016-03-04 23:09:15 -08:00
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Han Sangjin
f61e4b426d Use the method raw_ostream::resetColor instead of the escape code string
The Process::ResetColor() may return NULL if the LLVM library is built for Windows.
So, unguarded passing the return value to the raw_ostream may generate a crash.
The raw_ostream::resetColor() checks NULL and is used many time in the Clang.
2016-02-27 05:27:04 +09:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Chris Lattner
8dedfb31e3 Add support for #file/#line, etc according to SE-0028. __FILE__ and friends
are still accepted without deprecation warning as of this patch.
2016-02-04 14:22:22 -08:00
Xi Ge
d6f8ad0008 Add a method to RequirementRepr that breaks the deserialized written string into detail. NFC 2016-01-27 13:23:20 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Janek Spaderna
3abfaff23d Dump the trailing newline on the given stream 2016-01-23 23:05:52 +01:00
Doug Gregor
fd3f03f3be Remove UnresolvedConstructorExpr.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
2016-01-20 17:09:02 -08:00
Doug Gregor
c9c1d1390c [SE-0021] Allow naming of specific initializers via "self.init(foo:bar:)". 2016-01-20 17:09:02 -08:00
Doug Gregor
5f07f6b12f Remove all vestiges of UnresolvedSelectorExpr. NFC 2016-01-20 17:09:01 -08:00
Max Moiseev
9a018bd77d Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-20 14:38:22 -08:00
Michael Teper
f46ba311b5 [AST] Enclose value of writtenType attribute in quotes
Prior to this change, writtentType value was not enclosed in single quotes and could contain spaces (e.g. `writtenType='[[String : String]]'`). With this change, the value is enclosed in quotes matching the rendering of the `type` attribute.
2016-01-20 11:42:06 -08:00
Chris Lattner
8a77e15da1 improve ast dumping of capture lists. 2016-01-20 09:07:29 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Chris Lattner
dc333cfef8 Merge pull request #1015 from mteper/patch-1
[AST] Resolved name quotation inconsistency
2016-01-19 20:16:05 -08:00
Michael Teper
54915054af [AST] Formatting consistency in conditional compilation output
Before:
```
(#if_stmt
  (#if:
    (stuff)     #else
    (stuff))
```

After:
```
(#if_stmt
  (#if:
    (stuff))
  (#else:
    (stuff)))
```

Notable differences:
 - #if block is closed
 - #else block is treated same as #if block, starts on new line, token terminated with `:`
 - #else block is closed
2016-01-19 15:34:46 -08:00
Michael Teper
bc1104da41 Resolved name quotation inconsistency
Prior to this change, the AST would look something like this, note `id='incoming` missing the closing quote.

```swift
(type_named id='incoming
    (type_ident
        (component id='UIImage' bind=type)))
```

In reviewing conventions used throughout this class, it appears that this identifier should not need to be quoted at all, so I removed the leading quote. If I am wrong in my understanding, then perhaps the trailing quote should be introduced.
2016-01-19 14:06:58 -08:00
Chris Lattner
5ba57cb498 Fix ExprRewriter::coerceClosureExprToVoid to be resilient to type checking
closures which have already been transformed into void conversion closures.

This fixes 28213-swift-expr-walk.swift/28187-llvm-foldingset-swift-constraints-constraintlocator.swift
2016-01-17 12:07:13 -08:00
Chris Lattner
792be8330f In the deserializer, set the archetype for an associated type before
computing its type.  NFC, but it means that dumping the type in the
deubgger while in computeType() works better.

Make sure to set "isrecursive" in ArchetypeBuilder.cpp on an
associated type when the container is found to be recursive even if
we don't emit the diagnostic.  Spotted by inspection, NFC AFAIK.

Enhance the ASTDumper to print the recursive bit on associated types.
2016-01-17 11:37:34 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00