Commit Graph

7604 Commits

Author SHA1 Message Date
Alexis Laferrière
0c27a4c38c SwiftShims: memcmp should accept optional pointers on Darwin
Darwin defines memcmp with optional pointers. Update SwiftShims to
define it to the same type to avoid deserialization failures where we
get one over the other and the types don't match anymore.

rdar://140596571
2024-12-04 14:58:32 -08:00
Anthony Latsis
ec5bee8bc9 Merge pull request #77873 from AnthonyLatsis/day-10
test: Add regression test for #74545
2024-12-04 02:43:41 +00:00
Anthony Latsis
ea18b4b53c test: Add regression test for #74545 2024-12-03 20:59:20 +00:00
eeckstein
31cc6b8f54 Merge pull request #77901 from eeckstein/fix-test
tests: fix a wrong check line in `SILOptimizer/large_string_array.swift.gyb`
2024-12-03 02:36:05 +01:00
Pavel Yaskevich
8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Nate Chandler
f79def4cee [BarrierAccessScopes] Handle found gen locality.
As the utility runs, new gens may become local: as access scopes are
determined to contain deinit barriers, their `end_access` instructions
become kills; if such an `end_access` occurs in the same block above an
initially-non-local gen, that gen is now local.

Previously, it was asserted that initially-non-local gens would not
encounter when visiting the block backwards from that gen.  Iteration
would also _stop_ at the discovered kill, if any.  As described above,
the assertion was incorrect.

Stopping at the discovered kill was also incorrect.  It's necessary to
continue walking the block after finding such a new kill because the
book-keeping the utility does for which access scopes contain barriers.
Concretely, there are two cases:
(1) It may contain another `end_access` and above it a deinit barrier
which must result in that second scope becoming a deinit barrier.
(2) Some of its predecessors may be in the region, all the access scopes
which are open at the begin of this block must be unioned into the set
of scopes open at each predecessors' end, and more such access scopes
may be discovered above the just-visited `end_access`.

Here, both the assertion failure and the early bailout are fixed by
walking from the indicated initially-non-local gen backwards over the
entire block, regardless of whether a kill was encountered.  If a kill
is encountered, it is asserted that the kill is an `end_access` to
account for the case described above.

rdar://139840307
2024-12-02 15:36:00 -08:00
Erik Eckstein
15ead8aa48 tests: fix a wrong check line in SILOptimizer/large_string_array.swift.gyb
Triggered by https://github.com/swiftlang/swift/pull/77806
rdar://140778726
2024-12-02 19:26:39 +01:00
Erik Eckstein
c6408387a7 tests: add a missing -sil-print-types in validation-test/SILOptimizer/rdar114699006.swift
rdar://140405972
2024-11-22 14:32:52 +01:00
Pavel Yaskevich
e3b1f341f0 [CSDiagnostics] Adjust conformance failure diagnostic to check for locatable types
If conformance failure is associated with a `LocatableType`, use
its location to anchor the failure.
2024-11-21 14:13:16 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Pavel Yaskevich
9eaad6315c Merge pull request #77689 from JanBaig/issue-65500
[CSGen] Fix compiler crash when property wrapper applied to a param lacks wrappedValue initializer
2024-11-20 08:44:49 -08:00
Pavel Yaskevich
9665b0d4e3 Merge pull request #77592 from xedin/rdar-139675914
[CSSimplify] CGFloat-Double: Fix ambiguity when assigning CGFloat to …
2024-11-20 08:44:19 -08:00
JanBaig
8af3aef7c4 [CSGen] Fix compiler crash when property wrapper applied to a param lacks wrappedValue initializer 2024-11-18 19:23:28 -05:00
Hamish Knight
abec83f68e [test] Quote %original_path_env in swift-xcodegen.test
Ensure we can handle a PATH with spaces.
2024-11-16 22:28:13 +00:00
Dario Rexin
abfa450e3e Merge pull request #77597 from drexin/wip-139375022
[IRGen] Set minimum runtime availability version for CVW
2024-11-14 06:11:37 -08:00
Dario Rexin
c0c31c0613 [IRGen] Set minimum runtime availability version for CVW
rdar://139375022

