Commit Graph

78 Commits

Author SHA1 Message Date
swift-ci
2e9555437f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-29 20:19:54 -07:00
Alexis Laferrière
8dcfadd546 [Sema] Track the access level modifier on import full range 2023-09-27 22:30:28 -07:00
swift-ci
7fc36edb98 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-27 09:34:12 -07:00
Alexis Laferrière
291b09e6b8 [Sema] Add sourceloc to error on importing a package module from swiftinterface
Importing a package module from swiftinterface loses all package decls
and is reported as an error. Make the error point to the import.
2023-09-26 13:50:16 -07:00
Evan Wilde
11fcbbeea2 Cleaning up more deprecation warnings
Pointer `llvm/Support/Host.h` at `llvm/TargetParser/Host.h`.
Replacing deprecated API `startswith_insensitive` with replacement
`starts_with_insensitive`.
2023-08-10 16:19:24 -07:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Becca Royal-Gordon
1b81c3de7b [NFC] Adopt ValueDecl * for decl_declared_here 2023-07-19 13:08:12 -07:00
Alexis Laferrière
fabb345624 [Sema] Warn on uses of @_implementationOnly imports without library-evolution
@_implementationOnly was designed for use from resilient modules only,
using it from non-resilient modules in unsupported. This change adds a
warning about it.

If anyone hits this warning, they should either enable library-evolution
or consider adopting the new `internal import` when it is available as
it handles this scenario properly.

What leads to a crash: an @_implementationOnly import fully hides the
dependency from indirect clients. This can lead to the compiler being
unaware of some internal details of a non-resilient module when building
a client against it. In turn this may lead to run time crashes from
miscompilation.

In general one could still use @_implementationOnly in a non-resilient
modules as long as it's referenced only from function bodies. However,
references from even non-public properties does lead to important memory
layout information being hidden from clients of the module.

rdar://78129903
2023-07-05 16:20:42 -07:00
Alexis Laferrière
671cc805a8 [Sema] Refactor validateResilience to prepare for one more check 2023-07-05 16:20:42 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Ellie Shin
ceb2884183 Currently it errors when loading a module built from interface if it has package-name.
This disallows building an interface file that imports such module which should be allowed
since interface does not contain package symbols unless usableFromInline or inlinable.
This change limits erroring only when building a .swift file.

Resolves rdar://108633068
2023-04-27 16:25:11 -07:00
Alejandro Alonso
4a681160dc Merge pull request #64673 from Azoy/builtin-module-feature
[Frontend] Add BuiltinModule experimental feature
2023-03-29 23:12:40 -07:00
Alexis Laferrière
9e18563faf [Sema] Support -testable-import-module to load transitive non-public dependencies
When using the -testable-import-module argument to insert a testable
import, there's no ImportDecl on which to show the diagnostics when
loading transitive dependencies. Clean up the logic to still load
dependencies in such a case.
2023-03-29 13:59:29 -07:00
Alexis Laferrière
f7f69c6ae1 [Serialization] Load non-public transitive dependencies on @testable imports
A @testable import allows a client to call internal decls which may
refer to non-public dependencies. To support such a use case, load
non-public transitive dependencies of a module when it's imported
@testable from the main module.

This replaces the previous behavior where we loaded those dependencies
for any modules built for testing. This was risky as we would load more
module for any debug build, opening the door to a different behavior
between debug and release builds. In contrast, applying this logic to
@testable clients will only change the behavior of test targets.

rdar://107329303
2023-03-29 13:59:28 -07:00
Alejandro Alonso
c21899ee0f Add BuiltinModule experimental feature 2023-03-28 09:41:37 -07:00
zoecarver
96d0b35048 [cxx-interop] Fixit: std.x -> CxxStdlib.x. 2023-03-20 16:14:42 -07:00
Alexis Laferrière
2ef019610c [Sema] Error on resilient importing publicly a non-resilient module
Importing a non-library-evolution enabled module from a
library-evolution enabled module will lead to generating a
swiftinterface that can't be rebuilt by a different compiler.
Make it a hard error when using access level imports, and keep it as a
warning for @_implementationOnly imports.
2023-02-27 19:31:52 -08:00
Alexis Laferrière
c6c96c4688 [Sema] Report inconsistent access level on import
When targeting Swift 5 and earlier, the default import is public. To
notify of a possible unintentional public import, raise errors on
default imports when other imports of the same target have an explicit
type.

