Commit Graph

7754 Commits

Author SHA1 Message Date
Slava Pestov
64eb9dfbd4 Merge pull request #67798 from slavapestov/fix-rdar113103854
Sema: Fix a couple of problems in checkContextualRequirements()
2023-08-09 20:12:11 -04:00
Slava Pestov
a7c276bd14 Update 0161-issue-49119.swift 2023-08-09 17:11:11 -04:00
Slava Pestov
fbd1f1acbd Sema: Fix a couple of problems in checkContextualRequirements()
The original bug was a crash-on-invalid with a missing '}', but it
actually exposed a bug with nested protocols (SE-0404) and another
long-time bug.

- Whatever we do, we should skip this for protocols because their 'Self'
  parameter is not bound from context.

- getTrailingWhereClause() is not the right proxy for "has a generic
  signature different than its parent", in particular it doesn't
  round-trip through serialization. Instead, just compare generic
  signatures for pointer equality in the early return check.

The second change is source-breaking because it was possible to
write a nested type with a `where` clause and use it contradicting
its requirements across a module boundary.

Fixes rdar://113103854.
2023-08-08 15:06:08 -04:00
Slava Pestov
4ebbb60fae Regression test for rdar://problem/113492450 2023-08-08 11:03:11 -04:00
Pavel Yaskevich
27413f5624 [CSSimplify] Relax isBindable requirements for pack expansion variables
If type variable we are about to bind represents a pack
expansion type, allow the binding to happen regardless of
what the \c type is, because contextual type is just a hint
in this situation and type variable would be bound to its
opened type instead.

Resolves: rdar://112617922
2023-08-04 16:49:20 -07:00
eeckstein
b3cd553dba Merge pull request #67534 from eeckstein/fix-24-bit-enums
IRGen: fix a problem with 24-bit enum payloads in statically initialized global variables
2023-07-27 05:50:32 +02:00
Nate Chandler
35b37ab5f5 [Test] Disable test with debug stdlibs.
Now that the SwiftStdlib 5.9 macro has been defined, this test failing
with stdlib debug builds is exposed. That is occurring because the back
deployment fallback
`$ss9TaskLocalC13withValueImpl_9operation4file4lineqd__xn_qd__yYaKXESSSutYaKlFTwB`
is now being called.

In unoptimized stdlib builds, the version of that function that is
deserialized into the test case module features an unoptimized copy of
the argument `%1` into a temporary (`%10`):

```
  %10 = alloc_stack $Value                        // users: %14, %13, %11
  copy_addr %1 to [init] %10 : $*Value            // id: %11
  // function_ref swift_task_localValuePush
  %12 = function_ref @swift_task_localValuePush : $@convention(thin) <τ_0_0> (Builtin.RawPointer, @in τ_0_0) -> () // user: %13
  %13 = apply %12<Value>(%9, %10) : $@convention(thin) <τ_0_0> (Builtin.RawPointer, @in τ_0_0) -> ()
  dealloc_stack %10 : $*Value                     // id: %14
```

