Commit Graph

557 Commits

Author SHA1 Message Date
Xi Ge
59c4ca96e8 [InterfacePrint] When printing a type interface, omit the extensions that are not applicable.
Swift SVN r32663
2015-10-13 20:00:03 +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
Doug Gregor
6af6048c0c AST printing: take more care to only escape 'Self' when needed.
Cleans up AST printing somewhat as well as providing slightly better
type-to-declaration mappings for annotated AST printing and indexing.

Swift SVN r32420
2015-10-03 05:13:52 +00:00
Ben Langmuir
3f3d2a9be2 Use the TypeRepr when printing an extension with no extended type
.. which may happen because the extension is in an invalid context.

rdar://problem/22843778

Swift SVN r32342
2015-09-30 18:55:27 +00:00
Doug Gregor
ab9c735117 Fix recent build breakage I caused.
Swift SVN r32085
2015-09-18 22:30:27 +00:00
Doug Gregor
44b8d45288 Clean up inference of default arguments from imported APIs (mostly).
My temporary hackery around inferring default arguments from imported
APIs was too horrible. Make it slightly more sane by:

1) Actually marking these as default arguments in the type system,
rather than doing everything outside of the type system. This is a
step closer to what we would really do, if we go in this
direction. Put it behind the new -frontend flag
-enable-infer-default-arguments.

2) Only inferring a default argument from option sets and from
explicitly "nullable" parameters, as stated in the (Objective-)C API
or API notes. This eliminates a pile of spurious, non-sensical "=
nil"'s in the resulting output.

Note that there is one ugly tweak to the overloading rules to prefer
declarations with fewer defaulted arguments. This is a bad
implementation of what is probably a reasonable rule (prefer to bind
fewer default arguments), which intentionally only kicks in when we're
dealing with imported APIs that have default arguments.

Swift SVN r32078
2015-09-18 21:50:59 +00:00
Xi Ge
f63ab9f6f1 [ASTPrint] Still print extended types even though they err.
Swift SVN r32044
2015-09-17 20:48:07 +00:00
Doug Gregor
3648650822 Omit needless words: default more pointer-like types to nil.
Swift SVN r32009
2015-09-16 21:04:39 +00:00
Xi Ge
cc3c73afff [ASTPrint] Add an option to avoid printing unresolved extension decls. rdar://22676315
Swift SVN r31983
2015-09-16 01:13:57 +00:00
Doug Gregor
71284a80e0 Omit needless words: Unsafe(Mutable)Pointer and Selector have 'nil' defaults.
Swift SVN r31982
2015-09-16 00:10:09 +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
dc820315ba Omit needless words: fake defaulted imported optional and option-set arguments.
Introduce a hack that allows us to fake importing optional and
option-set parameters as "nil" or "[]", respectively.

Swift SVN r31977
2015-09-15 22:45:47 +00:00
Doug Gregor
398e9233b9 ASTPrinter: when skipping parameter names, indicate argument labels when they aren't the default.
For a function like

  func foo(string aString: String) { ... }

we previously printed

  func foo(string: String)

under -skip-parameter-names. Instead, print

  func foo(string _: String)

to make it clear that "string" is an argument label here.

The only thing that seems to use this flag are the omit-needless-words
experiments, and this change is tuned to minimally change the output
of such experiments for diff'ability.

Swift SVN r31907
2015-09-11 21:38:20 +00:00
Michael Gottesman
0606d5843a Remove calls to raw_svector_ostream::flush()
This function is deleted since LLVM r244928.

Swift SVN r31798
2015-09-09 04:37:13 +00:00
Chris Lattner
95ab61b52d Don't print @opened when AST printing types, unless we're generating a SIL file.
We don't want these to poke out in diagnostics.


Swift SVN r31426
2015-08-24 17:20:41 +00:00
Doug Gregor
83cb1e69bb Serialize the list of inherited types for all nominal types.
This provides better AST fidelity through module files and further
reduces our dependencies on storing a list of protocols on nominal
type declarations.

