Commit Graph

557 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
7e8f929941 [ASTPrinter] When enabling printing accessibility, use the accessibility keywords instead of comments.
Swift SVN r28772
2015-05-19 16:45:29 +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
Joe Groff
94eb4cb77f AST printer: Use the type substitution map to print archetype parents.
Fixes rdar://problem/20883889.

Swift SVN r28402
2015-05-10 20:33:21 +00:00
Argyrios Kyrtzidis
7e61a77d11 [module-interface] Add "/*not inherited*/" in-front of factory initializers to distinguish
those from normal initializers in a clear manner.

rdar://20044672

Swift SVN r28400
2015-05-10 19:03:20 +00:00
Slava Pestov
b294e5086b ASTPrinter: print 'throws' for generic and polymorphic function types
Swift SVN r28305
2015-05-08 01:07:10 +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
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Xi Ge
be33b9edb3 [InterfacePrinting] Avoid duplicating @autoclosure and @noescape when printing module interfaces.
rdar://20657950

Swift SVN r28217
2015-05-06 21:51:23 +00:00
Chris Lattner
7927a230ae remove compiler support for let/else. This simplifies PBD back to being
an unconditional binding, yay.


Swift SVN r28101
2015-05-03 22:13:02 +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
Argyrios Kyrtzidis
6c3dbab3fb [ASTPrinter] Make sure to print keyword arguments for subscripts.
Swift SVN r28031
2015-05-01 07:28:30 +00:00
Joe Groff
6849ebda87 SIL printer: Disambiguate context archetypes with name collisions.
This can happen in witnesses, whose context archetypes are composed from the type-level archetypes of the witnessing type, and the method-level archetypes of the requirement. If you have something like:

protocol Foo {
  func foo<T>(x: T)
}

struct Bar<T>: Foo {
  func foo<U>(x: U)
}

Bar's witness to Foo.foo will end up with two archetypes named "T". Deal with this by having the SIL printer introduce a name mapping that disambiguates colliding archetypes. Refactor the SIL printer to do streaming through the SILPrinter itself, rather than directly on its ostream, so that we make sure it controls how subelements like types are printed, and it can pass the appropriate options down to the AST type printer. Fixes rdar://problem/20659406.

Swift SVN r27991
2015-04-30 18:42:31 +00:00
Doug Gregor
d0282e0d62 Switch the AST printer over to getLocalProtocols().
Swift SVN r27968
2015-04-30 16:13:37 +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
b2cc34c241 Remove '#' for making parameter names into argument labels.
If you want to make the parameter and argument label the same in
places where you don't get the argument label for free (i.e., the
first parameter of a function or a parameter of a subscript),
double-up the identifier:

  func translate(dx dx: Int, dy: Int) { }

Make this a warning with Fix-Its to ease migration. Part of
rdar://problem/17218256.

Swift SVN r27715
2015-04-24 23:58:57 +00:00
Doug Gregor
793b3326af Implement the new rules for argument label defaults.
The rule changes are as follows:
  * All functions (introduced with the 'func' keyword) have argument
  labels for arguments beyond the first, by default. Methods are no
  longer special in this regard.
  * The presence of a default argument no longer implies an argument
  label.

The actual changes to the parser and printer are fairly simple; the
rest of the noise is updating the standard library, overlays, tests,
etc.

With the standard library, this change is intended to be API neutral:
I've added/removed #'s and _'s as appropriate to keep the user
interface the same. If we want to separately consider using argument
labels for more free functions now that the defaults in the language
have shifted, we can tackle that separately.

Fixes rdar://problem/17218256.

Swift SVN r27704
2015-04-24 19:03:30 +00:00
Argyrios Kyrtzidis
d61a1916ea [AST] Print requirements of protocol extensions.
rdar://20634360

Swift SVN r27686
2015-04-24 06:49:45 +00:00
Argyrios Kyrtzidis
f9150a58b5 [AST/Serialization] Add a string for the generic requirements "as written" in the module file, to use it for
the printed interface.

Previously we printed the typechecked and uniqued requirements and the result was non-sensical.
Long-term the requirements will be preserved in a better form but for now print the requirements
and serialize them.

rdar://19963093

Swift SVN r27680
2015-04-24 06:11:09 +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
Slava Pestov
59c4900af9 Improved Substitution::print()
Swift SVN r27605
2015-04-22 21:29:25 +00:00
Michael Gottesman
d64c08662a Revert "Improved Substitution::print()"
This reverts commit r27584. Fixes the build.

Swift SVN r27597
2015-04-22 19:38:45 +00:00
Slava Pestov
367f796fea Improved Substitution::print()
Swift SVN r27584
2015-04-22 17:18:44 +00:00
John McCall
3d3f1a7d7e Parsing/AST/Sema support for rethrows, and fix bugs with
throws/rethrows override and conformance checking.

