Commit Graph

808 Commits

Author SHA1 Message Date
Ankit Aggarwal
92d09f4e19 Extend @available to support PackageDescription
<rdar://problem/46548531> Extend @available to support PackageDescription

This introduces a new private availability kind "_PackageDescription" to
allow availability testing by an arbitary version that can be passed
using a new command-line flag "-swiftpm-manifest-version". The semantics
are exactly same as Swift version specific availability. In longer term,
it maybe possible to remove this enhancement once there is
a language-level availability support for 3rd party libraries.

Motivation:

Swift packages are configured using a Package.swift manifest file. The
manifest file uses a library called PackageDescription, which contains
various settings that can be configured for a package. The new additions
in the PackageDescription APIs are gated behind a "tools version" that
every manifest must declare. This means, packages don't automatically
get access to the new APIs. They need to update their declared tools
version in order to use the new API. This is basically similar to the
minimum deployment target version we have for our OSes.

This gating is important for allowing packages to maintain backwards
compatibility. SwiftPM currently checks for API usages at runtime in
order to implement this gating. This works reasonably well but can lead
to a poor experience with features like code-completion and module
interface generation in IDEs and editors (that use sourcekit-lsp) as
SwiftPM has no control over these features.
2018-12-08 09:38:40 +05:30
Marc Rasi
bf18697b4f parsing, typechecking, and SILGen for #assert
`#assert` is a new static assertion statement that will let us write
tests for the new constant evaluation infrastructure that we are working
on. `#assert` works by lowering to a `Builtin.poundAssert` SIL
instruction. The constant evaluation infrastructure will look for these
SIL instructions, const-evaluate their conditions, and emit errors if
the conditions are non-constant or false.

This commit implements parsing, typechecking and SILGen for `#assert`.
2018-11-07 16:34:17 -08:00
Rintaro Ishizaki
797761adae [CodeCompletion] Try to parse complete expression after CC token
Type may depend on its suffix. Parsing complete expression including its
suffix improves context type info around the CC token.

