Commit Graph

72 Commits

Author SHA1 Message Date
Robert Widmann
cedef16f54 [NFC] Mark SourceManager::getIDForBufferIdentifier const 2020-09-11 13:54:39 -06:00
Rintaro Ishizaki
8a39c8d9d8 [CodeCompletion Remember the replaced source range in SourceManager 2020-08-12 13:23:30 -07:00
Varun Gandhi
e64d4a0ca0 [NFC] Remove redundant includes for llvm/ADT/StringMap.h. 2020-05-31 13:07:45 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Owen Voorhees
f00953c62d [Diags-Experimental-Formatting] Fixes for printing diagnostics when #sourceLocation is used
- Always use the line number in the actual source file when extracting excerpts and adding highlights/fix-its
- Always use the display name when printing excerpt titles
- Don't print surrounding lines when an annotated line is in a virtual file

This reverts commit f919e047834eddf8863723b9db1fcb8d344d2006.
2020-05-12 18:40:20 -07:00
Owen Voorhees
69b513afaf [Diagnostics] Updated (experimental) diagnostic printing style (#30027)
* [Diagnostics] Experimental diagnostic printing updates

This new style directly annotates small snippets of code with
error messages, highlights and fix-its. It also uses color more
effectively to highlight important segments.

* [Diagnostics] Stage educational notes and experimental formatting behind separate frontend flags

educational notes -> -enable-educational-notes
formatting -> -enable-experimental-diagnostic-formatting

* [Diagnostics] Refactor expensive line lookups in diag formatting

* [Diagnostics] Refactor some PrintingDiagnosticConsumer code into a flush method

* [Diag-Experimental-Formatting] Custom formatting for Xcode editor placeholders

* [Diag-Experimental-Formatting] Better and more consistent textual description of fix its

* [Diags-Experimental-Formatting] Handle lines with tab characters correctly when rendering highlights and messages

Tabs are converted to 2 spaces for display purposes.

* [Diag-Experimental-Formatting] Refactor byte-to-column mapping for efficiency

* [Diag-Experimental-Formatting] Fix line number indent calculation

* [Diag-Experimental-Formatting] Include indicators of insertions and deletions in the highlight line

Inserts are underlined by green '+' chars, deletions by red '-' chars.

* [Diag-Experimental-Formatting] Change color of indicator arrow for non-ASCII anchored messages
* [Diag-experimental-formatting] Make tests less sensitive to line numbering

* [Diag-Experimental-Formatting] Update tests to allow windows path separators

* [Diag-Experimental-Formatting] Bug fixes for the integrated REPL
2020-03-03 08:48:32 -08:00
Rintaro Ishizaki
ff2ccd485c [CodeCompletion] Workaround fast-completion issue in UnqualifiedLookup
In fast-completion, a function body can be replaced with another function
body parsed from a new buffer. In such cases, during typechecking the
expressions in the *new* function body, a source location range check in
UnqualifiedLookup didn't work well because they are not from the same
buffer.

This patch workaround it by skipping the source range checks and returns
'success' in such cases.

rdar://problem/58881999
2020-02-12 10:41:43 -08:00
Meghana Gupta
b8960133ff Add source annotation to SILPrinter under flag -sil-print-sourceinfo (#29444)
* Add source annotation to SILPrinter under flag -sil-print-sourceinfo

rdar://58365252
2020-01-29 11:45:58 -08:00
Xi Ge
7d600eb27a ABI/API checker: teach the tool to emit diagnostics to serialized source location for decls 2019-10-17 16:31:56 -07:00
Xi Ge
76f269586b SourceManager: avoid using additional buffer Id map for external source buffers
SourceManager may outlive ASTContext where external source file paths are managed.
Therefore, we should use the identifier from the memory buffer as the key instead of
using a pointer from an ASTContext.
2019-10-15 16:48:20 -07:00
Xi Ge
c6035f68f0 AST: cache serialized source locations in Decl 2019-10-15 16:05:28 -07:00
Xi Ge
1e22e7c8aa AST: teach Decl::getLoc() to return serialized source loc.
When Decl::getLoc() is called upon a serialized AST and the
serialized source location is available, we lazily open the
external buffer and return a valid SourceLoc instance pointing
into the buffer.
2019-10-15 16:05:28 -07:00
Doug Gregor
1cd5d2edb3 Bring back SourceManager::rangeContainsCodeCompletionLoc() 2019-08-31 16:22:03 -07:00
Rintaro Ishizaki
8bd9fde575 Revert "[code-completion] Disable diagnostics in @functionBuilder bodies"
This reverts commit c6eade1c44.
2019-08-30 15:25:12 -07:00
Xi Ge
f27ccabdb1 SourceKit/Formatting: avoid indenting for consecutive dot-member calls
rdar://52392291
2019-07-12 14:03:03 -07:00
Jonas Devlieghere
fe2ad03f93 Revert "[ClangImporter] Merge Swift & Clang VFS" 2019-07-05 15:30:43 -07:00
Jonas Devlieghere
f359cef5d0 [ClangImporter] Merge Swift & Clang VFS
The clang importer has to deal with two virtual file systems, one coming
from clang, and one coming from swift. Currently, if both are set, we
emit a diagnostic that we'll pick the swift one.

This commit changes that, by merging the two virtual file systems into a
single overlay file system, and using that. To make this possible, we
always initialize the file manager with an overlay file system. In the
clang importer, we then create a new overlay file system, starting with
the one coming from clang, and adding overlays from swift on top.

The motivation for this change is the reproducer infrastructure in LLDB,
which adds a third virtual file system to the mix.
2019-07-03 17:40:31 -07:00
Ben Langmuir
c6eade1c44 [code-completion] Disable diagnostics in @functionBuilder bodies
When performing code-completion inside the body of a @functionBuilder
closure/function, set the flag to suppress diagnostics. This works
around a big performance problem in some complex bodies that do not
typecheck, which is typical during code-completion. A real-world example
with SwitfUI went from ~50 seconds to 0.5. We do not disable diagnostics
in general because the diagnostic paths provide falback types that are
useful to code-completion.

rdar://52356229
2019-07-02 07:33:14 -07:00
Saleem Abdulrasool
adcdc39791 swift: update for LLVM SVN r344140
Update swift's usage of clang::vfs which has been hoisted into LLVM.
2019-02-07 17:53:42 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Jordan Rose
71760bcc4e Replace StringMap with DenseMap when the keys don't need to be owned
StringMap always copies its strings into its own storage. A DenseMap
of StringRefs has the same caveats as any other use of StringRef, but
in the cases I've changed the string has very clear ownership that
outlives the map.

No functionality change, but should reduce memory usage and malloc
traffic a little.
2018-09-13 15:15:27 -07:00
Jordan Rose
4a93ab56e9 Remove SourceManager::getBufferIdentifierForLoc
And tidy up doc comments for other methods that do or don't respect
'#sourceLocation'.

'getBufferIdentifierForLoc' is no longer useful: it doesn't
consistently return either the name of an actual buffer or the name of
a file suitable for diagnostics. As seen in the previous commit, all
remaining uses of it were wrong anyway. Remove it.
2018-08-29 11:46:41 -07:00
Jordan Rose
fc9ea1e329 Add Lexer::IsHashbangAllowed, drop SourceManager::getHashbangBufferID (#18534)
Having this be a single buffer hardcoded in the SourceManager and set
by all clients is silly. SourceFiles with the 'Main' kind are allowed
to have hashbang lines (`#!`), other files are not. And anyone
manually setting up a Lexer can decide for themselves.

No intended behavioral change.
2018-08-07 08:25:05 -07:00
Robert Widmann
917e94d11c Introduce SourceManager::getDisplayNameForLoc
Add an abstraction to retrieve a name suitable for display for a given
source location for use with diagnostics, debug locations, and magic
file literals.
2018-07-31 13:16:14 -07:00
Robert Widmann
0e58b7fd14 Plumbing for a Virtual File System
Adds the -vfsoverlay frontend option that enables the user to pass
VFS overlay YAML files to Swift. These files define a (potentially
many-layered) virtual mapping on which we predicate a VFS.

Switch all input-based memory buffer reads in the Frontend to the new
FileSystem-based approach.
2018-07-31 13:16:14 -07:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
Bob Wilson
37e7d1c627 Merge remote-tracking branch 'origin/master' into master-next 2017-01-08 17:07:46 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Bob Wilson
13da3fa8b1 Merge remote-tracking branch 'origin/master' into master-next 2016-12-04 18:16:09 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Bob Wilson
1caba3e209 Merge remote-tracking branch 'origin/master' into master-next 2016-10-17 11:52:21 -07:00
Bob Wilson
3fd92f82e8 Use StringRef in more places to match recent llvm changes.
llvm r283043 and possibly other recent changes switch to use StringRef
instead of char* pointers. Update Swift to match. In some cases, this is
a clear improvement. It would be good to assess the impact on memory use,
particularly for the Filename component of source locations.

Note that the change to SILLocation::isNull fixes an apparent bug where
the location was treated as null when the filename was *not* null.
2016-10-15 11:02:07 -07:00
Mishal Shah
09cbffb3e4 Initialize CachedVFile with nullptr 2016-10-14 15:29:18 -07:00
Dan Raviv
29d76f3b68 Canonize swift header files headers and footers
- Added missing ifdef guard in PointerIntEnum header
- Consistent naming convention for ifdef guards
- Consistent 'end namespace swift'
- Consistent single EOL at end of header files
2016-03-23 09:04:12 +02:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Xi Ge
5ca83d97a5 [InterfacePrint] Enhance ASTPrinter to support type-specific interface printing.
When users try to print the interface of a specific type (most often through cursor
infor query of SourceKit), we should simplify the original decls by replacing
archetypes with instantiated types, hiding extension details, and omitting
unfulfilled extension requirements. So the users can get the straight-to-the-point
"type interface". This commit builds the testing infrastructure for this feature,
and implements the first trick that wraps extension contents into the interface body.

This commit also moves some generic testing support from SourceKit to Swift.

Swift SVN r32630
2015-10-12 19:14:58 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Jordan Rose
d3a9e58133 Use Nothing instead of {} to initialize Optionals.
In preparation for the switch to llvm::Optional, which has an explicit
default constructor.

Swift SVN r22470
2014-10-02 18:51:33 +00:00
Jordan Rose
ff59af1e69 Only test that all SourceManager buffers are valid when actually still valid.
Some of the buffers are owned by the ClangImporter, so after the
ClangImporter's been deallocated, the SourceManager isn't going to be fully
valid any more.

Should fix issues from r21958.

Swift SVN r21989
2014-09-16 22:41:27 +00:00
Jordan Rose
3d3c6fa730 [ClangImporter] Fix crash when a diagnostic is reported during module building.
This rare crash happens when
1. A diagnostic is reported when building a Clang module.
2. The diagnostic is mapped to a Swift diagnostic by mirroring the Clang
   source buffer as a Swift source buffer (via non-owning reference).
3. The Clang CompilerInstance used specifically to build the module is
   destroyed.
4. Some /new/ buffer is allocated in the same memory spot as the old buffer.
5. Some new Clang diagnostic occurs in the new buffer.
6. The Swift source manager asserts when trying to set up a virtual name
   for the diagnostic in the second imported buffer, because there's already
   a name for that region.

The fix, because we don't expect diagnostics from modules to appear very
often, is to keep any clang::SourceManagers alive if diagnostics are emitted
in their buffers. We can revisit this if/when Swift's source manager
(currently built on llvm::SourceMgr) has the ability to remove buffers.

Many thanks to Greg for noticing the problem, tracking it down, and providing
a diff to make it fail reproducibly under GuardMalloc. I've tried to preserve
the spirit of that diff in the new logic in ~SourceManager, which will also
fail reliably with GuardMalloc (and probably ASan).

rdar://problem/18285805

Swift SVN r21958
2014-09-15 22:26:48 +00:00
Dmitri Hrybenko
42b25d939d Update for upstream LLVM changes is MemoryBuffer APIs
Swift SVN r21409
2014-08-22 08:28:03 +00:00
Jordan Rose
0b933acfda [ClangImporter] Use #line when reporting module build errors.
...or at least the same machinery as #line. We add a (referential) mirror
of the Clang buffer to Swift's source manager, then remap that particular
line to whatever Clang currently thinks is the presumed location for that
line. (This means we respect Clang line directives too.)

This also modifies Swift's source manager to be more forgiving about adding
the same virtual file range twice; it will tell you when you try to do it.

<rdar://problem/16596800>

Swift SVN r20572
2014-07-25 23:01:45 +00:00
Jordan Rose
29f8c25d63 Move #line state into the Parser and out of the SourceManager.
As part of this change, allow #line directives to extend to the end of the
file, rather than requiring a reset.

Note that #line regions that start or end within function bodies will not
behave correctly when in delayed parsing modes. This was true before and
after this commit. (#line regions contained entirely within a function and
not within any other #line regions should be fine.)

Swift SVN r20571
2014-07-25 23:01:43 +00:00
Dmitri Hrybenko
b9b7121d5c More updates for '0' being new invalid buffer ID
Swift SVN r19610
2014-07-07 14:57:24 +00:00
Pete Cooper
c248852485 Update to ToT r212398 where BufferID is unsigned and has 0 be the invalid buffer.
Swift SVN r19608
2014-07-07 14:49:04 +00:00
Argyrios Kyrtzidis
e64821d268 [IDE] Search all comments for 'FIXME:', 'TODO:', 'MARK:' and report them in the syntax model.
Swift SVN r19423
2014-07-01 19:21:16 +00:00
Adrian Prantl
400f1774e9 Add support for a #line directive.
This patch extends the syntax with a new #line directive that is inspired
by the homonymous CPP directive. It can be specified in all locations a #if
is legal (Stmt, Decl).

Semantics
---------

#line 42 "file.swift"
This makes diagnostics and debug information behave as if the subsequent
lines came from file.swift+42.

#line // without arguments
This switches back to the main source file and the switches back to the
normal line numbering. Any previous #line directives will result in gaps
in the main file.

Rationale
---------

LLDB and the REPL need this for making expressions that are entered into
the expression evaluator or REPL debugable. For more info see
<rdar://problem/17441710> Need #line directive or something similar so we can enhance the debugging of expressions and REPL

Also, I believe the stdlib would benefit from this and it would allow us
to get rid of the line-directive wrapper script.

Swift SVN r19384
2014-06-30 23:50:11 +00:00
Jordan Rose
574054b8fd Distance SourceManager from llvm::SourceMgr.
...in preparation for non-source locations, i.e. locations that don't come
frome source buffers.

No functionality change, but a fair bit of SourceManager API and idioms have
changed.

Swift SVN r18942
2014-06-17 01:15:47 +00:00
Dmitri Hrybenko
86cd6260ce SourceManager: use 'unsigned' as buffer ID type
Swift SVN r14849
2014-03-09 16:24:11 +00:00