Skip to content

Merge main 2021-10-29 #3806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 134 commits into from
Oct 29, 2021
Merged

Merge main 2021-10-29 #3806

merged 134 commits into from
Oct 29, 2021

Conversation

kateinoigakukun
Copy link
Member

No description provided.

xedin and others added 30 commits October 21, 2021 15:22
Successful conjunction should preseve a score set by a follow-up
solve with outer context. Failure should reset the score back to
original one pre-conjunction.
To simplify clients, have the cursorinfo result be consistent whether
requesting a symbol within the current module or not, ie. do not skip
adding the module name.

Resolves rdar://77003299
…oid duplicates

It's always been the case that partial solutions introduce
some storage duplication when applied back to the constraint
system to form a more complete solution with outer context,
 but the constraint systems used to be small before
introduction of result builders (and now multi-statement
inference), which make the duplication more visible.
… to avoid duplicates

Same reasons as with `DefaultConstraints` but also improves
code ergonomics around opened types.
This ensures that while in OSSA, we have in the IR information about the lexical
lifetime of let variables.
We're seeing some C++ projects that cause an integer overflow when this is only 16 bits.
Previously, TempRValueElimination would peephole simple alloc_stacks,
even when they were lexical; here, they are left for Mem2Reg to properly
handle.

Previously, SemanticARCOpts would eliminate lexical begin_borrows,
incorrectly allowing the lifetime of the value borrowed by them to be
observably shortened.  Here, those borrow scopes are not eliminated if
they are lexical.

Added an executable test that verifies that a local variable strongly
referencing a delegate object keeps that delegate alive through the call
to an object that weakly references the delegate and calls out to it.
This library can and should be buildable with a standard compiler.
Disable the forced switch of the compiler.
Added some attributes to mark functions as taking format strings.

rdar://84571859
Adds two new IRGen-level builtins (one for allocating, the other for deallocating), a stdlib shim function for enhanced stack-promotion heuristics, and the proposed public stdlib functions.
[Runtime] Add format string attributes.
Turn on -Wformat-nonliteral so that any format string that is passed through
a variable is turned into an error.  There are a variety of reasonable ways
of fixing these where they occur, and it's safer to have this switched on.

rdar://84571859
…-only-on-failure

[CSStep] Conjunction: Reset current/best score only on failure
…m-storage

[ConstraintSystem] De-duplicate storage of constraint system elements
These new entries are false positives due to stale baselines that didn't record @_silgen_name.
test: update stability-stdlib-abi-with{out}-asserts.test
…ilitytest