Swift SVN r31345
2015-08-19 21:10:45 +00:00
Doug Gregor
dd68b9fc59 Start serializing the "inherited" list of extension declarations.
This improves the fidelity of the AST printed from a loaded module, as
well as consistency in the AST. Also teach the Clang importer to add
"inherited" clauses, providing better fidelity for the mapping from
Objective-C to Swift.

With trivial update to SDKAnalyzer test.

Swift SVN r31344
2015-08-19 21:10:42 +00:00
Ted Kremenek
60174804e1 Revert "Start serializing the "inherited" list of extension declarations."
This reverts commit r31337.

Swift SVN r31340
2015-08-19 20:13:13 +00:00
Doug Gregor
1393ee18a4 Start serializing the "inherited" list of extension declarations.
This improves the fidelity of the AST printed from a loaded module, as
well as consistency in the AST. Also teach the Clang importer to add
"inherited" clauses, providing better fidelity for the mapping from
Objective-C to Swift.

Swift SVN r31337
2015-08-19 18:29:11 +00:00
Doug Gregor
f0fcd594c0 Stop using TypeDecl::Protocols within abstract type parameters.
More baby steps toward sinking protocol lists down into
NominalTypeDecl. Fixes another 12 crashers along the way.

Swift SVN r31333
2015-08-19 06:42:30 +00:00
Doug Gregor
9c82081e3f Reduce type parameters and associated types' dependence on "getProtocols()".
This is a step toward weeding out the "getProtocols()" list on
TypeDecl. Now, use the Archetype's list of protocols for the set of
protocols to which the type parameter or associated type
conforms. Since that list is fully canonicalized, it's more generally
reliable. However, start serializing the list of inherited types for a
generic type parameter, so we can print it appropriately.

Swift SVN r31297
2015-08-18 17:57:37 +00:00
Xi Ge
5c8f327199 [ASTPrinter] Remove redundant accessibility filtering.
Swift SVN r31243
2015-08-14 04:30:48 +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
Chris Lattner
a899872d91 Reapply r31105, with some fixes to invalid unconstrained generics. These fixes correct
the regressions that r31105 introduced in the validation tests, as well as fixing a number
of other validation tests as well.

Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.





Swift SVN r31130
2015-08-11 06:06:05 +00:00
Chris Lattner
2204dbcbfd revert r31105, it causes some regressions on validation tests.
Swift SVN r31107
2015-08-10 15:01:22 +00:00
Chris Lattner
de79b60c89 Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.



Swift SVN r31105
2015-08-10 06:18:27 +00:00
Argyrios Kyrtzidis
e605b93b8e [IDE] For swift file interface generation, print the active parts and ignore IfConfigStmts.
Swift SVN r30938
2015-08-02 21:58:47 +00:00
Argyrios Kyrtzidis
791a7bfc3b [IDE] Make sure we are printing documentation comments for enum elements, when printing the interface.
rdar://21990220

Swift SVN r30727
2015-07-28 22:10:18 +00:00
Xi Ge
8e44a2f046 [InterfacePrinting] Address Jordan's comments on 30520.
We discussed this morning and agreed that the best way to fix rdar://20680375
is to differentiate between printing testable interfaces and printing general
interfaces, where the former includes internal decls and the latter does not.
Also, we always print accessibility keywords to be consistent.

Swift SVN r30543
2015-07-23 19:49:16 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Xi Ge
6471303c12 [InterfacePrinting] Alter PrintOptions for interface printing so that user-defined internal decls are visible in the generated interfaces.
Also, we always print accessibility keywords in the printed interfaces, so that users can differentiate public and
internal decls.
rdar://20680375

Swift SVN r30520
2015-07-23 01:37:20 +00:00
Xi Ge
af957bcad8 [InterfacePrinting] Add a print option to specify whether members of a decl should be separated by empty new lines.
By doing so, SourceKit can print Swift intefaces in the same fashion of what Xcode conventionally does.
rdar://21710381

Swift SVN r30430
2015-07-21 01:22:44 +00:00
Argyrios Kyrtzidis
b49c9de623 [IDE] Make sure to print documentation comment of a var in a pattern binding.
Test on the SourceKit side. rdar://21864571

