Commit Graph

557 Commits

Author SHA1 Message Date
Xi Ge
d81edcb6b6 ModulePrinting: Properly substitute via metatype to simplify complex bound generic types appearing in synthesized extensions. rdar://25063840 2016-03-09 17:09:34 -08:00
Xi Ge
ce12c6dc95 ModulePrinting: Add an option to synthesize unconditional extensions; true by default. 2016-03-08 18:34:38 -08:00
Ben Langmuir
c9d665ec98 [ASTPrinter] Print typealias generic parameters 2016-03-08 07:11:38 -08:00
Chris Lattner
fe9fe47b7e Implement support for generic typealiases. 2016-03-07 22:20:16 -08:00
Ben Langmuir
1e21357c31 [ASTPrinter] Use callPrintStructurePre consistently
I can't find anything that's actually broken here (symptom would be
annotations showing up ahead of newlines), but be consistent about
going through callPrintStructurePre to be safe.
2016-03-07 18:22:47 -08:00
Xi Ge
7e3e42c272 ModulePrinting: Teach synthesized extension analyzer to handle bounded generic types appearing in requirements. 2016-03-07 13:27:54 -08:00
Ben Langmuir
e752de0d20 [SourceKit] Print and annotate the raw value expression of enum elements
For now, only do this in SourceKit (printQuickHelpDeclaration), but
there are probably other printing modes that should do this.

rdar://problem/24292226
2016-03-07 12:36:47 -08:00
Ben Langmuir
3d424b5e96 [SourceKit] Annotate tuple types and nested function types
Move the type callbacks into the respective type/typerepr printers so
taht we get these callbacks even when we print the type directly, or in
a nested fashion.  Also make the returntype more explicit than just
"inside a function type", since visiting the function type currently
visits the input argument tuple (which is different than e.g. the
function *decl* printing, which walks the parameter list explicitly).

rdar://problem/24292226
2016-03-07 10:13:01 -08:00
Xi Ge
40f0c7c1f3 ModulePrinting: Save some copies by passing function pointer. NFC 2016-03-05 12:29:01 -08:00
Xi Ge
ccedc2ab6f ModulePrinter: Make sure synthesized extensions are printed in deterministic order. 2016-03-05 11:17:07 -08:00
Xi Ge
7abd2cc1ab ASTPrinter: make a function static. NFC 2016-03-05 10:52:01 -08:00
Xi Ge
7c90d2c83f ModuelPrint: when printing synthesized extensions, print the full name of the extended type. 2016-03-05 10:47:12 -08:00
Chris Lattner
868a795566 Introduce a new class between TypeDecl and NominalTypeDecl named GenericTypeDecl.
This factors the DeclContext and generic signature behavior out of NTD, allowing
it to be reused in the future.  NFC.
2016-03-04 23:09:15 -08:00
Ben Langmuir
ca1c7f1a70 [ASTPrinter] Fix a couple of 80-column violations NFC 2016-03-04 16:46:35 -08:00
Ben Langmuir
5c29920acd [ASTPrinter] Simplify callbacks by dropping the notion of 'pending' callbacks
The three varieties of 'pending callbacks' made it hard to reason about
how callbacks would be presented to subclasses of ASTPrinter.  I
recently added new callbacks that would have made this even more complex
to deal with.

Luckily, it turns out they weren't buying us much, and simply forcing
any pending newlines and indentation to be printed ahead of making
callbacks was almost identical to the old behaviour. One complication is
that we now need to check for clang doc comments up front so we will
emit a newline in the right place.

This also incidentally fixed a bug in Loc vs Decl callback order.
2016-03-04 16:26:35 -08:00
practicalswift
5b2800225d [gardening] Fix recently introduced typos
Fixed:
* perfomance → performance
* requirments → requirements
* satisified → satisfied
* template template → template
2016-03-04 11:10:50 +01:00
Ben Langmuir
bb152f14f9 [ASTPrinter] Fix decl/structure nested callbacks
For now, just force any pending callbacks before doing the structure
callbacks.  This should be fine, since we are always about to print
*something* that isn't whitespace, so there is no change in location.
2016-03-03 20:54:12 -08:00
Ben Langmuir
ba702b846f [SourceKit] Add tags for attribute names
As a first foray into annotating attribute, add tags around attribute
names. For now, treat any decl-modifiers as keywords. We will also want
to wrap the whole attribute (including any parameters) into tags as
well, but that will require more work in the callback hanlding.

