Commit Graph

111 Commits

Author SHA1 Message Date
Xi Ge
8e0e779cc2 migrator: handle the composite change of updating type alias to raw-representable and rename the referenced variables simultaneously. rdar://41732485 2018-07-02 12:13:20 -07:00
Xi Ge
46a1142b7f Merge pull request #17644 from nkcsgexi/global-name
migrator: handle member variables change to global ones. rdar://41658300
2018-07-02 09:25:44 -07:00
Xi Ge
c23d1a89a4 migrator: ensure we update unresolved member access correctly to global names. rdar://41658300 2018-06-29 17:29:53 -07:00
Xi Ge
4ed9f9a9a6 migrator: support the migration from member variables to global ones. rdar://41658300 2018-06-29 16:35:51 -07:00
Nathan Hawes
50f9c94ac8 [migrator] Migrate UIApplicationMain
In Swift 4.2 the second parameter of UIApplicationMain exactly matches the type
of CommandLine.unsafeArgv so it can be called as below:

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, ...)

This is how it was intended to be in Swift 4 as well, but the types had
optionality differences, so callers instead had to do something like the below
example from the Firefox-iOS project:

let pointer = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(
    to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
UIApplicationMain(CommandLine.argc, pointer, ...)

This migration simply replaces the the second argument with
CommandLine.unsafeArgv if the first argument is CommandLine.argc.

There is an open issue for providing a deprecated version with the old type so
we simply leave as is any callers that don't pass argc for the first argument.

Resolves rdar://problem/40045693.
2018-06-28 18:46:41 -07:00
Xi Ge
9a0196e991 migrator: avoid adding conversion functions when expression types change as well.
When inserting conversion functions around expressions, we should check
whether the type of the expression is a recognized name alias that is
known to be changed to raw-value representable type. We should avoid
inserting conversion functions in this case because doing so causes
build errors.

resolves: rdar://40463990
2018-06-25 14:44:58 -07:00
Xi Ge
859d918a78 Re-apply "[migrator] migrator: avoid inserting base name while renaming
if users' member access doesn't specify the base name. rdar://40373279"

Previously, we saw that unconditionally omitting type names can lead to
build errors (rdar://40458118). This revised fix omits type names only when
the new member name is identical to the old one.
2018-06-19 12:46:02 -07:00
Xi Ge
90303d12a6 migrator: handle the reversion of raw representable changes. rdar://39498127 2018-06-15 16:51:57 -07:00
Xi Ge
6433bc59e7 migrator: avoid migrating synthesized initializer calls. rdar://40860228 2018-06-11 15:30:38 -07:00
Xi Ge
55495ec267 migrator: avoid inserting round-trip conversion functions.
By postponing the insertion of conversion function calls, we can filter
out the expressions that require more than one helper function wrapper.

resolves: rdar://40979943
2018-06-11 15:08:26 -07:00
Xi Ge
7312fea3b2 migrator: emit error messages when migration scripts are missing.
We used to assert migration scripts exist. This patch further
decouples these scripts and the compiler by treating missing scripts
as a regular compiler error.

Related: rdar://40538097
2018-05-25 11:25:32 -07:00
Xi Ge
c8752d1570 [migrator] Revert "migrator: avoid inserting base name while renaming if users' member access doesn't specify the base name. rdar://40373279"
We've seen cases where using dot member names cause build errors. Thus, we revert this QOL fix.

rdar://40458118
2018-05-22 13:58:08 -07:00
Xi Ge
27b1621f90 migrator: avoid inserting base name while renaming if users' member access doesn't specify the base name. rdar://40373279 2018-05-18 12:36:10 -07:00
Xi Ge
6a83c51cf8 migrator: use raw type names from migration scripts instead of hard-coding them. 2018-05-16 17:56:48 -07:00
Nathan Hawes
61d7193814 [migrator] Treat the top-level argument parens of function types as an index level in the ChildIndexFinder
The APIDiffMigrator pass was ignoring them in all cases, but function type
argument parens are significant and the API differ includes them as an index
level in the generated json. This was causing a segmentation fault when trying
to migrate anything inside a function type argument. E.g given the function
below:

func member(_ x: ([Any]?) -> Void) {}

to migrate Any to Int, the API differ produces an index into the signauture of
1:1:0:0:0, meant to indicate Any. The APIDiffMigratorPass was interpreting this
incorrectly, however:

1: The type of first parameter of member: ([Any]?) -> Void
   Migrator agreed.
1: The type of the function type's argument: ([Any]?)
   Migrator saw this as [Any]? due to the parens not being an index level
0: The 0th child of the paren type: [Any]?
   Migrator saw the 0th child of the optional, [Any]
0: the 0th child of the optional type, [Any]
   Migrator saw the 0th child of the array, Any
0: the 0th child of the array type, Any
  Migrator tried to look up the 0th child of Any, causing a crash.

Resolves rdar://problem/40225476.
2018-05-15 12:05:21 -07:00
swift-ci
aa5cb47fec Merge pull request #16598 from nkcsgexi/migrator-arg-rename-hoist 2018-05-14 12:31:48 -07:00
Xi Ge
343d84ba35 migrator: handle argument renames when a global function is hoisted to a static member function. rdar://40145590 2018-05-14 11:33:25 -07:00
Xi Ge
0f71331d73 migrator: avoid inserting helper function call for nil expression. rdar://40173366 2018-05-11 17:24:52 -07:00
swift-ci
9aead6bff3 Merge pull request #16507 from nkcsgexi/avoid-reinsert-function 2018-05-10 13:54:57 -07:00
Xi Ge
b302bd30db migrator: avoid inserting helper functions if a function with the same name exists in the source file. rdar://40108285 2018-05-10 13:20:47 -07:00
Xi Ge
d89b716cf1 migrator: handle composite changes that're necessary to both side of an assignment expression. rdar://40106370 2018-05-10 12:08:00 -07:00
Xi Ge
ca3bf34daf Merge pull request #16479 from nkcsgexi/api-digester-type-change-diff
swift-api-digester: we should further detect if the declared type of a hoisted variable has been changed. rdar://40076924
2018-05-09 17:34:06 -07:00
Xi Ge
740e336e02 migrator: make sure we can handle the composite change of rename and string representable update. radr://40076924 2018-05-09 15:53:51 -07:00
Ben Langmuir
2e1f3afe05 Merge pull request #16460 from benlangmuir/mig-type-rename
[migrator] Handle simple renames for TypeDecl
2018-05-08 16:01:47 -07:00
Ben Langmuir
1bceacf7b8 [migrator] Handle simple renames for TypeDecl
Previously we only handle VarDecl, but it ought to work for types as
well.
2018-05-08 14:32:15 -07:00
Xi Ge
aef79e9b03 migrator: update type name in constructor call if the type becomes nested. rdar://40042252 2018-05-08 14:28:00 -07:00
Xi Ge
3ee07be5ba migrator: handle the migration of string enum variable references. 2018-04-18 14:24:19 -07:00
Xi Ge
5db971de0e migrator: handle assignment of attribute dictionary and others.
When users' codebase assigns an attribute dictionary that used to be of
type [String: Any], this migration inserts a helper function call on the source of
the assignment to bridge the type.
2018-04-18 11:11:27 -07:00
Xi Ge
6a4df3e820 migrator: handle return value migration introduced by string enum changes.
This patch migrates the function call whose return type used to "String" and
now becomes "StringRepresentableStruct".
2018-04-17 15:18:33 -07:00
Xi Ge
7cf8bf4d55 migrator: correct a typo in the inserted helper function. NFC 2018-04-16 13:36:00 -07:00
Xi Ge
65eaccb2fa migrator: teach the tool to handle ArrayMemberUpdate and OptionalArrayMemberUpdate attributes emitted from swift-api-digester.
This bridges the function call arguments that used to be of type [String] and
now become [StringRepresentableStruct].
2018-04-16 13:30:53 -07:00
Xi Ge
a138744e45 migrator: teach the tool to handle OptionalDictionaryKeyUpdate attributes emitted from swift-api-digester.
For a function call used to take [String: Any]? as argument and now
takes [StringRepresentableStruct: Any]?, a helper function is inserted
to help the bridging of types.
2018-04-16 10:57:36 -07:00
Xi Ge
4c10f16c0e migrator: teach the tool to handle DictionaryKeyUpdate attribute on arguments.
When a user's code calls a function that used to take [String: Any] as
argument and now takes [StringRepresentableStruct: Any], this migration
inserts a helper function to convert the argument to the
expected type.
2018-04-13 16:55:19 -07:00
Xi Ge
4c4e4d2b79 migrator: handle simple attribute assignment and reference.
This patch migrates simple attribute assignment and reference when the
attribute used to be of type String and later became StringRepresentable struct.

Related: rdar://38192995
2018-04-12 11:54:28 -07:00
Xi Ge
4705e0790c swift-api-digester: rename SDK nodes internally. NFC 2018-04-05 15:55:41 -07:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
David Zarzycki
408bf0d840 [AST] NFC: Migrate CompoundIdentTypeRepr to llvm::TrailingObjects 2017-12-30 10:56:37 -05:00
Xi Ge
f2ef42baed [migrator] When renaming a function decl, we should use underscore to represent empty external argument label. rdar://34569243 (#12221) 2017-10-02 12:31:09 -07:00
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -07:00
Harlan
e89e7f58b2 [Parse] [Syntax] Simplify TupleTypeRepr parsing and add attributes for Syntax (#8298)
* Simplify TupleTypeRepr parsing

This patch introduces a TupleTypeReprElement struct that holds the
locations for all relevant bits of tuple elements. It removes the
NameLoc and UnderscoreLoc arrays from TupleTypeReprElement in favor of
holding each of these on TupleTypeReprElement. These extra bits of info
are required for full-fidelity representation in the Syntax library.

* Remove TupleTypeReprBitfields and move EllipsisLoc out of TrailingObjects

* Update users of TupleTypeRepr

* Don't resize the elts if we're going to push_back

* getType -> getElementType

* Move ellipsis back into TrailingObjects.

* Move NumElements into TupleTypeReprBitfields
2017-06-27 10:54:47 -07:00
Xi Ge
476534d1e2 migrator: handle qualified replacement for member reference expression. rdar://32845918 (#10593)
Previously, we only handle dot syntax call expression for qualified
replacement, i.e. changing from A.a to B.b. This patch teaches the tool
to handle the migration of member reference expression tool.
2017-06-26 15:47:17 -07:00
David Farler
789bd3749f [Migrator] Use toLowercaseWord to lowercase SetterToProperty changes
Post-commit review follow-up:
This works better for properties that were all-caps, such as `URL`.

Thanks @harlanhaskins for the tip!

rdar://problem/32845968
2017-06-26 12:53:15 -07:00
David Farler
71e38d85d4 [Migrator] Make sure to lowercase properties in SetterToProperty
Previously we were only stripping `set` from the name and not
lowercasing the property.

rdar://problem/32845968
2017-06-23 16:37:16 -07:00
David Farler
c2876dfb69 [Migrator] Migrate x.toIntMax() to Int64(x)
These protocol methods were hard-obsoleted in Swift 4.

rdar://problem/32437759
2017-06-14 14:21:51 -07:00
David Farler
970127b745 [Migrator] Add special-case migration for NSOpenGLGetVersion
This was added in the AppKit overlay as a part of general
AppKit API improvements for Swift 4.

rdar://problem/32178777
2017-06-14 14:21:50 -07:00
Xi Ge
9f456b19a3 migrator: use the right method to get the location of return type. rdar://32545812
TypeLoc::getLoc() is not necessarily the start location of the type repr.
2017-06-02 15:17:24 -07:00
Xi Ge
0b8b0207e6 migrator: teach the tool to handle qualified replacement. rdar://32466196 2017-06-01 13:15:12 -07:00
Pavel Yaskevich
c94fe94d5d [Diagnostics] Add a fix-it for optional to raw representable type conversion
Situations where there is a contextual RawRepresentable type is
used incorrectly would produce `<Type>(rawValue: )` fix-it only
in cases where neither or both sides of the expression are optional.
Let's fix that by adding a fix-it for optional to contextual raw
value type conversion.

Resolves: rdar://problem/32431736
2017-05-31 13:58:17 -07:00
Xi Ge
824aaa11e2 swift-api-digester: detect the move of static members only.
This patch restricts the detection of moved members to be static members,
since only in this case we need to update qualified access to
them. The move of instance members will be either handled by rename or
we don't need to update anything at all.

Additionally, this patch introduces a sub-kind of type member diff item
called qualified replacement to describe the aforementioned case. However,
the migrator part has not started to honor this sub-kind yet.

rdar://32466196
2017-05-31 11:47:27 -07:00
Xi Ge
ee4293fea1 IDE Utils: For DeclNameViewer, we should use empty StringRef to represent empty argument label instead of using "_". (#9988) 2017-05-30 17:29:57 -07:00