Commit Graph

128 Commits

Author SHA1 Message Date
Owen Voorhees
901d947478 Improve diagnostic and add fixit to correct '#else if' to 'elseif'
Resolves SR-10581
2019-05-23 19:34:21 -07:00
Daniel Rodríguez Troitiño
f0a6948632 [android] Add a test for Android conditional compilation (AArch64)
There are similar tests for other architectures/OS pairs, but
android-aarch64 was missing. This should ensure that the conditional
compilation for Android works correctly in this case.
2019-05-10 14:38:13 -07:00
Saleem Abdulrasool
52952623db test: remove extraneous macro definitions
These tests were defining an unused macro for no clear reason.  Remove
them to simplify the tests.
2019-05-07 08:06:02 -07:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Han Sang-jin
859f144b75 [LangOptions] os(Cygwin) is not true on Cygwin
`Target.isOSWindows()` and `Target.isWindowsCygwinEnvironment()` are both true in Cygwin.
We should check the `os(Cygwin)` before `os(Windows)`.
2018-11-10 11:23:00 +09:00
Jordan Rose
ceaa5db623 Merge pull request #17960 from danielmartin/new-unary-operator-ifconfig
[Parser] Support "<" unary operator in #if swift() and #if compiler() expressions
2018-09-26 15:00:48 -07:00
Daniel Martín
5d6f4f697f Run #if compiler tests also in Swift 4 mode 2018-09-08 13:26:16 +02:00
Daniel Martín
ccbc3f7dcc Add some tests for #if compiler 2018-08-26 15:40:17 +02:00
Arnold Schwaighofer
f04aec58b2 Codesign test/Parse 2018-08-10 08:23:25 -07:00
Daniel Martín
e66095b10a [Parser] Support "<" unary operator in #if swift() expressions
Until now, only ">=" was supported in #if swift() expressions, for example:

```#if swift(>=2.1)
```#endif

This means that if we want to evaluate code only when the language version is
less than a particular version we need to do the following:

```#if !swift(>=2.1)
```#endif

An alernative to make this more readable (the "!" can be easily missed in a code
review) is to introduce another supported unary operator, "<". The previous
example could be rewritten like this:

```#if swift(<2.1)
```#endif

