Commit Graph

570 Commits

Author SHA1 Message Date
QuietMisdreavus
ab26b8b9d7 add support to getTopLevelDecls for clang submodules (#76401)
rdar://126031510
2025-01-30 09:39:58 -07: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
Hamish Knight
23e3f5f5de Merge pull request #77666 from hamishknight/lets-try-this-again
[AST] Remove `ModuleDecl::addFile`
2024-11-21 20:15:58 +00:00
Pavel Yaskevich
7c8000b3a5 [Frontend] Switch -interface-compiler-version to Version
`SWIFT_COMPILER_VERSION` has more than 4 components and it's
easier to use `Version` API over `VersionTuple` as well.
2024-11-18 15:11:36 -08:00
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00:00
Allan Shortlidge
239720897a AST: Rename TypeRefinementContext to AvailabilityScope. 2024-11-12 11:34:25 -08:00
Daniil Kovalev
0d7e37e4ec [AutoDiff] Enhance performance of custom derivatives lookup
In #58965, lookup for custom derivatives in non-primary source files was
introduced. It required triggering delayed members parsing of nominal types in
a file if the file was compiled with differential programming enabled.

This patch introduces `CustomDerivativesRequest` to address the issue.
We only parse delayed members if tokens `@` and `derivative` appear
together inside skipped nominal type body (similar to how member operators
are handled).

Resolves #60102
2024-10-29 12:45:14 +03:00
Pavel Yaskevich
84a62fc170 [Frontend/Serialization] Narrow -swift-compiler-version to -interface-compiler-version
It might be unexpected to future users that `-swift-compiler-version`
would produce a version aligned to .swiftinterface instead of one used
to build the .swiftmodule file. To avoid this possible confusion, let's
scope down the version to `-interface-compiler-version` flag and
`SWIFT_INTERFACE_COMPILER_VERSION` option in the module.
2024-10-28 13:45:27 -07:00
Pavel Yaskevich
39fb638516 [Frontend/AST] Make it possible to determine Swift compiler version used to build a ModuleDecl 2024-10-24 17:06:15 -07:00
Allan Shortlidge
3847c344a5 AST: Clean up ImportFilterKind comments.
NFC.
2024-09-30 10:31:43 -07:00
Allan Shortlidge
fb86a721a6 AST: Remove default argument from ModuleDecl::getImportedModules(). 2024-09-30 10:31:43 -07:00
Allan Shortlidge
07b84fccfb AST: Introduce ModuleDecl::isClangHeaderImportModule() convenience. 2024-09-27 12:00:03 -07:00
Steven Wu
e0541b0357 [Macro][Dependencies] Properly model macro dependencies in the scanner
Add function to handle all macro dependencies kinds in the scanner,
including taking care of the macro definitions in the module interface
for its client to use. The change involves:
  * Encode the macro definition inside the binary module
  * Resolve macro modules in the dependencies scanners, including those
    declared inside the dependency modules.
  * Propagate the macro defined from the direct dependencies to track
    all the potentially available modules inside a module compilation.
2024-09-19 16:41:53 -07:00
Doug Gregor
8febd3fb32 Reimplement ModuleDecl::getSourceFileContainingLocation() using SourceManager
ModuleDecl kept track of all of the source files in the module so that it
could find the source file containing a given location, which relied on
a sorted array all of these source files. SourceManager has its own
similar data structure for a similar query mapping the locations to
buffer IDs.

Replace ModuleDecl's dats structure with a use of the SourceManager's version
with the mapping from buffer IDs to source files.
2024-09-18 07:45:50 -07:00
Alexis Laferrière
8d28ed4fa9 Merge pull request #76269 from xymus/public-module-name
Diagnostics: Intro the public module name concept to hide support modules from clients
2024-09-09 16:57:12 -07:00
Alexis Laferrière
c60fea3aac Sema: Use clearer param name in getPublicModuleName
Use onlyIfImported instead of mustBeVisible.
2024-09-05 12:45:13 -07:00
Alexis Laferrière
214da85183 Sema: Keep public module name in ModuleDecl 2024-09-04 16:20:12 -07:00
Augusto Noronha
141c96fee1 Account for multiple modules when looking up the DeclContext of a type
When looking up the decl context of a type, ASTDemangler has to take
into account that there are multiple different modules where that type
could've come from. This is due to two facts:

- Thanks to the `-module-abi-name` flag, multiple modules can share
the same ABI name (which is the module name that is usually used when
mangling a type).
- In some situations mangling can use the module's real name, for
example, when mangling for the debugger or USRs coupled with @_originallyDefinedIn.

rdar://134095412
2024-09-03 16:44:41 -07:00
Slava Pestov
30587184d3 Merge pull request #75789 from slavapestov/global-conformance-lookup-part-2
Move global conformance lookup entry points to ConformanceLookup.h
2024-08-09 10:01:25 -04:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
Allan Shortlidge
02255d2c42 Sema: Move diagnoseMissingImportForMember() to Sema.
This will make it possible to use type checking APIs to determine the
appropriate access level for suggested imports.

NFC.
2024-08-05 11:28:26 -07:00
Allan Shortlidge
fff4bebc44 AST: Clarify SourceFile's existing missing imports record.
In anticipation of adding a new kind of missing import record to `SourceFile`,
clarify the purpose of the existing "missing imports" record with more specific
naming and documentation.
2024-08-05 11:28:26 -07:00
Kavon Farvardin
8624b175b9 NFC: check ModuleDecl file invariant always 2024-07-12 15:49:58 -07:00
Ellie Shin
18681c43fb Drop experimental prefixes from PackageCMO flags.
Deprecate experimental- flags with prompts to use the proper flags.

rdar://131498517
2024-07-10 16:19:16 -07:00
Slava Pestov
b7117aa877 AST: Start untangling ModuleDecl from conformance lookup 2024-07-06 12:05:45 -04:00
Artem Chikin
71ec06e656 Cache visible Clang modules for interface printing in 'ModuleDecl'
Instead of caching the collection of visible Clang modules in the 'TypePrinter', compute and cache them in the 'ModuleDecl'. When printing a textual interface, the compiler will instantiate many new instances of 'TypePrinter', which means caching them there is not useful.
2024-06-11 13:04:16 -07:00
Ellie Shin
063d159d1b Rename isFragile() as isStrictlyResilient() in var decl.
Add isStrictlyResilient() to nominal type and module decl.
2024-05-21 18:25:10 -07:00
Daniel Grumberg
cffb637f2d Merge pull request #73080 from daniel-grumberg/export-import-sgf-extract
[SymbolGraphGen] Correctly handle exported imports in swift-symbolgraph-extract
2024-05-02 15:39:26 +01:00
Daniel Grumberg
9964884809 Recursively collect exported imports to allow fetching all visible Decls for symbol graph generation
This change is two fold. Firstly it enables collection of exported
imports from non source file units. Additionally this recurses through
the exported imports to ensure the transitive set is collected.

Fixes https://github.com/apple/swift/issues/59920
rdar://89687175
2024-04-25 11:33:11 +01:00
Ellie Shin
45e8454a9e Merge branch 'main' into elsh/pkg-sil-verify 2024-04-17 22:46:55 -07:00
Ellie Shin
fbb3382e21 During Package CMO, SIL cloning happens during which
SILOptions::EnableSerializePackage info is lost.

SILVerifier needs this info to determine whether resilience
can be bypassed for decls serialized in a resiliently
built module when Package CMO optimization enabled.

This PR adds SerializePackageEnabled bit to Module format
and uses that in SILVerifier.

Resolves rdar://126157356
2024-04-17 22:37:48 -07:00
Allan Shortlidge
bd59db6e15 AST: Refactor missing import diagnostic into standalone utility.
NFC.
2024-04-16 16:29:51 -07:00
Ellie Shin
30669fca65 Currently when checking if resilience check can be bypassed within a package,
we only check if the loaded module is built from a package interface. This is
not enough as a binary module could just contain exportable decls if built with
experimental-skip-non-exportable-decls, essentially resulting in content equivalent
to interface content. This might be made a default behavior so this PR requires
a module to opt in to allow non-resilient access by a participating client in the
same package.

Since it affects module format, SWIFTMODULE_VERSION_MINOR is updated.

rdar://123651270
2024-03-01 15:13:58 -08:00
Joe Groff
fe7049ed13 SIL: More accurate for type lowering whether a type is trivial based on conditional Copyable requirements.
We want a conditionally-copyable type to still be classified as trivial in cases
where it's bitwise-copyable, has a trivial deinit, and is Copyable. The previous
implementation here only checked at the declaration level whether a type was
Copyable or not; get a more accurate answer by consulting the combination
of information in the substituted type and abstraction pattern we have
available during type lowering so that we classify definitely-copyable substitutions
of a conditionally-copyable type as trivial. Should fix rdar://123654553 and
rdar://123658878.
2024-02-27 15:01:20 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Ellie Shin
4bd9e2524c More cleanup 2024-02-15 13:50:18 -08:00
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -08:00
Ellie Shin
7d4e5678c7 Compare the package names of the accessing module and the decl's defining module.
Update tests.
2024-02-13 19:11:32 -08:00
Ellie Shin
4588cc2261 Support bypassing resilience checks for package decls at use site in a package.
By default package decls are treated as resilient, similar to public (non-frozen).
This PR adds support to allow direct access to package decls at use site if opted-in.
Requires the loaded module to be a binary module in the same package.

Resolves rdar://121626315
2024-02-13 19:09:31 -08:00
Slava Pestov
6027bf46a6 AST: Simplify collectExistentialConformances() 2024-02-10 09:36:37 -05:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00
Pavel Yaskevich
182ba1bb2d [AST] Make it possible to find what Swift version was used to build a module
For imported modules the version is empty because they don't carry
this information.
2024-02-01 13:28:25 -08:00
Slava Pestov
14d1fcb51a AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance() 2024-01-16 17:08:00 -05:00
Kavon Farvardin
30a4740962 [NFC] clean-up collectExistentialConformances 2024-01-11 14:52:20 -08:00
Kavon Farvardin
4eccbe136e [NFC] combine collectExistentialConformances
There are a bunch of static `collectExistentialConformances` copied
around Sema and SILGen that are almost the same, save for whether they
want to permit missing conformances and/or check conditional
conformances.

This commit requestifies and combines all but one of these functions
into a `ModuleDecl::collectExistentialConformances`. The motivation for
this clean-up is another place that will need this procedure.
2024-01-10 19:39:07 -08:00
Alexis Laferrière
8b91e4ca17 Sema: Remove isExportedAs, it's no longer used and it was outdated 2023-12-20 15:34:20 -08:00
Ellie Shin
d570d41d99 s/ModuleInterfaceOptionIgnorablePrivate/ModuleInterfaceOption and formatting 2023-10-30 13:58:13 -07:00
Ellie Shin
7c80976081 Package name is only printed in private swiftinterface. This causes
ambiguity during lookup when there are multiple public or inlinalbe
package decls in public interfaces. This PR adds a package name to
public swiftinterface and lets typecheck look up the package name
to narrow down the scope of access to package decls from an external
module.

Resolves rdar://117699160
2023-10-30 13:38:17 -07:00