Commit Graph

53 Commits

Author SHA1 Message Date
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
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
Ted Kremenek
fa730db1c2 Allow ‘getEffectiveLanguageVersion’ to take a minor component for 4.2
Further, when ‘4’ is specified on its own for the language
version without a minor component, assume ‘4.1’ as the
language version.
2018-03-21 14:40:31 -07:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09: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
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
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
e3e0f440a1 Serialization: Recovery for protocol conformances with changed witness or requirement signatures.
Deserializing a witness record in a conformance may fail if either of the requirement or witness changed name or type, most likely due to SDK modernization changes across Swift versions. When this happens, leave an opaque placeholder in the conformance to indicate that the witness exists but we don't get to see it. For expedience, right now this just witnesses the requirement to itself, so that code in the type checker or elsewhere that tries to ad-hoc devirtualize references to the requirement just gets the requirement back. Arguably, we shouldn't include the witness at all in imported conformances, since they should be an implementation detail, but that's a bigger, riskier change. This patch as is should be enough to address rdar://problem/31185053.
2017-05-09 09:15:04 -07:00
Ted Kremenek
dcc43ec602 Adjust to return compatibility version in Swift 3 mode. 2017-04-19 12:17:54 -07: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
Jordan Rose
3456d04925 "-swift-version 3" means Swift 3.1, not 3.0. (#7883)
Put in a general mechanism for mapping user-specified "compatibility
versions" to proper "effective versions" (what #if and @available
checking should respect). This may still be different from the
intrinsic "language version"; right now master is considered a "3.1"
compiler with a "Swift 4 mode", and we plan to ship a "4.0" compiler
with a "Swift 3 mode" that will have a version number of something
like "3.2".

rdar://problem/29884401 / SR-3791
2017-03-03 13:28:01 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Hugh Bellamy
50e94af377 Generate empty *Revision.inc files during the build process 2016-12-02 17:13:28 +00:00
Hugh Bellamy
56dfb08727 Port swift/basic to Windows 2016-12-02 16:57:00 +00: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
EMatejska
1fa8dd45bc Adding getSwiftRevision(). This is to aid cleaning up some lldb code that could use this API. 2016-11-07 00:06:22 -08:00
Graydon Hoare
5cf343f8f6 Logically compare swift versions as though X == X.0 == X.0.0, etc. 2016-10-24 20:23:02 -07:00
Michael Ilseman
5d540ababd [Swift version] Note all supported versions when -swift-version is misused. 2016-10-18 14:43:21 -07:00
Michael Ilseman
12efcc9db6 [Version] Don't allow effective sub-versions, only major versions
Also offer a note when the major version is valid on its own.
2016-10-18 14:43:21 -07:00
Graydon Hoare
7183f9cc66 Add conversion operator between version::Version and clang::VersionTuple 2016-10-12 11:20:42 -07:00
Michael Ilseman
12fb0bad7b [swift-version] Allow swift-version 4 and tests
The recent @escaping on variadic argument closures back-compat fix is
the first Swift 3.0 compatibility behavior that we don't want to carry
forwards indefinitely into the future. To address this, we
version-gate the diagnostic suppression.

Makes it an official compatibility check. Creates new test directory
for compatibility testing. Allow -swift-version 4 so that we can test
it both ways.
2016-10-11 17:42:25 -07:00
Graydon Hoare
8970d44675 Add "-swift-version <n>" that sets LangOpts.EffectiveLanguageVersion.
This flag switches the "effective language version" of the compiler,
at least to any version supported (as of this change: "3" or "3.0").