Also factor the attribute printing to handle any special cases early,
which will simplify wrapping attributes in tags, since we can then just
put the whole switch intside the pre/post callbacks.

rdar://problem/24292226
2016-03-03 18:39:21 -08:00
Ben Langmuir
f61a241dfc [ASTPrinter] Rename parameter callback to widen scope NFC
I want to start using this for other things like function types and
attributes, so rename it to reflect the new scope. I'm not really happy
with "PrintStructureKind", etc. but haven't come up with anything
better so far.
2016-03-03 18:39:20 -08:00
Xi Ge
591249f953 Simplify some code. NFC 2016-03-03 18:25:35 -08:00
Xi Ge
8bde763ba2 IDETypeChecking: make parameter consistently pass reference. NFC 2016-03-03 18:02:13 -08:00
Xi Ge
326514e397 ModulePrinting: when printing synthesized extensions, avoid printing requirements that are known to be true. 2016-03-03 17:42:35 -08:00
Ben Langmuir
65f0e7eb94 [SourceKit] Add annotation tags for generic type requirements
Each requirement gets tagged. We could also tag the whole where clause
if we need to, but so far it hasn't been interesting.

rdar://problem/24292226
2016-03-03 16:11:07 -08:00
Ben Langmuir
ceb1069199 Prefer original spelling of 'static' vs. 'class'
Try to match the original spelling of static/class in diagnostics and
when printing the AST. Also fixes cases with
PrintOptions.PrintImplicitAttrs = false, where we would just print
'class', which was not valid code.
2016-03-03 13:48:30 -08:00
Ben Langmuir
1182e41e01 [SourceKit] Add tags for generic parameters to annotated decl
Like typerefs, we want to show the USR in the tag.

rdar://problem/24292226
2016-03-03 12:47:09 -08:00
Xi Ge
bafe60e91b Refactoring: move IsInSynthesizedExtension to Analyzer. NFC. 2016-03-02 17:30:11 -08:00
Xi Ge
3f20eb242d Refactoring: Moving the logic of collecting synthesized extensions to Analyzer. NFC. 2016-03-02 17:30:11 -08:00
Ben Langmuir
d12f1f0665 [ASTPrinter] Funnel keyword printing through a common interface NFC
Start threading all keyword (and contextual keyword) printing through
printName, and add a new PrintNameContext for keywords.  For now we just
pass this through without changing behaviour.

Also add an operator<< for printing from the tok:: kind for keywords,
which makes it much more convenient for performing the required
callbacks.

