Commit Graph

298 Commits

Author SHA1 Message Date
Rintaro Ishizaki
2aec5d4d28 [CodeCompletionn] Block completions in other threads
if fast-completion is enabled. So they have higher chance to use the cached
completion instance.
If it's disabled, don't block, use an ephemeral instance so we can peform
multiple completions simultaneously.
2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
044477e7a3 [SourceKit/CodeCompletion] Use callback function to run the second pass
To controls the lifetime of CompilerInstance within CompletionIntance.

- Prevent from using the same CompilerInstance from multiple completion
  requests
- Separate the stacktrace between "fast" and "normal" completions
- Further code consolidation between various completion-like requests
2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
fcb50d6354 [SourceKit] Add more test cases for fast completions 2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
2160134dc3 [SourceKit] Add test file for fast completion 2019-12-18 21:52:20 -08:00
Rintaro Ishizaki
3e1de28c85 [complete-test] Stop inserting \0 in complete-test
Using \0 as a representation of the cursor position is a implementation
detail and is done by SourceKit. Client including complete-test should
not do it.

This inserted test used to be treated as EOF in compiler so the code
after the completion position is completely ignored.
2019-11-21 14:14:22 +09:00
Daniel Rodríguez Troitiño
a1a891e47a [windows] Use the temporal directory for root of VFS tests.
The VFS tests were using Unix absolute paths, which does not play well
when Windows see them as relative to the current drive letter.

By using the temporal directory, both Windows and Unix can use the same
paths and avoid the problem.

Additionally, a couple of inputs have to be transformed into the native
path format, because sourcekitd-test compares the inputs as strings, and
they need to match exactly. So the source file and the name of the VFS
entries are transformed into native using the helper from LLVM support.
2019-11-15 15:20:01 -08:00
Rintaro Ishizaki
2564a6e494 [CodeCompletion] Avoid typechecking all toplevel decls in the current file
- Use `performParseAndResolveImportsOnly()` to invoke the frontend
- Do `bindExtensions()` in `ide::typeCheckContextUntil()`
- Typecheck preceding `TopLevelCodeDecl`s only if the compleiton is in
  a `TopLevelCodeDecl`
- Other related tweaks

rdar://problem/56636747
2019-11-12 12:57:18 +09:00
Nathan Hawes
eabb561994 [code-completion] Give Modules a SemanticContextKind of None
This seems more correct than OtherModule, and means they're treated as
low-priority results for the session-based completion APIs. With default
options that means won't be shown in global completion results but will be
once there's some matching filter text. It also sorts them below any symbols
that actually come from other modules, which is desirable, since most symbols
don't need to be module qualified.

The SemanticContextKind change doesn't seem to affect Xcode's handling of the
results.
2019-11-01 11:11:52 -07:00
Nathan Hawes
b871454b8f [code-completion] Suggest module names in type and expression position
They can be used to qualify both.
2019-10-30 11:28:56 -07:00
Harlan Haskins
d3b8ce7ae2 [test] Update ParseableInterface to ModuleInterface
Also remove uses of -emit-parseable-module-interface from tests
2019-09-13 14:55:48 -07:00
Nathan Hawes
feb48a61b9 [code-completion] Fix correctness regressions from disabling diagnostics in code completion
There were some changes to completion results because AST mutations that were
made while diagnosing are no longer happening.

