Commit Graph

519 Commits

Author SHA1 Message Date
Dmitri Hrybenko
dab6dde2eb Undo an accidental change that I committed in r32866
Swift SVN r32902
2015-10-27 00:27:49 +00:00
Joe Groff
2368ce774b Remove self types from mangling by default.
And include some supplementary mangling changes:

- Give the first generic param (depth=0, index=0) a single character mangling. Even after removing the self type from method declaration types, 'Self' still shows up very frequently in protocol requirement signatures.
- Fix the mangling of generic parameter counts to elide the count when there's only one parameter at the starting depth of the mangling.

Together these carve another 154KB out of a debug standard library. There's some awkwardness in demangled strings that I'll clean up in subsequent commits; since decl types now only mangle the number of generic params at their own depth, it's context-dependent what depths those represent, which we get wrong now. Currying markers are also wrong, but since free function currying is going away, we can mangle the partial application thunks in different ways.

Swift SVN r32896
2015-10-26 22:05:20 +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
Joe Groff
9ffa0b218e Add demangler support for protocol descriptor symbols.
Swift SVN r32791
2015-10-21 17:44:09 +00:00
Joe Groff
7e119d0d53 Optimize the mangling of associated types in generic signatures.
Canonical dependent member types are always based from a generic parameter, so we can use a more optimal mangling that assumes this. We can also introduce substitutions for AssociatedTypeDecls, and when a generic parameter in a signature is constrained by a single protocol, we can leave that protocol qualification out of the unsubstituted associated type mangling. These optimizations together shrink the standard library by 117KB, and bring the length of the longest Swift symbol in the stdlib down from 578 to 334 characters, shorter than the longest C++ symbol in the stdlib.

Swift SVN r32786
2015-10-20 17:52:07 +00:00
Joe Groff
b77ea5e5ae Mangle the generic signature of a constrained extension after the containing module.
A microoptimization; since the module is likely to come up often in the subsequent mangling, we want to make it more likely to get the coveted S_ substitution.

Swift SVN r32784
2015-10-20 17:51:51 +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
Doug Gregor
8a044152da Omit needless words: lowercase the initial words of all names, including acroynums.
Cocoa's naming guidelines use lowercase initial words for selector
pieces and property names except when the first word is an
acronym. Force the first word of all imported APIs to be lowercase,
including acronyms.

Swift SVN r32719
2015-10-16 06:28:03 +00:00
Doug Gregor
f8b246980a Omit needless words: drop "with" from the beginning of first argument labels.
For example, copy(withZone:) becomes copy(zone:).

Swift SVN r32708
2015-10-15 18:53:51 +00:00
Doug Gregor
382746cd0d Omit needless words: stop splitting first selector pieces for Boolean parameters.
Swift SVN r32692
2015-10-14 23:29:20 +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
Xi Ge
1138a9cd27 Suppress warnings, NFC
Swift SVN r32662
2015-10-13 20:00:02 +00:00
Jordan Rose
116d19cead [CMake] Remove accidentally-added extra quotes from SWIFT_COMPILER_VERSION.
The use of it already uses a TOSTR macro to wrap a bare substitution in a
string, to match the previous definition of the macro without quotes
(removed in r32625). Thanks, David!

Swift SVN r32656
2015-10-13 16:05:56 +00:00
Xi Ge
5ca83d97a5 [InterfacePrint] Enhance ASTPrinter to support type-specific interface printing.
When users try to print the interface of a specific type (most often through cursor
infor query of SourceKit), we should simplify the original decls by replacing
archetypes with instantiated types, hiding extension details, and omitting
unfulfilled extension requirements. So the users can get the straight-to-the-point
"type interface". This commit builds the testing infrastructure for this feature,
and implements the first trick that wraps extension contents into the interface body.

This commit also moves some generic testing support from SourceKit to Swift.

Swift SVN r32630
2015-10-12 19:14:58 +00:00
Joe Groff
42c71b7972 Don't mangle directness into type metadata symbols.
Anywhere we can't directly address type metadata in Swift, we've found we need a function call. Directness isn't useful here.

Swift SVN r32626
2015-10-12 17:22:40 +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
John McCall
76e324a950 Refactors leading towards the use of protocol witness table access functions.
This re-applies r32541 with a few changes to the demangling logic and associated test fixes.

Swift SVN r32553
2015-10-09 05:49:18 +00:00
Erik Eckstein
19bb23a63f Revert r32541 "Refactors leading towards the use of protocol witness table access functions."
It broke the build: 2 demangle tests failed.




Swift SVN r32552
2015-10-09 04:42:19 +00:00
John McCall
9af9b9914d Refactors leading towards the use of protocol witness table
access functions.  NFC for now.

Swift SVN r32541
2015-10-09 01:06:06 +00:00
Doug Gregor
2dcc3afd34 Omit needless words: never reduce a name down to "using", "for", or
"with"

Treat these prepositions as vacuous names, so we never reduce any
parameter name down to one of them. If that would happen, leave the
entire parameter name alone. This makes our transformation a bit more conservative.

