Commit Graph

2350 Commits

Author SHA1 Message Date
Doug Gregor
264b680e96 Merge branch 'master' into immortal-type-checker 2018-10-10 20:36:23 -07:00
Doug Gregor
599e07e5d9 [Type checker] Keep the type checker alive as long as the ASTContext is.
It is possible for the SIL optimizers, IRGen, etc. to request information
from the AST that only the type checker can provide, but the type checker
is typically torn down after the “type checking” phase. This can lead to
various crashes late in the compilation cycle.

Keep the type checker instance around as long as the ASTContext is alive
or until someone asks for it to be destroyed.

Fixes SR-285 / rdar://problem/23677338.
2018-10-10 16:44:42 -07:00
swift-ci
2fedf28c64 Merge pull request #19800 from compnerd/repackage 2018-10-09 16:51:49 -07:00
Saleem Abdulrasool
0295a83237 SourceKit: re-package libdispatch, BlocksRuntime
The SourceKit component requires libdispatch and BlocksRuntime to run.
We build the libraries as part of the build and use it via imported
targets.  Ensure that the dependencies get installed for use at runtime.
2018-10-09 13:23:24 -07:00
Saleem Abdulrasool
db7b7a7010 SourceKit: the swift-lang requires the standard library
The swift-lang swift module requires the standard library to be built and is
part of the standard library component.  Ensure that this is taken into
consideration when we attempt to build it.
2018-10-09 12:14:11 -07:00
Nathan Hawes
5c568af436 [incrParse] Fix bug mapping a node's location back to its location in the cached syntax tree
Also fix Edit::intersectsOrTouchesRange check only returning true when the
ranges overlapped, rather than when they overlapped or 'touched'.