Swift SVN r27508
2015-04-20 23:39:12 +00:00
Joe Groff
76ed49f474 Print opened existential archetypes as non-simple types.
Because of the @opened attr, they need to be parenthesized in some positions, particularly in opened existential metatypes like (@opened P).Type. This should fix the parse_stdlib validation tests.

Swift SVN r27424
2015-04-17 06:19:10 +00:00
Xi Ge
1f27ccb30c [ModulePrint] Remove relics of containing return types when printing optional init.
rdar://20044672

Swift SVN r27360
2015-04-16 17:27:55 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Doug Gregor
e87a925c9c ASTPrinter: print "throws" on throwing function declarations.
Swift SVN r27258
2015-04-13 21:30:55 +00:00
Joe Groff
b03795e5f7 Add a '@convention(xxx)' attribute for specifying function conventions.
This is new attribute we're using to coalesce @thin, @objc_block, and @cc, and to extend to new uses like C function pointer types. Parse the new attribute, but preserve support for the old attributes, and print with the old attributes for now to separate out test changes. Migration fixits and test updates to come. I did take the opportunity here to kill off the '@cc(cdecl)' hack for AST-level function pointer types, which are now only spelt with @convention(c).

Swift SVN r27247
2015-04-13 04:27:02 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Doug Gregor
5c33c8eab6 Properly print generic signatures of normal protocol conformances (only).
Fixes rdar://problem/20409234.

Swift SVN r27083
2015-04-07 15:51:19 +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
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 Willmore
690daa539a Back out changes for in-place methods/operators from Xcode 7.
This reverts commits r26508, r26545, and r26576.

Swift SVN r26900
2015-04-02 21:14:28 +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
Joe Groff
ebed0946fa Rename 'isSimpleEnum' to 'hasOnlyCasesWithoutAssociatedValues'.
Eliminate a bit of jargon that never caught on. This condition isn't used pervasively enough to need a short name.

Swift SVN r26781
2015-03-31 22:10:23 +00:00
Joe Pamer
eee40fc53f Add basic parsing, sema and mangling support for throwing function types. Next up, metadata and serialization support, as well as more tests.
Swift SVN r26767
2015-03-31 18:55:19 +00:00
Chris Lattner
b6e13bd1fe - Diagnose conditional PBD's without an else, conditional ones that do have an else,
and refutable pattern bindings without an initializer.
- Enhance ASTDumper to dump where/else clauses on PBDs.
- Merge if/let conditional PBD logic into the mainline logic now that they are all
  potentially conditional (more simplifications coming for this)

add tests for the fixits, which exercise the earlier SourceRange enhancments, e.g.:

x.swift:3:5: error: refutable pattern match can fail; add an else {} to handle this condition
let o? = a
    ^~
           else {}




Swift SVN r26751
2015-03-31 05:31:47 +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
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
Chris Willmore
1ee6f7e67c Implement syntax changes for in-place methods.
Rename 'assignment' attribute of infix operators to 'mutating'. Add
'has_assignment' attribute, which results in an implicit declaration of
the assignment version of the same operator. Parse "func =foo"
declaration and "foo.=bar" expression. Validate some basic properties of
in-place methods.

Not yet implemented: automatic generation of wrapper for =foo() if foo()
is implemented, or vice versa; likewise for operators.

Swift SVN r26508
2015-03-25 00:22:41 +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
Doug Gregor
159ecf7b84 SILPrinter: print the name of protocol conformance using its generic signature.
When we print the name of a protocol conformance, we normally use the generic parameters as written. However, since some requirements may be inferred (particularly by an extension of a generic type), it's better for the SIL printer to use the generic signature, which is fully expanded and will also be correct, e.g., when working with a deserialized conformance.

Swift SVN r26437
2015-03-23 17:51:39 +00:00
John McCall
a0a16d78d2 Implement the do/catch statement. Tests to follow.
This patch also introduces some SILGen infrastructure for
dividing the function into "ordinary" and "postmatter"
sections, with error-handling-like stuff going into the
final section.  Currently, this is largely undermined by
SILBuilder, but I'm going to fix that in a follow-up.

Swift SVN r26422
2015-03-23 02:08:26 +00:00
Doug Gregor
f50ef5005c Start detangling the uses of TypeDecl::getProtocols(). NFC
Getting the protocols of an arbitrary type doesn't make sense, so start phasing this out by introducing specialized entry points that do make sense:
  - get the inherited protocols of a ProtocolDecl
  - get the conforming protocols for an associated type or generic
  type parameter
  - (already present) ask for the protocols to which a nominal type conforms

Swift SVN r26411
2015-03-22 12:35:17 +00:00