Swift SVN r32460
2015-10-06 07:40:34 +00:00
Doug Gregor
e60e5a3605 Omit needless words: more verbs from Cocoa
Add apportion, cast, defer, flip, and generate.

Swift SVN r32459
2015-10-06 07:03:18 +00:00
Doug Gregor
7778790a68 Omit needless words: prepend "is" to Boolean property names.
Prepend       "is" to        Boolean property names (e.g., "empty" becomes
"isEmpty") unless the property name strongly indicates its Boolean
nature or we're   likely to ruin the name. Therefore, the  presence of
one of the following in  the property name will suppress   this
transformation:

* An auxiliary verb, such as "is", "has", "may", "should", or "will".

* A word ending in "s", indicating either a plural (for which
  prepending "is" would be incorrect) or a verb in the continuous
  tense (which indicates its Boolean nature, e.g., "translates" in
  "translatesCoordinates").

Swift SVN r32458
2015-10-06 07:03:17 +00:00
Doug Gregor
bf55d2712e Omit needless words: add some more verbs found in Cocoa.
Add adjust, alter, animate, capture, center, collapse, define, dim,
echo, enable, export, import, localize, maintain, notify, preload,
require, retain, resize, reuse, suppress, translate, traverse,
<re>verb and auto<verb>.

Swift SVN r32457
2015-10-06 07:03:09 +00:00
John McCall
cc7938ad21 Implement a trie data structure. Specifically, implement
a ternary tree with a fixed-length per-node inline key buffer.

I plan to use this for metadata path caches, where it's useful to
be able to quickly find the most-derived point along a path that
you've already cached, but it should be useful for other things
in the compiler as well, like function-with-argument-label
lookups and possibly code completion.

This is quite a bit more space-efficient (and somewhat faster)
than doing scans after a lower_bound on a std::map<std::string, T>.

I haven't implemented balancing yet, and I don't need delete at
all for metadata paths, so I don't plan to work on that.

Swift SVN r32453
2015-10-06 01:14:30 +00:00
Joe Groff
6e31ea5c08 Introduce standard substitutions for Unsafe*Pointer.
Together, UnsafePointer, UnsafeMutablePointer, UnsafeBufferPointer, and UnsafeMutableBufferPointer appear in standard library manglings over 1000 times, and they're fairly long names. Giving them standard substitutions shrinks the stdlib by 44KB.

Swift SVN r32410
2015-10-02 22:39:48 +00:00
Joe Groff
0cd5aa8c7c Change mangling for the Swift module from 'Ss' to 's'.
'Ss' appears in manglings tens of thousands of times in the standard library and is also incredibly frequent in other modules. This alone is enough to shrink the standard library by 59KB.

Swift SVN r32409
2015-10-02 22:39:44 +00:00
Doug Gregor
44e34850ae Omit needless words: give initial Boolean parameters argument labels.
When the first parameter of a function has Boolean type, try to create
an argument label for it. We start with the (normally non-API)
parameter name as the argument label, then try to match that against
the end of the base name of the method to eliminate redundancy. Add a
little magic, and here are some diffs:

    -  func openUntitledDocumentAndDisplay(_: Bool) throws -> NSDocument
    +  func openUntitledDocument(display _: Bool) throws -> NSDocument

    -  func fontMenu(_: Bool) -> NSMenu?
    -  func fontPanel(_: Bool) -> NSFontPanel?
    +  func fontMenu(create _: Bool) -> NSMenu?
    +  func fontPanel(create _: Bool) -> NSFontPanel?

    -  func lockFocusFlipped(_: Bool)
    +  func lockFocus(flipped _: Bool)

    -  func rectForSearchTextWhenCentered(_: Bool) -> NSRect
    +  func rectForSearchText(whenCentered _: Bool) -> NSRect

    -  func dismissPreviewAnimated(_: Bool)
    -  func dismissMenuAnimated(_: Bool)
    +  func dismissPreview(animated _: Bool)
    +  func dismissMenu(animated _: Bool)

Swift SVN r32392
2015-10-01 23:34:21 +00:00
Doug Gregor
cf7cc554cd Omit needless words: make _t a skippable type suffix.
Swift SVN r32384
2015-10-01 22:37:43 +00:00
Doug Gregor
2d5d3d240c Omit needless words: use the actual mapped names for builtin C types.
This provides better fidelity between omit-needless-words acting on
Clang types vs. acting on Swift types.

Swift SVN r32383
2015-10-01 22:37:40 +00:00
Doug Gregor
f90f9a61dc Omit needless words: verb adjustments.
Added verbs: decode, encode, normalize, truncate
Removed verbs: beam

Swift SVN r32381
2015-10-01 21:44:10 +00:00
David Farler
69b6763797 Emit a warning when using unknown arch/os build configurations
'arch' and 'os' build configurations with valid identifiers as
arguments, but which are unknown to the compiler, will cause the
compiler to silently skip over that code as it has an inactive clause.
Emit a diagnostic, but not an error so as not to inadvertantly break
code that may be in a compiler without knowledge of a particular
operating system or architecture.

