Commit Graph

6321 Commits

Author SHA1 Message Date
Rintaro Ishizaki
54fc26f6bd Merge pull request #34282 from rintaro/parse-opaque-closure
[Parse] Parse opaque result types in closure signature position
2020-10-12 16:58:44 -07:00
Rintaro Ishizaki
d9963596ea [Parse] Parse opaque result types in closure signature position
'canParseType()' didn't use to handle 'some'.

Also, use 'isContexttualKeyword("some")' for checking 'some' keyword.

https://bugs.swift.org/browse/SR-10769
2020-10-12 14:05:31 -07:00
Slava Pestov
ac116cf56a Parse: Remove AlreadyHandledDecls set 2020-10-12 16:05:22 -04:00
Rintaro Ishizaki
1696f4d3ef Merge pull request #34256 from rintaro/ide-completion-rdar69890297
[CodeCompletion] Remove parser hacks regarding type body fingerprints
2020-10-12 09:25:51 -07:00
Arnold Schwaighofer
2a2cf91dcd Add support for marking a _specialize attribute as SPI
```
  @_specialize(exported: true, spi: SPIGroupName, where T == Int)
  public func myFunc() { }
```

The specialized entry point is only visible for modules that import
using `_spi(SPIGroupName) import ModuleDefiningMyFunc `.

rdar://64993425
2020-10-12 09:19:29 -07:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Rintaro Ishizaki
df94c4f464 [CodeCompletion] Remove parser hacks regarding type body fingerprints
Take type body fingerprints into account for inteface hash checking.
Since `SourceFile.getInterfacehash()` doesn't digest the type body
fingerprints in the file, enabling type body fingerprints regressed
fast-completion.

rdar://problem/69890297
2020-10-10 16:52:04 -07:00
Rintaro Ishizaki
1de9668e90 Merge pull request #34257 from rintaro/syntax-typeexpr-rdar70101520
[Syntax] Parse attributed types in expr position as TypeExprSyntax
2020-10-10 16:22:08 -07:00
Rintaro Ishizaki
411751218c [Syntax] Parse attributed types in expr position as TypeExprSyntax
rdar://problem/70101520
https://bugs.swift.org/browse/SR-13711
2020-10-09 17:19:36 -07:00
Nathan Hawes
a91cede79b [Parse][CodeCompletion] Don't special case code completion when forming single-expression closures/function bodies (NFC)
Code completion used to avoid forming single expression closures/function
bodies when the single expression contained the code completion expression
because a contextual type mismatch could result in types not being applied
to the AST, giving no completions.

Completions that have been migrated to the new solver-based completion
mechanism don't need this behavior, however. Rather than trying to guess
whether the type of completion we're going to end up performing is one of
the ones that haven't been migrated to the solver yet when parsing, instead
just always form single-expression closures/function bodies (like we do for
regular compilation) and undo the transformation if and when we know we're
going to perform a completion kind we haven't migrated yet.

Once all completion kinds are migrated, the undo-ing code can be removed.
2020-10-09 16:02:13 -07:00
Slava Pestov
cb70220fe4 Merge pull request #34226 from slavapestov/astscope-source-range-sorting
ASTScope: Stop sorting declarations by source range
2020-10-08 16:07:05 -04:00
Alexis Laferrière
fa6f1b6b96 Merge pull request #33439 from xymus/expand-avail
[Sema] Define availability specification macros with a frontend flag
2020-10-08 09:25:32 -07:00
Doug Gregor
15fc0fe201 Merge pull request #34234 from DougGregor/concurrency-async-parse-labeled-params
[Concurrency] Fix parsing bug async function types and labeled parameters
2020-10-08 08:14:45 -07:00
Doug Gregor
63dcd4e560 [Concurrency] Fix parsing bug async function types and labeled parameters. 2020-10-07 23:52:57 -07:00
Slava Pestov
ee0d008178 Parse: Preserve source order when code completion adds delayed declarations 2020-10-07 23:28:29 -04:00
Slava Pestov
da1c5c99a9 Parse: Fix repeat/while error recovery path
We were creating an ErrorExpr whose source range overlaps with
the following statement, which is now flagged by ASTScope.
2020-10-06 15:39:10 -04:00
Alexis Laferrière
5ed261683d [Sema] Report availability macros in inlinable code
Availability macros can’t be used in inlinable code
as inlinable is copied textually in the generated
swiftinterface files. Further would could lift this
limitation.
2020-10-06 11:26:45 -07:00
Alexis Laferrière
c6fc53e844 [Sema] Define availability via compiler flag
Introduce availability macros defined by a frontend flag.
This feature makes it possible to set the availability
versions at the moment of compilation instead of having
it hard coded in the sources. It can be used by projects
with a need to change the availability depending on the
compilation context while using the same sources.