Resolves rdar://problem/45108439
2018-10-08 15:44:38 -07:00
Saleem Abdulrasool
0df7b2f4be SourceKit: enable builds for Windows
SourceKit's build is now ammenable to building for Windows.  Generalize the path
to enable building it for Windows as well as Linux.  The libdispatch build for
the compiler is needed for all non-Darwin targets currently.
2018-10-04 16:44:54 -07:00
Saleem Abdulrasool
6ab8389ecf Merge pull request #19674 from compnerd/shared-blocks-are-back
SourceKit: use shared BlocksRuntime
2018-10-04 15:31:57 -07:00
Nathan Hawes
b5b1d9ab23 Revert "[SourceKit] Make each Variant keep a strong reference to its SourceKitdResponse context" 2018-10-04 10:36:17 -07:00
Saleem Abdulrasool
a140c41ce0 build: be a bit more resilient
In the case that a system update temporarily breaks the command, the output may
be empty, and this can cause CMake to fail in a weird manner.  Quote the
variable to be more resilient to the transient failure.
2018-10-03 18:24:17 -07:00
Saleem Abdulrasool
7c9b6f03bf Merge pull request #19668 from compnerd/explicit-BlocksRuntime
SourceKit: explicitly link against BlocksRuntime as well
2018-10-03 18:13:36 -07:00
swift-ci
ebd4d9f67c Merge pull request #19680 from compnerd/exports 2018-10-03 16:43:33 -07:00
Nathan Hawes
700384aed4 Merge pull request #19689 from nathawes/keep-sourcekitd-response-alive-while-variant-lives
[SourceKit] Make each Variant keep a strong reference to its SourceKitdResponse context
2018-10-03 16:11:20 -07:00
Saleem Abdulrasool
309e4dafc1 SourceKit: correct header include order
Internal.h must be included before sourcekitd.h to ensure that we get the
correct definition for Windows targets.  The inclusion of `sourcekitd.h` is not
needed after the inclusion of `Internal.h` so simply remove the inclusion.
2018-10-03 13:56:40 -07:00
Saleem Abdulrasool
e7bc37b748 SourceKit: explicitly link against BlocksRuntime as well
On Darwin platforms, libdispatch and libBlocksRuntime are re-exported from
libSystem (via LC_REEXPORT_DYLIB).  Other platforms do not have libdispatch and
libBlocksRuntime in their C runtime, so we need to explicitly link against them.
Now that we are building BlocksRuntime with hidden visibility, we do not
accidentally get the symbols from libdispatch.
2018-10-03 13:36:18 -07:00
Nathan Hawes
88b1ae9d50 [SourceKit] Make each Variant keep a strong reference to its SourceKitdResponse context
sourcekitd_variant_t is only safe to use while the sourcekitd_response_t it was
retrieved from is still alive, so keep a strong reference to SourceKitdResponse
(the Swift wrapper of sourcekitd_response_t) in each Variant (the Swift wrapper
of sourcekitd_variant_t).
2018-10-03 11:07:04 -07:00
Saleem Abdulrasool
3469797df5 SourceKit: use shared BlocksRuntime
Adjust the SourceKit's embedded libdispatch build to use the shared build of
BlocksRuntime now that we can generate that.
2018-10-03 09:27:49 -07:00
Saleem Abdulrasool
2493b11f27 sourcekitd-test: be more error resilient
Ensure that we handle the error case as well.  Fix up the type mismatches in the
process.
2018-10-02 15:45:53 -07:00
Saleem Abdulrasool
33e9037f64 SourceKit: handle Windows codepaths better
Fill in some of the Windows codepaths that were previously missing.  This allows
us to at least compile the SourceKit sources.  More changes are required to the
build system to use the correct compiler when cross-compiling to get the
dependencies correct.
2018-10-01 21:35:14 -07:00
Saleem Abdulrasool
6c8c7151ff SourceKit: repair the build when cross-compiling
Not all targets (CMAKE_SYSTEM_NAME) use `lib` and `.a` for the static library
name.  Adjust the name properly for the host that we are building for.  This
repairs the build when performing a cross-compile from Linux to Windows.
2018-10-01 14:54:06 -07:00
swift-ci
9034066396 Merge pull request #19642 from compnerd/inproc-or-xpc 2018-10-01 12:29:28 -07:00
Saleem Abdulrasool
daabc237fa SourceKit: libdispatch swift requires swift stdlib
When building libdispatch for SourceKit, only enable the swift overlay
components if the swift standard library is being built.  This allows building
just the compiler and SourceKit.
2018-10-01 10:02:17 -07:00
Saleem Abdulrasool
f1997236fe SourceKit: hoist decision for building InProc
The decision to whether build InProc or as an XPC service is needed for the
test tools as well.  Rather than recompute it for the tests as well, hoist it to
the top level for the SourceKit project.  This repairs the build of the
SourceKit tests on non-Darwin hosts.
2018-10-01 09:58:53 -07:00
Bruno Rocha
bf84b297f8 [SourceKit] Allow module references to be indexed (#19243)
Module references get indexed as a 'module' symbol; they get USRs similar to how clang would assign a USR for a module reference.

JIRA: https://bugs.swift.org/browse/SR-8677
2018-09-28 12:21:38 -07:00
Ben Langmuir
b04ffcca86 [sourcekit] Change getASTManager() to return shared_ptr
Addressing review feedback: this avoids calling shared_from_this() from
outside the implementation.  Note: it is not possible to use private
inheritance of enable_shared_from_this to prevent this issue in general,
because enabled_shared_from_this relies on the shared_ptr constructor
being able to detect that the type has this inheritance, which means it
must be public.
2018-09-25 16:42:41 -07:00
Ben Langmuir
2fbe270c6d [sourcekit] Make NotificationCenter a strong reference
Addressing review feedback: the notification center does not introduce a
cycle, so no need for weak.
2018-09-25 16:23:24 -07:00
Ben Langmuir
f51df32478 [sourcekit] Remove bare reference to SwiftLangSupport in editor document
While I'm not aware of this causing an issue in practice it was just
begging to trigger a use-after-free if we ever used this reference in a
new method since the editor document is accessed asynchronously.
2018-09-25 14:57:33 -07:00
Ben Langmuir
b3422c1e9d [sourcekit] Stop storing a bare reference to LangSupport in ASTManager
This fixes a use-after-free when an AST build finishes after shutdown().
2018-09-25 14:57:33 -07:00
Ben Langmuir
1015da026e [sourcekit] Remove reference to global context from SwiftLangSupport NFC
While the SwiftLangSupport doesn't currently outlive the global context
it clarifies the ownership to just store the weak reference we care
about instead of referencing the owning context. In the future we may
want to ref-count the lang support, in which case we'd need to do this
to avoid a cycle anyway.
2018-09-25 14:57:32 -07:00
Ben Langmuir
cc22c61d92 [sourcekit] Use a shared_ptr for the SwiftASTManager
When the server shuts down we may still have outstanding async work to
build an AST, so use a shared_ptr + weak_ptr instead of unique_ptr +
unowned references.
2018-09-25 14:57:32 -07:00
Ben Langmuir
c6776db83d [sourcekit] Use a shared_ptr for the NotificationCenter
When the server shuts down we may still have outstanding async work that
can attempt to trigger a notification, so use a shared_ptr + weak_ptr
instead of unique_ptr + unowned references.
2018-09-25 14:57:32 -07:00
Ben Langmuir
a7b00dda88 Merge pull request #19507 from benlangmuir/fix-editing-lock-inversion
[sourcekit] Fix a lock inversion in editorReplaceText found by TSan
2018-09-25 11:46:47 -07:00
Ben Langmuir
e2ee2b6a67 [sourcekit] Fix a lock inversion in editorReplaceText found by TSan
When triggering replaceText we were locking the EditorDocument then the
ASTProducer, but during AST building we do the reverse. This would cause
a deadlock if these two bits of code raced. Break the cycle by dropping
the editor lock when calling the ASTManager.

Thank you TSan!
2018-09-21 11:24:58 -07:00
Nathan Hawes
44f4df49df [sourcekit] Fix line+column -> offset conversion when on the last line of a file with no terminating newline
This was causing local refactorings (which are line+column-based) to fail due to
the provided location being considered invalid, even though the available
refactorings request (which uses offset directly) reported them as available.
2018-09-20 18:25:45 -07:00
Ben Langmuir
a8d549326a [sourcekit] Fix a race between AST processing and reopening a document
When a document is opened twice without closing it we re-initialize its
internal data. Make sure we don't race with code that accesses that data.

Found by TSan!
2018-09-13 14:39:46 -07:00
Jordan Rose
37ec248823 Add ModuleDecl::ReverseFullNameIterator
Package up the logic that generates a full Clang module name, so that
(a) we don't have to deal with clang::Module in quite as many places
in the /Swift/ compiler, and (b) we can avoid the cost of a temporary
string in a few places.

The main places where this is /not/ adopted is where we don't just
want to know the parent module name, but actually the module itself.
This is mostly indexing-related queries, which use the very similar
ModuleEntity class also defined in Module.h. I didn't quite see an
obvious way to unify these, but that might be where we want to go.

No functionality change.
2018-09-06 19:53:59 -07:00
Slava Pestov
8801aa67d3 Merge pull request #19133 from slavapestov/access-level-cleanup
Access level cleanup
2018-09-06 16:46:40 -07:00
Xi Ge
24b0eac9a4 Parser: parse members in extension decls incrementally. 2018-09-05 17:00:39 -07:00
Slava Pestov
c51f884879 SourceKit: Just always call getFormalAccess() 2018-09-05 16:51:20 -07:00
Jordan Rose
2f6b4cdbe8 Merge pull request #19054 from jrose-apple/nocturnal
Honor #sourceLocation filenames in several more places
2018-08-30 13:02:50 -07:00
Brent Royal-Gordon
4d7046f95a [SourceKitSwiftLang] Avoid call with null this
If an imported Objective-C method had no owning clang module, passCursorInfoForDecl() would call clang::Module::getFullModuleName() on a null instance. The current implementation of this method happens to terminate its loop immediately and return an empty string, but it’s best not to depend on this. Fixes a UBSan error in SourceKit/Mixed/cursor_mixed_header.swift.
2018-08-29 22:53:40 -07:00
Brent Royal-Gordon
461a213441 [SourceKit] Perform unaligned access safely
CompactArrayReader has a bad habit of doing type-punning in ways that could cause unaligned memory accesses. 21 tests trigger a UBSan assertion because of this. Use memcpy instead to avoid the issue.
2018-08-29 22:53:40 -07:00
Alex Hoppen
49d0d5b7a3 [libSyntax] Make the ByteTree protocol version consist of a major and minor component 2018-08-29 13:40:50 -07:00
Jordan Rose
63cd1258ea Stop using SourceManager::getBufferIdentifierForLoc to find buffer IDs
The right way is findBufferContainingLoc. getBufferIdentifierForLoc is
both slower and wrong in the presence of #sourceLocation.

I couldn't come up with a test for the change in IDE/Utils.cpp because
refactoring still seems to be broken around #sourceLocation. I'll file
bugs for that.
2018-08-29 11:46:41 -07:00
Jordan Rose
9a794531c7 [SourceKit] Honor #sourceLocation in reporting diagnostics 2018-08-29 11:46:41 -07:00
Jordan Rose
e4e4f3e4f5 Break Driver's dep on Frontend: make createCompilerInvocation uglier
But not even that much uglier; at all three call sites this will save
an allocation, and for the most important one (SourceKit) we can now
avoid creating a temporary CompilerInvocation just to copy into a
longer-lived one.

With this change, Driver no longer depends on Frontend, which means...
well, slightly faster builds of the compiler itself, but not much
else.
2018-08-27 20:47:58 -07:00
John McCall
140ee562d3 Merge pull request #18840 from rjmccall/dematerializeForSet
Replace materializeForSet with the modify coroutine
2018-08-27 21:02:24 -04:00
Alex Hoppen
209ba2d691 Merge pull request #18955 from ahoppen/optimized-fixed-data
[byteTree] Write fixed sized data using an optimized form
2018-08-27 15:27:14 -07:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
Alex Hoppen
33d86d5cb6 [byteTree] Write fixed sized data using an optimized form
If we know the size of a type at compile time (like we do for all the
integer types), it is cheaper to assign the data buffer directly instead
of using a memcpy.
2018-08-24 15:27:23 -07:00