Commit Graph

41 Commits

Author SHA1 Message Date
Becca Royal-Gordon
9454c0aaa4 Emit module selectors in swiftinterfaces
This support is currently opt-in and can be disabled by a blocklist.
2025-10-31 16:48:06 -07:00
Allan Shortlidge
d00e102fd1 Frontend: Remove the -skip-import-in-public-interface flag.
This flag is unsafe since the compiler does not verify that the resulting
public interface will compile with the module import removed. The modern
alternative to this flag is `@_spiOnly import`. Since the flag is no longer
used by any projects it should be removed.

Resolves rdar://134351088.
2025-02-09 18:52:10 -08:00
Doug Gregor
34c020d5f4 Revert "Emit mangled names for public symbols into the .swiftinterface"
This reverts commit 0aff85ced7.
2024-11-12 22:38:47 -08:00
Allan Shortlidge
e49b248bee Frontend: Remove -disable-print-package-name-for-non-package-interface.
It is unsound to expose `package` declarations in textual interfaces without a
package identity for them to belong to so we should not offer this flag.

Resolves rdar://139361524.
2024-11-06 11:16:18 -08:00
Allan Shortlidge
fa5b783e3f Revert https://github.com/swiftlang/swift/pull/76244.
Partially resolves rdar://139236053.
2024-11-05 14:13:39 -08:00
Steven Wu
8150fb001d [InterfaceFile] Improve flag extraction from interface file
Improve the version/flags extract from interface file by moving away
from using Regex and limiting the search to the beginning of the file.

Switch away from Regex will give 5-10% improvement in time and
instruction counts, and limiting the search lines can save a lot of time
if the swiftinterface is large. For example, the extract time for Swift
stdlib is 10x faster after the patch.

Current strategey for limiting the line to search is by only parsing the
first comment block.
2024-10-31 12:46:05 -07:00
Allan Shortlidge
9e93b7b730 Frontend: Remove support for -experimental-spi-imports flag.
Its functionality has been superseded by `@_spiOnly import`. There are no
longer any known clients and the flag was already unsupported in Swift 6, so
the functionality is now removed (but the flag is only deprecated for Swift 5).

Resolves rdar://136867210.
2024-10-01 17:27:22 -07:00
Doug Gregor
0aff85ced7 Emit mangled names for public symbols into the .swiftinterface
When the frontend option `-abi-comments-in-module-interface` is provided
during interface printing, the printed interface will contain
additional comments that provide the mangled names for public symbols.
This is an experiment in seeing how much information we can
meaningfully extract from a printed Swift interface for the purpose of
bridging with other languages.
2024-09-25 15:49:34 -07:00
elsh
60f1ea4f85 Revert "Revert "Do not print package-name in non-package interface by default.""
This reverts commit 4b8e76fbeb.
2024-09-13 08:20:50 -07:00
Xi Ge
4b8e76fbeb Revert "Do not print package-name in non-package interface by default." 2024-09-05 21:36:32 -07:00
elsh
640b1252fc Do not print package-name in non-package interface by default.
Having package-name printed in public or private interface led to strange dependency errors in the past. For example, an SPI module is a dependency within a package, but due to the package-name being printed in public or private interface, dependency scanner tries to find it even for an external client of the package, causing a `no such module found` error. The  -disable-print-package-name-for-non-package flag helps with such case, but to enforce the correct behavior, we should make it a default to not print package-name in public or private interface.

Resolves rdar://135260270
2024-09-04 02:40:19 -07:00
Allan Shortlidge
a621059f80 ModuleInterface: Avoid crashing on invalid extensions in lazy typechecking mode.
With `-experimental-lazy-typecheck` specified during module interface emission,
`collectProtocols()` may be the first piece of code to request the extended
type for a given extension and it therefore needs to ignore invalid extensions
and ensure that diagnostics are emitted.

Also, add some `PrettyStackTrace` coverage to `ModuleInterfaceSupport.cpp` to make
investigating future issues easier.

