Commit Graph

81 Commits

Author SHA1 Message Date
Robert Widmann
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
Gwen Mittertreiner
25ceaab96d Merge pull request #26203 from gmittert/Symlinks
[Windows] Create symlinks properly in sema_symlink.swift
2019-09-06 16:15:45 -07:00
Gwen Mittertreiner
30788eca59 [Windows] Create symlinks properly in lit tests
The mingw `ln -s` doesn't make a proper symlink on Windows. Instead add a
script to use `cmd.exe /C mklink ...` on Windows.
2019-08-14 16:07: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
4787730b51 Add additional VFS tests
* VFS attached to open document, persists after edit
* VFS reset after re-opening document
* VFS override for cursor_info
2019-07-16 10:19:24 -07:00
Ben Langmuir
6e2a7e5a3a Allow passing key.sourcetext to provide in-memory-vfs contents
For testing, passing `-vfs-files=source=@target` with an '@' on the
target file will pass it as source text.
2019-07-16 10:19:24 -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
be05eb8085 Make reading sourcefile from the real filesystem an error with VFS
Using key.sourcefile to provide the contents of key.sourcetext is meant
for testing, and does not have a straightforward meaning in the future
when the documents are combined with the VFS. Make it an error to mix
this with a VFS for now.
2019-07-16 10:19:24 -07:00
Ben Langmuir
6884d3a1fd Move VFS to SwiftLangSupport layer 2019-07-16 10:19:24 -07:00
Marc Rasi
7e15723805 add custom fs to editor.open and cursorinfo 2019-07-16 10:19:24 -07:00
Argyrios Kyrtzidis
cf65b8f952 Disable typo-correction by default until we can make it work within acceptable performance bounds
Typo-correction can be so expensive that it can slow down typechecking over 10x.
It can be a significant productivity drain for developing on large projects.

Unfortunately it is best that we disable it until we can dedicate the time to address its performance issues
and we are certain it works within acceptable performance bounds.

rdar://51966070
2019-06-22 17:02:03 -07:00
Doug Gregor
d430ddb717 [SE-0258] Minor diagnostic fix for $ and a test case update 2019-05-31 21:33:56 -07:00
Doug Gregor
7f293f66b3 [Parser] Allow use of $ declarations in all modes.
Allow the use of declarations whose names start with $ in all
modes. However, normal code cannot define new entities with names that
start with $: only the implementation can do that, e.g., for property
delegates.
2019-04-23 11:31:58 -07:00
Stephen Canon
c5e3f85378 Revert SE-0246 (#23800)
* Revert "Merge pull request #23791 from compnerd/you-know-nothing-clang"

This reverts commit 5150981150, reversing
changes made to 8fc305c03e.

* Revert "Merge pull request #23780 from compnerd/math-is-terrible"

This reverts commit 2d7fedd25f, reversing
changes made to 0205150b8f.

* Revert "Merge pull request #23140 from stephentyrone/mafs"

This reverts commit 777750dc51, reversing
changes made to 0c8920e747.
2019-04-04 19:35:25 -04:00
Steve (Numerics) Canon
3fda509805 Implementation of ElementaryFunctions / Real protocols.
This commit implements SE-0246, by adding conformance to Real to the Float, CGFloat, Double, and Float80 types, implemented either in terms of the system's C math library, existing standard library functionality, or LLVM intrinsics. It includes basic test coverage for these new functions, and deprecates and obsoletes *some* existing functionality in the Platform overlay. We still need to make a decision about how to handle the remaining "tgmath" functions, because obsoleting them is technically a source-breaking change (if users have unqualified names like "exp(1)", it's fine, but it would break users who have used qualified names like "Darwin.exp(1)".)
2019-04-02 18:49:31 -04:00
John McCall
7815892a76 Add unique typo corrections to the main diagnostic with a fix-it.
Continue to emit notes for the candidates, but use different text.
Note that we can emit a typo correction fix-it even if there are
multiple candidates with the same name.

Also, disable typo correction in the migrator, since the operation
is quite expensive, the notes are never presented to the user, and
the fix-its can interfere with the migrator's own edits.

Our general guidance is that fix-its should be added on the main
diagnostic only when the fix-it is highly likely to be correct.
The exact threshold is debateable.  Typo correction is certainly
capable of making mistakes, but most of its edits are right, and
when it's wrong it's usually obviously wrong.  On balance, I think
this is the right thing to do.  For what it's worth, it's also
what we do in Clang.
2018-04-07 16:01:39 -04:00
Ben Langmuir
ce1cfcc73d [frontend] Input buffers have names too
There's no need to skip filename checks for in-memory buffers, and
indeed we want sourcekitd to behave the same for main.swift files as the
compiler.