CVW should not be generated when the deployment target does not have the necessary runtime functions.
2024-11-13 22:36:15 -08:00
Pavel Yaskevich
7c35c881a9 [CSSimplify] CGFloat-Double: Fix ambiguity when assigning CGFloat to double property/variable
Situations like:
```
  let _: Double = <<CGFloat>>
  <var/property of type Double> = <<CGFloat>>
```

Used to be supported due to an incorrect fix added in
diagnostic mode. Lower impact here means that right-hand
side of the assignment is allowed to maintain CGFloat
until the very end which minimizes the number of conversions
used and keeps literals as Double when possible.

Resolves: rdar://139675914
2024-11-13 13:45:56 -08:00
Meghana Gupta
184058e4ac Merge pull request #76588 from meg-gupta/lifetimeremovefeatureguardincompiler
Remove feature guard on lifetime dependence inference
2024-11-12 18:38:41 -08:00
Meghana Gupta
827caa9fce XFAIL typechecker test which leads to a cycle in the requirement machine
This PR introduces a `mapTypeIntoContext` in `InterfaceTypeRequest::evaluate` which introduces a cycle in this test.
2024-11-12 12:05:23 -08:00
Nate Cook
e12e968570 Add contains(_:) methods to (Closed)Range (#76891)
The _StringProcessing module provides a generic, collection-based
`contains` method that performs poorly for ranges and closed ranges.
This addresses the primary issue by providing concrete overloads
for Range and ClosedRange which match the expected performance for
these operations.

This change also fixes an issue with the existing range overlap tests.
The generated `(Closed)Range.overlap` tests are ignoring the "other"
range type when generating ranges for testing, so all overlap tests
are only being run against ranges of the same type. This fixes things
so that heterogeneous testing is included.
2024-11-12 11:47:24 -08:00
Henrik G. Olsson
0678829cf7 Add @PointerBounds macro (#76969)
Add @PointerBounds macro

@PointerBounds is a macro intended to be applied by ClangImporter when
importing functions with pointer parameters from C headers. By
leveraging C attributes we can get insight into bounds, esapability, and
(eventually) lifetimes of pointers, allowing us to map them to safe(r)
and more ergonomic types than UnsafePointer.

This initial macro implementation supports CountedBy and Sizedby, but
not yet EndedBy. It can generate function overloads with and without an
explicit count parameter, as well as with UnsafeBufferPointer or Span
(if marked nonescaping), and any of their combinations. It supports
nullable/optional pointers, and both mutable and immutable pointers.
It supports arbitrary count expressions. These are passed to the macro
as a string literal since any parameters referred to in the count
expression will not have been declared yet when parsing the macro.

It does not support indirect pointers or inout parameters. It supports
functions with return values, but returned pointers can not be bounds
checked yet.

Bounds checked pointers must be of type Unsafe[Mutable]Pointer[?]<T>
or Unsafe[Mutable]RawPointer[?]. Count expressions must conform to
the BinaryInteger protocol, and have an initializer with signature
"init(exactly: Int) -> T?" (or be of type Int).

rdar://137628612

---------

Co-authored-by: Doug Gregor <dgregor@apple.com>
2024-11-11 14:54:25 -08:00
Slava Pestov
f702e46751 Merge pull request #77475 from slavapestov/fix-rdar139237781
Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
2024-11-08 15:15:27 -05:00
Slava Pestov
d67e89d89c Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
When we replay a solution, we must record changes in the trail, so fix the
logic to do that. This fixes the first assertion failure with this test case.

The test case also exposed a second issue. We synthesize a CustomAttr in
applySolutionToClosurePropertyWrappers() with a type returned by simplifyType().
Eventually, CustomAttrNominalRequest::evaluate() looks at this type, and passes
it to directReferencesForType(). Unfortunately, this entry point does not
understand type aliases whose underlying type is a type parameter.
However, directReferencesForType() is the wrong thing to use here, and we
can just call getAnyNominal() instead.

Fixes rdar://139237781.
2024-11-08 10:46:07 -05:00
Pavel Yaskevich
392dac41f1 [CSSolver] DynamicMemberLookup: Ignore disabled choices while filtering disjunctions
`filterDisjunction` should ignore the choices that are already
disabled while attempting to optimize disjunctions related to
dynamic member lookup.

Resolves: rdar://139314763
2024-11-07 18:31:52 -08:00
Hamish Knight
43be5456b1 [xcodegen] Allow output to be missing in compile_commands.json
This may not always be present for CI builds.
2024-11-06 12:20:44 +00:00
Hamish Knight
a9efa842a9 Merge pull request #77406 from hamishknight/a-new-generation
Introduce swift-xcodegen
2024-11-06 11:58:14 +00:00
Hamish Knight
03d8ea5248 Introduce swift-xcodegen
This is a tool specifically designed to generate
Xcode projects for the Swift repo (as well as a
couple of adjacent repos such as LLVM and Clang).
It aims to provide a much more user-friendly experience
than the CMake Xcode generation (`build-script --xcode`).
2024-11-05 22:42:10 +00:00
Pavel Yaskevich
c2299ecaa4 Merge pull request #77377 from xedin/rdar139235128
[BuildTransform] Fix `walkExplicitReturnStmts` to walk implicit state…
2024-11-05 09:16:36 -08:00
Pavel Yaskevich
c5d0916746 [BuildTransform] Fix walkExplicitReturnStmts to walk implicit statements
Some statements introduce implicit braces and other things,
`walkExplicitReturnStmts` cannot ignore that while trying
to find explicit returns.

Resolves: rdar://139235128
2024-11-04 16:42:50 -08:00
Hamish Knight
7061a20edd [CS] Remove ConstraintSystem::getVarType
The logic here for completion wasn't actually
helping things since it would result in adding the
var overload to the system, which would result
in an ErrorType binding. We could turn the ErrorType
into a placeholder when resolving the overload,
but the simpler solution is to just allow CSGen
to turn the reference into a PlaceholderType. This
matches what we do for regular solving, and fixes
a crash with an IUO completion.

rdar://89369091
2024-11-04 17:08:20 +00:00
Daniel Rodríguez Troitiño
798f0e6b6b Merge pull request #77330 from drodriguez/swift-obj-root-strikes-back
[test] Fix incorrect usage of swift_obj_root in unified builds
2024-11-03 09:05:04 -08:00
Daniel Rodríguez Troitiño
6b27d33596 [validation-test] Add missing REQUIRES: macosx-x86_64 to test (#77357)
This test forces the usage of macosx-x86_64 and will fail if the x86_64
slice of the stdlib has not been built. Mark it as only running on
macosx-x86_64 to avoid the test failure in that case.
2024-11-02 19:00:22 -07:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Daniel Rodríguez Troitiño
facdb57f39 [test] Transform Swift Features.def into Lit available features
Take the `Features.def` file used in other parts of the code and create
a file that can be used from the LLVM Lit configuration files to add new
available features that can be checked from the tests with `REQUIRES`
and others.

The file `lit.swift-features.cfg.inc` is preprocessed by Clang and
generates a file with Python syntax that can be loaded from both
`lit.site.cfg.in` files. The preprocessing output is copied into the
different test directories in the build directory, and added it is added
as a dependency of them, so it will be generate when the test run or
when `Features.def` changes.

`EXPERIMENTAL_FEATURES` are only enabled if they are available in
production or the compiler is being built with assertions, while
`UPCOMING_FEATURES` and the rest of the `LANGUAGE_FEATURES` are always
available.
2024-11-02 11:41:09 -07:00
Daniel Rodríguez Troitiño
1e5903773b [test] Fix incorrect usage of swift_obj_root in unified builds
When doing an unified build (Swift being an external project of LLVM),
the Swift build is at `<llvm build dir>/tools/swift`, and that is the
value of `swift_obj_root`. However many products are actually placed in
`<llvm build dir>`, like `bin/`, `include/` and things like
`lib/swift/...` and others.

A couple of macros tests check the error messages printed by the
compiler against `swift_obj_root` (by the replacement done in
`PathSanitizingFileCheck` of `BUILD_DIR`) when it should have been
checking them against the top-level build directory, which will work in
both unified and non-unified builds (like `build-script` builds).
2024-11-01 11:25:59 -07:00
Slava Pestov
1acb61d23a SIL: Fix SILType::isLoweringOf() to correctly handle opaque archetypes
This predicate is meant to ask if the loweredType is equal to
`getLoweredType(pattern, formalType)` for *some* abstraction pattern.

If the formal type contained an opaque archetype, we performed a
different check, because we asked if loweredEqual is equal to
`getLoweredType(AbstractionPattern(formalType), formalType)`.

This caused a spurious SIL verifier failure when the payload of an
existential contained an opaque archetype, because we lower the
payload with the most general AbstractionPattern, so that
@thin metatypes become @thick, etc.

The regression test exercises this bug, and also another bug that was
present in 6.0 but was already fixed on main by one of my earlier
refactorings.

Fixes rdar://problem/138655637.
2024-10-30 13:19:46 -04:00
Ben Barham
f59b2f19e6 Merge branch 'main' into 2024-rebranch-to-main 2024-10-28 13:03:35 -07:00
Alex Hoppen
a313d4f50e Merge pull request #77120 from ahoppen/sdk-symlink
[SourceKit] Check if the realpath of a module is inside the SDK to decide if it's system
2024-10-24 15:48:23 -07:00
Ben Barham
746517c9f2 Merge remote-tracking branch 'origin/main' into manually-merge-main-to-rebranch
Conflicts:
  - `test/IRGen/has_symbol.swift` test updates in rebranch. The new test
    will fail, will fix in the next commit.
2024-10-24 14:20:17 -07:00
Slava Pestov
308b4f4161 Sema: Re-enable validation-test/Sema/type_checker_perf/slow/nil_coalescing.swift.gyb 2024-10-22 20:14:42 -04:00
swift-ci
98cf59bfc9 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-22 11:14:06 -07:00
Pavel Yaskevich
6754918b08 Merge pull request #77153 from xedin/issue-77003
[CSBindings] Limit `BindingSet::isViable` binding skipping to stdlib …
2024-10-22 11:11:48 -07:00
swift-ci
f55e335912 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-21 19:14:25 -07:00
Slava Pestov
1cbd7d3163 Merge pull request #77152 from slavapestov/fix-issue-77008
Sema: Give constraints a more dignified retirement
2024-10-21 22:10:05 -04:00
Pavel Yaskevich
2b11ecbec9 [CSBindings] Limit BindingSet::isViable binding skipping to stdlib collection types
This is follow-up to https://github.com/swiftlang/swift/pull/76487

It's reasonable to coalesce bindings of different kind if they don't
allow implicit conversions like stdlib collection types do.

Resolves: https://github.com/swiftlang/swift/issues/77003
2024-10-21 14:48:45 -07:00
Slava Pestov
6648508184 type_checker_perf tests should require no_asan
Fixes rdar://problem/138246764.
2024-10-21 17:25:38 -04:00
Alex Hoppen
a287e2ae8e [SourceKit] Check if the realpath of a module is inside the SDK to decide if it's system
On Windows, we run into the following situation when running SourceKit-LSP tests:
- The SDK is located at `S:\Program Files\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk` with `S:` being a substitution drive
- We find `Swift.swiftmodule` at `S:\Program Files\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\Swift.swiftmodule`
- Now, to check if `Swift.swiftmodule` is a system module, we take the realpath of the SDK, which resolves the substitution drive an results in something like `C:\Users\alex\src\Program Files\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk`
- Since we don’t take the realpath of `Swift.swiftmodule`, we will assume that it’s not in the SDK, because the SDK’s path is on `C:` while `Swift.swiftmodule` lives on `S:`

To fix this, we also need to check if a module’s real path is inside the SDK.

Fixes swiftlang/sourcekit-lsp#1770
rdar://138210224
2024-10-19 10:35:09 -07:00
swift-ci
02078feb01 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-19 06:16:37 -07:00
Slava Pestov
15db24238e Merge pull request #77112 from slavapestov/solver-perf-tests
Add a couple of solver performance tests
2024-10-19 09:14:15 -04:00
Slava Pestov
d502e556e9 Add a couple of solver performance tests 2024-10-18 17:54:25 -04:00