Commit Graph

82 Commits

Author SHA1 Message Date
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
Joe Pamer
7b771affd9 Add limited build configuration support for testing against compiler submit versions. (rdar://problem/16337966)
This is meant to be utilized for a narrow set of scenarios specific to dogfooding our pre-1.0 compiler, so please do not take any dependencies on this.  In fact, I'll be removing this in the next milestone.  (See rdar://problem/16380797.)

Also included - improve error recovery when parsing broken build configuration clauses.

Swift SVN r15694
2014-03-31 20:34:02 +00:00
Argyrios Kyrtzidis
778c6cbe37 [Driver] When printing out the version also print out the submission version.
Swift SVN r13756
2014-02-10 19:10:01 +00:00
Connor Wakamo
ed2038585f Initial set of changes to add a new 'swift_driver' executable.
- Added a couple of new targets:
  - libswiftDriver, which contains most of the driver implementation
  - swift_driver, which produces the actual executable

- Added centralized version information into libswiftBasic.

- Added a new "Driver Design & Internals" document, which currently describes
  the high-level design of the Swift driver.

- Implemented an early version of the functionality of the driver, including
  versions of the Parse, Pipeline, Bind, Translate, and Execute driver stages.
  Parse, Pipeline, and Bind are largely implemented; Translate and Execute are
  early placeholders. (Translate produces "swift_driver --version" and "ld -v"
  commands, while Execute performs all subtasks sequentially, rather than in
  parallel.)

This is just the starting point for the Swift driver. Tests for the existing
behavior are forthcoming.

Swift SVN r10933
2013-12-06 21:23:01 +00:00