Commit Graph

519 Commits

Author SHA1 Message Date
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
Joe Groff
8e2ce60f5b 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, and also makes IR a lot less cluttered. 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.

Swift SVN r31515
2015-08-27 01:34:22 +00:00
Doug Gregor
6e1b8323f7 Revert "Omit needless words: don't drop the first parameter name for failability initializers."
This reverts commit r31431. This isn't a good heuristic.

Swift SVN r31449
2015-08-25 14:36:04 +00:00
Doug Gregor
8ac10845b6 Omit needless words: don't drop the first parameter name for failability initializers.
Swift SVN r31431
2015-08-24 18:26:27 +00:00
Doug Gregor
25311277c1 Omit needless words: skip some type suffixes to make it more likely we'll match.
Specifically, "Ref", "Ptr", and dimensionality suffixes (1D, 2D, 3D)
in the type name should not prevent us from finding redundancy in type
information.

Swift SVN r31428
2015-08-24 18:26:25 +00:00
Doug Gregor
c02cd1a424 Factor omit-needless-words logic out of the Clang importer.
Sink the actual logic for omitting needless words way down into
Basic, so we can re-use it elsewhere. Tie the Clang importer into that
logic, mapping Clang types down to strings appropriately. NFC

Swift SVN r31233
2015-08-13 23:39:29 +00:00
Jordan Rose
cb2c6a6d08 Demangle 'So' as '__ObjC' rather than 'ObjectiveC'.
And similarly 'SC' as '__C' rather than 'C'.

There's a real module named 'ObjectiveC', and imported decls are not
all in it.

Swift SVN r31225
2015-08-13 21:22:02 +00:00
Jordan Rose
f5b1efb354 Move client-affecting configuration options into a generated Config.h.
This way they can be used from other projects, like LLDB. The downside
is we now have to make sure the header is included consistently in all
the places we care about, but I think in practice that won't be a problem,
especially not with tests.

rdar://problem/22240127

Swift SVN r31173
2015-08-12 17:50:13 +00:00
David Farler
8d441c0391 Simplified demangling: continue to print context names
The demangler recently regressed to not printing any context
names, including nominal type contexts. This means that symbols
like Optional.init where only printed as init. Continue printing
contexts but not modules (per the original simplified demangling
design).

rdar://problem/19312992

Swift SVN r31066
2015-08-07 05:37:38 +00:00
David Farler
b460aa0c86 Further shorten demangled names in simplified mode
Break up "Simplified" demangling mode (shortened demangled descriptions
for the sake of displaying in UI with small areas) into more
fine-grained options instead of an opaque "Simplified" option and
provide a static preset of options for displaying stack traces in
Xcode UI and other tools, for example.

- Don't print unmangled suffixes
- Don't print module names
- Shorten various generic specialization descriptions as just
  "specialized"
- Don't display long protocol conformances
- Truncate where clauses
- Don't display so-called "entity" types
- Shorten "partial apply *"
- Shorten thunk phrases
- Shorten value witness phrases
- Truncate archetype references

rdar://problem/21753651

Swift SVN r30247
2015-07-16 03:35:46 +00:00
Slava Pestov
cdd5a4121c IRGen: Generate value witnesses to get enum tag and project payload
These will be used for reflection, and eventually to speed up generic
operations on single payload enums as well.

Progress on <rdar://problem/21739870>.

Swift SVN r30214
2015-07-15 06:03:18 +00:00
Joe Groff
db0fea590e stdlib: Use unqualified names in 'print'.
Leave the qualification off of enum cases and type names when 'print'-ing them, but keep them on 'debugPrint'. (At least, at the outermost level; since ad-hoc printing of structs and tuples uses debugPrint, we'll still get qualification at depth, which kind of sucks but needs more invasive state management in print to make possible.) Implements rdar://problem/21788604.

Swift SVN r30166
2015-07-13 21:42:11 +00:00
Michael Gottesman
7ac6831bc6 [func-sig-opts] Eliminate dead arguments that are dead besides an @owned release.
This enables dead argument elimination to be paired with @owned -> @guaranteed
optimization. It has the additional advantage of allowing us to potentially
eliminate additional retains, releases since the fact that the use is dead
implies that the lifetime of the value no longer needs to be live across the
function call.

Since dead argument elimination can be composed with @owned -> @guaranteed, I
had to modify the mangler, remangler, demangler, to be able to handle a mangling
that combines the two.

I just saw noise in the perf test suite.

rdar://21114206

Swift SVN r29966
2015-07-08 06:26:25 +00:00
Jordan Rose
45189f9feb [Driver] Add a basic tracing mode to determine why files are getting rebuilt.
Enabled with -driver-show-incremental. For debugging purposes only.

Swift SVN r29804
2015-06-30 19:31:07 +00:00
John McCall
aae8ef2603 Harden against malformed extension manglings.
rdar://20276865

Swift SVN r29587
2015-06-24 00:51:07 +00:00
Joe Groff
7388b56035 Mangler: Include the error result of SILFunctionTypes in their mangling.
Fixes a mangling collision when e.g. reabstraction thunks for T -> U and T throws -> U are needed in the same module.

Swift SVN r29362
2015-06-10 20:27:24 +00:00
Joe Groff
2bf783dfe8 Runtime: Generate a mangled name as the ObjC runtime name of generic class instances.
Our hack to generate a unique name by appending the class pointer doesn't produce a stable class name that can persist in NSKeyedArchiver, or eventually be used as a key for dynamic runtime instantiation. Generate a proper mangled name for the class instance by building a demangling AST from the metadata nodes and feeding it into the remangler. Should fix rdar://problem/18884563, though I need to try using an archiver with a generic class to verify.

Swift SVN r29316
2015-06-05 14:27:58 +00:00
Joe Groff
7cb6fa320a AST: Mangle the generic params of constrained extensions.
Constrained and protocol extensions should always include the extension context in their mangling, since they are never equivalent to definitions in the original type context. Have them use the extension mangling, and include the generic signature of the extension in its mangling, which is necessary to disambiguate properties and other definitions that are defined with the same name and type in differently constrained extensions. Fixes rdar://problem/21027215.

Swift SVN r29209
2015-06-01 21:25:54 +00:00
Enrico Granata
8a5726d966 Revert 28997
The consensus is against this change and we're going for a much more targeted fix in PlaygroundLogger only



Swift SVN r28999
2015-05-24 23:16:57 +00:00