Revert "test: update stability-stdlib-abi-with{out}-asserts.test"
Revert "ABI checker: use dedicated mangled name field to diagnose mangled name changes"
…pes (swiftlang#39903)

* Fix `_customContainsEquatableElement` implementation for `Stride*` types

* Add tests for `Stride*.contains`
…buffers

[SE-0322] Temporary uninitialized buffers
nate-chandler and others added 28 commits October 27, 2021 13:55
Previously, when encountering a borrow of a guaranteed value, the
end_borrows of that reborrow were marked alive.  Only doing that enables
end_borrows of the outer borrow scope can be marked as dead.  The result
is that uses of the reborrowed value (including its end_borrow) can
outstrip the outer borrow scope, which is illegal.

Here, the outer borrow scope's end_borrows are marked alive.  To do
that, the originally borrowed values have to be identified via
findGuaranteedReferenceRoots.
[Diagnostics] Add a fix-it to insert 'some' when associated type inference failed because existential types can't conform to protocols.
[CursorInfo] Always add module name to response
…mepointer-backdeploy

Disable the definition and use of swift_async_extendedFramePointerFlags on watchOS
…ond_fail errors.

We use it in a subsequent commit in this PR to guard BuiltinMove.
…rol usage of move only features.

These include _move and @_noImplicitCopy. I still need to wire up the parsing of
those behind this feature.

The reason that I am adding this now is that I am going to now need to make some
changes behind a feature flag and I have not yet needed to add one. The specific
reason I needed to add one here is to ensure that I properly guard inside _move
the call to Builtin.move so as to prevent a "cond_fail" incident.

P.S.: This work depends on experimental lexical lifetimes being enabled as well,
so I did that at the same time in this PR.
…n non-generic, non-existential values.

This patch introduces a new stdlib function called _move:

```Swift
  @_alwaysEmitIntoClient
  @_transparent
  @_semantics("lifetimemanagement.move")
  public func _move<T>(_ value: __owned T) -> T {
  #if $ExperimentalMoveOnly
    Builtin.move(value)
  #else
    value
  #endif
  }
```

It is a first attempt at creating a "move" function for Swift, albeit a skleton
one since we do not yet perform the "no use after move" analysis. But this at
leasts gets the skeleton into place so we can built the analysis on top of it
and churn tree in a manageable way. Thus in its current incarnation, all it does
is take in an __owned +1 parameter and returns it after moving it through
Builtin.move.

Given that we want to use an OSSA based analysis for our "no use after move"
analysis and we do not have opaque values yet, we can not supporting moving
generic values since they are address only. This has stymied us in the past from
creating this function. With the implementation in this PR via a bit of
cleverness, we are now able to support this as a generic function over all
concrete types by being a little clever.

The trick is that when we transparent inline _move (to get the builtin), we
perform one level of specialization causing the inlined Builtin.move to be of a
loadable type. If after transparent inlining, we inline builtin "move" into a
context where it is still address only, we emit a diagnostic telling the user
that they applied move to a generic or existential and that this is not yet
supported.

The reason why we are taking this approach is that we wish to use this to
implement a new (as yet unwritten) diagnostic pass that verifies that _move
(even for non-trivial copyable values) ends the lifetime of the value. This will
ensure that one can write the following code to reliably end the lifetime of a
let binding in Swift:

```Swift
  let x = Klass()
  let _ = _move(x)
  // hypotheticalUse(x)
```

Without the diagnostic pass, if one were to write another hypothetical use of x
after the _move, the compiler would copy x to at least hypotheticalUse(x)
meaning the lifetime of x would not end at the _move, =><=.

So to implement this diagnostic pass, we want to use the OSSA infrastructure and
that only works on objects! So how do we square this circle: by taking advantage
of the mandatory SIL optimzier pipeline! Specifically we take advantage of the
following:

1. Mandatory Inlining and Predictable Dead Allocation Elimination run before any
   of the move only diagnostic passes that we run.

2. Mandatory Inlining is able to specialize a callee a single level when it
   inlines code. One can take advantage of this to even at -Onone to
   monomorphosize code.

and then note that _move is such a simple function that predictable dead
allocation elimination is able to without issue eliminate the extra alloc_stack
that appear in the caller after inlining without issue. So we (as the tests
show) get SIL that for concrete types looks exactly like we just had run a
move_value for that specific type as an object since we promote away the
stores/loads in favor of object operations when we eliminate the allocation.

In order to prevent any issue with this being used in a context where multiple
specializations may occur, I made the inliner emit a diagnostic if it inlines
_move into a function that applies it to an address only value. The diagnostic
is emitted at the source location where the function call occurs so it is easy
to find, e.x.:

```
func addressOnlyMove<T>(t: T) -> T {
    _move(t) // expected-error {{move() used on a generic or existential value}}
}

moveonly_builtin_generic_failure.swift:12:5: error: move() used on a generic or existential value
    _move(t)
    ^
```

To eliminate any potential ABI impact, if someone calls _move in a way that
causes it to be used in a context where the transparent inliner will not inline
it, I taught IRGen that Builtin.move is equivalent to a take from src -> dst and
marked _move as always emit into client (AEIC). I also took advantage of the
feature flag I added in the previous commit in order to prevent any cond_fails
from exposing Builtin.move in the stdlib. If one does not pass in the flag
-enable-experimental-move-only then the function just returns the value without
calling Builtin.move, so we are safe.

rdar://83957028
The clang importer sets the clang resource directory to
`RuntimeResourcePath`/clang (usually "lib/swift/clang", a symbolic link
into "lib/clang/<version>"). This was inadvertently being removed in a
check to remove the clang *executable* path.

Modify that check to only the first argument so the resource directory
is properly passed through.
…0fa0608409ef1c732d1fd2b

[moveOnly] Add a skeleton _move function
Do not attempt to use a cross-compiled compiler for a foreign target.  This is not guaranteed to work (e.g. building for ARM on x64).  This at least surfaces the error properly.
…-move-only

I included a helpful diagnostic that explains to the user that they need to pass
-enable-experimental-move-only to use this language feature.
ABIChecker: teach wmo mode to emit ABI descriptor files
…es/avoid-incorrect-elimination

[SILOptimizer] Keep lexical lifetime markers.
…licitCopy variables.

NOTE: This is only available when the flag -enable-experimental-move-only. There
are no effects when the flag is disabled.

The way that this works is that it takes advantage of the following changes to
SILGen emission:

* When SILGen initializes a let with NoImplicitCopyAttribute, SILGen now emits
a begin_borrow [lexical] + copy + move_only. This is a pattern that we can check
and know that we are processing a move only value. When performing move
checking, we check move_only as a move only value and that it isn't consumed
multiple times.

* The first point works well for emitting all diagnostics except for
initializing an additional let var. To work around that I changed let
initialization to always bind to an owned value to a move of that owned
value. There is no semantic difference since that value is going to be consumed
by the binding operation anyways so we effectively just move the cleanup from
the original value we wanted to bind to the move. We still then actually borrow
the new let value with a begin_borrow [lexical] for the new let value. This
ensures that an initialization of a let value appears to be a consuming use to
the move only value checker while ensuring that the value has a proper
begin_borrow [lexical].

Some notes on functionality:

1. This attribute can only be applied to local 'let'.

2. "print" due to how we call it today with a vararg array is treated as a
   consuming use (unfortunately).

3. I have not added the builtin copy operator yet, but I recently added a _move
   skeleton attribute so one can end the lifetimes of these values early.

4. This supports all types that are not address only types (similar to
   _move). To support full on address only types we need opaque values.

rdar://83957088
…530be2c6890f7f5fea35fc5

[moveOnly] Move @_noImplicitCopy behind the flag -enable-experimental-move-only
…andle-missing-main-executor-decl

Workaround to cope with older SDK missing `getMainExecutor`
[libswift] Undefine IBAction/IBOutlet ObjC macros when building lib swift
…cc5fae25efd75c625e57d3c

[moveOnly] Add a new experimental move only checker that checks noImplicitCopy variables.
…es/mem2reg-end-single-block-lifetimes-with-valid-memory

[Mem2Reg] Handled unreachables for single-block allocations.
…borrow-scope-alive-when-reborrowing

[DCE] Keep outer borrows alive when reborrowing.
…ce-dir

[DepScanner] Do not remove the resource directory path
…compiling

Update SwiftWindowsSupport.cmake
…ol-list

Amend _swift_stdlib_getCurrentStackBounds() to do nothing when SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is defined.
@kateinoigakukun kateinoigakukun merged commit c64b8b9 into swiftwasm Oct 29, 2021
@kateinoigakukun kateinoigakukun deleted the katei/merge-main-2021-10-29 branch October 29, 2021 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.