Commit Graph

51 Commits

Author SHA1 Message Date
Alex Hoppen
c6c40de73d [IDE] Pass a SourceRange instead of a CharSourceRange in SemaAnnotator::passReference
Most `SemaAnnotator`s don’t actually care about the char source range. Instead, they only care about the start location of the reference, which is also included in `SourceRange`. Computing a `CharSourceRange` from a `SourceRange` is kind of expensive because it needs to start a new lexer.

To avoid this overhead, pass `SourceRange` to `SemaAnnotator::passReference` and related functions and let the clients compute the `CharSourceRange` when needed.

This reduces the overhead of index-while-building by about 10%.
2025-06-04 18:01:47 +02:00
Jan Svoboda
0aeba05790 [Frontend] Use new LockFileManager APIs (#80123) 2025-03-24 10:14:24 -07:00
Xi Ge
eb6933bbed Merge pull request #78337 from nkcsgexi/141850408
FineModuleTracing/CAS: move the computation of whether fine module trace will be emitted to an early stage.
2025-01-02 09:26:45 -08:00
Doug Gregor
d593442cc4 Add module trace information for strict memory safety
Extend the module trace format with a field indicating whether a given
module, or any module it depends on, was compiled with strict memory
safety enabled. This separate output from the compiler can be used as
part of an audit to determine what parts of Swift programs are built
with strict memory safety checking enabled.
2024-12-24 12:27:35 -08:00
Xi Ge
049f381807 FineModuleTracing: being blocklisted in collecting fine trace shouldn't change that the promised file is being emitted 2024-12-20 21:33:24 -08:00
Xi Ge
c8fa52b96d FineModuleTracing/CAS: move the computation of whether fine module trace will be emitted to an early stage.
CAS needs to determine if an output is needed very early (when computing supplementary outputs) in the pipeline so we can do caching and replays.

Resolves: rdar://141850408
2024-12-20 19:09:35 -08:00
Xi Ge
c965343f54 Frontend: add a flag to disable fine-grained module tracing 2024-12-13 16:07:15 -08:00
Xi Ge
7f3c9cbeb1 FineModuleTrace: add a blocklist action for skipping fine module tracing 2024-12-13 13:49:38 -08:00
Xi Ge
3f69aed0f8 FineModuleTracing: use requested action type to further gate whether emitting fine-grained module trace is supported.
Emitting fine-grained module tracing files during full compilation should be sufficient for the use case in design. Other
swift-frontend invocations, such as emitting modules, doesn't need fully type-checked AST to perform the action, therefore
requesting/walking the fully typechecked AST to emit those tracing files may introduce performance overhead.
2024-12-10 22:10:25 -08:00
Xi Ge
c868515fae FineModuleTracing: only collect fine-grained tracing for those source files that compiler promises to type check.
rdar://141065994
2024-12-10 16:56:16 -08:00
Xi Ge
5deb21d4fe FineModuleTrace: avoid emitting trace file when lazy type checking is enabled.
When lazy type checking is enabled, the generated AST to walk on may contain function bodies that
are not fully type-checked. Walking on these function bodies could expose latent bugs.

Resolves rdar://140818215
2024-12-07 22:13:10 -08:00
Xi Ge
4a5d041932 FineModuleTrace: reposition the currently ObjC message specific trace files to be a more general purposed file for tracing fine-grained dependencies. NFC 2024-11-20 12:41:21 -08:00
Xi Ge
51a68ecdd1 ModuleObjCTrace/CAS: compute objc trace file paths via the canoical supplementary output paths computation
CAS support in compiler relies on supplementary paths to decide the mapping between input and output files. Therefore, we
have to compute the paths of the module ObjC trace files in this canonical place to have CAS support for
this newly added ObjC message trace files.
2024-11-20 08:52:15 -08:00
Xi Ge
fc1dac7e77 ObjCMessageTracing: append trace file content atomically to a canonical file location provided by the build environment
To simplify post-processing of these collected ObjC message traces, this PR teaches the compiler to atomically append the content of
ObjC message trace to a file location provided by the build environment, instead of emitting multiple files.
2024-11-19 11:57:29 -08:00
Akira Hatanaka
555c00a731 ModuleTrace: use clang API to emit information in JSON (#77422) 2024-11-07 15:31:55 -08:00
Xi Ge
1116e2882b ModuleTrace: check source file category using SourceFileKind instead of their file extensions. NFC 2024-11-05 08:55:12 -08:00
Xi Ge
94d1333072 ModuleObjCTrace: walk only Swift source files to collect used ObjC method invocations 2024-11-04 18:56:12 -08:00
Xi Ge
3cb5fbd411 ModuleObjCTrace: allow configuring the directory path to where the objc message trace file will be emitted to via an environment variable 2024-11-04 12:51:35 -08:00
Xi Ge
6e42dfb470 ModuleObjcMessageTrace: also include a field for the current compiler version 2024-11-01 21:35:14 -07:00
Xi Ge
95f2523ef3 ModuleObjcMessageTrace: report ObjC method calls from all source files under compilation 2024-10-31 14:52:09 -07:00
Xi Ge
8d0815e16f ModuleObjcMessageTrace: also report method calls from protocol types 2024-10-30 17:24:10 -07:00
Xi Ge
3fc9e273f3 ModuleObjcMessageTrace: use a more generalized directory name. NFC 2024-10-29 13:42:31 -07:00
Xi Ge
58e40166fb ModuleObjcMessageTrace: consolidate all source code file paths to a side table 2024-10-28 18:19:46 -07:00
Xi Ge
84ba789707 ModuleObjcMessageTrace: include target and target variant info and a format version number 2024-10-28 16:52:28 -07:00
Xi Ge
1b025bacc5 ModuleObjcMessageTrace: specify whether the owning context is an interface or category 2024-10-28 16:16:02 -07:00
Xi Ge
b1fa3e65b5 ModuleObjcMessageTrace: indicate whether a method is instance method or class method 2024-10-28 15:58:57 -07:00
Xi Ge
7b32de27c6 ModuleObjcMessageTrace: also include the source file name where an ObjcMethod is referenced. rdar://138776708 2024-10-28 10:47:16 -07:00
Xi Ge
6a2ae4d594 ModuleTrace: include ObjC methods' containing type name 2024-10-25 16:03:30 -07:00
Xi Ge
541cfdb904 ModuleTrace: address code review comments. NFC 2024-10-25 12:52:01 -07:00
Xi Ge
7bf010777e Frontend: when emitting loaded module trace file, also emit a JSON file tracking Objc method calls issued from the source code. 2024-10-24 17:19:21 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Rintaro Ishizaki
a61ed80813 [Macros] Track macro dependency separately in module trace
Macro plugins are not normal Swift modules, track them differently.
Add "swiftmacros" field to the JSON file.

rdar://118013482
2024-01-19 12:56:02 -08:00
Hamish Knight
ccd32eb452 NFC: Remove ClangModuleLoader.h include from ExtInfo.h
This was unnecessarily pulling in a whole bunch
of Clang headers when all was needed was a
forward declaration.
2023-10-09 20:29:03 +01:00
Steven Wu
da62873402 [OutputBackend] Virtualize LoadedModuleTraceFile
Virtualize LoadedModuleTraceFile output using the new appending support
in virtual output backend.
2023-07-11 13:42:29 -07:00
Rintaro Ishizaki
a551c01d6a [Macros] Track plugin dependencies
* Factor out ASTContext plugin loading to newly introduced 'PluginLoader'
* Insert 'DependencyTracker' to 'PluginLoader'
* Add dependencies right before loading the plugins

rdar://104938481
2023-04-25 10:50:32 -07:00
Rintaro Ishizaki
59f744c36a [Macros] Track loaded plugin paths in each ASTContext
PluginRegistry is now shared between multiple ASTContext. ASTContext
should track its loaded plugin library paths separately.
2023-03-27 16:55:34 -07:00
Alexis Laferrière
205a2edf38 [Sema] Intro set of import filters for general use
Calling getImportedModules requires to list the desired kind of imports.
With the new kind of imports this has become cumbersome. Let's simplify
it by offering common sets of imports. Advanced call sites can still
list the desired imports explicitly.
2023-03-17 16:05:44 -07:00
Richard Wei
c6139f2f78 [Macros] Emit loaded module trace for plugins loaded from search paths
When loading plugins from `-plugin-path`, use the global `PluginRegistry` to keep a record of what's loaded. Emit these dependencies to the loaded module trace.
2023-03-06 02:19:56 -08:00
Alexis Laferrière
6980cf211b [Serialization] Intro package-only module wide information and serialize it 2023-03-03 11:43:20 -08:00
Alexis Laferrière
4330921806 [Sema] Remove ImportFilterKind::SPIAccessControl
That filter wasn't needed in practice, we can remove it.
2023-03-03 11:42:59 -08:00
Richard Wei
4480d89536 [Macros] Emit plugin dependencies to loaded module trace. (#63367)
Emit plugins loaded with `-load-plugin-library` to loaded module trace.

Resolves rdar://102212316.
2023-02-03 09:16:14 +08:00
Doug Gregor
aa969c7ccb [Module trace] Eliminate use of report_fatal_error in non-assertions builds
This code path can have its invariants broken by catastrophic build
failures and needs to not crash.
2022-12-22 09:47:47 -08:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Ben Barham
c676dfc2fa [rebranch] Update uses of ErrorHandling.h functions
llvm-project `ErrorHandling.h` was updated to remove std::string. This
added a new `report_fatal_error` overload taking a `const Twine &`,
removed the overload that took `const std::string &`, and updated
`fatal_error_handler_t` to use `const char *` rather than `const
std::string &`.

Fix uses of these functions to take into account these updates. Note
that without the `const std::string &` overload, passing a `std::string`
into `report_fatal_error` now results in an ambiguous match between the
`StringRef` and `Twine` overloads so we need to be explicit about one or
the other.
2021-11-13 15:33:09 +10:00
Artem Chikin
2905433c6f Emit module trace atomically.
Ensure that we only have one writer to the module trace file at a time by using LLVM's `LockFileManager` utilities, similarly to `ModuleInterfaceBuilder`

Resolves rdar://76743462
2021-10-26 14:59:12 -07:00
Evan Wilde
8112cda531 Updated F_Text and F_Append
These enum cases were also updated to OF_Text and OF_Append.
2021-06-23 14:29:52 -07:00
Robert Widmann
d946df7895 Include Incremental Dependencies in Module Trace 2021-03-02 12:52:52 -08:00
Robert Widmann
76d25e7097 [NFC] Fixup InputFile Convenience Getters
Follow programming guidelines for these getters more closely and have them return a non-owning view of the underlying data instead of relying on callers to take const references to the copy that is returned here.
2020-11-12 14:54:02 -08:00
Robert Widmann
19e6bee374 [NFC] Use the Correct const-Qualification in Dependency Code
T *const does not prevent logically non-const accesses to the underlying data, it merely indicates that the pointer value itself is const. This modifier can be cast off by a copy, so it's not generally what you want here. Switch to const T * instead.
2020-11-12 10:57:56 -08:00