This commit adds support for that unary operator, along with some tests.
2018-08-02 20:35:58 +02:00
Rintaro Ishizaki
5cbbadb750 [Parse] Migrate tests to Swift4 2018-07-07 01:29:43 +09:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Jordan Rose
701975ad1d Add parsing support for @unknown (SE-0192)
This is our first statement attribute, made more complicated by the
fact that a 'case'/'default' isn't really a normal statement. I've
chosen /not/ to implement a general statement attribute logic like we
have for types and decls at this time, but I did get the compiler
parsing arbitrary attributes before 'case' and 'default'. As a bonus,
we now treat all cases within functions as being switch-like rather
than enum-like, which is better for recovery when not in a switch.
2018-04-05 16:35:14 -07:00
Ted Kremenek
3da51018b6 Teach ClangImporter to handle effective Swift version with minor release.
Needed to support Swift 4.2.
2018-03-23 00:30:44 -07:00
Sho Ikeda
b68be20e9d [test][gardening] Prefer os(macOS) over os(OSX) 2018-03-11 10:58:58 +09:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Jordan Rose
a16d8a73d1 Bump the compiler version to 4.2 (and 3.4) (#13767)
https://swift.org/blog/4-2-release-process/
2018-03-02 18:09:45 -08:00
Graydon Hoare
111674acdb [typo] s/plaform/platform/ everywhere. 2018-02-26 09:29:29 -08:00
gregomni
0c3c0fd59b Support for fallthrough into cases with pattern variables. 2018-01-20 11:10:00 -08:00
Rintaro Ishizaki
39746a9e58 [Parse] Inline skipExtraTopLevelRBraces()
Removed from 'parseTopLevel()'. There's no particular reason to diagnose
it in 'parseTopLevel()'.
2017-12-25 23:32:55 +09:00
Graydon Hoare
d31bad45b8 [Parse] Add fixit for targetEnvironment(simulator) 2017-11-28 13:51:01 -08:00
Graydon Hoare
d3613b8017 [Platform] Support triple.isSimulatorEnvironment() 2017-11-28 13:51:01 -08:00
Graydon Hoare
3807b3fa1e [Parse] Add platform conditional targetEnvironment(simulator) 2017-11-28 13:51:01 -08:00
Robert Widmann
75a83da03e Implement SE-0075: CanImport
This implementation required a compromise between parser
performance and AST structuring.  On the one hand, Parse
must be fast in order to keep things in the IDE zippy, on
the other we must hit the disk to properly resolve 'canImport'
conditions and inject members of the active clause into the AST.
Additionally, a Parse-only pass may not provide platform-specific
information to the compiler invocation and so may mistakenly
activate or de-activate branches in the if-configuration decl.

The compromise is to perform condition evaluation only when
continuing on to semantic analysis.  This keeps the parser quick
and avoids the unpacking that parse does for active conditions
while still retaining the ability to see through to an active
condition when we know we're moving on to semantic analysis anyways.
2017-08-28 18:35:06 -04:00
Ewa Matejska
1272cd3aac Making master call itself 4.1, updating the swift 3 compatiblity mode to be 3.3 (from 3.2), adding ability to pass swift-version 5. Importer work not done yet. 2017-08-17 20:57:01 -07:00
Robert Widmann
0cf1b52452 Treat Cygwin as a separate OS
Cygwin is considered a distinct target with a distinct ABI, environment
conditions, and data types.  Though the goal of the project is
native Windows integration with UNIX-likes, that is not compatible with
the idea that the platform can be ignored as Win-like enough to have the
existing os(Windows) condition apply.
2017-06-28 13:31:05 -07:00
Rintaro Ishizaki
f6310b4b9b [test] Add test executable test case for nested #if in switch cases 2017-06-22 12:10:08 +09:00
Rintaro Ishizaki
5d478bdb3b [Parse] Allow #if to guard switch case clauses
Resolves:
https://bugs.swift.org/browse/SR-4196
https://bugs.swift.org/browse/SR-2
2017-06-17 10:03:03 +09:00
Slava Pestov
732b215b88 Merge pull request #9413 from rintaro/ast-eliminate-ifconfigstmt
[AST] Eliminate IfConfigStmt
2017-06-16 15:39:47 -07:00
Rintaro Ishizaki
4c6ece6fe0 [Parse] Don't invalidate compilation condition with invalid platform condition argument (#10221)
It's just a warning.
2017-06-14 15:09:24 +09:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Rintaro Ishizaki
04f31a76c0 Merge pull request #7955 from rintaro/parse-ifconfig-validate
[Parse] Separate compilation condition validation and evaluation
2017-05-16 12:06:31 +09:00
Joe Groff
9222960df5 Update ConditionalCompilation test. 2017-04-21 12:16:30 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
Rintaro Ishizaki
bd3b2c6601 [Parse] Add warning for compound name in compilation condition in swift3 2017-03-29 00:43:28 +09:00
Rintaro Ishizaki
b56ab17fa5 [Parse] Separate compilation condition validation and evaluation
Fixes:
https://bugs.swift.org/browse/SR-3455
https://bugs.swift.org/browse/SR-3663
https://bugs.swift.org/browse/SR-4032
https://bugs.swift.org/browse/SR-4031

Now, compilation conditions are validated at first, then evaluated. Also,
in non-Swift3 mode, '&&' now has higher precedence than '||'.
'A || B && C || D' are evaluated as 'A || (B && C) || D'.

Swift3 source breaking changes:

* [SR-3663] This used to be accepted and evaluate to 'true' because of short
  circuit without any validation.

  #if true || true * 12 = try Anything is OK?
  print("foo")
  #endif

  In this change, remaining expressions are properly validated and
  diagnosed if it's invalid.

* [SR-4031] Compound name references are now diagnosed as errors.
  e.g. `#if os(foo:bar:)(macOS)` or `#if FLAG(x:y:)`

Swift3 compatibility:

* [SR-3663] The precedence of '||' and '&&' are still the same and the
  following code evaluates to 'true'.

  #if false || true && false
  print("foo")
  #endif
2017-03-23 01:25:29 +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
1d499546eb [Parse] Don't construct DeclRefExpr in #if conditions (#7522)
This code should compile:

  func foo(FOO: Int, swift: String, Linux: Bool) {
  #if FOO && swift(>=3.0) && os(Linux)
    // do something
  #endif
  }
2017-02-17 12:41:42 +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
Rintaro Ishizaki
cfe742d1eb [Parse] Minor improvements in conditional compilation block parsing
* Don't emit duplicated 'expected #else or #endif at end of conditional
  compilation block' error.

    class Foo {
      #if true
        func foo() {}
    [EOF]

* Improve error message when seeing '}' in config block.

    class Foo {
    #if true
        func foo();
    } // error: unexpected '}' in conditional compilation block
    #else
    #endif
2017-02-16 11:35:51 +09:00
Jacob Bandes-Storch
e1fd8aa6c7 [Parse] Fix crash in conditional compilation parsing (#7331) 2017-02-08 23:10:26 -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
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
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
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
practicalswift
9e60bdbffa [gardening] Fix typos. 2016-12-21 21:33:30 +01: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
Robert Widmann
a7957a199b Walk into top level pattern binding decls to resolve conditions 2016-12-15 04:50:02 -05:00