SR-6624
rdar://36113282
2018-02-27 12:04:57 -08:00
Argyrios Kyrtzidis
0cfc56ec04 [SourceKit] If diagnostics are 'stale' for a particular snapshot then ignore them and only return the syntactic parser diagnostics (#10388)
This makes sure that diagnostics returned for a particular state of source buffer are consistent and accurate.
rdar://32769873
2017-06-20 12:26:32 -07:00
Robert Widmann
6509f78f13 tests: replace remaining 'mkdir -p' calls with %empty-directory(...)'
These changes were made manually.
2017-06-04 11:08:39 -07:00
Argyrios Kyrtzidis
8f8c87ef41 Merge pull request #9854 from akyrtzi/sourcekit-sil-diags-opts
[SourceKit] Make sure to propagate the SIL options from the compiler invocation when doing performSILGeneration() to get the SIL diagnostics
2017-05-22 19:54:24 -07:00
Argyrios Kyrtzidis
323c07e562 [SourceKit] Make sure to propagate the SIL options from the compiler invocation when doing performSILGeneration() to get the SIL diagnostics
rdar://32329669
2017-05-22 18:27:41 -07:00
Slava Pestov
cde493de0d Sema: Support member types in preCheckExpression()
This folds member access on types to a TypeExpr if the member
resolves to a nested type.

This allows [Foo.Bar]() to become an ApplyExpr of a TypeExpr,
rather than an ApplyExpr of an array literal; previously,
only [Foo]() worked.

Two cases that are still unsupported:

1) If G is a generic type and T is a generic typealias, then
   G.T<X> cannot be folded to a TypeExpr, because we cannot
   represent a generic typealias with an unbound generic
   parent type. Such lookups remain member lookups, where
   Sema first opens the base type to produce a bound generic
   type G<$T0>, and then resolves the generic typealias
   member on that.

2) If T is a generic parameter and X is an associated type,
   T.X is not folded down to a TypeExpr either.

Fixes <rdar://problem/16849958>.
2017-05-21 18:12:12 -07:00
Xi Ge
b5256f53b2 Sema: introduce a language option flag, DiagnosticsEditorMode. (#7982)
SourceKit always sets it positively. This may lead to more aggressive fixits however
less informative messages. We currently use the flag only for filling protocol stubs.
2017-03-08 12:46:02 -08:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
John McCall
3fc2291733 Add basic typo correction for unqualified lookup.
There's a lot of room for better QoI / performance here.
2016-05-20 11:04:58 -07:00
Dmitri Gribenko
3d3d4540e1 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-20 14:37:49 -08:00
Argyrios Kyrtzidis
10dfe5ab5a [SourceKit] Fix issue where the offset of diagnostic fixits is not updated after an edit request.
rdar://23919223
2016-02-19 19:18:44 -08:00
Max Moiseev
a1c05e6c95 fixing post-merge failures 2015-12-11 15:55:02 -08:00
Chris Willmore
c99c02b5a6 Transform EditorPlaceholderExpr into trap if executed in playground
mode (take 2)

Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

When generating constraints for an iterated sequence of type T, emit

    T convertible to $T1
    $T1 conforms to SequenceType

instead of

    T convertible to SequenceType

This ensures that an untyped placeholder in for-each sequence position
doesn't get inferred to have type SequenceType. (The conversion is still
necessary because the sequence may have IUO type.) The new constraint
system precipitates changes in CSSimplify and CSDiag, and ends up fixing
18741539 along the way.

(NOTE: There is a small regression in diagnosis of issues like the
following:

    class C {}
    class D: C {}
    func f(a: [C]!) { for _: D in a {} }

It complains that [C]! doesn't conform to SequenceType when it should be
complaining that C is not convertible to D.)

<rdar://problem/21167372>

(Originally Swift SVN r31481)
2015-12-10 22:05:16 -08:00
Argyrios Kyrtzidis
8ff6a98a99 [sourcekit] Merge SourceKit into the Swift repo.
The code goes into its own sub-tree under 'tools' but tests go under 'test',
so that running 'check-swift' will also run all the SourceKit tests.

SourceKit is disabled on non-darwin platforms.
2015-11-05 01:09:08 -08:00