This is a problem because `swift_task_localValuePush` allocates in the
async stack (see rdar://107275872) but that fact isn't encoded in SIL
(the fix for which is tracked by rdar://108260399), so the
`alloc_stack`/`dealloc_stack` surrounding that call result in a
violation of stack discipline.

```
push // alloc_stack
push // swift_task_localValuePush
pop // dealloc_stack -- oops
```

In optimized stdlib builds, the copy has been optimized away by the time
the function is deserialized into the test case module:

```
bb0(%0 : $*R, %1 : $*Value, %2 : @guaranteed $@noescape @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error any Error) for <R>, %3 : @guaranteed $String, %4 : $UInt, %5 : @guaranteed $TaskLocal<Value>):
  // function_ref _checkIllegalTaskLocalBindingWithinWithTaskGroup(file:line:)
  %6 = function_ref @$ss039_checkIllegalTaskLocalBindingWithinWithC5Group4file4lineySS_SutF : $@convention(thin) (@guaranteed String, UInt) -> () // user: %7
  %7 = apply %6(%3, %4) : $@convention(thin) (@guaranteed String, UInt) -> ()
  // function_ref TaskLocal.key.getter
  %8 = function_ref @$ss9TaskLocalC3keyBpvg : $@convention(method) <τ_0_0 where τ_0_0 : Sendable> (@guaranteed TaskLocal<τ_0_0>) -> Builtin.RawPointer // user: %9
  %9 = apply %8<Value>(%5) : $@convention(method) <τ_0_0 where τ_0_0 : Sendable> (@guaranteed TaskLocal<τ_0_0>) -> Builtin.RawPointer // user: %11
  // function_ref swift_task_localValuePush
  %10 = function_ref @swift_task_localValuePush : $@convention(thin) <τ_0_0> (Builtin.RawPointer, @in τ_0_0) -> () // user: %11
  %11 = apply %10<Value>(%9, %1) : $@convention(thin) <τ_0_0> (Builtin.RawPointer, @in τ_0_0) -> ()
```

The argument `%1` is forwarded into the apply of `swift_task_localValuePush`.

rdar://112898559
2023-07-26 16:16:55 -07:00
Erik Eckstein
a3822cd2c5 IRGen: fix a problem with 24-bit enum payloads in statically initialized global variables
IRGen crashed in case an enum, which has a 24 bit payload (e.g. three `UInt8`), is used as a payload of another enum, e.g. `Optional`, in a statically initialized global variable.

rdar://112823823
2023-07-26 15:36:31 +02:00
Pavel Yaskevich
33a37b9516 Merge pull request #67377 from xedin/rdar-112090069
[CSSimplify] Extend same-shape detection to account for pack archetypes
2023-07-24 10:01:29 -07:00
Erik Eckstein
7f54c63b29 tests: Disable some tests which fail due to problems in Foundation
Those tests should be part of the Foundation overlay, which is no longer part of the Swift project.

rdar://112643333
2023-07-24 08:34:06 +02:00
Pavel Yaskevich
5a5edcafc3 [CSSimplify] Extend same-shape detection to account for pack archetypes
`same-shape` mismatch detection logic shouldn't expect that types are
always packs because they could be either invalid (i.e. Void) or pack
archetypes too.

Resolves: rdar://112090069
2023-07-20 22:50:22 -07:00
Holly Borla
43c300408b [NFC] Update additional parameter pack tests. 2023-07-20 15:36:20 -07:00
Slava Pestov
9e73dad311 Merge pull request #67342 from slavapestov/open-type-workaround
Sema: Workaround for issue in ConstraintSystem::openType()
2023-07-19 07:49:45 -04:00
Slava Pestov
e0a1a11a6b SIL: Fix substituted function type visitor for PackExpansionType with concrete pattern type
If the pattern doesn't have any pack parameters in it anymore,
we need to recover the substituted count type from the original
count type.

Fixes rdar://problem/112065340.
2023-07-18 12:19:22 -04:00
Slava Pestov
415b70584a Sema: Workaround for issue in ConstraintSystem::openType() 2023-07-17 15:33:34 -04:00
Mike Ash
e89de6e7e0 Merge pull request #67252 from mikeash/remove-foundation-tests
[Test] Remove stdlib/NSStringAPI.swift and some supporting code.
2023-07-17 11:45:49 -04:00
Slava Pestov
aa026f4d06 Merge pull request #67266 from slavapestov/transform-type-parameter-packs
Fix various places where we didn't handle "bound" pack references correctly
2023-07-13 08:09:04 -04:00
Slava Pestov
e6253b282a AST: Re-implement mapPackTypeIntoElementContext() in terms of mapContextualPackTypeIntoElementContext() 2023-07-12 18:02:14 -04:00
Mike Ash
ea6a2e26f2 [Test] Remove stdlib/NSStringAPI.swift and some supporting code.
This is testing the Foundation overlay, which is no longer part of the Swift project.
2023-07-12 12:18:58 -04:00
Tim Kientzle
a897fcb47c Correctly project enums with zero-sized payloads
I earlier overhauled the enum layout logic to correctly consider
enums with generic cases and cases that have zero size.
This updates the enum projection logic to use that information
as well.

In particular, this fixes a bug where an MPE with zero-sized cases
would be incorrectly projected by RemoteMirror (with consequences
for the `leaks` tool and lldb).

Resolves rdar://111705059
2023-07-12 08:46:32 -07:00
Alex Hoppen
4f5743c8c6 [IDE] Adjust more test cases 2023-07-07 19:51:01 +02:00
Alex Hoppen
c7e0bfae02 [IDE] Adjust test cases for migrating all completion kinds to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
928a03a2e0 [CodeCompletion] Migrate conforming methods list to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
4c186c0a9a [CodeCompletion] Fix code completion issues related to type checking tap expressions in the cosntraint system 2023-07-07 19:50:46 +02:00
Eric Miotto
266c00d285 Skip build system tests when targeting remote executors
These will be still exercised when targeting macOS, Linux and Windows.

Addresses rdar://111854328
2023-07-06 09:50:02 -07:00
Slava Pestov
e01822ca20 Add regression test for rdar://problem/108319167 2023-07-03 18:41:44 -04:00
Arnold Schwaighofer
a56b148747 Fix validation-test/IRGen tests 2023-06-23 06:57:38 -07:00
Arnold Schwaighofer
90c7193651 More IRGen test to move over 2023-06-14 10:49:50 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
Slava Pestov
7cc8063889 SIL: Forgot to pass SubstFlags::PreservePackExpansionLevel in one place 2023-06-07 15:17:54 -04:00
Alastair Houghton
d67354473f Merge pull request #66335 from al45tair/eng/PR-110261712
[Backtracing][Linux] Add support for Linux in the _Backtracing module.
2023-06-07 13:48:46 +01:00
Alastair Houghton
a890ec2c0f [Backtracing][Linux][Tests] Fix verify_all_overlays test.
The `_Backtracing` module has a number of private implementation only
imports that aren't used outside of the module and that don't require
any additional libraries (hence they aren't relevant to the outside
world).  `verify_all_overlays.py` needs to know about these when it
does its test, because it loadas the module as the main module, which
results in implementation only imports being required instead of
ignored.

rdar://110261712
2023-06-07 09:03:50 +01:00
swift-ci
c74fd074c6 Merge pull request #64280 from hamishknight/platypus
[CS] Allow ExprPatterns to be type-checked in the solver
2023-06-06 20:21:45 -07:00
Hamish Knight
7a137d6756 [CS] Allow ExprPatterns to be type-checked in the solver
Previously we would wait until CSApply, which
would trigger their type-checking in
`coercePatternToType`. This caused a number of
bugs, and hampered solver-based completion, which
does not run CSApply. Instead, form a conjunction
of all the ExprPatterns present, which preserves
some of the previous isolation behavior (though
does not provide complete isolation).

We can then modify `coercePatternToType` to accept
a closure, which allows the solver to take over
rewriting the ExprPatterns it has already solved.

This then sets the stage for the complete removal
of `coercePatternToType`, and doing all pattern
type-checking in the solver.
2023-06-07 00:35:01 +01:00
swift-ci
4ef135cc10 Merge pull request #66201 from nate-chandler/dealloc-on-stack-packs
[IRGen] Dealloc on-stack metadata/wtable packs on the dominance frontier.
2023-06-05 13:30:18 -07:00
Eric Miotto
44a40979e5 tsan-ignores-arc-locks.swift: post process test binary on Darwin (#66308)
This allows the `DYLD_LIBRARY_PATH` override to work as expected and
avoid crashes when running.

Addresses rdar://108188149
2023-06-05 12:31:11 -07:00
Nate Chandler
d1ec1e6693 [IRGen] Dealloc metadata packs on dom frontier.
Deallocate dynamic allocas done for metadata/wtable packs.  These
stackrestore calls are inserted on the dominance frontier and then stack
nesting is fixed up.  That was achieved as follows:

Added a new IRGen pass PackMetadataMarkerInserter; it
- determines if there are any instructions which might allocate on-stack
  pack metadata
- if there aren't, no changes are made
- if there are, alloc_pack_metadata just before instructions that could
  allocate pack metadata on the stack and dealloc_pack_metadata on the
  dominance frontier of those instructions
- fixup stack nesting

During IRGen, the allocations done for metadata/wtable packs are
recorded and IRGenSILFunction associates them with the instruction that
lowered.  It must be the instruction after some alloc_pack_metadata
instruction.  Then, when visiting the dealloc_pack_metadata instructions
corresponding to that alloc_pack_metadata, deallocate those packs.
2023-06-05 08:11:28 -07:00
Nate Chandler
0b5a233d73 [GenPack] Always heapify metadata packs.
Until the optimization to leave packs on-stack is in place.  Even then,
we'll want to keep this as a fallback.

rdar://110123679
2023-06-03 07:30:09 -07:00
Nate Cook
fb52491dcd Fix String capacity growth tests for watchOS
watchOS devices can have different allocation characteristics
from other devices. This modifies the string capacity growth
tests to be more flexible about measuring the growth in
capacity, specifically when more is allocated than requested.
2023-06-01 12:11:52 -05:00
Erik Eckstein
92fab06d96 IRGen: fix generation of static enums with function payloads
fixes a compiler crash

rdar://109999583
2023-05-31 14:22:48 +02:00
Erik Eckstein
fe367e8013 Optimizer/IRGen: allow enums in static initializers of globals
The main change here is in IRGen which needs to be able to emit constant enum values.
Use `emitValueInjection` to create the enum constant.
Usually this method creates code in the current function.
But if all arguments to the enum are constant, the builder never has to emit an instruction.
Instead it can constant fold everything and just returns the final constant.

Also, create statically initialized let-globals as constant global (`constant` instead of `global`).
2023-05-25 16:28:41 +02:00
Eric Miotto
1aaaef91cc Relax FileCheck directives for skip_clean_llbuild.test (#66062)
This is needed short term to allow the test to pass when running on
Python 3.11 and later and avoid errors like

```
<stdin>:44:1: note: non-matching line after previous match is here
<string>:1: DeprecationWarning: 'pipes' is deprecated and slated for removal in Python 3.13
^
```

Long term we want to replace uses of the obsolete `pipes.quotes`
function with `shlex.quotes`.

Addresses rdar://109664710
2023-05-24 08:18:10 -07:00
nate-chandler
efe762de0b Merge pull request #66014 from nate-chandler/rdar109540863
[IRGen] Cast dynamic alloca to appropriate type.
2023-05-19 07:00:08 -07:00
Nate Chandler
4b46622e49 [IRGen] Cast dynamic alloca to appropriate type.
Fix the type of the `alloca` created by `GenPack`'s for type metadata
and witness tables by fixing its callee, `emitDynamicAlloca` to always
return a `StackAddress` whose `Address`' type is the one specified by
the caller.

rdar://109540863
2023-05-18 20:51:54 -07:00
Nate Cook
23c19333df [stdlib] Fix String.reserveCapacity underallocation (#65902)
When called on a string that is not uniquely referenced,
`String.reserveCapacity(_:)` ignores the current capacity, using
the passed-in capacity for the size of its new storage. This can
result in an underallocation and write past the end of the new
buffer.

This fix changes the new size calculation to use the current UTF-8
count as the minimum. Non-native or non-unique strings
now allocate the requested capacity (or space enough for the
current contents, if that's larger than what's requested).

rdar://109275875
Fixes #53483
2023-05-17 12:11:23 -05:00
Alex Hoppen
1eadffcc00 [CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types
When completing, we call `getExistentialType` on the contextual type to get a nice and concise description of the contextual parameter’s type that doesn’t contain archetypes and which we can also serialize into a USR so we are able to calculate type relations for code completion results from the code completion cache.

When completing in a position that has a contextual type which only constrains one of two primary associated protocol types, this fails because `getExistentialType` (which calls `getDependentUpperBounds`) tries to form a `ParameterizedProtocolType`, which fails since not all primary associated types have been constrained.

AFAICT the fix here is to just fall back to the default behavior of returning the plain protocol type instead of `abort`ing.

rdar://108835466
2023-05-10 16:38:30 -07:00
Alex Hoppen
50249551a7 [CodeCompletion] Fix another test that was causing an assertion failure in the stress tester 2023-05-09 17:19:31 -07:00
Hamish Knight
c0e013907e [AST] Allocate PlaceholderTypes in the correct arena
We shouldn't be allocating placeholders for type
variables in the permanent arena, and we should be
caching them such that equality works.

To achieve this, we need to introduce a new
"solver allocated" type property. This is required
because we don't want to mark placeholder types
with type variable originators as themselves having
type variables, as it's not part of their structural
type. Also update ErrorType to use this bit, though
I don't believe we currently create ErrorTypes
with type variable originators.
2023-05-06 20:42:02 +01:00
swift-ci
f31d7cdab4 Merge pull request #65704 from hamishknight/revert-placeholder
Revert "[AST] Allocate PlaceholderTypes in the correct arena"
2023-05-05 14:12:13 -07:00