Resolves rdar://126232836.
2024-07-23 10:32:50 -07:00
Allan Shortlidge
a6faa5a4bf Frontend: Only print the -project-name flag in private and package interfaces.
Resolves rdar://130992944.
2024-07-03 09:10:48 -07:00
Allan Shortlidge
f6e30ea83c Frontend: Refactor how flags are saved for module interfaces.
There are two axes on which a saved frontend flag can be categorized for
printing in a `.swiftinterface` file:

1. Whether the flag is "ignorable" or not.
2. Which levels of interface the flag should be in (public, package).

This refactor ensures that those two axes are modeled independently and
prepares the infrastructure to allow flags to appear in the private and package
interfaces without being included in the public interface.
2024-07-03 09:10:48 -07:00
Allan Shortlidge
a28b729594 Frontend: Remove unused ModuleInterfaceOptionIgnorablePrivate. 2024-07-03 08:51:02 -07:00
Ellie Shin
ea8a05399f Drop package-name if needed in SaveModuleInterfaceArgs 2024-06-28 20:24:28 -07:00
Ellie Shin
e5b4655108 Option to disable printing package-name in public or private interface.
Having package-name flag in non-package interfaces causes them to be built as if
belonging to a package, which causes an issue for a loading client outside of the
package as follows.

For example, when building X that depends on A with the following dependency chain:
  X --> A --> B --(package-only)--> C

1. X itself is not in the same package as A, B, and C.
2. When dependency scanning X, and opening up B, because the scan target is in a
   different package domain, the scanner decides that B's package-only dependency
   on C is to be ignored.
3. When then finally building A itself, it will load its dependencies, but because
   the .private.swiftinterface of A still specifies -package-name, when it loads
   B, it will then examine its dependencies and deem that this package-only dependency
   on C is required.

Because (2) and (3) disagree, we get an error now when building the private A textual interface.

rdar://130701866
2024-06-28 15:06:21 -07:00
Ellie Shin
9d716394b1 Add an interface mode getter/setter in PrintOptions and ModuleInterfaceOptions
Update args parsing
2023-11-13 13:48:07 -08:00
Ellie Shin
e5ca8e5c0b Allow loading package interface if in same package.
Add a new flag to enable package interface loading.
Use the last value of package-name in case of dupes.
Rename PrintInterfaceContentMode as InterfaceMode.
Update diagnostics.
Test package interface loading with various scenarios.
Test duplicate package-name.
2023-11-09 18:44:06 -08:00
Ellie Shin
aba3b6c24e Introduce a package interface.
It has an extension .package.swiftinterface and contains package decls
as well as SPIs and public/inlinable decls. When a module is loaded
from interface, it now looks up the package-name in the interface
and checks if the importer is in the same package. If so, it uses
that package interface found to load the module. If not, uses the existing
logic to load modules.

Resolves rdar://104617854
2023-11-08 14:56:20 -08:00
Allan Shortlidge
0e7ad1e9a4 Frontend: Don't append -target-min-inlining-target target to implicit module builds.
When performing an implicit module build, the frontend was prepending
`-target-min-inlining-target target` to the command line. This was overriding
the implicit `-target-min-inlining-target min` argument that is implied when
`-library-level api` is specified. As a result, the wrong overload could be
picked when compiling the body of an inlinable function to SIL for emission
into the client, potentially resulting in crashes when the client of the module
is back deployed to an older OS.

Resolves rdar://109336472
2023-05-30 13:33:26 -07:00
Ellie Shin
b081404daa Print package-name in .private.swiftinterface only for better abstraction
Resolves rdar://107638447
2023-04-20 17:45:22 -07:00
Alexis Laferrière
010973c276 [Frontend|NFC] Rename ModuleInterfaceOptions::PrintPrivateInterfaceContent 2022-12-08 15:10:03 -08:00
Alexis Laferrière
66586b5f63 [ModuleInterface] Print alias for module names in swiftinterface files
Ambiguities are introduced in generated swiftinterfaces when a type
shares a name with a module (i.e. XCTest). This workaround uses the
module-alias feature to avoid these ambiguities. Writing module
references with a distinguishable prefix should allow normal
type-checking to avoid the usual ambiguities.