The availability macro is defined with the `-define-availability` flag:

swift MyLib.swift -define-availability "_iOS8Aligned:macOS 10.10, iOS 8.0" ..

The macro can be used in code instead of a platform name and version:
@available(_iOS8Aligned, *)
public func foo() {}

rdar://problem/65612624
2020-10-06 11:25:20 -07:00
John McCall
d1070dac07 Merge pull request #34172 from rjmccall/compiler-abstraction
[NFC] A trio of patches to improve incremental build times and compiler abstraction
2020-10-03 14:45:45 -04:00
John McCall
0fb407943f [NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available. 2020-10-03 02:54:56 -04:00
Slava Pestov
04c21c18c9 Parse: Disable circular definition check when parser lookup is off 2020-10-02 22:12:39 -04:00
Robert Widmann
92cb6808fe Merge pull request #34151 from CodaFi/body-paint
Remove Type Body Fingerprints Flags
2020-10-02 11:45:53 -07:00
Holly Borla
355fbb3a8b Merge pull request #34109 from hborla/local-property-wrappers
[Property Wrappers] Support local property wrappers
2020-10-01 22:45:41 -07:00
Robert Widmann
74765a8ba8 Remove Type Body Fingerprints Flags
This infrastructure has more than proven itself. Drop the code paths and tests supporting the status quo.
2020-10-01 13:09:00 -07:00
Slava Pestov
445d747622 AST: Move GenericParamList and friends to GenericParamList.{h,cpp} 2020-09-29 19:51:03 -04:00
Slava Pestov
025921c927 Parse: Move the lookup of 'self' for a SuperRefExpr to preCheckExpression() 2020-09-28 17:50:52 -04:00
Holly Borla
3a47087cc1 [Parser] Don't resolve decl references in the parser if the declaration
has a custom attribute.
2020-09-26 18:58:42 -07:00
Slava Pestov
fa4f7dd664 Parse: Don't create PatternBindingDecls with overlapping source ranges
This was happening in the error recovery path when parsing accessors
on a pattern binding declaration that does not bind any variables, eg

let _: Int { 0 }
2020-09-22 00:16:54 -04:00
Robert Widmann
4d875ee337 Merge pull request #33096 from CodaFi/my-private-eyes
Drop Legacy Cascading Dependencies From the Frontend
2020-09-21 14:04:59 -06:00
Robert Widmann
7fb448071c Remove DependencyScope 2020-09-21 10:37:41 -06:00
Doug Gregor
7b1a6e4171 Merge pull request #33998 from DougGregor/concurrency-actor-independent
[Concurrency] Introduce `@actorIndependent` attribute.
2020-09-21 09:37:34 -07:00
Slava Pestov
d4cc35a938 AST: Remove VarDecl::hasNonPatternBindingInit() 2020-09-18 16:11:06 -04:00
Doug Gregor
ab4c58482e [Concurrency] Centralize rejection of concurrency-only attributes.
Reject concurrency-only attributes in the parser if the experimental
concurrency mode is not enabled.
2020-09-18 12:24:19 -07:00
Slava Pestov
d7f4b1a1bd AST: Capture list bindings now point back to their parent CaptureListExpr
We'll need this to get the right 'selfDC' when name lookup
finds a 'self' declaration in a capture list, eg

class C {
  func bar() {}
  func foo() {
    _ = { [self] in bar() }
  }
}
2020-09-18 02:59:15 -04:00
Doug Gregor
3c49e46f4f Merge pull request #33906 from DougGregor/concurrency-actors
[Concurrency] Basic support for actor classes and actor isolation
2020-09-11 15:10:45 -07:00
Nathan Hawes
4b389cd4f1 Merge pull request #33907 from nathawes/make-hascodecompletion-flag-not-imply-haserror
[Parse][CodeCompletion] Stop code completion within a closure causing parser recovery after the closure.
2020-09-11 14:54:12 -07:00
Nathan Hawes
bb773232a8 [Parse][CodeCompletion] Stop code completion within a closure causing parser recovery after the closure.
For example, the completion below would trigger error recovery within the
closure, which we recover from by skipping to the first inner closure's right
brace. The fact that we recovered though, was not recorded. The closure is
treated as still being an error, triggering another recovery after it that
skips over the 'Thing' token, giving a lone closure expression, rather than a
call.

CreateThings {
    Thing { point in
      print("hello")
      point.#^HERE^#
    }
    Thing { _ in }
}

This isn't an issue for code completion when the outer closure is a regular
closure, but when it's a function builder, invalid elements result in no types
being applied (no valid solutions) and we end up with no completion results.

The fix here is removing the error status from the parser result after the
initial parser recovery.
2020-09-10 21:59:09 -07:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
Doug Gregor
22a350b1ac [Concurrency] Add parsing support for actor classes.
Introduce the "actor class" syntax. Ensure that it is only used for
root classes or classes that inherit from other actor classes.
2020-09-09 20:46:30 -07:00
Nathan Hawes
a1ef6e4dac Merge pull request #33749 from nathawes/new-member-completion
[CodeCompletion] Update member completion to handle ambiguous and invalid base expressions
2020-09-09 18:51:22 -07:00
Nathan Hawes
b15c1fd349 [CodeCompletion] Deduplicate the two isMemberCompletion functions in ParseExpr.cpp and ParseDecl.cpp
Also:
- propagate the Solution -> Result rename to Solution parameter of deliverDotExprResults
- fixup header comment in CodeCompletionTypeChecking.h
2020-09-09 12:14:53 -07:00
Owen Voorhees
c6a266ef62 Merge pull request #29735 from owenv/multiple-varargs
[SE-0284] Allow Multiple Variadic Parameters in Functions, Subscripts, and Initializers
2020-09-05 11:27:21 -05:00
Slava Pestov
56f6d9eee0 Merge pull request #33805 from slavapestov/remove-enable-astscope-lookup-flag
Remove -enable-astscope-lookup flag
2020-09-04 22:47:49 -04:00
Doug Gregor
11154b1398 Merge pull request #33807 from DougGregor/concurrency-nested-await-try
[Concurrency] Fix nested await/try parsing and effects checking.
2020-09-04 17:32:42 -07:00
Slava Pestov
193cf0de87 Code review feedback from @davidungar 2020-09-04 19:59:17 -04:00
Doug Gregor
6489e1aaac [Concurrency] Fix nested await/try parsing and effects checking.
Fix the parsing of await/try/try?/try! so that the two can be nested
(e.g., `await try f()` or `try await f()`).

Then, fix the effects checking logic to preserve all throws-related
information under an `await`, and preserve all async/await-related
information under `try`/`try?`/`try!`.

Add a number of tests, and fix 'await' handling for string
interpolations as well.
2020-09-04 13:36:58 -07:00
Slava Pestov
f3e7963c0d Parse: Mark declarations as hoisted in DebuggerContextChange
Expression evaluation in lldb wraps the entire user-written expression
in a new function body, which puts any new declarations written by the
user in local context.

There is a mechanism where declarations can get moved to the top level,
if they're only valid at the top level (imports, extensions etc), or
if the name of the declaration begins with '$'. This mechanism used to
actually add the declaration to the SourceFile's TopLevelDecls list,
which would break ASTScope invariants about source ranges being
monotonically increasing and non-overlapping.

Instead, we use the new 'hoisted' flag to mark the declarations as
hoisted, which leaves them syntactically in their original location
in the AST, but treats them as top level in SILGen and IRGen.

Part of <rdar://problem/53971116>.
2020-09-03 16:18:07 -04:00
Xi Ge
773eec1a71 Merge pull request #33683 from nkcsgexi/clang-importer-options-refactor
ClangImporter: refactor ClangImporterOptions to be ASTContext-owned. NFC
2020-09-02 07:27:12 -07:00
Nathan Hawes
491b691dbc [CodeCompletion][NFC] Add doc comments and rename symbols for clarity in the new member completion implementation. 2020-09-01 15:04:42 -07:00
Xi Ge
c403b140e1 ClangImporter: refactor ClangImporterOptions to be ASTContext-owned. NFC
We need ClangImporterOptions to be persistent for several scenarios: (1)
when creating a sub-ASTContext to build Swift modules from interfaces; and
(2) when creating a new Clang instance to invoke Clang dependencies scanner.

This change is NFC.
2020-09-01 14:04:22 -07:00