Commit Graph

1737 Commits

Author SHA1 Message Date
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
Doug Gregor
81850079ac Omit needless words: "file", "name", and "point" are terrible verbs.
The noun forms of these words dominate.

Swift SVN r32118
2015-09-21 19:46:08 +00:00
Doug Gregor
627a1820b8 Omit needless words: split the base name when the first parameter is defaulted.
Split the base name at the last preposition, but *only* when the first
parameter is defaulted, because defaulted arguments might not show up
at the call site and the longer base name can feel odd in such
cases. With this, stop avoiding the argument label "with": it's fine
when we have actual context at the call site, and the "with: nil" case
no longer happens now that we're defaulting nil.

Swift SVN r32098
2015-09-20 05:16:46 +00:00
Doug Gregor
0e3ef0c69d Revert "Omit needless words: split base names on the last preposition."
This reverts commit r31976; this was still not a good idea.

Swift SVN r32079
2015-09-18 21:51:08 +00:00
Jordan Rose
c040e33731 Add a comment describing the conversion from SourceRange to CharSourceRange.
This is related to Xi's recent change, though it's been this way for
quite a while. Good thing this is just a debugging interface.

Swift SVN r32026
2015-09-17 01:27:52 +00:00
Xi Ge
7f6a8b1315 Remove the constructor of CharSourceRange that takes SourceRange;
And add a utility function at lexer that converts SourceRange to CharSourceRange.

Swift SVN r32023
2015-09-17 01:15:34 +00:00
Doug Gregor
838759d155 Omit needless words: remove arguments that match the default arguments.
For cases where the Clang importer provides a defaulted argument,
e.g., "[]" for option sets and "nil" for optionals, remove the
corresponding arguments at any call sites that simply specify "[]" or
"nil". Such arguments are basically noise, and tend to harm
readability when there are low-content argument labels like "with:" or
"for".

Some examples from Lister:

  self.updateUserActivity(AppConfiguration.UserActivity.watch,
                          userInfo: userInfo, webpageURL: nil)

becomes

  self.updateUserActivity(AppConfiguration.UserActivity.watch,
                          userInfo: userInfo)

and

  contentView.hitTest(tapLocation, with: nil)

becomes

  contentView.hitTest(tapLocation)

and

  document.closeWithCompletionHandler(nil)

becomes simply

  document.close()

and a whole pile of optional "completion handler" arguments go away.

Swift SVN r31978
2015-09-15 22:45:50 +00:00
Doug Gregor
2f0fc4ce4b Omit needless words: split base names on the last preposition.
For methods with at least a single parameter, split the base name at
the last preposition, so long as there are no other verbs or gerunds
in between. This separates out the action of the method from the
description of the first parameter, the latter of which can still have
needless words removed. This is particularly fun with
appendBezierPath*:

  func appendBezierPath(with _: NSRect)
  func appendBezierPath(withPoints _: NSPointArray, count: Int)
  func appendBezierPathWithOval(`in` _: NSRect)
  func appendBezierPathWithArc(withCenter _: NSPoint, radius: CGFloat,
  startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool)
  func appendBezierPathWithArc(withCenter _: NSPoint, radius: CGFloat,
  startAngle: CGFloat, endAngle: CGFloat)
  func appendBezierPathWithArc(from _: NSPoint, to: NSPoint, radius:
  CGFloat)
  func appendBezierPath(with _: NSGlyph, `in`: NSFont)
  func appendBezierPath(withGlyphs _: UnsafeMutablePointer<NSGlyph>,
  count: Int, `in`: NSFont)
  func appendBezierPath(withPackedGlyphs _: UnsafePointer<Int8>)
  @available(OSX 10.5, *)
  func appendBezierPath(withRoundedRect _: NSRect, xRadius: CGFloat,
  yRadius: CGFloat)

Note: "point" and "name" are terrible verbs.

Swift SVN r31976
2015-09-15 22:45:43 +00:00
Chris Lattner
3dfda6c58c remove unused variable in omitNeedlessWords
Swift SVN r31885
2015-09-11 03:58:13 +00:00
Doug Gregor
550bcb10f9 Omit needless words: always split the base name/first argument label on "With".
"With" is an indication that the first argument is not the direct
object of the base name. Therefore, label the first argument with
everything that follows the "With". Examples:

-  func addButtonWithTitle(_: String) -> NSButton
+  func addButton(title: String) -> NSButton