rdar://problem/44143964
2018-10-16 06:08:29 +09:00
Christopher Ian Stern
469a0f3eb0 fix stack overflow on deeply nested parens [SR-4866] (#19631)
Make sure StructureMarkerRAII checks structure nesting level on all paths.  Previously swift crashed with  no diagnostic on deeply nested '('. Now we print an error when more than 256 parens deep, just as we always have for '['.

fixes SR-4866
2018-10-10 13:42:18 +09:00
John McCall
32c7e4bbfa Fix libSyntax support for yields with expression lists. 2018-10-09 15:34:54 -04:00
Rintaro Ishizaki
4797a7caf6 Merge pull request #18919 from rintaro/ide-complete-pound
[CodeCompletion] Implement completion for # directives
2018-08-31 10:50:40 +09:00
gregomni
ff04fbdae8 Fix name lookup and parser so that where clauses decl refs in case statements correctly bind to the current pattern instead of always to the first pattern. Thus the hacky var decl juggling in where clauses in SILGen can be deleted. 2018-08-28 19:18:56 -07:00
Slava Pestov
c360c82850 AST: Automatically create the 'self' parameter when needed
Parsed declarations would create an untyped 'self' parameter;
synthesized, imported and deserialized declarations would get a
typed one.

In reality the type, if any, depends completely on the properties
of the function in question, so we can just lazily create the
'self' parameter when needed.

If the function already has a type, we give it a type right there;
otherwise, we check if a 'self' was already created when we
compute a function's type and set the type of 'self' then.
2018-08-25 10:44:55 -07:00
Rintaro Ishizaki
deb4aa84e0 [CodeCompletion] Add completion for platform condition
* 'true'/'false' keyword
* 'os(<name>)', 'canImport(<module>)' etc.
* Custom flags specified with '-D'

rdar://problem/19572779
2018-08-24 12:24:54 +09:00
Rintaro Ishizaki
5ef5f5ed84 [CodeCompletion] Implement completion for # directives
rdar://problem/29976235
2018-08-24 12:24:54 +09:00
Rintaro Ishizaki
2052d4bc83 [CodeCompleiton] Enable after '#' completion in arbitrary expr position
Previously, it's enabled only at stmt condition position.
2018-08-24 11:12:48 +09:00
Rintaro Ishizaki
6bd888fde1 [Parse] Recover missing initializer in stmt condition
Fix a crash introduced in aac92da252.

rdar://problem/43395202
2018-08-17 15:49:54 +09:00
Rintaro Ishizaki
318c98a323 [Parse] Remove Status |= Status (#18666)
This was meant to be `Status |= ThePattern`. But it actually should be
removed because we don't want to propagate isParseError() status as it's
recovered, and we propagate hasCodeCompletion() below.
2018-08-14 00:57:42 +09:00
Rintaro Ishizaki
5e001f1913 Merge pull request #18626 from rintaro/ide-completion-unresolved-refactor
[CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
2018-08-11 09:10:28 +09:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
Rintaro Ishizaki
aac92da252 [CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
Using dummy UnresolvedMemberExpr doesn't give us much benefit. Instead, use
CodeCompletionExpr which is type checked as type variable so can use
CodeCompletionTypeContextAnalyzer to infer context types.
This way, we can eliminate most of special logic for UnresolvedMember.

rdar://problem/39098974
2018-08-10 22:23:23 +09:00
Argyrios Kyrtzidis
a6fd08226e Merge pull request #18616 from akyrtzi/input-complete-invalid-interpolation
[parser] Make corrections for the isInputIncomplete() functionality
2018-08-09 18:46:21 -07:00
Argyrios Kyrtzidis
1f117b4848 [parser] Make sure the isInputIncomplete() function works as expected for multi-line strings 2018-08-09 17:30:49 -07:00
Huon Wilson
75934be398 [Parse] Fixit for inserting 'if' for 'else ... {' all on one line.
Fixes rdar://problem/33023297.
2018-08-09 20:08:11 +10:00
Huon Wilson
507d3625bc [Parse] Factor out "find instance of token on current line" logic. NFC. 2018-08-09 16:37:32 +10:00
Rintaro Ishizaki
c5a84565d7 [Parse] Fix end location of dummy top level code for code completion
Fix ASTVerifier error for end location of 'IfConfigDecl'.
Previously, for:
```
  #if
  // something
  <COMPLETE>
```
End location of the dummy body of 'TopLevelCodeDecl' was at the eof, but the
end loc of the 'IfConfigDecl' was at the code-completion token. That
caused the ASTVerifier error "invalid IfConfigStmt end location".

https://bugs.swift.org/browse/SR-2364
rdar://problem/41217187
2018-07-30 20:23:26 +09:00
John McCall
a41ccb2afe Don't change the token kind of yield until we commit to a statement.
Per Rintaro's code review.
2018-07-24 03:18:03 -04:00
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
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
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
Alex Hoppen
1b3baf908f [incrParse] Add error nodes to the end of a CodeBlockItem
Creating a new CodeBlockItem meant that when doing an edit in the error
nodes, the prefix gets reused and thus the code is parsed as invalid
although it is not.
2018-05-22 09:07:55 -07:00
Alex Hoppen
e1a99efd57 [incrParse] Fix parsing of nodes covering no source text 2018-05-22 08:52:39 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Rintaro Ishizaki
df10afd1a2 [Parse] Discriminate local variables
Set local discriminator for all local `VarDecl`s. Otherwise, they cannot
be discriminated with USRs. This change is needed for rename refactoring which
uses USR for discrimiating variable names.

https://bugs.swift.org/browse/SR-7205,
rdar://problem/34701880
2018-05-11 15:34:42 +09:00
Doug Gregor
1ac8926467 [Parser] Don't lose outer "disabled" variables when checking a guard's "else".
When checking for uses of "disabled" variables within the "else"
statement of a "guard", keep track of the disabled variables from
outer scopes. This is a pattern used everywhere else in the parser,
but got missed here. Fixes SR-7567 / rdar://problem/39868144.
2018-05-04 12:57:24 -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
Rintaro Ishizaki
07fd8b8a4b [Parse] Handle edge case of '@unknown' for switch case
* Previously, hit assertion if '@unknown' has argument clause
* Diagnose multiple '@unknown' for single 'case'
2018-04-12 01:27:40 +09:00
Jordan Rose
701975ad1d Add parsing support for @unknown (SE-0192)
This is our first statement attribute, made more complicated by the
fact that a 'case'/'default' isn't really a normal statement. I've
chosen /not/ to implement a general statement attribute logic like we
have for types and decls at this time, but I did get the compiler
parsing arbitrary attributes before 'case' and 'default'. As a bonus,
we now treat all cases within functions as being switch-like rather
than enum-like, which is better for recovery when not in a switch.
2018-04-05 16:35:14 -07:00
Jordan Rose
f26664b1f1 [AST] Adjust the API of CaseLabelItem for unknown
Get these simple changes out of the way first. No functionality change.
2018-04-04 16:19:11 -07:00
Rintaro Ishizaki
4488e99a04 [Syntax] Parse 'switch' statement 2018-03-28 00:30:21 +09:00
Joe Groff
a146361389 SIL: Fix parse issues with sil_property declarations
- Properly detect the sil_property token at toplevel
- Avoid dereferencing null GenericEnvironment if property declaration has no generic environment
2018-03-22 13:58:52 -07:00
Harlan
aa1059c9a3 [Syntax] Parse WhileStmtSyntax nodes (#15186) 2018-03-12 17:50:07 -04:00
Rintaro Ishizaki
6c0af2a24f [Syntax] Introduce CodeBlockItem (#14458)
CodeBlockItem represents Decl, Stmt or Expr that optionally followed by
semi-colon.
SourceFile syntax holds a list of CodeBlockItem.
2018-02-08 10:31:01 +09:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Rintaro Ishizaki
39746a9e58 [Parse] Inline skipExtraTopLevelRBraces()
Removed from 'parseTopLevel()'. There's no particular reason to diagnose
it in 'parseTopLevel()'.
2017-12-25 23:32:55 +09:00
Rintaro Ishizaki
62ac618dc6 [Parse] small cleanup in parseBraceItems()
* Reorder 'if ... else if' branches to simplify conditions.
* use 'append()' instead of `for { push_back() }`
2017-12-25 22:48:58 +09:00
Rintaro Ishizaki
1dc6a3f775 [Syntax] Parse "for-in statement" node 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
1e83ad2cbf [Syntax] Parse "if statement" and "guard statement" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
d01f5d1da3 [Syntax] Parse "statement condition" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
02769d77c2 [Parse] Factor out StmtConditionElement parsing 2017-12-22 18:28:04 +09:00
Rintaro Ishizaki
cd5fdff9bb [Syntax] Parse "repeat-while statement" syntax node 2017-12-21 17:16:26 +09:00