Skip to content

Commit 73ca7cf

Browse files
authored
Merge pull request #2370 from swiftwasm/main
[pull] swiftwasm from main
2 parents 9db63b9 + 008ce5b commit 73ca7cf

File tree

63 files changed

+1584
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1584
-496
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,12 @@ if(SWIFT_HOST_VARIANT_ARCH)
610610
else()
611611
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
612612
set(SWIFT_HOST_VARIANT_ARCH_default "x86_64")
613-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64")
614-
set(SWIFT_HOST_VARIANT_ARCH_default "aarch64")
613+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
614+
if(SWIFT_HOST_VARIANT_SDK_default STREQUAL OSX)
615+
set(SWIFT_HOST_VARIANT_ARCH_default "arm64")
616+
else()
617+
set(SWIFT_HOST_VARIANT_ARCH_default "aarch64")
618+
endif()
615619
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
616620
set(SWIFT_HOST_VARIANT_ARCH_default "powerpc64")
617621
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")

docs/HowToGuides/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ git remote add my-remote https://github.com/username/swift.git
343343
Finally, create a new branch.
344344
```sh
345345
# Using 'my-branch' as a placeholder name
346-
git checkout my-branch
346+
git checkout -b my-branch
347347
git push --set-upstream my-remote my-branch
348348
```
349349

docs/SIL.rst

Lines changed: 119 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,17 +1675,17 @@ Ownership SSA
16751675
A SILFunction marked with the ``[ossa]`` function attribute is considered to be
16761676
in Ownership SSA form. Ownership SSA is an augmented version of SSA that
16771677
enforces ownership invariants by imbuing value-operand edges with semantic
1678-
ownership information. All SIL values are statically assigned an ownership kind
1678+
ownership information. All SIL values are assigned a constant ownership kind
16791679
that defines the ownership semantics that the value models. All SIL operands
16801680
that use a SIL value are required to be able to be semantically partitioned in
1681-
between "normal uses" that just require the value to be live and "consuming
1682-
uses" that end the lifetime of the value and after which the value can no longer
1683-
be used. Since operands that are consuming uses end a value's lifetime,
1684-
naturally we must have that the consuming use points jointly post-dominate all
1685-
non-consuming use points and that a value must be consumed exactly once along
1686-
all reachable program paths, preventing leaks and use-after-frees. As an
1687-
example, consider the following SIL example with partitioned defs/uses annotated
1688-
inline::
1681+
between "non-lifetime ending uses" that just require the value to be live and
1682+
"lifetime ending uses" that end the lifetime of the value and after which the
1683+
value can no longer be used. Since by definition operands that are lifetime
1684+
ending uses end their associated value's lifetime, we must have that the
1685+
lifetime ending use points jointly post-dominate all non-lifetime ending use
1686+
points and that a value must have exactly one lifetime ending use along all
1687+
reachable program paths, preventing leaks and use-after-frees. As an example,
1688+
consider the following SIL example with partitioned defs/uses annotated inline::
16891689

