Commit Graph

2331 Commits

Author SHA1 Message Date
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
Robert Widmann
2fb5afb755 Remove the @_downgrade_exhaustivity_check hack
This hack was only needed for Swift 3 mode in a narrow case.  Flush it out of the compiler so we can simplify the space engine.
2018-08-24 10:54:43 -07:00
Alex Hoppen
8310056714 Merge pull request #18887 from ahoppen/exp-growth-stream
[SourceKit] Use an exponentially growing appending binary stream to serialize the syntax tree
2018-08-24 08:13:27 -07:00
Alex Hoppen
49f2e14094 [swiftBasic] Use a SmallVector as the underlying storage for ExponentialGrowthAppendingBinaryByteStream 2018-08-23 09:00:27 -07:00
Alex Hoppen
491b11c73c [SourceKit] Use the exponential growth binary stream to write the syntax tree 2018-08-23 08:14:02 -07:00
Saleem Abdulrasool
df208b370c build: honour the libdispatch build type
When configuring libdispatch as part of the swift build on Linux with SourceKit
enabled, we would default to a release build.  However, that results in known
leaks being reported with LSAN when building with a debug standard library.
Pass along the `LIBDISPATCH_BUILD_TYPE` into the CMake build and map that to the
CMAKE_BUILD_TYPE for the project.
2018-08-22 11:16:03 -07:00
Alex Hoppen
7720f55688 Merge pull request #18735 from ahoppen/incremental-serialization
[libSyntax] Add support for incremental (de)serialisation of ByteTree syntax trees
2018-08-21 20:28:29 -07:00
Alex Hoppen
b735673e97 Merge pull request #18848 from ahoppen/remove-reuse-regions
[SourceKit] Remove option to regions reused as part of incremental parsing
2018-08-21 13:52:11 -07:00
Alex Hoppen
9eb0208bb5 [libSyntax] Add support for incremental serialization of ByteTrees 2018-08-21 10:55:15 -07:00
Xi Ge
c4ff67957c cmake/sourcekitd: disable SwiftLang on linux. rdar://43165161 2018-08-20 18:03:03 -07:00
Alex Hoppen
750e7e8f73 [SourceKit] Remove option to regions reused as part of incremental parsing 2018-08-20 11:15:50 -07:00
Erik Eckstein
9a71a0b533 SourceKit: fix a missing cmake dependency of swiftLang on Darwin 2018-08-17 15:47:23 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Xi Ge
b9703c9ef0 cmake/sourcekitd: teach SwiftLang to depend on the actual framework. (#18713)
Tentatively fixing rdar://43165161
2018-08-14 15:51:49 -07:00
Alex Hoppen
d962c8394b Merge pull request #18690 from ahoppen/syntax-tree-as-bytetree
[libSyntax] Support serializing the syntax tree as ByteTree
2018-08-14 11:11:49 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Alex Hoppen
4cda5cbeb0 [libSyntax] Support serializing the syntax tree as ByteTree 2018-08-13 20:03:47 -07:00
Ted Kremenek
fb6b24f1c1 Revert "build: extract libdispatch build for swift" 2018-08-13 10:06:45 -07:00
Michael Gottesman
ba3fa2f5d3 Merge pull request #18500 from compnerd/swift-syntax-dependency
build: extract libdispatch build for swift
2018-08-09 14:38:49 -07:00
Saleem Abdulrasool
f140734584 build: extract libdispatch build for swift
Extract the ExternalProject handling for libdispatch needed to build
SourceKit on Linux into a separate CMake list.  This will allow us to
pull in a dependency on Foundation as well to allow building SwiftSyntax
on Linux which requires Foundation.  Foundation has a dependency on
libdispatch requiring that the external project handling is centralised.
2018-08-08 13:41:49 -07:00