We should still aim for a proper fully-qualified named syntax, but this
may help in the mean time.

rdar://101969500
2022-11-04 12:30:33 -07:00
Alexis Laferrière
9e3f5f9cea [ModuleInterface] Print missing imports in swiftinterface
Hack to fix swiftinterfaces in case of missing imports. We can get rid
of this logic when we don't leak the use of non-locally imported things
in API.
2022-08-19 12:32:43 -07:00
Xi Ge
1115332ab9 ModuleInterface: add a frontend flag to skip printing import statement corresponding to a module name.
Related: rdar://63465931
2022-02-24 15:33:26 -08:00
Xi Ge
03e0006a48 ModuleInterface: move -user-module-version to a new field
Titled as "// swift-module-flags-ignorable:", this new field contains new
frontend arguments that can be safely ignored by the older version of the compiler.
For compilers that don't know the field at all, all arguments in it are ignored.

rdar://78233352
2021-05-21 14:52:10 -07:00
Xi Ge
3d6662f382 ModuleInterface: refactor out a utility to extract compiler flags from a module interface file. NFC 2021-05-02 22:46:32 -07:00
Varun Gandhi
983399c1e7 [Printer] Conditionally print Clang types in emitted SIL. 2020-09-16 10:34:43 -07:00
Brent Royal-Gordon
3c69837102 Add a debug flag to emit invalid swiftinterface files 2020-08-07 16:00:15 -07:00
Alexis Laferrière
fb364ae2b7 Merge pull request #33207 from xymus/spi-ioi-check-workaround
[ModuleInterface] Print some implementation-only imports in the private interface
2020-07-30 14:33:43 -07:00
Alexis Laferrière
0cce54954a [ModuleInterface] Print some implementation-only imports in the private interface
Print implementation-only imports in the private textual interface
only if also importing SPI. This allows to export types from
implementation-only imports in SPI and brings the private textual
interfaces in line with the binary interfaces.

This is a temporary solution as we need to better design the language
feature around this.

This feature requires passing -experimental-spi-imports to the frontend
that generates the private swiftinterface file.
2020-07-30 09:20:12 -07:00
Varun Gandhi
a174e5714b [Gardening] Update clang-function-type-serialization comments.
We have landed support for serialization Clang function types, but there is
still work to be done here.

Moreover, we should use a consistent style with `[(FIXME|TODO|NOTE): label]`,
instead of using different styles throughout the code.
2020-07-25 23:27:18 -07:00
Brent Royal-Gordon
a7a5e340aa Improve diagnostic for broken module interfaces
Currently, when a swiftinterface file fails to load, we emit the specific diagnostics for the failures, followed by a generic “failed to load module ‘Foo’” message. This PR improves that final diagnostic, particularly when the cause may be that the interface was emitted by a newer compiler using backwards-incompatible syntax.
2020-03-13 20:31:55 -07:00
Alexis Laferrière
901392896d [Frontend] Output the private module interface with the SPI info 2020-02-19 14:17:14 -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
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
Varun Gandhi
afc6ccdeb5 Re-land parsing and printing for Clang function types.
This reverts commit e805fe486e, which reverted
the change earlier. The problem was caused due to a simultaneous change to some
code by the PR with parsing and printing for Clang function types (#28737)
and the PR which introduced Located<T> (#28643).

This commit also includes a small change to make sure the intersecting region
is fixed: the change is limited to using the fields of Located<T> in the
`tryParseClangType` lambda.
2020-01-07 15:58:32 -08:00
Saleem Abdulrasool
e805fe486e Revert "Clang function types v2: Electric Boogaloo (parsing + printing)" 2020-01-06 16:26:08 -08:00
Varun Gandhi
96604470ae [AST] Add printing for Clang function types in the AST. 2020-01-06 13:00:04 -08:00
Harlan Haskins
c82c9b8210 [ModuleInterfaces] Remove references to 'parseable' interfaces everywhere
Now that we've settled on Module Interface as the name, let's remove the
vestiges of "Parseable Interfaces"
2019-09-13 14:55:48 -07:00