Commit Graph

1012 Commits

Author SHA1 Message Date
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Slava Pestov
df9f7f979a Parse: Remove uses of getParameterLists() from default argument parsing 2018-07-22 20:56:56 -07:00
Slava Pestov
bfc4121971 AST: Rework AbstractFunctionDecl construction away from multiple parameter lists
There are two general constructor forms here:

- One took the number of parameter lists, to be filled in later.
  Now, this takes a boolean indicating if there is an implicit
  'self'.

- The other one took the actual parameter lists and filled them
  in right away. This now takes a separate 'self' ParamDecl and
  ParameterList.

Instead of storing the number of parameter lists, an
AbstractFunctionDecl now only needs to store if there is a 'self'
or not.

I've updated most places that construct AbstractFunctionDecls to
properly use these new forms. In the ClangImporter, there is
more code that remains to be untangled, so we continue to build
multiple ParameterLists and unpack them into a ParamDecl and
ParameterList at the last minute.
2018-07-21 07:30:30 -07:00
John McCall
06edd256c2 Generalize the recording of parsed accessors.
As part of this, lift the now-unnecessary restriction against
combining a non-mutable addressor with a setter.  I've also
tweaked some of the diagnostics.

This is in preparation for generalized accessors.
2018-07-20 17:54:57 -04:00
Alex Hoppen
c8226d1507 [libSyntax] Make a typealias to unsigned to represent SyntaxNodeIds 2018-07-19 13:57:08 -07:00
Alex Hoppen
419ba044f1 [libSyntax] Record reused node IDs
This is cheaper than recording reused region offsets and the reused node
IDs will later be used to incrementally transfer the syntax to
SwiftSyntax.
2018-07-19 13:55:57 -07:00
Alex Hoppen
7a750bf024 [libSyntax] Allow syntax cache reuse info to be passed back via SourceKit 2018-07-18 13:35:10 -07:00
Ben Langmuir
62d93aea6f Merge pull request #17857 from benlangmuir/cc-if-else-if
[codecomplete] Add completion of `if` after `else`
2018-07-11 10:54:10 -07:00
Ben Langmuir
b394e35fdd [codecomplete] Add completion of if after else
At some point we stopped completing keywords after `else` in an if
statement. Bring back the completion of `if`, which is the only valid
continuation other than a brace.