-  func updateWithPanRecognizer(_: NSPanGestureRecognizer)
+  func update(panRecognizer: NSPanGestureRecognizer)

-  func appendBezierPathWithRoundedRect(_: NSRect, xRadius: CGFloat,
   yRadius: CGFloat)
+  func appendBezierPath(roundedRect: NSRect, xRadius: CGFloat,
   yRadius: CGFloat)

Swift SVN r31872
2015-09-10 23:56:24 +00:00
Doug Gregor
a2f4f7da22 Omit needless words: usingBlock/withBlock -> "body"
"body" is the term we tend to use for the closure argument to an API.

Swift SVN r31856
2015-09-10 21:06:57 +00:00
Doug Gregor
2921614713 Omit needless words: use hanging "With" as a reason to name the first argument.
When omitting words from the end of the base name because it is
redundant with the type of the first parameter leaves a hanging "With"
in the base name, drop that "with" and instead use the tail of the
base name as the label for the first parameter. The poster child for
this is -copyWithZone, which now turns into "copy(zone:)":

-  func copyWith(_: NSZone) -> AnyObject
+  func copy(zone: NSZone) -> AnyObject

The intuition behind this change is that the "With" is stating that
the method isn't directly acting on its argument; rather, the argument
is something additional, and argument labels are a fine way to model this.

Swift SVN r31836
2015-09-10 00:03:12 +00:00
Doug Gregor
c5cb633aab Omit needless words: don't produce parameters with the argument label "with".
When dropping the redundant type information from a parameter name
would leave us with "with", instead drop the "with" and lowercase the
rest of the parameter name. It's still redundant information, but it's
less bad than simply "with".

Swift SVN r31835
2015-09-10 00:03:11 +00:00
Doug Gregor
406e7c6e48 Omit needless words: generalize the scratch space for strings.
NFC for now, but we'll need to handle multiple strings soon.

Swift SVN r31834
2015-09-10 00:03:09 +00:00
Doug Gregor
9651b956a4 Camel casing: cope with acronym/prefix conflicts when matching names to types.
When matching a word from a name to a word from a type, handle the
ambiguity between type prefixes (NS, UI) and acronyms (URL, HTTP) by
matching the name word to the end of the type word so long as we don't
have lowercase letters or underscores preceding the match. This
allows a name word "URL" or "HTTP" to match a type word like "NSURL"
or "NSHTTP" without having to hardcode knowledge of prefixes.

This mostly affects the omit-needless-words mode, but can also help us
identify more factory methods that can become initializers.

Swift SVN r31703
2015-09-05 00:24:14 +00:00
Doug Gregor
5b0423c9f2 Omit needless words: prefer removing leading redundant type information first.
We intentionally avoid collapsing a method name down to just a
preposition. When we end up in such cases, prefer to strip leading
redundant type information (which corresponds to both context and
return types) rather than trailing type information. This can help
keep close method families together, e.g., in NSFontDescriptor:

-  func fontDescriptorWith(_: UIFontDescriptorSymbolicTraits) -> UIFontDescriptor
-  func fontDescriptorWithSize(_: CGFloat) -> UIFontDescriptor
-  func fontDescriptorWithMatrix(_: CGAffineTransform) ->  UIFontDescriptor
-  func fontDescriptorWithFace(_: String) -> UIFontDescriptor
-  func fontDescriptorWithFamily(_: String) -> UIFontDescriptor
+  func withSymbolicTraits(_: UIFontDescriptorSymbolicTraits) ->  UIFontDescriptor
+  func withSize(_: CGFloat) -> UIFontDescriptor
+  func withMatrix(_: CGAffineTransform) -> UIFontDescriptor
+  func withFace(_: String) -> UIFontDescriptor
+  func withFamily(_: String) -> UIFontDescriptor

Note especially the first case, where we don't want to just go down to
"with" for the name, even though "SymbolicTraits" is redundant with
the parameter type.

Swift SVN r31702
2015-09-04 23:57:09 +00:00
Doug Gregor
60b770b60d Omit needless words: <context type><preposition> --> <preposition>
When the start of a name describes both the type of the context and
the type of the result, and is followed by a preposition, the start of
the name is redundant with the 'self' value, so strip it off. For
example:

  url.URLWithHTTPS

becomes

 url.withHTTPS