At the moment nothing uses it except the language version build
configuration statements (#if swift(...)) and various other places
that report, encode, or otherwise check version numbers.

In the future, it's intended as scaffolding for backwards compatibility.

Fixes SR-2582
2016-09-20 15:11:37 -07:00
Jordan Rose
5ffb151f77 [ClangImporter] Predefine __swift__ in imported (Obj)C code. (#4510)
This macro expands to a numeric value representing the current Swift
language version; for Swift 3.1.2, it would be 30102.

See discussion in https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160822/002754.html.

rdar://problem/26921435
2016-08-25 18:26:35 -07:00
Slava Pestov
d49d054efd Muffle a warning 2016-06-28 17:58:11 -07:00
Jordan Rose
8f820dea2b [serialization] Diagnose loading modules from older Swifts.
...with a better message than the generic "older version of the
compiler" one, when we know it's actually a different version of
Swift proper.

This still uses the same internal module version numbers to check
if the module is compatible; the presentation of language versions
is a diagnostic thing only.

Speaking of module version numbers, this deliberately does NOT
increment VERSION_MINOR; it's implemented in a backwards-compatible
way.

This will only work going forwards, of course; all existing modules
don't have a short version string, and I don't feel comfortable
assuming all older modules we might encounter are "Swift 2.2".

rdar://problem/25680392
2016-04-29 16:25:33 -07:00
Jordan Rose
6272941c5c Rename "build configurations" to "conditional compilation blocks".
...because "build configuration" is already the name of an Xcode feature.

- '#if' et al are "conditional compilation directives".
- The condition is a "conditional compilation expression", or just
  "condition" if it's obvious.
- The predicates are "platform conditions" (including 'swift(>=...)')
- The options set with -D are "custom conditional compilation flags".
  (Thanks, Kevin!)

I left "IfConfigDecl" as is, as well as SourceKit's various "BuildConfig"
settings because some of them are part of the SourceKit request format.
We can change these in follow-up commits, or not.

rdar://problem/19812930
2016-02-12 11:09:26 -08:00
David Farler
be58b3c2e3 Extract Version value out of optional when parsing _compiler_version
rdar://problem/24476174
2016-02-02 23:50:13 -08:00
David Farler
c32fb8e7b9 SE-0020: Swift Language Version Build Configuration
Introduce a new "swift" build configuration that guards declarations
and statements with a language version - if the current language version
of the compiler is at least that version, the block will parse as normal.
For inactive blocks, the code will not be parsed an no diagnostics will
be emitted there.

Example:

    #if swift(>=2.2)
      print("Active")
    #else
      this code will not parse or emit diagnostics
    #endif

https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md
rdar://problem/19823607
2016-01-21 16:31:19 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Wang Hanlin
b9ee2eb14d Fix missing period in comments 2015-12-04 11:26:56 +00:00
Agarwal, Ashish(ashishagarwal)
472eaccf5f Fixed typo in comments
Fixed a couple of typos while going thru the code
2015-12-04 11:22:54 +05:30
Chris Willmore
f83595f642 Append "-dev" to printed version of builds not meant for release.
<rdar://problem/22851991>
2015-11-04 18:12:14 -08:00
Dmitri Hrybenko
dab6dde2eb Undo an accidental change that I committed in r32866
Swift SVN r32902
2015-10-27 00:27:49 +00:00
Dmitri Hrybenko
27dae236ab CMake: allow choosing the deployment target
Based on a patch by Sonny Falk.

Swift SVN r32866
2015-10-24 04:56:33 +00:00
David Farler
fb1cc93c80 Clean up uses of swift-compiler-verison and clang_repository_string
Bring this build setting in line with swift-compiler-version:

- Use "clang-compiler-version" instead of "repository_string"
- Don't append the clang compiler version to the swift one.
- Clean up uses in build-script-impl and build-presets.ini.
- Clean up uses in CMake

Swift SVN r32794
2015-10-21 18:54:54 +00:00
David Farler
5e3ba2b1cc Update getCurrentCompilerVersion call to parseCompilerVersionString
This is a leftover change from the last refactoring.

Swift SVN r32727
2015-10-16 18:03:34 +00:00
David Farler
e1a7a0f0ab Refactor CompilerVersion
This is a WIP to make CompilerVersion more general.

- Rename CompilerVersion to just "Version"
- Make version comparison general and put _compiler_version special logic
  with its second version component in a specialized parsing function
- Add a generic version parsing function

Swift SVN r32726
2015-10-16 17:43:28 +00:00
David Farler
7c48e3a362 Define __SWIFT_COMPILER_VERSION in the ClangImporter
Pass a preprocessor definition for the internal compiler
version when importing types.

rdar://problem/23100689

Swift SVN r32725
2015-10-16 17:43:27 +00:00
David Farler
a67596a9d9 Enforce practical limits of _compiler_version
Internal compiler versions must be able to be packed into a 64-bit
value, and there is a limit on how many components we can use and which
values they can take on.

Versions must have no more than five components, assuming a version
X.Y.Z.a.b, where X, Y, Z, a, and b are integers with the following
inclusive ranges:

X: [0 - 214747]
Y: [0 - 999]
Z: [0 - 999]
a: [0 - 999]
b: [0 - 999]

Swift SVN r32724
2015-10-16 17:43:24 +00:00
David Farler
6f34a1467b SWIFT_COMPILER_VERSION needs TOSTR wrapper
The extra quotation marks were already removed, so this needs to be
wrapped.

Follow up to:
rdar://problem/22928762

Swift SVN r32676
2015-10-14 04:33:36 +00:00
David Farler
962a1c0ddc Warn and fix-it if second _compiler_version component isn't a *
To better indicate that the second _compiler_version component isn't
used in the ordering, warn and provide a fix-it replacement if it's
not a '*' in source code.

To make the diagnostics a little easier to emit, I cleaned up the
parsing code to use StringRef::split instead of a hand-written
tokenizer.

rdar://problem/23080845

Swift SVN r32673
2015-10-14 01:26:58 +00:00
Jordan Rose
b7bc622f63 If there's no SWIFT_COMPILER_VERSION, show the revisions Swift was built with.
Modeled after the same feature in Clang. Example (from swift -version):

  Swift version 2.1 (LLVM bf75799360, Clang 340dfbb3d5, Swift 32557)

rdar://problem/22959963

Swift SVN r32625
2015-10-12 16:32:52 +00:00
David Farler
b73ca15aea Build fix: Ask stream's string for its size
Don't ask the output string for its size since the stream may not
have flushed.

Swift SVN r32554
2015-10-09 06:01:43 +00:00
David Farler
2a0f027317 Review changes for _compiler_version
A couple of small tweaks to _compiler_version based on review comments:
- Fix &&/|| rejection to work with _compiler_version on either side of the
expression. Also add some test cases around this.
- Use clang/LLVM facilities for isdigit and atoi.
- Assert if parsing an invalid version string and there is no diagnostic
engine.
- Clean up some crumbs in the CMake configs.

rdar://problem/22730282

Swift SVN r32212
2015-09-24 22:47:01 +00:00
David Farler
27fac39a7d Build fix: last compiler version component not null terminated for atoi
rdar://problem/22730282

Swift SVN r32196
2015-09-24 03:18:57 +00:00
David Farler
9d373d0fc7 Add _compiler_version build configuration
This configuration clause will suppress lex diagnostics and skip parsing
altogether if the code under the clause isn't active - the compiler must
have a repository version greater than or equal to the version given to
_compiler_version.

This option is only meant to be used sparingly and not to track the
Swift *language* version.

Example, if using a compiler versioned 700.0.28:

  #if _compiler_version("700.0.23")
    print("This code will compile for versions 700.0.23 and later.")
  #else
    This + code + will + not + be + parsed
  #endif

Included are new diagnostics for checking that the version is formatted
correctly and isn't empty.

New tests:
- Compiler version comparison unit tests
- Build configuration diagnostics
- Skipping parsing of code under inactive clauses

rdar://problem/22730282

Swift SVN r32195
2015-09-24 02:14:47 +00:00
Dmitri Hrybenko
41cd10e3f1 build-script/libSwiftBasic: properly propagate the Swift version down to
Version.cpp

rdar://19166288 rdar://19445760

Swift SVN r24592
2015-01-21 05:01:42 +00:00
Adrian Prantl
801dc3d20e Debug info: Actually encode the Swift version number instead of constant 1.
<rdar://problem/18729762> CU's RuntimeVersion field should have the Swift runtime version number

Swift SVN r23087
2014-11-03 17:48:06 +00:00
Jordan Rose
9804a1c85e Fix Version.cpp to actually stringify the version, not the macro name.
Swift SVN r15916
2014-04-04 01:40:55 +00:00
Ted Kremenek
9d580f6ebd CMake: Fix string escaping of compiler version so that it works with the Xcode generator. Xcode did not like parsing strings with unbalanced quotes
in the plist file.

This was exposed by r15694, but probably did not manifest as
the string escaping logic previously only happened on B&I submissions.

In this approach, the final version quad is turned into a string
within Version.cpp, not at the -D invocation.

Swift SVN r15708
2014-03-31 23:32:21 +00:00