Commit Graph

479 Commits

Author SHA1 Message Date
Robert Widmann
2ca8e66770 [NFC] Refactor the construction of SILRemarksStreamer
The Remarks Streamer's installation seemed a bit overly complex, so simplify it in a few places:

* Refactor sil-opt to install the remarks options into the SILOptions for the SILModule

This reduces the parameter bloat in createSILRemarkStreamer. All of this data is freely derivable from the SILModule alone.

* Refactor createSILRemarkStreamer into SILRemarkStreamer::create

With the new reduction in parameters, we can hide the internal constructor and introduce a smart constructor that vends a unique pointer to clients.

* setSILRemarkStreamer -> installSILRemarkStreamer

Since the information to create a streamer is now entirely derivable from a module, remove a layer of abstraction and have the module directly construct a streamer for itself.

* Give SILRemarkStreamer its own LLVMContext

The remarks streamer just needs scratch space. It's not actually "installed" in a given context. There no reason to use Swift's Global Context here.

* Give the SILRemarkStreamer ownership of the underlying file stream

The SILModule didn't actually use this member, and it seems like somebody needs to own it, so just give it to the remarks streamer directly.
2020-04-17 14:02:45 -07:00
Robert Widmann
bc31c7fe47 [NFC] Internalize the LLVMContext for LLVM IR Code Generation 2020-04-17 12:22:36 -07:00
Robert Widmann
85fdc7a555 Merge pull request #31080 from CodaFi/why-I-R-ta
Give IRGenModule Ownership of its LLVMContext
2020-04-17 10:32:46 -07:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Robert Widmann
de304b5bee [NFC] Introduce GeneratedModule
swift::GeneratedModule encapsulates an llvm::Module, llvm::LLVMContext
pair that must live and die together. It has  convenient accessors for
projecting the module and context components. The meat of this type is
the two conversion functions, which transfer ownership of either the
module component to the caller or the module and context to ORCJIT.

This is because ORC enforces an ownership contract that is distinct from
LLVM's rather wild ownership story for modules and their associated
contexts. See http://llvm.org/docs/ORCv2.html#how-to-use-threadsafemodule-and-threadsafecontext
2020-04-16 11:57:44 -07:00
David Ungar
9dcd2b52b2 Allocate LLVMContext in IRGenModule. 2020-04-16 11:57:44 -07:00
Robert Widmann
a337b67f69 Stage In Flags To Fall Back To Manual Tracking
Request-based incremental dependencies are enabled by default. For the time being, add a flag that will turn them off and switch back to manual dependency tracking.
2020-03-31 16:16:53 -07:00
Robert Widmann
58e63f7185 Merge pull request #28313 from owenv/verifier-consumer
[DiagnosticVerifier] Make DiagnosticVerifier a DiagnosticConsumer
2020-03-30 17:46:30 -07:00
Owen Voorhees
465bab002f [DiagnosticVerifier] Make Diagnostic Verifier a DiagnosticConsumer subclass
Update DiagnosticVerifier to respect color flags

Improve DiagnosticVerifier test coverage