Swift SVN r30301
2015-07-17 05:11:34 +00:00
Xi Ge
0ad59157ae Revert "[InterfacePrinting] Print stdlib internal protocols whose names start with no '_'"
This reverts commit ca7c1e5692bdd51cb0800be42c964462a3c84436.

Swift SVN r30191
2015-07-14 18:39:49 +00:00
Xi Ge
a6e43171e3 [InterfacePrinting] Print stdlib internal protocols whose names start with no '_'
rdar://21515803

Swift SVN r30178
2015-07-14 00:30:45 +00:00
Xi Ge
1eac2874b1 [InterfacePrinting] Move utf8 sanitizer from SourceKit to ASTPrinter.
We sanitize comments by replacing invalid utf8 subsequence with � .

Swift SVN r30031
2015-07-09 18:26:02 +00:00
Joe Groff
0a7e9d359b AST printer: Fix printing of Builtin.Vec types.
Swift SVN r29889
2015-07-02 17:05:25 +00:00
Xi Ge
79f293c4b3 Address Argyrios' comments on r29520 and r29528
Swift SVN r29559
2015-06-22 23:16:40 +00:00
Chris Lattner
876c156a76 add some crazy overly defensive code to avoid crashing when printing a type while
in the middle of the type checker.  NFC unless you're a compiler hacker we'd hope.


Swift SVN r29537
2015-06-20 23:47:38 +00:00
Xi Ge
8098f2cc41 [ASTPrinting] Print the types of named patterns appearing in VarDecl.
Swift SVN r29528
2015-06-19 23:41:07 +00:00
Xi Ge
9a52f54fc9 [ASTPrinting] make VarDecl respect accessibility filters in PrintOptions.
Swift SVN r29520
2015-06-19 21:15:29 +00:00
Joe Groff
e57c470019 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

This time, fix a paste-o that caused SILBlockStorageTypes to get replaced with SILBoxTypes during type substitution. Oops.

Swift SVN r29489
2015-06-18 15:21:52 +00:00
Mark Lacey
39087cd36b Revert "Introduce a "@box T" type for SIL."
This reverts commit r29474 because it looks like it is breaking the
build of the SpriteKit overlay.

Swift SVN r29482
2015-06-18 06:28:04 +00:00
Joe Groff
7b0045c790 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

Swift SVN r29474
2015-06-18 04:07:03 +00:00
Xi Ge
88ba249f1a [InterfacePrinting] Print document comments for enum element decls. rdar://18457785
Swift SVN r29330
2015-06-06 00:56:39 +00:00
Jordan Rose
de81a3e15f Prefer using known-identifiers to using getIdentifier.
I didn't add anything to the table, just made use of what was already there.
We have plenty of additional calls to getIdentifier that could probably benefit
from this kind of easy access as well.

This commit also removes FOUNDATION_MODULE_NAME and OBJC_MODULE_NAME from
Strings.h. Neither of these is likely to change in the future, and both
already have KnownIdentifiers equivalents in use.

No intended functionality change.

Swift SVN r29292
2015-06-04 04:01:08 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
Joe Groff
eef3fab391 SIL printer: Sort same-type requirements to the right depth.
They appear out of order relative to other requirements, so do a cheesy linear scan to find the requirements that belong at each depth. This shouldn't be too bad since there are at most two depths in practice today. Fixes a parse_stdlib failure after enabling OptionSetType.

Swift SVN r28903
2015-05-22 05:47:25 +00:00
Chris Lattner
d6ba8666ca various parts of the compiler are doggedly trying to figure out
whether a getter is mutating or a setter is nonmutating, centralize
it into methods on AbstractStorageDecl, NFC.


Swift SVN r28823
2015-05-20 05:00:13 +00:00
Argyrios Kyrtzidis
ef213fddcd [ASTPrinter] Add an extra print option to control printing 'internal' keyword if accessibility printing is enabled.
Swift SVN r28813
2015-05-20 01:45:56 +00:00