Commit Graph

65 Commits

Author SHA1 Message Date
Robert Widmann
18b79ffcfd Resolve a Layering Violation in libBasic
Basic should not be allowed to link Parse, yet it was doing so
to allow Version to provide a constructor that would conveniently
parse a StringRef. This entrypoint also emitted diagnostics, so it
pulled in libAST.

Sink the version parser entrypoint down into Parse where it belongs
and point all the clients to the right place.
2022-09-09 00:21:30 -07:00
Alexis Laferrière
36b87d3c5c [Serialization] Use a more reliable macro to get the compiler tag
Use only the SWIFT_COMPILER_VERSION macro to check for swiftmodules
being written by the same compiler that reads it. In practice, it's the
macro used for release builds of the compiler.

rdar://96868333
2022-07-18 13:20:20 -07:00
swift-ci
645d73f27e Merge pull request #58480 from beccadax/so-i-put-versions-in-your-version-numbers
Update SWIFT_COMPILER_VERSION language features
2022-05-24 17:47:43 -07:00
Alexis Laferrière
c341010fbd [Basic][Serialization] Intro and use isCurrentCompilerTagged 2022-05-17 16:45:34 -07:00
Becca Royal-Gordon
3843c7cd5e Update SWIFT_COMPILER_VERSION language features
The `SWIFT_COMPILER_VERSION` define is used to stamp a vendor’s version number into a Swift compiler binary. It can be queried from Swift code using `#if _compiler_version` and from Clang by using a preprocessor definition called `__SWIFT_COMPILER_VERSION`. These are unsupported compiler-internal features used primarily by Apple Swift.

In Swift 1.0 through 5.5, Apple Swift used a scheme for `SWIFT_COMPILER_VERSION` where the major version matched the embedded clang (e.g. 1300 for Apple Clang 13.0.0) and the minor version was ignored. Starting in Swift 5.6, Apple Swift started using major and minor version numbers that matched the Swift.org version number. This makes them easier to understand, but it means that version 1300.0.x was followed by version 5.6.x. Not only did version numbers go backwards, but also the old logic to ignore minor versions was now a liability, because it meant you would not be able to target a change to 5.7.x compilers but not 5.6.x compilers.

This commit addresses the problem by:

* Modifying the existing `#if _compiler_version(string-literal)` feature so it transforms the major version into a major and minor that will compare correctly to new version numbers. For instance, “1300.*” is transformed into “1.300”, which will compare correctly to a “5.6” or “5.7” version even if it doesn’t really capture the fact that “1300” was a Swift 5.5 compiler. As a bonus, this allows you to use the feature to backwards-compatibly test new compilers using the existing feature: “5007.*” will be seen by compilers before 5.7 as an unknown future version, but will be seen by 5.7 compilers as targeting them.

* Modifying the `__SWIFT_COMPILER_VERSION` clang define similarly so that, to preprocessor conditions written for the old scheme, a 5.7 compiler will appear to have major version 5007.

* Adding a new variant of `#if _compiler_version` with the same syntax as `#if swift` and `#if compiler`—that is, taking a comparison operator and a bare set of dotted version numbers, rather than a string literal. Going forward, this will be how version checks are written once compatibility with compilers before this change is no longer a concern.

These changes are only lightly tested because tests have to work without any compiler version defined (the default in most configurations), but I’ve tested what I can.

Fixes rdar://89841295.
2022-04-27 18:27:52 -07:00
Alexis Laferrière
362cacf5a1 [Basic] Update getSwiftRevision to return a StringRef 2021-09-21 10:02:40 -07:00
Becca Royal-Gordon
1fbded6629 Allow -swift-version 6 in asserts compilers only
To allow us to start testing language changes tied to a future Swift 6 mode without actually *shipping* a Swift 6 mode to customers who might accidentally use it before it's ready.

This commit also adds parallel tests for a number of already existing (but untested) Swift 6 mode behaviors.
2021-08-03 18:44:49 -07:00
Hamish Knight
f9d70661dd [IRGen] Hash compiler version instead of lang version
The LLVM passes we apply don't depend on the language
version, only the compiler version.
2020-07-15 16:46:41 -07:00
David Zarzycki
aefeab859e [Basic] Revise version printing
Now that we use the LLVM mono-repo, we don't need to worry about clang's
version number. Also, git has the ability to estimate the safe number of
digits a hash can be truncated to and now git estimates that large
projects like LLVM and Linux "require" 12 digits for safe commit hash
abbreviation. Let's stay a little ahead of the curve and statically
truncate to 15.
2020-06-16 05:37:30 -04:00
Ted Kremenek
46510a5eba Bump compiler version to Swift 5.
Main pieces:

- Bump swift-version to 5
- Remove -swift-version 3 support
2018-11-06 14:38:55 -08: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
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
Bob Wilson
c3e02955bb [master-next] Adjust for VersionTuple moving from clang to llvm.
LLVM r334399 (and related Clang changes) moved clang::VersionTuple to
llvm::VersionTuple. Update Swift to match.

Patch by Jason Molenda.
rdar://problem/41025046
2018-06-12 16:44:11 -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
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