verifier updates to support new llvm stable branch
2020-03-28 12:29:53 -07:00
Owen Voorhees
791312fb74 Turn Educational Notes On-By-Default (#30583)
* [Diagnostics] Turn educational notes on-by-default

* [Diagnostics] Only include educational notes in printed output if -print-educational-notes is passed

* Make -print-educational-notes a driver option

* [Diagnostics] Issue a printed remark if educational notes are available, but disabled

* [docs] Update educational notes documentation and add a contributing guide

* [Diagnostics] Cleanup PrintingDiagnosticConsumer handling of edu notes

* Revert "[Diagnostics] Issue a printed remark if educational notes are available, but disabled"
For now, don't notify users if edu notes are available but disabled. This decision can be reevaluated later.
2020-03-27 15:29:48 -07:00
Hamish Knight
6f212634c8 Add getOperatorDecls to FileUnit and ModuleDecl
Query the SourceLookupCache for the operator decls,
and use ModuleDecl::getOperatorDecls for both
frontend stats and to clean up some code
completion logic.

In addition, this commit switches getPrecedenceGroups
over to querying SourceLookupCache.
2020-03-27 09:44:55 -07:00
Nathan Hawes
a785fa6cee [Frontend][Index] Add frontend option to skip indexing the stdlib (for test performance)
Several tests related to indexing system modules were taking a considerable
amount of time (100+ seconds in the worst case) indexing the standard library.
This adds a frontend option to skip it and updates those tests to pass it.
2020-03-25 14:36:23 -07:00
Michael Forster
345a9147ec Explicit SmallString->std::string conversion.
This is only needed temporarily until commit d7049213 from upstream
LLVM hits the swift/master branch.
2020-03-13 19:16:49 +01:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Xi Ge
df0493c288 PrintAsObjC: allow users to specify bridging header relative path for printing
Compatibility header may #import bridging header if specified with -import-underlying-module.
How these two headers are relative to each other is subject to project setting. To accommodate
this, we should allow users to specify bridging header directory for header generating purposes.

rdar://59110975
2020-03-11 17:09:53 -07:00
Robert Widmann
ef149d5c86 Merge pull request #30135 from CodaFi/verily-i-depend-on-thee
[Incremental] Introducing: DependencyVerifier
2020-03-03 22:01:38 -08:00
Robert Widmann
f85ec3825f Address review feedback 2020-03-03 16:46:04 -08:00
Visoiu Mistrih Francis
aaab1869af Merge pull request #29650 from francisvm/sil-remark-streamer
[Remarks] Add a specialized RemarkStreamer for SIL remarks
2020-03-03 09:30:17 -08: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
Francis Visoiu Mistrih
e724ebab6b [Remarks] Add a specialized RemarkStreamer for SIL remarks
This allows the usage of the whole remark infrastructure developed in
LLVM, which includes a new binary format, metadata in object files, etc.

This gets rid of the YAMLTraits-based remark serialization and does the
plumbing for hooking to LLVM's main remark streamer.

For more about the idea behind LLVM's main remark streamer, see the
docs/Remarks.rst changes in https://reviews.llvm.org/D73676.

The flags are now:

* -save-optimization-record: enable remarks, defaults to YAML
* -save-optimization-record=<format>: enable remarks, use <format> for
serialization
* -save-optimization-record-passes <regex>: only serialize passes that
match <regex>.

The YAMLTraits in swift had a different `flow` setting for the debug
location, resulting in some test changes.
2020-03-02 18:33:20 -08:00
Robert Widmann
6ccba70bb3 [Incremental] Introducing: DependencyVerifier
The DependencyVerifier is a DiagnosticVerifier-alike utility that takes annotations in user code and transforms them into a set of expectations. Those expectations are met by corresponding "obligations", which are constructed by reading the contents of the referenced name tracker associated with the source files for each of the primary inputs to a frontend job. The verifier will then pair off expectations and obligations, and ensure that any remaining unpaired obligations are diagnosed as failures.

This tool will not only ensure the correctness of the referenced name tracker's output, it will provide us with tests that ensure its output is stable, and give us the confidence to replace it with an evaluator-based tracking scheme in the future.

Resolves rdar://59773883
2020-03-02 16:45:37 -08:00
Robert Widmann
d3edb5b15a [Incremental] Plumb -verify-incremental-dependencies Through The Frontend and Driver
When enabled at the driver level, the frontends will inherit the flag. For each frontend that recieves this option, all primaries will have their reference dependencies validated.
2020-03-02 16:45:37 -08:00
Robert Widmann
a6651a920d Generalize and fix compiler resource freeing before LLVM
Centralize part of the routine that selects which resources to free. Then, add an additional condition for -dump-api-path.

Before, if this option were specified along with -emit-llvm or -c, the compiler would try to rebuild the torn-down ModuleDecl and crash trying to access the torn-down ASTContext.
2020-02-27 17:12:58 -08:00
Robert Widmann
7dd000bdb5 [NFC] Remove the stats reporter parameter from FrontendTool entrypoints
Now that the CompilerInstance owns the stats reporter, use that instead.
2020-02-27 17:12:58 -08:00
Robert Widmann
535bb9bf8f [NFC] UnifiedStatsReporter is owned by CompilerInstance
The lifetime of the UnifiedStatsReporter was not entirely clear from context. Stick it in the CompilerInstance instead so it can live as long as the compile job.

It is critical that its lifetime be extended beyond that of the ASTContext, as the context may be torn down by the time code generation happens, but additional statistics are recorded during LLVM codegen.
2020-02-27 17:12:57 -08:00
Varun Gandhi
2dfd5694fa [NFC] Don't crash when we see an empty filename for a module. (#30099)
Fixes rdar://problem/59769612.
2020-02-27 12:58:47 -08:00
Xi Ge
8c2a041822 Front-end: add an option to not lock interface file when building module
This could help fix a flaky test.

Related to: rdar://58578342
2020-02-25 12:13:14 -08:00
Alexis Laferrière
901392896d [Frontend] Output the private module interface with the SPI info 2020-02-19 14:17:14 -08:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00
Xi Ge
e013f1fb81 TBDGen: add a flag for embedding external symbols in emitted tbd file
Static-linked libraries could add symbols to the final tbd file. We need
this flag to specify additional module names to collect symbols from.

rdar://59399684
2020-02-12 13:47:59 -08:00
swift-ci
9d310503ce Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-03 19:03:03 -08:00
Brent Royal-Gordon
c964d18467 Add target variant to -print-target-info 2020-02-01 15:33:38 -08:00
swift-ci
9ddff174ce Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-22 18:24:42 -08:00
Xi Ge
366e24ed51 IRGen: don't proceed to IRGen if collecting linker directives failed 2020-01-22 16:22:33 -08:00
swift-ci
11550b4c0c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-22 09:43:43 -08:00
Varun Gandhi
f6643af650 [Printer] Update printSIL to make sure LLDB doesn't break.
For more context, see:
1. https://github.com/apple/swift/pull/29239 - original PR which introduced
   the change, including an LLDB-side change.
2. The immediately preceding commit, which reverted this change.
3. https://github.com/apple/swift/pull/29350 which revealed some breakage
   caused by the changes in PR 29239 (unrelated to printing).
2020-01-22 09:05:39 -08:00
Varun Gandhi
d9a7a7d49e Revert "[Printer] Conditionally print Clang types in emitted SIL."
This reverts commit a27c5f0a16.
2020-01-22 09:04:52 -08:00
swift-ci
e28c558c72 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 09:43:46 -08:00
Varun Gandhi
a27c5f0a16 [Printer] Conditionally print Clang types in emitted SIL.
Hopefully, this helps us debug Clang type mismatches better.
2020-01-17 16:22:39 -08:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00
Varun Gandhi
8510b9234b [NFC] Add an EmitSortedSIL member to SILOptions for consistency. (#29210)
It is a bit strange to have the FrontendOptions being used in writeSIL
instead of SILOptions, so this PR fixes that.
2020-01-15 16:25:41 -08:00
Robert Widmann
2af598fb52 [Gardening] Const-qualify Many Usages of CompilerInstance
For those operations that do not need to emit diagnostics or manipulate modules, there's no reason to mutate the passed instance.
2020-01-14 09:02:10 -08:00
Robert Widmann
8fe25f7530 [NFC] Remove CompilerInstance::setSILModule
The REPL was using the CompilerInstance to stash this parameter, then it would immediately move it into IRGen.  Drop the setter and pass this data directly.
2020-01-13 22:01:41 -08:00
Robert Widmann
bd57f14661 [NFC] Push const IRGenOptions and SILOptions everywhere 2020-01-13 22:01:41 -08:00
Robert Widmann
d63053d64e [Gardening] Remove more unused parameters 2020-01-13 22:01:41 -08:00
Robert Widmann
5c746fafaa [NFC] Compute remaining IRGen options in the argument parser
Add an extra phase after all the argument parsing has completed that sets inter-option-dependent flags.  This allows for the const-qualification of IRGenOptions, and removes some weird state flipping in FrontendTool.
2020-01-13 22:01:41 -08:00
Robert Widmann
eb61931012 [NFC] Grab the private discriminator for a file in IRGenDebugInfo
This was being done at an odd point in the frontend presumably because by that point the private discriminator had been fully computed.  Instead, push the conditions for generating the prefix data down to debug info generation and stop mutating IRGenOptions::DebugFlag in the frontend.
2020-01-13 22:01:41 -08:00
swift-ci
b03a280b3b Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 21:23:26 -08:00
Xi Ge
90f59e4336 TBDGen: teach the compiler to take a json file indicating previous install names
Using the new linker directives $ld$previous requires the compiler to know the previous
install names for the symbols marked as removed. This patch teaches the compiler
to take a path to a Json file specifying the map between module names and previous
install names. Also, these install names can be platform-specific.

Progress towards: rdar://58281536
2020-01-13 17:45:40 -08:00
swift-ci
e280ebe9b7 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-12 21:44:31 -08:00