rdar://problem/24292226
2016-03-02 16:46:25 -08:00
Xi Ge
cf7d483304 ModulePrinting: Avoid hard-coding unsatisfiable type requirements, query constraint solver for answers.
Thank Doug and Joe P for suggesting this!
2016-03-02 12:28:02 -08:00
Ben Langmuir
1b22116639 [SourceKit] Refactor parameter printing to use its own callbacks NFC
The current approach of visiting the param decl won't work when we want
to visit the parameters of function *types*, or when visiting tuple
elements (which aren't themselves decls).

rdar://problem/24292226
2016-03-02 11:01:11 -08:00
Ben Langmuir
8955cdc644 [SourceKit] Add decl.var.type tags in property declarations
These Type::print can just reuse the printTypeLoc logic even if they
don't have a TypeRepr.

rdar://problem/24292226
2016-03-01 16:49:33 -08:00
Xi Ge
60be59953a ModulePrinting: Add the basic infrastructure to remove inapplicable synthesized extensions.
As the initial step, we remove any synthesized extensions requiring a tuple's conforming to nominals, which
never happens. This will remove multiple useless synthesized extensions for Dictionary.
2016-03-01 15:44:41 -08:00
Ben Langmuir
f0d306eb10 [ASTPrinter] Enforce pairing of pre/post decl callbacks
We can have multiple printDeclPre callbacks pending (e.g top-level-code
decls), so use a vector to ensure we don't lose the earlier callbacks.

We also may end up calling printDeclPost without forcing the
corresponding printDeclPre first if the decl doesn't actually print
anything (e.g. an if-config statement when skipping those). So add a
wrapper callPrintDeclPost that can check for this and skip both
callbacks.  In theory, we could handle this case by instead making all
ast nodes go through something like shouldPrint() and making an
invariant that something will be printed if and only if shouldPrint
returns true.  However, that is not an obvious win, because it forces us
to walk all the first-level statements and decls inside a top-level-code
decl to determine if anything will be printed, and it also means we can
never make local decisions about whether something will be printed.  For
now, I've chosen to maintain flexibility by recovering from unprinted
decls.

Finally, add a bunch of assertions to try to keep callbacks sane.
2016-02-29 14:59:58 -08:00
Ben Langmuir
dbd32f31b9 [SourceKit] Add cursor/doc info for enum elements
Similarly to pattern binding decls, we want to be able to explode a case
decl out into a synthesized enum case for each individual enum element.
2016-02-26 16:28:13 -08:00
Ben Langmuir
6926fa4cb5 [ASTPrinter] Resolve duplication between shouldPrint[InContext]
By moving enum element handling completely to shouldPrint(), which is
called in visi(). We don't print enum element decls as part of their
decl context so it's not correct to use shouldPrintInContext() here
anyway.
2016-02-26 15:27:11 -08:00
Chris Lattner
79968ab7e9 simplify some code related to the inout move. 2016-02-26 11:30:47 -08:00
Chris Lattner
dfaaebc0a0 Merge pull request #1333 from dduan/SE-0031
[SE-0031] Adjusting 'inout' Declarations for Type Decoration
2016-02-26 10:41:58 -08:00
Daniel Duan
620f1e73cb [AST] update 'inout' print order in ASTPrinter 2016-02-26 01:33:23 -08:00
Ben Langmuir
e9211c8e4f [SourceKit] Fix cursor-info crash with mismatched pre/post callbacks
The problem was that shouldPrint returned true, but shouldPrintInContext
returned false, so we called printDeclPost without ever printing
anything and therefore never calling the pending printDeclPre. Also
remove the avoidPrintDeclPost in the annotation printer, since it was
incorrectly assuming that avoidPrintDeclPost was paired with
printDeclPre (it's not clear to me that it isn't sometimes paired
though...).

Future work: remove or properly document the difference between the two
shouldPrint* variants; and ensure that callbacks will always be paired
even if we don't end up printing anything. Also verify that
avoidPrintDeclPost behaves correctly with respect to printDeclPre being
called (or not).
2016-02-25 19:40:26 -08:00
Ben Langmuir
c07791880b [ASTPrinter] Use TypeLoc printing for subscript element type
Printing as a TypeRepr gives better results.
2016-02-25 12:50:05 -08:00
Ben Langmuir
86bc29cfc6 [SourceKit] Add type tags for parameters and return types
When the type is not just a reference to a nominal type, we still need
to be able to delineate it.

rdar://problem/24292226
2016-02-25 09:07:16 -08:00
Doug Gregor
1c2ce6f22f [Omit needless words] Add a flag to let us skip overrides and witnesses.
When performing Swift API dumps, it's helpful to avoid putting
redundant APIs into the results. Therefore, filter out any APIs that
are overrides of another API or are witnesses for a protocol
requirement, since the original definition (that doesn't override any
other or is a protocol requirement) is what determines the APIs name.
2016-02-24 17:47:31 -08:00
Ben Langmuir
d3e98f52ef [SourceKit] Add parameter.name.local and parameter.name.external tags
... for the fully annotated declarations. More substructure more better.
This has to go through a callback mechanism similar to printDeclLoc and
printDeclPre since it should be scheduled after both of those are
printed.

rdar://problem/24292226
2016-02-24 15:26:46 -08:00
Ben Langmuir
3e9bfa137d [SourceKit] Add decl.var.parameters entries to the fully annotated decl
This is the first part of adding parameter substructure so that clients
can reason about more of the function declaration.

rdar://problem/24292226
2016-02-24 11:39:47 -08:00
practicalswift
6eefb5f8db [gardening] Fix recently introduced typo: "inteface" → "interface" 2016-02-19 14:19:56 +01:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Xi Ge
17cde5322f [gardening] ASTPrinter: encapsulate archetype-transformation related stuff into a sub-structure. NFC 2016-02-17 15:35:28 -08:00
Xi Ge
d4f704bb2f ASTPrinter: Add pre and post callbacks for printing synthesized extensions and call them.
This is necessary for jump to synthesized extensions in IDE.
2016-02-15 17:41:49 -08:00
Ben Langmuir
63667ce852 [SourceKit] Move generic parameters out of struct/class/enum decl.name
And add tests for this and for function generic parameters.

rdar://problem/24292226
2016-02-15 10:40:00 -08:00
Ben Langmuir
f3ca9dc992 [SourceKit] Move bang/question-mark out of annotated name for init
rdar://problem/24292226
2016-02-15 10:07:49 -08:00