rdar://37467474
2018-07-10 11:45:10 -07:00
Xi Ge
fd6b5941dd libSyntax: rename SyntaxParsingContext.setDiscard() to SyntaxParsingContext.setBackTracking(). NFC 2018-07-09 14:02:26 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Andrew Trick
7c4d15f96a SILModule::isVisibleExternally utility for VarDecls. (#16834)
* SILModule::isVisibleExternally utility for VarDecls.

* Fix the SIL parser so it doesn't drop global variable decls.

This information was getting lost in SIL printing/parsing.
Some passes rely on it. Regardless of whether passes should rely on it,
it is totally unacceptable for the SIL passes to have subtle differences
in behavior depending on the frontend mode. So, if we don't want passes
to rely on global variable decls, that needs to be enforced by the API
independent of how the frontend is invoked or how SIL is serialized.

* Use custom DemangleOptions to lookup global variable identifiers.
2018-06-26 12:27:26 -07:00
John McCall
69f4dd1ec9 Generalize accessor storage to preserve the original accessor list.
Only not NFC because it's detectable by source tools.
2018-06-16 18:16:31 -04:00
John McCall
9022b5152f Rename accessor kinds from IsGetter -> IsGet, etc.
Introduce some metaprogramming of accessors and generally prepare
for storing less-structured accessor lists.

NFC except for a change to the serialization format.
2018-06-14 17:08:55 -04:00
Pavel Yaskevich
82025f8e2d [Parse] Don't try to diagnose extraneous & while parsing
Trying to diagnose extraneous use of `&` in parser is too early
and affects some valid cases like patterns in `case` statements,
where we still want to allow use of `&`.
2018-06-08 20:14:45 -07:00
Robert Widmann
28a8fb1c0b [NFC] Drop mutability from parameter context changes
Refactoring in this area means we no longer mutate the array, just
call non-const members on the elements.
2018-05-24 12:15:14 -07:00
Rintaro Ishizaki
c83917ce07 Merge pull request #16763 from rintaro/parse-type-argumentlabel
[Parse] Parse label in tuple type as tok::identifier
2018-05-23 09:22:34 +09:00
Alex Hoppen
4e44e6805d [libSyntax] Store shared SyntaxParsingContext data in RootContextData 2018-05-22 09:07:57 -07:00
Alex Hoppen
2decf8ffaf [libSyntax] Rename recordReuseInformation to setRecordReuseInformation 2018-05-22 09:07:56 -07:00
Alex Hoppen
9a3ff5bdfd [libSyntax] Add a debug dump function to SyntaxParsingContext 2018-05-22 08:52:39 -07:00
Alex Hoppen
92f8f34d22 [incrParse] Store reused regions and output them after parsing 2018-05-22 08:52:34 -07:00
Alex Hoppen
65ac4f57a4 [incrParse] Refactor node reusability into separate function 2018-05-22 08:52:34 -07:00
Alex Hoppen
186feb6f0e [incrParse] Allow information about node reused be outputted 2018-05-22 08:52:33 -07:00
Alex Hoppen
60d11d24f8 [incrParse] Reparse a node if the next leaf node has been modified 2018-05-22 08:52:33 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Rintaro Ishizaki
4a247efc0a [Parse] Parse label in tuple type as tok::identifier
Made an utility method 'consumeArgumentLabel', and use it for:
* Labels in tuple type
* Labels in tuple expression
* Argument and parameter names in parameter clause
2018-05-22 13:46:42 +09:00
Rintaro Ishizaki
a6f7a8ea35 [Parser] Set local discriminator to ParamDecls
We have to discriminate between params and local variables.
2018-05-11 15:37:40 +09:00
Huon Wilson
0de6c9ee6b [Parse] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:06 +10:00
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Xi Ge
e8c80878ed Merge pull request #16158 from nkcsgexi/synthesize-node
libSyntax: add a mechanism to synthesize syntax nodes in SyntaxParsingContext.
2018-04-26 11:24:50 -07:00
Xi Ge
a1a6c19959 libSyntax: add a mechanism to synthesize syntax nodes in SyntaxParsingContext.
To enhance the error-recovery of syntax parsing, this patch allows the
parser to synthesize missing nodes to satisfy the requirement of a
syntax node under parsing. As proof-of-concept, we synthesize r-braces
for function body to avoid regressing a function decl to an unknown
decl.
2018-04-26 10:48:57 -07:00
Alex Hoppen
3e9ae802c2 [libSyntax] Make parsing of attribute arguments more structured
This also fixes several issues where attribute arguments could not be
parsed as a TokenList since some of its arguments already had structure
and were not tokens
2018-04-24 13:18:15 -07:00
David Zarzycki
7174d14dad [Parsing] NFC: metaprogram contextual decl keywords into Attr.def 2018-04-07 18:00:12 -04:00
Huon Wilson
00c32698e2 [Parse] Put indent-is-4-spaces assumption in one place.
This single location can, theoretically, be made more intelligent about
deducing indent from elsewhere and all the consumers will just work.
2018-04-04 10:34:33 +10:00
Rintaro Ishizaki
18b28b9184 [Parse] Factor out declaration modifier list parsing (#15702) 2018-04-03 19:58:57 +09:00
David Zarzycki
42890e97ef Merge pull request #15597 from davezarzycki/more_TVO_CanBindToInOut_removal
[Sema] NFC: More TVO_CanBindToInOut removal
2018-03-31 16:39:07 -04:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00
Sho Ikeda
46aae67a1e [gardening][Parse] Replace typedef with using 2018-03-30 12:59:41 +09:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Rintaro Ishizaki
ea83df4c9d Merge pull request #15267 from rintaro/parse-exprprimary
[Parse] Rename 'parseExprPostfixWithoutSuffix' to 'parseExprPrimary' and cleanups
2018-03-17 13:16:35 +09:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Rintaro Ishizaki
3347d56465 [gardening] Rename parseExprPostfixWithoutSuffix to parseExprPrimary 2018-03-15 17:45:32 +09:00
Rintaro Ishizaki
444451eb6c [gardening] Remove unused LSquareLoc parameter from parseExprCollection 2018-03-15 15:45:37 +09:00
Rintaro Ishizaki
0a26e287ba [Parse] Diagnose unknown pound expressions
Implemented diagnostics for `'#' identifier arguments?` at expression
position.
Also, added back diagnostics (and fix-it) for legacy object literals.
2018-03-15 15:36:51 +09:00
Rintaro Ishizaki
bdcd87754d [Parse] Eliminate POUND_OLD_OBJECT_LITERAL tokens
We don't want to handle them in libSyntax
2018-03-14 21:50:53 +09:00
Rintaro Ishizaki
54b28b6cb6 Merge pull request #15152 from omochi/lex-remove-fields
[Parse] Remove unnecessary Lexer fields
2018-03-13 12:19:36 +09:00
Doug Gregor
d138575da2 Merge pull request #15170 from ikesyo/enum-class-uint8_t
[gardening][enum class] Replace `unsigned char` with `uint8_t` for consistency
2018-03-12 09:05:13 -07:00
omochimetaru
3c8057e13f [Parse] Remove unnecessary Lexer fields 2018-03-12 23:35:13 +09:00
Rintaro Ishizaki
c612da2805 [Lexer] Remove dead code (#15179)
Remove Lexer::getSubstring()
The last usage was deleted in d522cd4270.
2018-03-12 22:44:24 +09:00
Sho Ikeda
422136e1a2 [gardening][enum class] Replace unsigned char with uint8_t for consistency
Before the changes:

- `git grep -E "enum class .+ : uint8_t \{" | wc -l`: 90
- `git grep -E "enum class .+ : unsigned char \{" | wc -l`: 26
2018-03-12 13:57:36 +09:00