Commit Graph

574 Commits

Author SHA1 Message Date
Alexis Laferrière
39fb1c5f55 [ModuleInterface] Intro export-as for Swift modules
Introduce a new flag `-export-as` to specify a name used to identify the
target module in swiftinterfaces. This provides an analoguous feature
for Swift module as Clang's `export_as` feature.

In practice it should be used when a lower level module `MyKitCore` is
desired to be shown publicly as a downstream module `MyKit`. This should
be used in conjunction with `@_exported import MyKitCore` from `MyKit`
that allows clients to refer to all services as being part of `MyKit`,
while the new `-export-as MyKit` from `MyKitCore` will ensure that the
clients swiftinterfaces also use the `MyKit` name for all services.

In the current implementation, the export-as name is used in the
module's clients and not in the declarer's swiftinterface (e.g.
`MyKitCore`'s swiftinterface still uses the `MyKitCore` module name).
This way the module swiftinterface can be verified. In the future, we
may want a similar behavior for other modules in between `MyKitCore` and
`MyKit` as verifying a swiftinterface referencing `MyKit` without it
being imported would fail.

rdar://103888618
2023-01-26 14:27:31 -08:00
Alexis Laferrière
77d8c464df [Serialization] Recover from deserialization failures in ModuleFile::lookupObjCMethods
This was reported by deserialization safety in:

Interpreter/SDK/Foundation_NSString.swift
2023-01-18 16:36:33 -08:00
Adrian Prantl
28d7f8813c Turn (most) deserialization errors from a crash into a fatal diagnostic (NFC)
Currently, ModuleFileSharedCore::fatal() calls abort(), which may be reasonable
in a swift-frontend invocation, but has dire consequences when the Swift
frontend is embedded into another process, for example, LLDB where the abort()
kills the entire debugging session.

This patch introduces a few alternatives to the ModuleFile::fatal() familiy of
functions that instead push a fatal diagnostic to the ASTContext's
DiagnosticsEngine and return an llvm::Error so the error can be roperly
communicated and the ASTContext can be wound down without killing the parent
process.

The transition is not complete, this patch does not yet handle
fatalIfUnexpected(), for example.

This patch is NFC for the Swift compiler: When DebuggerSupport in off
ModuleFile::diagnoseFatal() will still call abort(), but if it is on, the error
will be passed up, together with a pretty stack trace.

rdar://64511878
2022-11-28 15:54:27 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Alexis Laferrière
3ca1de0a0f [Sema] Clean up lookupImportedSPIGroups 2022-11-08 16:35:43 -08:00
Slava Pestov
cfb4e60a48 Merge pull request #60523 from slavapestov/fix-opened-generic-environment-identity
Serialization: Preserve identity of opened generic environments
2022-08-16 14:33:44 -04:00
Slava Pestov
b36f37cc72 Serialization: Preserve identity of opened generic environments
We used to create a new environment for each opened archetype, which is
incorrect when deserializing a nested type of another opened archetype.
2022-08-15 13:59:12 -04:00
swift-ci
55000f53be Merge remote-tracking branch 'origin/main' into rebranch 2022-06-17 10:15:14 -07:00
Becca Royal-Gordon
9b5f89963b [NFC] Serialize ObjC selectors for protocols
The ObjCMethodLookupTable for protocols was not being serialized and rebuilt on load, so NominalTypeDecl::lookupDirect() on selectors was not working correctly for deserialized types. Correct this oversight.
2022-06-16 14:07:49 -07:00
swift-ci
f6cdcc736d Merge remote-tracking branch 'origin/main' into rebranch 2022-05-18 15:18:15 -07:00
Alexis Laferrière
c8059a09e9 [Serialization] Soft-reject swiftmodules built against a different SDK
Change the way swiftmodules built against a different SDK than their
clients are rejected. This makes them silently ignored when the module
can be rebuilt from their swiftinterface, instead of reporting a hard
error.

rdar://93257769
2022-05-16 13:22:35 -07:00
Ben Barham
4e1eb1abe8 Merge pull request #58620 from bnbarham/rebranch-fixes
[rebranch] Various fixes to get macos to a compiling state
2022-05-06 09:59:38 -07:00
Alexis Laferrière
1757061342 [Serialization] Allow loading modules built on some SDK variants
When restricting loading swiftmodules to the SDK used to build them,
an exception should be made for modules built against an SDK that is a subset
of the SDK used when loading the module. In such a case, the swiftmodule
file is more reliable.

rdar://92827584
2022-05-05 17:08:19 -07:00
Ben Barham
114b4d96e4 [next] Use new VersionTuple API
The `VersionTuple` API was changed llvm/llvm-project
219672b8dd06c4765185fa3161c98437d49b4a1b to return `VersionTuple`
from `get*Version` rather than pass in major, minor, and subminor output
parameters. Update uses to the new API.

Note that `getMacOSXVersion` is slightly different in that it returns a
boolean while taking a `VersionTuple` output parameter to match its
previous behaviour. There doesn't seem to be any use that actually
checks this value though, so we should either update the API to return
an `Optional` and actually check it *or* remove the "failure" case and
return a `VersionTuple` like all the others.
2022-05-05 16:25:10 -07:00
Alexis Laferrière
48e23a6261 Merge pull request #41647 from xymus/recover-from-anyobject-lookup
[Serialization] Recover from failures under AnyObjectLookup
2022-03-04 11:07:44 -05:00
Alexis Laferrière
4d75242ec6 [Serialization] Recover from failures under AnyObjectLookup
rdar://89494507
2022-03-03 13:54:30 -08:00
John McCall
713bb43a94 Rework the serialization schema for conformances and requirements.
We now schedule conformance emissions in basically the same way
we do for types and declarations, which means that we'll emit them
uniquely in the module file instead of redundantly at every use.
This should produce substantially smaller module files overall,
especially for modules that heavily use generics.  It also means
that we can remove all the unfortunate code to support using
different abbrev codes for them in different bitcode blocks.

Requirement lists are now emitted inline in the records that need
them instead of as trailing records.  I think this will improve
space usage, but mostly it assists in eliminating the problem
where abbrev codes are shared between blocks.
2022-02-28 17:32:00 -05:00
Victoria Mitchell
cab1669e09 only recurse getDisplayDecls in SymbolGraphGen 2022-02-19 10:32:29 -07:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
Xi Ge
645a27f108 Deserialization: ignore search paths pointing into the SDK. rdar://84125071 2021-12-04 09:18:58 -08:00
Xi Ge
6377c3a742 Revert "Revert "serialization: obfuscate the serialized search paths"" 2021-12-02 13:21:04 -08:00
Saleem Abdulrasool
11d5d6d4ca Revert "serialization: obfuscate the serialized search paths" 2021-12-02 08:18:23 -08:00
Xi Ge
0047d81f9a serialization: obfuscate the serialized search paths
We noticed some Swift clients rely on the serialized search paths in the module to
find dependencies and droping these paths altogether can lead to build failures like
rdar://85840921.

This change teaches the serialization to obfuscate the search paths and the deserialization
to recover them. This allows clients to keep accessing these paths without exposing
them when shipping the module to other users.
2021-12-01 11:47:41 -08:00
elsh
2efab715cd Use real module names to load modules
Add ModuleInterface option meta tag for -module-alias
Add tests loading modules with -module-alias for swiftmodule and swiftinterface
with various loaders incl. serialized, explicit, and source loader.
2021-10-05 13:41:48 -07:00
Richard Howell
140c02466a Add -prefix-serialized-debugging-options (#39555)
This commit adds a new frontend flag that applies debug path prefixing to the
paths serialized in swiftmodule files. This makes it possible to use swiftmodule
files that have been built on different machines by applying the inverse map
when debugging, in a similar fashion to source path prefixing.

The inverse mapping in LLDB will be handled in a follow up PR.

Second pass at #39138

Tests updated to handle windows path separators.

This reverts commit f5aa95b381.
2021-10-04 22:41:32 -07:00
Meghana Gupta
f458d9b490 Fix unnecessary one-time recompile of stdlib with -enable-ossa-flag (#39516)
* Fix unnecessary one-time recompile of stdlib with -enable-ossa-flag

This includes a bit in the module format to represent if the module was
compiled with -enable-ossa-modules flag. When compiling a client module
with -enable-ossa-modules flag, all dependent modules are checked for this bit,
if not on, recompilation is triggered with -enable-ossa-modules.

* Updated tests
2021-10-04 18:46:40 -07:00
Saleem Abdulrasool
f5aa95b381 Revert "Add -prefix-serialized-debugging-options" (#39544)
Reverts #39138

This is causing a failure on Windows: https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019/6659/consoleText
2021-10-01 11:19:44 -07:00
Richard Howell
49f37abb95 Add SearchPathRemapper to SearchPathOptions
This is intended to be used from LLDB to apply the remappings
specified in target.source-map to remap any serialized
Swiftmodule search paths that were prefixed using
`-prefix-serialized-debugging-options`.
2021-09-30 08:18:03 -07:00
Alexis Laferrière
cc909b7e8f [Serialization] Minor style clean up in SDKName logic 2021-09-20 18:06:35 -07:00
Alexis Laferrière
c38d1773d2 [Serialization] Restrict loading swiftmodule files to the builder's SDK
Serialize the canonical name of the SDK used when building a swiftmodule
file and use it to ensure that the swiftmodule file is loaded only with
the same SDK. The SDK name must be passed down from the frontend.

This will report unsupported configurations like:

- Installing roots between incompatible SDKs without deleting the
swiftmodule files.
- Having multiple targets in the same project using different SDKs.
- Loading a swiftmodule created with a newer SDK (and stdlib) with an
older SDK.

All of these lead to hard to investigate deserialization failures and
this change should detect them early, before reaching a deserialization
failure.

rdar://78048939
2021-09-13 16:44:08 -07:00
Alexis Laferrière
4f0c57a2d3 [Serialization] Recover from failures in ModuleFile::lookupClassMembers
Access to a missing member on an AnyObject triggers a typo correction
that looks at all class members in imported modules. Make sure it
recovers from deserializing members referencing implementation-only
imported types.

rdar://79427805
2021-06-22 18:36:46 -07:00
Ben Barham
b9a97586c3 [Serialization] Cleanup allow module with errors references 2021-05-22 13:12:46 +10:00
Hamish Knight
ed104a8134 Merge pull request #37014 from hamishknight/entry-sign 2021-05-19 08:32:40 +01:00
Ben Barham
c763ab5d1e [Serialization] Store offset of decls in .swiftsourceinfo
The locations stored in .swiftsourceinfo included the presumed file,
line, and column. When a location is requested it would read these, open
the external file, create a line map, and find the offset corresponding
to that line/column.

The offset is known during serialization though, so output it as well to
avoid having to read the file and generate the line map.

Since the serialized location is returned from `Decl::getLoc()`, it
should not be the presumed location. Instead, also output the line
directives so that the presumed location can be built as per normal
locations.

Finally, move the cache out of `Decl` and into `ASTContext`, since very
few declarations will actually have their locations deserialized. Make
sure to actually write to that cache so it's used - the old cache was
never written to.
2021-04-29 12:33:05 +10:00
Hamish Knight
272090752b [AST] Upgrade MainDecl to a ValueDecl
This will make it easier to store in a SILDeclRef.
2021-04-26 11:42:31 +01:00
eeckstein
149446b0f0 Merge pull request #36858 from eeckstein/remove-oat-tracker
SIL: remove the SILOpenedArchetypesTracker
2021-04-14 12:17:54 +02:00
Erik Eckstein
6ec788ff09 SIL: remove the SILOpenedArchetypesTracker
Instead, put the archetype->instrution map into SIlModule.

SILOpenedArchetypesTracker tried to maintain and reconstruct the mapping locally, e.g. during a use of SILBuilder.
Having a "global" map in SILModule makes the whole logic _much_ simpler.

I'm wondering why we didn't do this in the first place.

This requires that opened archetypes must be unique in a module - which makes sense. This was the case anyway, except for keypath accessors (which I fixed in the previous commit) and in some sil test files.
2021-04-14 08:36:10 +02:00
Ben Barham
c54c9c7079 [Gardening] Extract basic source info structs from RawComment.h 2021-04-14 10:05:27 +10:00
Ben Barham
3ea9bed415 [SourceKit/CursorInfo] Add constructor to call results
Cursor info for a constructor would previously give the cursor info for
the containing type only. It now also adds cursor info for the
constructor itself in a "secondary_symbols" field.

Refactor `passCursorInfoForDecl` to use a single allocator rather than
keeping track of positions in a buffer and assigning everything at the
end of the function.

Refactor the various available refactoring gathering functions to take a
SmallVectorImpl and to not copy strings where they don't need to.

Resolves rdar://75385556
2021-03-30 13:23:59 +10:00
David Ungar
90ee114b4a add fingerprint excluding to basic source file info 2021-02-26 17:20:44 -08:00
Rintaro Ishizaki
bb45b2a822 [CodeCompletion] Lazily populate 'BasicSourceFileInfo' 2021-02-25 14:56:55 -08:00
David Ungar
6e034cac4e Revert "[NFC; Incremental] Rename BasicSourceFileInfo.InterfaceHash" 2021-02-25 09:06:53 -08:00
Ben Barham
f410958c9c [Serialization] Import incompatible targets when allowing errors
If allowing modules to be output with compile errors
(-experimental-allow-module-with-errors), import targets regardless of
whether they are compatible or not, and still output the module. The
error diagnostic will still be output (preventing SILGen), but the AST
will be available for various editor functionality.
2021-02-25 09:14:19 +10:00
David Ungar
cbd92e65ff Rename BasicSourceFileInfo.InterfaceHash 2021-02-24 09:13:22 -08:00
swift-ci
89c8005a80 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 15:52:25 -08:00
Egor Zhdan
cb5936688c SourceKit: do not print implementation-only imports
Implementation-only imports are unnecessary in generated module interfaces, since they aren't exported to the module's dependencies, and the module's public API cannot refer to symbols imported as implementation-only.
2021-01-24 20:09:19 +03:00
swift-ci
b5748f255b Merge remote-tracking branch 'origin/main' into rebranch 2021-01-16 14:52:22 -08:00
David Ungar
d913dfe9ac Check for fromString failure in ModuleFile.cpp 2021-01-15 13:57:17 -08:00
swift-ci
c49bdea2f1 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-15 10:12:20 -08:00
Rintaro Ishizaki
4e391119e0 [Serialization] Serialize mtime with nanosecond precision
There's no reason to lose accuracy here.
2021-01-14 09:52:35 -08:00