16901690
sil @stash_and_cast : $@convention(thin) (@owned Klass) -> @owned SuperKlass {
16911691
bb0(%kls1 : @owned $Klass): // Definition of %kls1
@@ -1710,12 +1710,101 @@ inline::
17101710

17111711
Notice how every value in the SIL above has a partionable set of uses with
17121712
normal uses always before consuming uses. Any such violations of ownership
1713-
semantics would trigger a static SILVerifier error allowing us to know that we
1713+
semantics would trigger a SILVerifier error allowing us to know that we
17141714
do not have any leaks or use-after-frees in the above code.
17151715

1716+
Ownership Kind
1717+
~~~~~~~~~~~~~~
1718+
17161719
The semantics in the previous example is of just one form of ownership semantics
1717-
supported: "owned" semantics. In SIL, we allow for values to have one of four
1718-
different ownership kinds:
1720+
supported: "owned" semantics. In SIL, we map these "ownership semantics" into a
1721+
form that a compiler can reason about by mapping semantics onto a lattice with
1722+
the following elements: `None`_, `Owned`_, `Guaranteed`_, `Unowned`_, `Any`. We
1723+
call this the lattice of "Ownership Kinds" and each individual value an
1724+
"Ownership Kind". This lattice is defined as a 3-level lattice with::
1725+
1726+
1. None being Top.
1727+
2. Any being Bottom.
1728+
3. All non-Any, non-None OwnershipKinds being defined as a mid-level elements of the lattice
1729+
1730+
We can graphically represent the lattice via a diagram like the following::
1731+
1732+
+------+
1733+
+-------- | None | ---------+
1734+
| +------+ |
1735+
| | |
1736+
v v v ^
1737+
+-------+ +-----+------+ +---------+ |
1738+
| Owned | | Guaranteed | | Unowned | +--- Value Ownership Kinds and
1739+
+-------+ +-----+------+ +---------+ Ownership Constraints
1740+
| | |
1741+
| v | +--- Only Ownership Constraints
1742+
| +-----+ | |
1743+
+-------->| Any |<----------+ v
1744+
+-----+
1745+
1746+
One moves down the lattice by performing a "meet" operation::
1747+
1748+
None meet OtherOwnershipKind -> OtherOwnershipKind
1749+
Unowned meet Owned -> Any
1750+
Owned meet Guaranteed -> Any
1751+
1752+
and one moves up the lattice by performing a "join" operation, e.x.::
1753+
1754+
Any join OtherOwnershipKind -> OtherOwnershipKind
1755+
Owned join Any -> Owned
1756+
Owned join Guaranteed -> None
1757+
1758+
This lattice is applied to SIL by requiring well formed SIL to:
1759+
1760+
1. Define a map of each SIL value to a constant OwnershipKind that classify the
1761+
semantics that the SIL value obeys. This ownership kind may be static (i.e.:
1762+
the same for all instances of an instruction) or dynamic (e.x.: forwarding
1763+
instructions set their ownership upon construction). We call this subset of
1764+
OwnershipKind to be the set of `Value Ownership Kind`_: `None`_, `Unowned`_,
1765+
`Guaranteed`_, `Owned`_ (note conspiciously missing `Any`). This is because
1766+
in our model `Any` represents an unknown ownership semantics and since our
1767+
model is strict, we do not allow for values to have unknown ownership.
1768+
1769+
2. Define a map from each operand of a SILInstruction, `i`, to a constant
1770+
Ownership Kind, Boolean pair called the operand's `Ownership
1771+
Constraint`_. The Ownership Kind element of the `Ownership Constraint`_
1772+
determines semantically which ownership kind's the operand's value can take
1773+
on. The Boolean value is used to know if an operand will end the lifetime of
1774+
the incoming value when checking dataflow rules. The dataflow rules that each
1775+
`Value Ownership Kind`_ obeys is documented for each `Value Ownership Kind`_
1776+
in its detailed description below.
1777+
1778+
Then we take these two maps and require that valid SIL has the property that
1779+
given an operand, ``op(i)`` of an instruction ``i`` and a value ``v`` that
1780+
``op(i)`` can only use ``v`` if the ``join`` of
1781+
``OwnershipConstraint(operand(i))`` with ``ValueOwnershipKind(v)`` is equal to
1782+
the ``ValueOwnershipKind`` of ``v``. In symbols, we must have that::
1783+
1784+
join : (OwnershipConstraint, ValueOwnershipKind) -> ValueOwnershipKind
1785+
OwnershipConstraint(operand(i)) join ValueOwnershipKind(v) = ValueOwnershipKind(v)
1786+
1787+
In words, a value can be passed to an operand if applying the operand's
1788+
ownership constraint to the value's ownership does not change the value's
1789+
ownership. Operationally this has a few interesting effects on SIL::
1790+
1791+
1. We have defined away invalid value-operand (aka def-use) pairing since the
1792+
SILVerifier validates the aforementioned relationship on all SIL values,
1793+
uses at all points of the pipeline until ossa is lowered.
1794+
1795+
2. Many SIL instructions do not care about the ownership kind that their value
1796+
will take. They can just define all of their operand's as having an
1797+
ownership constraint of Any.
1798+
1799+
Now lets go into more depth upon `Value Ownership Kind`_ and `Ownership Constraint`_.
1800+
1801+
Value Ownership Kind
1802+
~~~~~~~~~~~~~~~~~~~~
1803+
1804+
As mentioned above, each SIL value is statically mapped to an `Ownership Kind`_
1805+
called the value's "ValueOwnershipKind" that classify the semantics of the
1806+
value. Below, we map each ValueOwnershipKind to a short summary of the semantics
1807+
implied upon the parent value:
17191808

17201809
* **None**. This is used to represent values that do not require memory
17211810
management and are outside of Ownership SSA invariants. Examples: trivial
@@ -1739,10 +1828,7 @@ different ownership kinds:
17391828
bitcasting a trivial type to a non-trivial type. This value should never be
17401829
consumed.
17411830

1742-
We describe each of these semantics in more detail below.
1743-
1744-
Value Ownership Kind
1745-
~~~~~~~~~~~~~~~~~~~~
1831+
We describe each of these semantics in below in more detail.
17461832

17471833
Owned
17481834
`````
@@ -1912,10 +1998,26 @@ This is a form of ownership that is used to model two different use cases:
19121998
trivial pointer to a class. In that case, since we have no reason to assume
19131999
that the object will remain alive, we need to make a copy of the value.
19142000

2001+
Ownership Constraint
2002+
~~~~~~~~~~~~~~~~~~~~
2003+
2004+
NOTE: We assume that one has read the section above on `Ownership Kind`_.
2005+
2006+
As mentioned above, every operand ``operand(i)`` of a SIL instruction ``i`` has
2007+
statically mapped to it:
2008+
2009+
1. An ownership kind that acts as an "Ownership Constraint" upon what "Ownership
2010+
Kind" a value can take.
2011+
2012+
2. A boolean value that defines whether or not the execution of the operand's
2013+
instruction will cause the operand's value to be invalidated. This is often
2014+
times referred to as an operand acting as a "lifetime ending use".
2015+
19152016
Forwarding Uses
19162017
~~~~~~~~~~~~~~~
19172018

1918-
NOTE: In the following, we assumed that one read the section above, `Value Ownership Kind`_.
2019+
NOTE: In the following, we assumed that one read the section above, `Ownership
2020+
Kind`_, `Value Ownership Kind`_ and `Ownership Constraint`_.
19192021

19202022
A subset of SIL instructions define the value ownership kind of their results in
19212023
terms of the value ownership kind of their operands. Such an instruction is

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,9 @@ NOTE(note_add_async_to_function,none,
41324132
"add 'async' to function %0 to make it asynchronous", (DeclName))
41334133
NOTE(note_add_asynchandler_to_function,none,
41344134
"add '@asyncHandler' to function %0 to create an implicit asynchronous context", (DeclName))
4135+
NOTE(note_add_actorindependent_to_decl,none,
4136+
"add '@actorIndependent' to %0 to make this %1 independent of the actor",
4137+
(DeclName, DescriptiveDeclKind))
41354138
NOTE(note_add_globalactor_to_function,none,
41364139
"add '@%0' to make %1 %2 part of global actor %3",
41374140
(StringRef, DescriptiveDeclKind, DeclName, Type))
@@ -4255,10 +4258,6 @@ WARNING(shared_mutable_state_access,none,
42554258
ERROR(actor_isolated_witness,none,
42564259
"actor-isolated %0 %1 cannot be used to satisfy a protocol requirement",
42574260
(DescriptiveDeclKind, DeclName))
4258-
ERROR(actor_isolated_witness_could_be_async_handler,none,
4259-
"actor-isolated %0 %1 cannot be used to satisfy a protocol requirement; "
4260-
"did you mean to make it an asychronous handler?",
4261-
(DescriptiveDeclKind, DeclName))
42624261
ERROR(global_actor_isolated_requirement,none,
42634262
"%0 %1 must be isolated to the global actor %2 to satisfy corresponding "
42644263
"requirement from protocol %3",

include/swift/IDE/CodeCompletion.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ class CodeCompletionStringChunk {
8989
/// The "override" keyword.
9090
OverrideKeyword,
9191

92-
/// The "throws" keyword.
93-
ThrowsKeyword,
94-
95-
/// The "rethrows" keyword.
96-
RethrowsKeyword,
92+
/// The "throws", "rethrows" and "async" keyword.
93+
EffectsSpecifierKeyword,
9794

9895
/// The keyword part of a declaration before the name, like "func".
9996
DeclIntroducer,
@@ -220,8 +217,7 @@ class CodeCompletionStringChunk {
220217
static bool chunkHasText(ChunkKind Kind) {
221218
return Kind == ChunkKind::AccessControlKeyword ||
222219
Kind == ChunkKind::OverrideKeyword ||
223-
Kind == ChunkKind::ThrowsKeyword ||
224-
Kind == ChunkKind::RethrowsKeyword ||
220+
Kind == ChunkKind::EffectsSpecifierKeyword ||
225221
Kind == ChunkKind::DeclAttrKeyword ||
226222
Kind == ChunkKind::DeclIntroducer ||
227223
Kind == ChunkKind::Keyword ||

include/swift/Parse/SyntaxParsingContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
220220
setCreateSyntax(Kind);
221221
}
222222

223+
SyntaxParsingContext(const SyntaxParsingContext &other) = delete;
224+
SyntaxParsingContext &operator=(const SyntaxParsingContext &other) = delete;
225+
223226
~SyntaxParsingContext();
224227

225228
/// Try looking up if an unmodified node exists at \p LexerOffset of the same

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ForwardingOperand {
8686
OwnershipConstraint getOwnershipConstraint() const {
8787
// We use a force unwrap since a ForwardingOperand should always have an
8888
// ownership constraint.
89-
return *use->getOwnershipConstraint();
89+
return use->getOwnershipConstraint();
9090
}
9191
ValueOwnershipKind getOwnershipKind() const;
9292
void setOwnershipKind(ValueOwnershipKind newKind) const;

0 commit comments

Comments
 (0)