rdar://problem/22052176

Swift SVN r32219
2015-09-25 05:24:34 +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
Doug Gregor
65b7666298 Omit needless words: stop introducing "body" for usingBlock/withBlock.
The special rule of introducing "body" isn't helping readability. We
might want to have a special rule around closure (or, especially,
trailing closure) parameters, but this is not it.

Swift SVN r32166
2015-09-22 22:37:53 +00:00
Doug Gregor
9b008714a5 Omit needless words: make "Type" a skippable suffix.
"Type" shows up in type names from time to time, but tends to be
omitted from selector pieces in such cases. This lets us skip that
suffix, fixing, e.g.,

  -  func changeCountTokenForSaveOperation(_: NSSaveOperationType) -> AnyObject
  +  func changeCountTokenFor(_: NSSaveOperationType) -> AnyObject

Swift SVN r32165
2015-09-22 22:37:48 +00:00
Doug Gregor
c2aee8429d Omit needless words: drop "with" and "using" leading subsequent parameters.
Beyond the first parameter, the "with" or "using" at the beginning of
an argument label is needless, because one does not read the base name
of the method as if it distributed to the parameters. Some examples:

-  func setProperty(_: String, withValue: AnyObject? = nil)
+  func setProperty(_: String, value: AnyObject? = nil)

-  func hitTest(_: NSRect, withImageDestinationRect: NSRect, context:
   NSGraphicsContext? = nil, hints: [String : AnyObject]? = nil,
   flipped: Bool) -> Bool
+  func hitTest(_: NSRect, imageDestinationRect: NSRect, context:
   NSGraphicsContext? = nil, hints: [String : AnyObject]? = nil,
   flipped: Bool) -> Bool

-  func track(_: NSRulerMarker, withMouseEvent: NSEvent) -> Bool
+  func track(_: NSRulerMarker, mouseEvent: NSEvent) -> Bool

Swift SVN r32141
2015-09-22 00:46:53 +00:00
Doug Gregor
158a2b1ad5 Omit needless words: remove the Ref/Ptr type-stripping rule.
Instead, when mapping a Clang type to its name for omission purposes,
map CF types to their appropriate names. This more directly mirrors
what will happen on the Swift side, but is otherwise NFC.

Swift SVN r32140
2015-09-22 00:35:10 +00:00
Doug Gregor
7d6babd53a Omit needless words NFC: factor out options for OmissionTypeName.
Swift SVN r32139
2015-09-22 00:35:07 +00:00
Doug Gregor
a75c28dee1 Omit needless words: split first selector after omitting needless words.
It's a cleaner rule to specify that we omit needless words from the
base name of a method and *then* split it for default arguments. This
tweak actually caught a small number of cases where we weren't
splitting properly, but should have.

Swift SVN r32133
2015-09-21 23:18:35 +00:00
Doug Gregor
b71ebde067 Omit needless words: "flatten" is a verb.
Swift SVN r32130
2015-09-21 22:52:17 +00:00
Doug Gregor
f3b20a4412 Omit needless words: strip context type from the name prefix consistently.
When the context type of a declaraton matches the result type,
strip off redundant type information at the beginning of the
declaration name if it is followed by a preposition. This covers the
class of transformations on performs on a class that produce a value
of the same type as that class, e.g., NSURL's "URLWithHTTPS" or
NSString's "stringByAppendingString".

When that preposition is the magical "By" and is followed by a gerund,
strip the "By" as well. Note that this is slightly more conservative
now for methods, which previously stripped based on the result type
(always). For example, in NSCalendar:

-  func adding(_: NSDateComponents, to: NSDate, options:
   NSCalendarOptions = [])
 -> NSDate?
+  func dateByAdding(_: NSDateComponents, to: NSDate, options:
   NSCalendarOptions
 = []) -> NSDate?

but it's more general for properties, e.g.,

-  @NSCopying var bezierPathByFlattening: NSBezierPath { get }
-  @NSCopying var bezierPathByReversing: NSBezierPath { get }
+  @NSCopying var byFlattening: NSBezierPath { get }
+  @NSCopying var reversing: NSBezierPath { get }

The important part is that the rules are more uniform and the code is
more regularly structured: we strip this leading type information when
it's redundant with the context and result type, regardless of whether
we have a property or a method, and the "By" rule is no longer special
in that regard.

Swift SVN r32129
2015-09-21 22:52:14 +00:00
Doug Gregor
65b7e6d787 Omit needless words: "customize" is a verb.
Swift SVN r32120
2015-09-21 19:46:13 +00:00
Doug Gregor
8e6d7665ce Omit needless words: strip result type info from both sides of a zero-argument method.
This takes an highly-redundant API name like NSBezierPath's

  func bezierPathByReversingPath() -> NSBezierPath

and turns it into

  func reversing() -> NSBezierPath

Also, handle 'instancetype' properly when omitting words matching the
result type from the front of the base name.

Swift SVN r32119
2015-09-21 19:46:12 +00:00