Commit Graph

784 Commits

Author SHA1 Message Date
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Robert Widmann
370b08a927 Revise diagnostic message for availability fixit 2017-04-30 21:48:06 -04:00
David Rönnqvist
f45196d022 [SR-4231] Add diagnostic (& fix-it) for mixed syntax availability attribute (#9122)
* [Parse] Add diagnostic for mixed syntax availability attribute

When parsing a list of availablity specifications in the shorthand syntax, check to see that the next specification is also in shorthand syntax. If the next specification looks like an explicit “deprecated” (or similad) attribute, then emit a specific diagnostic about it to help the developer understand the problem.

https://bugs.swift.org/browse/SR-4231

* [Parse] Add fix-it for single mixed availability syntax

For the scenario that’s described in SR-4231, when there is one shorthard syntax followed by ‘deprecated’ (or similar), then we can guess that the intention was to treat the shorthand as ‘introduced’ so that the two of them work together.

This guess is only made if there is one platform version constrain, that is followed by ‘deprecated’, ‘renamed’, etc. but not ‘introduced’.

https://bugs.swift.org/browse/SR-4231

* Automatic formatting using git-clang-format

* Fix typos in test code and language in comment

Also, consistently names test functions as “deprecated” and "introduced"

* [Parse] Add note to explain the mixed availability syntax fix-it insertion

This change also moves the fix-it from the error to the note.
2017-04-30 19:39:38 -04:00
swift-ci
af53cb9778 Merge pull request #7733 from rintaro/parse-ifconfig-refactoring 2017-02-28 19:10:59 -08:00
Xi Ge
daac020c61 Sema: Reject empty switch statements during type checking so that we can issue fixits to fill the unhandled switch cases. (#7766) 2017-02-25 08:01:13 -08:00
Rintaro Ishizaki
58c079e306 [Parse] Split out IfConfig related functions into ParseIfConfig.cpp 2017-02-24 11:07:27 +09:00
Rintaro Ishizaki
78b92a56c7 [Parse] Only one conditional compilation clause can be active (#7627) 2017-02-21 02:13:11 +09:00
Rintaro Ishizaki
3b42894f13 [Parse] Fix parsing three-version-components in #if
* Narrow allowance of 3+ components numeric literal to condition part of the
  directive.
* Allow 3+ components in '#if' directive in decl list position as well.
2017-02-16 11:35:51 +09:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Jacob Bandes-Storch
e1fd8aa6c7 [Parse] Fix crash in conditional compilation parsing (#7331) 2017-02-08 23:10:26 -08:00
Jacob Bandes-Storch
c98e515734 [QoI] Improvements to function call & closure diagnostics (#7224) 2017-02-07 17:36:11 -08:00
Rintaro Ishizaki
9b4f549943 [Parse] Improve diagnostics for consecutive identifiers 2017-01-26 15:37:19 +09:00
Slava Pestov
a67f4bdff4 Merge pull request #6948 from matthewcarroll/SR-3599-Better-Recovery-For-Decl-Names
[DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
2017-01-23 17:37:07 -08:00
David Farler
902880a51a Merge pull request #6963 from bitjammer/decl-escaped-from-ifconfig-bit
Add 'EscapedFromIfConfig' bit to Decl
2017-01-23 14:23:06 -08:00
Rintaro Ishizaki
6305529fe5 [Parse] Add back TrailingSemiLoc to Expr, Stmt, and Decl 2017-01-23 13:18:11 +09:00
David Farler
8944ec0ceb Add 'EscapedFromIfConfig' bit to Decl
This is a temporary stop-gap for getting round-trip parsing
off the ground. The real fix, not re-injecting declarations
into an if-config's declaration context, is a deep dive and
is still ongoing.
2017-01-20 21:50:49 -08:00
Slava Pestov
e8bd7020fa Merge pull request #6855 from rintaro/parse-ifconfig-invalid-binary
[Parse] Disallow unsupported condition expression in #if directive
2017-01-20 20:27:45 -08:00
Matthew Carroll
93a7a9f80d [DiagnosticsQoI] SR-3599: Better recovery for decls with consecutive identifiers
Add diagnostics to fix decls with consecutive identifiers. This applies to
types, properties, variables, and enum cases. The diagnostic adds a camel-cased option if it is different than the first option.

https://bugs.swift.org/browse/SR-3599
2017-01-19 23:44:33 -05:00
Rintaro Ishizaki
b2d549e0c1 [Parse][Swift3] Add a warning for unsupported conditional compiliation expression 2017-01-18 05:25:14 +09:00
Rintaro Ishizaki
b950f06f3e [Parse] Disallow unsupported condition expression in #if directive
In non-Swift3 mode.

Previously:

  #if FOO = false
  #elseif FOO ? false : true
  #endif

were silently accepted.
i.e. '= false' and '? false : true' were silently ignored.
2017-01-17 22:11:11 +09:00
Rintaro Ishizaki
055ee48908 [Parse] Split Decl list parsing from parseList()
Parsing declaration list (e.g. member list of nominal decl) is very
different from comma separated list, because it's elements are separated with
new-line or semi-colon. There's no good reason to consolidate them.

Also, declaration list in 'extension' or inside of decl '#if' didn't
emit diagnostics for consecutive declarations on a line.

    class C {
    #if true
      var value: Int = 42 func foo() {}
    #endif
    }
    extension C {
      func bar() {} subscript(i: Int) -> Int {
        return 24
      }
    }

This change consolidates declaration list parsing for
members of nominal decls, extensions, and inside of '#if'.

In addition, removed unnecessary property 'TrailingSemiLoc' from decl.
2017-01-17 17:19:36 +09:00
Rintaro Ishizaki
2f1a3e1617 [AST] Remove unused property 'TrailingSemiLoc' from Stmt and Expr 2017-01-17 17:17:03 +09:00
Jacob Bandes-Storch
49f5251c73 [QoI] offer typo correction for platform conditionals 2017-01-12 09:07:53 -08:00
Robert Widmann
d2570cb964 Restore local type declarations list 2017-01-06 16:16:39 -07:00
Robert Widmann
0febbf0b72 Effectively revert #5778
This reverts the contents of #5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in #6279 we get the best of both worlds
with a performance win and a simpler implementation.
2017-01-06 16:16:39 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
96f2a04f55 Merge pull request #6490 from modocache/ast
[SR-2757][Sema] Mark VarDecl in capture lists
2017-01-05 21:36:16 -07:00
Robert Widmann
dfa41d625b Optimize Condition Resolution (#6279)
* Pack the bits for IfConfigDecls into Decl

* Don't open symbols into a module when evaluating canImport statements

The module loaders now have API to check whether a given module can be
imported without importing the referenced module.  This provides a
significant speed boost to condition resolution and no longer
introduces symbols from the referenced module into the current context
without the user explicitly requesting it.

The definition of ‘canImport’ does not necessarily mean that a full
import without error is possible, merely that the path to the import is
visible to the compiler and the module is loadable in some form or
another.

Note that this means this check is insufficient to guarantee that you
are on one platform or another.  For those kinds of checks, use
‘os(OSNAME)’.
2017-01-05 12:08:54 -07:00
Brian Gesiak
4108e1d9af [Sema] Mark VarDecl in capture lists
Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
2017-01-01 12:41:06 -05:00
Brian Gesiak
1e001d434a Merge pull request #6298 from modocache/sr-2605
[Parse] Improve diagnostics for if-condition-else
2016-12-19 15:40:28 -05:00
Robert Widmann
9fd7b5a29c Validate the entire #if configuration
Being lazy here just means we don’t validate the entire if
configuration.  We need to be able to emit diagnostics even in
condition clauses with indeterminate expressions.
2016-12-19 02:32:47 -05:00
Brian Gesiak
d44dc26d1b [Parse] Improve diagnostics for if-condition-else
Addresses SR-2605.

If you're refactoring a `guard` into an `if`, it's easy to
accidentally end up with invalid code like this in the transition:

```
if condition else {
}
```

The parser rightly complains about the `else`, but has poor recovery
afterward, interpreting the following brace as a closure, which may in
turn lead to other unhelpful errors after:

```
error: expected '{' after 'if' condition
    if condition else {
                 ^

error: braced block of statements is an unused closure
    if condition else {
                      ^
```

Improve the diagnostics to instead explicitly detect this pattern and
mark it as an error.
2016-12-15 19:51:17 -05:00
Robert Widmann
cededef0d6 Add condition resolution as a new phrase post-parse
An unfortunately necessary thing to delay defrosting function bodies as
long as we can.
2016-12-14 15:39:19 -05:00
Robert Widmann
72beb9d80d Extract common code into StmtTransformer 2016-12-14 14:59:47 -05:00
Robert Widmann
a060eb5aca [SE-0075] Transfer the power of config resolution to Namebinding
This completely removes Parse’s ability to make any judgement calls
about compilation conditions, instead the parser-relevant parts of
‘evaluateConditionalCompilationExpr’ have been moved into
‘classifyConditionalCompilationExpr’ where they exist to make sure only
decls that we want to parse actually parse later.

The condition-evaluation parts have been moved into NameBinding in the
form of a Walker that evaluates and collapses IfConfigs.  This walker
is meant as an homage to PlaygroundLogger.  It should probably be
factored out into a common walker at some point in the future.
2016-12-14 14:59:47 -05:00
Robert Widmann
4426e410e5 [SE-0075] Do the naive thing.
Implemented in the naive way by way of the current ASTContext’s
‘LoadedModules’.  In theory this list should be in one-to-one
correspondence with the definition of “importable” as any module that
is required for compilation is loaded *before* we start parsing the
file.  This means we don’t have to load the module, just check that
it’s in the set of loaded modules.

Note that this approach will most likely fall apart if submodules are
introduced and are lazily loaded.  At that point this will need to be
refactored into a format that defers the checking of conditions
sometime before or during typechecking (after namebinding).
2016-12-14 14:59:47 -05:00
Rintaro Ishizaki
42ebd38c29 [Parse] Skip non-case-label statements in switch (#6215) 2016-12-13 03:37:09 +09:00
practicalswift
8962c8819f Merge pull request #6139 from practicalswift/remove-never-read-variables
[gardening] Remove never-read variables + tighten scope.
2016-12-12 13:32:36 +01:00
practicalswift
850ef04895 [gardening] Remove never-read bool HaveFirst. 2016-12-08 13:36:17 +01:00
Hugh Bellamy
732e3c5fdc Fix warnings building swift/Parse on Windows using MSVC 2016-12-07 22:20:49 +00:00
Rintaro Ishizaki
ec53b6885f [Parse] Let #if diretives be parsed in parseBraceItems()
parseBraceItems() has specific logic for pasing conditional compilation blocks.
Withoutout that, decralations in the block cannot be propagated to outside.
For instance:

  FOO: #if true
  func foo() {}
  #endif
  foo() // error: use of unresolved identifier 'foo'
2016-12-06 22:28:53 +09:00
Rintaro Ishizaki
54efbbbf87 [Parse] Let #sourceLocation be parsed in parseBraceItems()
Returning 'makeParserSuccess()' as a 'ParserResult<Stmt>' causes assertion error.

  Assertion `Status.isError()' failed
2016-12-06 22:28:53 +09:00
Argyrios Kyrtzidis
fc678740db [code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range.
The tentantive parse is used for diagnostic purposes but can cause code-completion to delay the same decl twice.
The range of CodeCompletionExpr was previously character range which invalidated invariants of the AST.

Fixes:
	validation-test/IDE/crashers_fixed/084-swift-parser-consumedecl.swift
	validation-test/IDE/crashers_fixed/104-swift-gettypeofcompletioncontextexpr.swift
2016-12-05 17:09:49 -08:00
Slava Pestov
0f7a455d7d AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls 2016-11-29 03:05:33 -07:00
Rintaro Ishizaki
9b243526b8 [AST] Hold element name information in TupleTypeRepr
For now, only 'TupleTypeRepr::isParentType()' is using this informations.
Next commit will eliminate NamedTypeRepr.
2016-11-26 14:15:29 +09: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
David Farler
f450f0ccdf Revert "Preserve whitespace and comments during lexing as Trivia"
This reverts commit d6e2b58382.
2016-11-18 13:23:31 -08:00
David Farler
44f15558d6 Revert "Refactor: Rename Parser::consumeToken, consumeLoc. Add consumeToken API."
This reverts commit 39bfc123a3.
2016-11-18 13:23:31 -08:00
David Farler
ff98e5fd81 Merge pull request #5811 from bitjammer/syntax
Preserve source trivia in the lexer
2016-11-16 11:47:32 -08:00
Rintaro Ishizaki
887fb3750a [Parse] Fix range containment problem in statement condition
For constructing the dummy expression for missing initializer,
use the end location of the pattern instead of the location of the
current token.

Previous behavior used to build AST like:

  { if let x [eof]
       |---|       Pattern range
             |---| Dummy introducer range
    |------------| IfStmt range
  |--------|       BraceStmt range

Now:

  { if let x [eof]
       |---|       Pattern range
           |       Dummy introducer range
    |------|       IfStmt range
  |--------|       BraceStmt range
2016-11-16 10:30:15 +09:00