This patch 1) changes expression type checking to allow unresolved types when
solving constraint systems, so we get a solution and apply its types in more
cases, and 2) fixes a parsing issue where we would drop a ternary expression
completely if the code completion point was in its true branch.
2019-08-30 15:26:27 -07:00
Ben Langmuir
7124235540 [test] Improve tests for filtered results with vfs
When filtering, make sure the FileCheck sees only the filtered results
and not accidentally pick up the unfiltered output from the initial
"open" request.
2019-07-16 10:19:25 -07:00
Ben Langmuir
2e268a512d Fix new VFS tests that use modules to pass the target consistently
Prevent mismatch between compiling and loading the module.
2019-07-16 10:19:25 -07:00
Ben Langmuir
3b652bfeb5 Add VFS support to codecomplete.open, codecomplete.update 2019-07-16 10:19:25 -07:00
Ben Langmuir
78a7d95f07 Factor getting the filesystem into a method with error handling 2019-07-16 10:19:24 -07:00
Ben Langmuir
6884d3a1fd Move VFS to SwiftLangSupport layer 2019-07-16 10:19:24 -07:00
marcrasi
eb8f384c01 fix SourceKit injected VFS with .swiftinterface files
Use `.setFileSystem()` instead of new `setup` method.
2019-07-16 10:19:24 -07:00
Marc Rasi
a6e0210b6d thread a vfs through the completion handler 2019-07-16 10:19:24 -07:00
Gwen Mittertreiner
518196cde9 Properly Compare True and False Order in Sourcekit
Comparing "false" > "true" will return 0, which when returned by compare
indicates the two are equal which will result in a non deterministic
ordering of "false" and "true". Using .compare returns a negative number
as expected.
2019-07-10 18:25:53 -07:00
Rintaro Ishizaki
9525f16440 [SourceKit] Add completion kind field to completion response
rdar://problem/52352045
2019-07-01 14:40:03 -07:00
Rintaro Ishizaki
db2c11787b [AST] Inherit doc-brief comment from protocol, superclass, and requirement
rdar://problem/38422822
2019-06-20 10:04:05 -07:00
Jordan Rose
22f9853b76 [ParseableInterface] Turn on -enable-parseable-module-interface always (#23331)
...and remove the option. This is ~technically~ CLI-breaking because
Swift 5 shipped this as a hidden driver option, but it wouldn't have
/done/ anything in Swift 5, so I think it's okay to remove.

Note that if a parseable interface (.swiftinterface) and a binary
interface (.swiftmodule) are both present, the binary one will still
be preferred. This just /allows/ parseable interfaces to be used.

rdar://problem/36885834
2019-03-16 15:31:11 -07:00
Rintaro Ishizaki
c99af83901 [CodeCompletion] Consolidate parameter list processing funcitons
There were 2 functions to output argument list. Consolidate them and
consistently use it from every call like production (i.e. function call,
constructor call, enum with associated values, subscript)
2019-03-05 16:45:48 -08:00
Nathan Hawes
6aad52aa6c Merge pull request #22550 from nathawes/code-complete-parseable-interface
[ParseableInterface] Fix failing to build a module when the importing file has errors.
2019-02-13 14:12:27 -08:00
Rintaro Ishizaki
0bebba840e Merge pull request #22539 from rintaro/ide-codecompletion-dottype-rdar22072865
[CodeCompletion] Implement .Type completion in expression context
2019-02-12 16:03:29 -08:00
Nathan Hawes
e146630b63 [ParseableInterface] Fix failing to build a module when the importing file has errors.
We were checking the parent invocation's DiagnosticEnginer rather than the
subinstance's to determine if there were any errors building the module, which
meant we would fail to load the module if there were errors prior to the import
statement in the importing file.

This also meant code completion would fail to load the module, because it always
emits a bogus error in order to mark the AST as erroneous so that different
parts of the compiler (e.g. the verifier) have less strict assumptions.

rdar://problem/43906499
2019-02-12 12:32:32 -08:00
Rintaro Ishizaki
01b8fbc1bf [CodeCompletion] Implement .Type completion in expression context
rdar://problem/22072865
2019-02-12 10:40:08 -08:00
Brent Royal-Gordon
031166e25b Revert "[ParseableInterface] Fix failing to build a module when the importing file has errors." 2019-02-11 15:59:42 -08:00
Nathan Hawes
2a746da9bc [ParseableInterface] Fix failing to build a module when the importing file has errors.
We were checking the parent invocation's DiagnosticEnginer rather than the
subinstance's to determine if there were any errors building the module, which
meant we would fail to load the module if there were errors prior to the import
statement in the importing file.

This also meant code completion would fail to load the module, because it always
emits a bogus error in order to mark the AST as erroneous so that different
parts of the compiler (e.g. the verifier) have less strict assumptions.

rdar://problem/43906499
2019-02-08 09:08:27 -08:00
Slava Pestov
7d33177b84 LookupVisibleDecls: Don't use getReasonForSuper() for members of protocols and superclass constraints on an archetype
Semantically, these are not superclass/refined-protocol members.
If I have a generic parameter <T : P & Q>, then when looking at
a value of type T, members of P and Q are at the same "level" as
if I had a value of type (P & Q).
2019-01-08 00:14:52 -05:00
Doug Gregor
85d488d461 [stdlib] Remove magnitude-based overload of abs(_:).
The standard library has two versions of the `abs(_:)` function:

```
func abs<T : SignedNumeric>(_ x: T) -> T where T.Magnitude == T
func abs<T : SignedNumeric & Comparable>(_ x: T) -> T
```

The first is more specialized than the second because `T.Magnitude` is
known to conform to `Comparable`. Indeed, it’s a more specialized
implementation that returns `magnitude`.

However, this overload behaves oddly: in the expression `abs(-8)`, the type
checker will pick the first overload because it is more specialized. That’s
a general guiding principle for overloading: pick the most specialized
overload that works.

However, to select that overload, it needs to pick a type for the literal
“8” for which that overload works, and it chooses `Double`. The “obvious”
answer, `Int`, doesn’t work because `Int.Magnitude == UInt`.

There is a conflict between the two rules, here: we prefer more-specialized
overloads (but we’ll fall back to less-specialized if those don’t work) and we prefer to use `Int` for integer literals (but we’ll fall back to `Double` if it doesn’t work). We have a few options from a type-checker
perspective:

1. Consider the more-specialized-function rule to be more important
2. Consider the integer-literals-prefer-`Int` rule to be more important
3. Call the result ambiguous and make the user annotate it

The type checker currently does #1, although at some point in the past it
did #2. Moving forward, #1 is a better choice because it prunes the number
of overloads that need to be considered: if the more-specialized overload
succeeds its type-check, the others need not be considered. It’s also
easier to reason about than the literal-scoring approach, because there can
be a direct definition for “more specialized than” that can be reasoned
about.

I think we should dodge the issue by removing the more-specialized version
of `abs(_:)`. Its use of `magnitude` seems unlikely to provide a
significant performance benefit, and the presence of overloading either
forces us to consider both overloads always (which is bad for type checker
performance) or accept the regression that `abs(-8)` is `Double`. Better
to eliminate the overloading and, if needed in the future, find a better
way to introduce the more-specialized implementation without it being a
separate signature.

Fixes rdar://problem/42345366.
2018-12-04 23:10:04 -08:00
Rintaro Ishizaki
c68157a27d [CodeCompletion] Remove unresolved type in prepareForRetypechecking()
Unresolved type attached to expressions may fail re-typechecking.
Also, disallow unresolved type in typeCheckCompletionSequence(). It doesn't
provide useful completions to developers.

rdar://problem/41224316
2018-08-15 20:39:12 +09:00
Bob Wilson
6786eda69c [master-next] Update more tests for LLVM r336847
LLVM r336847 changed FileCheck's CHECK-DAG feature to stop supporting
overlapping matches. I already fixed one test by invoking FileCheck with the
-allow-deprecated-dag-overlap option, but it turns out there are a bunch
more of them. This change applies the same workaround to all of them.
2018-07-24 23:29:20 -07:00
Mark Lacey
8ee52763f0 Remove the '++' and '--' operators.
We still had unavailable versions of these for floating-point types
only. We shouldn't need to keep these around, and can instead just
emit a helpful diagnostic for anyone that attempts to use them.

Unfortunately I don't see any way for the diagnostic to produce an
actual fix-it, so it just suggests '+= 1' or '-= 1' without actually
producing a fix.
2018-07-12 15:46:57 -07:00
Stephen Canon
ff89fce7df Make FloatingPoint require that Self.Magnitude == Self (#17323)
* Make FloatingPoint require that Self.Magnitude == Self

We didn't have the where clause to express this constraint at the time that the FloatingPoint protocol was implemented, but we do now. This is not a semantic change to FloatingPoint, which has always bound IEEE-754 arithmetic types, for which this constraint would necessarily hold, but it does effect the type system.

For example, currently the following function does not type check:
~~~~
func foo<T>(x: T) -> T where T: FloatingPoint {
  var r = x.remainder(dividingBy: 1)
  return r.magnitude
}
~~~~
with this change, it compiles correctly.

Having done this, we no longer need to have a separate `abs` defined on FloatingPoint; we can use the existing function defined on `SignedNumeric` instead. Additionally mark the global `fabs` defined in the platform C module deprecated in favor of the Swift `abs`; we don't need to carry two names for this function going forward.
2018-06-20 19:56:22 -04:00
Robert Widmann
df698d2ee8 Remove __consuming from CodeCompletion
Set the UserInaccessible bit to remove __consuming from code
completion until we commit to a real keyword.

rdar://40828289
2018-06-10 15:06:28 -07:00
Rintaro Ishizaki
66c71d1bf7 [SourceKit] Force print '?' for optional method call in code completion. (#16910)
Calling '@objc optional func' requires '?' or '!' after its name. When
completing method calls for them, 'key.sourcetext' should have '?'
whereas 'key.name' shouldn't.
Note that we deliberately do not use optional type name for
'key.typename'. This is consistent with optional chain '?.<propertyName>'
behavior.

rdar://problem/37904574
2018-05-31 16:06:23 -07:00
fischertony
131d36d381 updated SourceKit tests 2018-05-19 07:41:14 +03:00
Jordan Rose
6d30272bfd Merge pull request #14382 from jrose-apple/unknown-case
Implementation for `@unknown default`
2018-04-10 11:19:53 -07:00
David Zarzycki
7174d14dad [Parsing] NFC: metaprogram contextual decl keywords into Attr.def 2018-04-07 18:00:12 -04: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
Ben Langmuir
20cb3e3eb2 [driver] Add -working-directory option
Adds a -working-directory option which can be used to modify how
relative paths are resolved. It affects all other paths used in driver
options (controlled by a new ArgumentIsPath flag on options) as well as
the contents of output file maps and auxilliary file paths generated
implicitly by the compiler itself.

rdar://37713856
2018-02-21 09:42:05 -08:00
Ben Langmuir
368e25ec05 [sourcekit] Fix tests that depend on accepting frontend arguments
These tests were relying on sourcekitd parsing as frontend instead of
using the driver.  Update them now to avoid churn when we fix command
line argument parsing in sourcekit.

The changes from clang-importer-sdk to clang-importer-sdk-nosource -I %t
are because clang-importer-sdk implies using -enable-source-import.
Rather than hack them up to use -Xfrontend, it is cleaner to just stop
using source import at all for these tests.  Incidentally, this improved
fidelity in a few places.  When using the generated swift modules we
also need to pass a target triple to sourcekit, which exposed some tests
that had mac-specific data.  This is a systemic issue for sourcekit
tests, but for now just make those few specific tests that we had
problems with run only on mac.
2018-02-05 10:09:03 -08:00
Pavel Yaskevich
d3cd61d8eb Merge pull request #13291 from xedin/rdar-34920390
[Mangling/ABI] Mangle function names with parameter labels
2017-12-19 10:50:18 -08:00
Pavel Yaskevich
533171debf [Mangling/ABI] NFC: Fix SourceKit tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Ben Langmuir
36d7acd1fa [code-complete] Set call-arg-heuristics flag in SourceKit
In the new code-completion path, expose an option to control this
behaviour; in the old path turn it off.

rdar://31113161
2017-12-18 13:20:24 -08:00
Ben Langmuir
b6d5a1f1a5 [code-complete] Do not insert rparen after a call pattern completion
When completing
  Foo(<here>
We will now provide
  bar: <#value#>
instead of
  bar: <#value#>)

Inserting the rparen caused some problems in practice:
* the old behaviour optimized for typing Foo(<complete> instead of
  Foo(<complete>), which can conflict with user behaviours or ...
* in editors with automatic brace-matching, we often conflicted with the
  editor, leading to extraneous closing parens

And in general, it is much more predictable for tooling to either insert
matching ( and ) or to not insert either.  While this change may not be
ideal For users of editors that do not do automatic brace-matching, I
believe it is still better overall to have to type a missing paren than
to have to delete an extraneous one.

rdar://31113161
2017-12-18 11:59:49 -08:00
Ben Langmuir
93956eb34b [code-complete] Put call-pattern heuristics under a flag
The original hope was we could make these heuristics really good, but
since that is not currently in sight (and may never be), we want to be
able to turn them off.  For now, just plumb through an internal flag to
control the behaviour.  A future change will customize the behaviour in
SourceKit.

rdar://31113161
2017-12-15 13:23:44 -08:00
Slava Pestov
93c80da77c Parse: __shared and __owned should be contextual keywords
This was a source compatibility regression, someone actually had
an identifier named __shared.
2017-10-24 20:45:50 -07:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00