This check isn't necessary in the tentative Swift 6 mode.
2023-02-27 19:31:52 -08:00
Alexis Laferrière
1afc6af739 Merge pull request #63912 from xymus/access-level-import-parsing
[Parser|Sema] Accept access level on imports with experimental flag
2023-02-27 09:27:26 -08:00
Alexis Laferrière
38fbe1d49b [Sema] Preserve information about access level on imports 2023-02-25 09:47:36 -08:00
Alejandro Alonso
023c40c809 Add option to explicitly import Builtin 2023-02-16 15:23:45 -08:00
Slava Pestov
34ce74aea8 AST: Stricter invariants when constructing TypeAliasType 2022-11-28 23:57:53 -05:00
Xi Ge
5987654b3a Merge branch 'main' into allowable-serialization 2022-11-28 09:36:04 -08:00
Xi Ge
c3db946517 sema: diagnose importation from disallowed modules 2022-11-25 23:37:01 -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
3aa1c1afd8 [Frontend] Support underlying module for an aliased module 2022-11-04 11:10:47 -07:00
Alexis Laferrière
2cb6d72444 Merge pull request #61058 from xymus/spi-only-consistent 2022-09-13 07:49:22 -07:00
Alexis Laferrière
99d9bebf84 [Sema] Cleaner diagnostics for conflicting import modifiers 2022-09-12 17:17:23 -07:00
Alexis Laferrière
47d2f1acc4 [Sema] Check inconsistent @_spiOnly imports within one source file 2022-09-12 17:17:23 -07:00
Alexis Laferrière
329599d2d3 [Sema|NFC] Refactor findInconsistentImports
Break findInconsistentImportsAcrossFile into two services, one finding
inconsistencies across a whole module and a new one finding them across
a single file.
2022-09-12 17:17:23 -07:00
Alexis Laferrière
622e47c89c [Sema] Report conflicting attributes on imports 2022-09-12 17:17:23 -07:00
QuietMisdreavus
f674b473ec introduce a @_documentation(...) attribute to influence SymbolGraphGen (#60242)
* add @_documentation(...) attribute to influence SymbolGraphGen

rdar://79049241
2022-09-06 14:12:42 -06:00
Alexis Laferrière
aaaef3411e [Sema] Intro @_spiOnly attribute and import filter
Introduce the attribute and basic import filter logic.
2022-09-01 15:16:44 -07:00
Allan Shortlidge
1739528f6c Sema: Diagnose inconsistent use of @_weakLinked on import declarations. 2022-08-12 09:45:49 -07:00
Allan Shortlidge
a67c7f77f5 Sema: Refactor CheckInconsistentImplementationOnlyImportsRequest to make the inconsistency detection general so that it can be reused for checking for inconsistent @_weakLinked imports. 2022-08-12 09:45:49 -07:00
Allan Shortlidge
bc5f13cb6b AST: Accept @_weakLinked on import decls to force weak linkage of symbols from a module.
The effect of declaring an import `@_weakLinked` is to treat every declaration from the module as if it were declared with `@_weakLinked`. This is useful in environments where entire modules may not be present at runtime. Although it is already possible to instruct the linker to weakly link an entire dylib, a Swift attribute provides a way to declare intent in source code and also opens the door to diagnostics and other compiler behaviors that depend on knowing that all the module's symbols will be weakly linked.

rdar://96098097
2022-08-11 11:02:57 -07:00
Doug Gregor
7149702d12 Rename @_predatesConcurrency to @preconcurrency.
Introduce the `@preconcurrency` attribute name for `@_predatesConcurrency`,
which has been the favored name in the pitch thread so far. Retain the
old name for now to help smooth migration.
2022-01-26 08:39:01 -08:00
Doug Gregor
7552cf9fc8 Maintain module name location in UnboundImport (again).
The change to add the `import` keyword location to AttributedImport also
removed the module name location in UnboundImport. However, we want to
keep both locations, for different diagnostic reasons, so reinstate the
module name location.
2021-12-21 15:17:42 -08:00
Doug Gregor
23cc638ccc Suggest @_predatesConcurrency import to suppress diagnostics.
When diagnosing a `Sendable` violation, suggest the use of
`@_predatesConcurrency` on the corresponding import to suppress those
diagnostics.
2021-12-21 11:24:56 -08:00
Doug Gregor
0367213929 Implement predates-concurrency imports for Sendable diagnostic downgrades 2021-12-21 11:24:56 -08: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
Alexis Laferrière
3401ebcf51 [Sema] Don't insert an @_spi on imports for clang SPIs
This attribute is no more needed as we now fast-track accepting all
Objective-C SPIs at access control.

rdar://85617355
2021-12-02 15:54:48 -08:00
Xi Ge
f2c868db5c ClangImporter: import SPIs from underlying clang modules by default
rdar://82822440
2021-09-09 15:22:15 -07:00
Xi Ge
4e4bae64cb ClangImporter: import SPIs from bridging headers by default
rdar://82822440
2021-09-07 14:55:17 -07:00
Xi Ge
36f25c3130 ClangImporter: teach clang importer to import Clang SPI symbols and model them similarly as Swift SPIs
For clang symbols marked with SPI_AVAILABLE, we add SPIAccessControlAttr to them so they will be
considered as SPIs in the AST. To be able to use all these symbols, we also add an implicit SPI import
statement for all clang modules. All clang SPIs belong to the same SPI group named "OBJC_DEFUALT_SPI_GROUP" because clang
currently doesn't support custom SPI group.

rdar://73902734
2021-08-28 11:11:09 -07:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Brent Royal-Gordon
bf074b093e Run some implicit imports through import resolution
Unloaded implicit imports (e.g. the `-import-module` flag) will now be processed by import resolution, and will be fully validated and cross-imported. Preloaded imports, like the standard library import, are still not run through full import resolution, but this is a definite improvement over the status quo.

This also folds `-import-underlying-module` and `@_exported import <ParentModule>` into a single code path, slightly changing the diagnostic for a failed overlay-style underlying module import.
2020-10-09 18:59:19 -07:00
Brent Royal-Gordon
d02b34cccc [NFC] Add conveniences to clean up import code 2020-10-09 18:59:19 -07:00