Swift SVN r31701
2015-09-04 23:57:09 +00:00
Doug Gregor
e05ba143e7 Omit needless words: abbreviate, standardize, and resolve are verbs.
Swift SVN r31700
2015-09-04 23:57:08 +00:00
Doug Gregor
7960ca1619 Omit needless words: strip out prefixes that are redundant with the result type.
When the prefix of a method/property name is restating the result
type, followed by "By" and then a gerund, drop everything up to the
gerund. For example:

  func stringByAppendingString(string: String) -> String

becomes

  func appending(string: String) -> String

Swift SVN r31683
2015-09-04 00:07:38 +00:00
Doug Gregor
86eb26a88c Factor out the matching of type names at the beginning of a name. NFC
Swift SVN r31682
2015-09-04 00:07:27 +00:00
Doug Gregor
21f3153025 Omit needless words: "Index" in the name matches "Int" or "Integer" in the type.
Swift SVN r31671
2015-09-03 21:05:50 +00:00
Doug Gregor
4925d24fdb Omit needless words: "toggle" is a verb.
Swift SVN r31669
2015-09-03 20:39:49 +00:00
Doug Gregor
685539875f Omit needless words: "object" is a terrible verb
Swift SVN r31667
2015-09-03 17:06:53 +00:00
Doug Gregor
c439f0f5f0 Omit needless words: remove plural forms of element names when the type is a collection.
When the type name we're looking at is a collection of some element
type, also try to match the plural form of the element type name. For
example:

-  func deselectItemsAtIndexPaths(_: Set<NSIndexPath>)
+  func deselectItemsAt(_: Set<NSIndexPath>)

Swift SVN r31666
2015-09-03 17:06:50 +00:00
Doug Gregor
c3497fb378 Omit needless words: allow removal of words following a gerund.
Identify gerunds by stripping off the "ing" and looking for a
verb. This lets us transform, e.g., "stringByAppendingString" to
"stringByAppending", since "append" is a verb.

Swift SVN r31660
2015-09-03 05:44:20 +00:00
Doug Gregor
271fc2057e Omit needless words: add some verbs found in Cocoa APIs
Swift SVN r31659
2015-09-03 05:44:17 +00:00
Doug Gregor
8c9eb1cfba Omit needless words: don't map a base name or property name down to a keyword.
Swift SVN r31657
2015-09-03 05:04:15 +00:00
Doug Gregor
8ce50fbd76 Omit needless words: only omit words when they are preceded by a verb or preposition.
The presence of a verb or preposition prior to the redundant part
provides a firm linguistic split that lets the actual argument fill in
for the reader. For other parts of speech (adjectives, especially)
it's awkward to transition from "reading part of the name" to "reading
the argument". This eliminates a significant number of bad omissions,
e.g., "setTextColor()" -> "setText()", and generally makes the
transformation more conservative.

Swift SVN r31656
2015-09-03 05:04:11 +00:00
Doug Gregor
e09bed2a9e Omit needless words: stop dropping "With" indiscriminately.
"With" tends to have value in separating the verb of the base of a
method name from the description of the first argument. The poster
child here is "copyWithZone", where "copy(_:)" makes it sound like
we're copying the argument. We're considering a more nuanced rule that
can drop "With" in cases where it's not separating a verb from a
description of the argument; that will follow if we do come across
such a result.

Swift SVN r31627
2015-09-02 06:21:33 +00:00
Doug Gregor
e480ac6525 Omit needless words: don't drop the first argument label in initializers.
While there are cases where it makes sense to drop the first argument
label in initializers---when they're primarily conversions---it's an
heuristic that produces poor results (e.g., init(_:) rather than
init(coder:)) more often than not. Thus, remove this heuristic.

Swift SVN r31626
2015-09-02 06:21:32 +00:00
Doug Gregor
6358c9a54f Omit needless words: Don't avoid keywords
We want to see the results of the omit-needless-words heuristics under
the assumption that we won't need to quote these argument labels in
the future, and it avoids some head-scratching to not have this
heuristic in place.

Swift SVN r31625
2015-09-02 06:21:18 +00:00
Joe Groff
43d620c7e0 IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline. We also aren't able to generate references to aliases within the same module due to an MC bug with alias refs on i386 and armv7 (rdar://problem/22450593).

Swift SVN r31523
2015-08-27 05:18:38 +00:00
Joe Groff
f705c561e3 Revert "IRGen: Export direct metadata symbols at the address point of the metadata object."
This reverts commit r31515. It causes an LLVM error on the release bots.

Swift SVN r31516
2015-08-27 01:44:56 +00:00