Skip to content

Commit 1e74bdf

Browse files
authored
Merge branch 'main' into timing
2 parents 440ebee + 43ec13a commit 1e74bdf

File tree

137 files changed

+4526
-1857
lines changed

Some content is hidden

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

137 files changed

+4526
-1857
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceInsertion.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ private func insertParameterDependencies(apply: LifetimeDependentApply, target:
272272

273273
sources.initializeBases(context)
274274

275+
assert(target.value.type.isAddress,
276+
"lifetime-dependent parameter must be 'inout'")
277+
275278
Builder.insert(after: apply.applySite, context) {
276279
insertMarkDependencies(value: target.value, initializer: nil, bases: sources.bases, builder: $0, context)
277280
}
@@ -285,14 +288,14 @@ private func insertMarkDependencies(value: Value, initializer: Instruction?,
285288
let markDep = builder.createMarkDependence(
286289
value: currentValue, base: base, kind: .Unresolved)
287290

288-
// Address dependencies cannot be represented as SSA values, so it does not make sense to replace any uses of the
289-
// dependent address.
290-
//
291-
// TODO: either (1) insert a separate mark_dependence_addr instruction with no return value, or (2) perform data
292-
// flow to replace all reachable address uses, and if any aren't dominated by base, then insert an extra
293-
// escaping mark_dependence at this apply site that directly uses the mark_dependence [nonescaping] to force
294-
// diagnostics to fail.
295-
if !value.type.isAddress {
291+
if value.type.isAddress {
292+
// Address dependencies cannot be represented as SSA values, so it does not make sense to replace any uses of the
293+
// dependent address.
294+
//
295+
// TODO: insert a separate mark_dependence_addr instruction with no return value and do not update currentValue.
296+
} else {
297+
// TODO: implement non-inout parameter dependencies. This assumes that currentValue is the apply immediately
298+
// preceeding the mark_dependence.
296299
let uses = currentValue.uses.lazy.filter {
297300
if $0.isScopeEndingUse {
298301
return false

docs/ABI/Mangling.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ types where the metadata itself has unknown layout.)
259259
global ::= from-type to-type generic-signature? 'Tr' // obsolete mangling for reabstraction thunk
260260
global ::= entity generic-signature? type type* 'TK' // key path getter
261261
global ::= entity generic-signature? type type* 'Tk' // key path setter
262+
global ::= entity generic-signature? type type* 'Tkmu' // key path unapplied method
263+
global ::= entity generic-signature? type type* 'TkMA' // key path applied method
262264
global ::= type generic-signature 'TH' // key path equality
263265
global ::= type generic-signature 'Th' // key path hasher
264266
global ::= global generic-signature? 'TJ' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff function

docs/EmbeddedSwift/UserManual.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ $ swiftc -target <target triple> -enable-experimental-feature Embedded -wmo \
3737
input1.swift input2.swift ... -c -o output.o
3838
```
3939

40+
On macOS, it's common to have Xcode installed, which comes with a toolchain that does not support Embedded Swift yet. Unless you download, install, and activate a swift.org toolchain, you'll see this error:
41+
42+
```bash
43+
$ swiftc input1.swift -enable-experimental-feature Embedded -wmo
44+
<unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx15.0'
45+
```
46+
47+
To resolve it, download and install a nightly toolchain from swift.org. Then, don't forget to activate it in your terminal by setting the `TOOLCHAINS` environment variable, for example with this command (if you installed into the `/Library` path):
48+
49+
```bash
50+
$ export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw /Library/Developer/Toolchains/swift-latest.xctoolchain/Info.plist)
51+
```
52+
4053
## Examples
4154

4255
### Building Swift firmware for an embedded target

include/swift/AST/ASTMangler.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,20 @@ class ASTMangler : public Mangler {
346346
AutoDiffLinearMapKind linearMapKind,
347347
const AutoDiffConfig &config);
348348

349-
std::string mangleKeyPathGetterThunkHelper(const AbstractStorageDecl *property,
350-
GenericSignature signature,
351-
CanType baseType,
352-
SubstitutionMap subs,
353-
ResilienceExpansion expansion);
349+
std::string mangleKeyPathGetterThunkHelper(
350+
const AbstractStorageDecl *property, GenericSignature signature,
351+
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion);
354352
std::string mangleKeyPathSetterThunkHelper(const AbstractStorageDecl *property,
355353
GenericSignature signature,
356354
CanType baseType,
357355
SubstitutionMap subs,
358356
ResilienceExpansion expansion);
357+
std::string mangleKeyPathUnappliedMethodThunkHelper(
358+
const AbstractFunctionDecl *method, GenericSignature signature,
359+
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion);
360+
std::string mangleKeyPathAppliedMethodThunkHelper(
361+
const AbstractFunctionDecl *method, GenericSignature signature,
362+
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion);
359363
std::string mangleKeyPathEqualsHelper(ArrayRef<CanType> indices,
360364
GenericSignature signature,
361365
ResilienceExpansion expansion);

include/swift/AST/Decl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8171,6 +8171,18 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
81718171
/// The async function marked as the alternative to this function, if any.
81728172
AbstractFunctionDecl *getAsyncAlternative() const;
81738173

8174+
/// True if the storage can be referenced by a keypath directly.
8175+
/// Otherwise, its override must be referenced.
8176+
bool isValidKeyPathComponent() const;
8177+
8178+
/// Do we need to use resilient access patterns outside of this
8179+
/// method's resilience domain?
8180+
bool isResilient() const;
8181+
8182+
/// Do we need to use resilient access patterns when accessing this
8183+
/// method from the given module?
8184+
bool isResilient(ModuleDecl *M, ResilienceExpansion expansion) const;
8185+
81748186
/// If \p asyncAlternative is set, then compare its parameters to this
81758187
/// (presumed synchronous) function's parameters to find the index of the
81768188
/// completion handler parameter. This should be the only missing

include/swift/AST/DiagnosticsSema.def

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ NOTE(keypath_static_member_access_from_unsupported_module_note,none,
689689
ERROR(expr_keypath_enum_case,none,
690690
"%select{key path|dynamic key path member lookup}1 cannot refer to enum case %0",
691691
(const ValueDecl *, bool))
692+
ERROR(expr_keypath_mutating_method,none,
693+
"%select{key path|dynamic key path member lookup}1 cannot refer to mutating method %0",
694+
(const ValueDecl *, bool))
692695
ERROR(expr_keypath_empty,none,
693696
"empty key path does not refer to a property", ())
694697
ERROR(expr_unsupported_objc_key_path_component,none,
@@ -718,8 +721,8 @@ ERROR(expr_swift_keypath_empty, none,
718721
"key path must have at least one component", ())
719722
ERROR(expr_string_interpolation_outside_string,none,
720723
"string interpolation can only appear inside a string literal", ())
721-
ERROR(expr_keypath_subscript_index_not_hashable, none,
722-
"subscript index of type %0 in a key path must be Hashable", (Type))
724+
ERROR(expr_keypath_arg_or_index_not_hashable, none,
725+
"%select{method argument|subscript index}0 of type %1 in a key path must be Hashable", (bool, Type))
723726
ERROR(expr_smart_keypath_application_type_mismatch,none,
724727
"key path of type %0 cannot be applied to a base of type %1",
725728
(Type, Type))
@@ -1560,6 +1563,8 @@ ERROR(cannot_pass_inout_arg_to_subscript,none,
15601563
"cannot pass an inout argument to a subscript; use "
15611564
"'withUnsafeMutablePointer' to explicitly convert argument "
15621565
"to a pointer", ())
1566+
ERROR(cannot_pass_inout_arg_to_keypath_method,none,
1567+
"cannot pass an inout argument to a keypath method", ())
15631568

15641569
ERROR(incorrect_property_wrapper_reference,none,
15651570
"cannot convert value %0 of type %1 to expected type %2, "
@@ -5596,8 +5601,8 @@ ERROR(actor_isolated_keypath_component,none,
55965601
"cannot form key path to %0 %kind1",
55975602
(ActorIsolation, const ValueDecl *))
55985603
ERROR(effectful_keypath_component,none,
5599-
"cannot form key path to %0 with 'throws' or 'async'",
5600-
(DescriptiveDeclKind))
5604+
"cannot form %select{key path|dynamic key path member lookup}1 to %0 with 'throws' or 'async'",
5605+
(DescriptiveDeclKind, bool))
56015606
ERROR(local_function_executed_concurrently,none,
56025607
"concurrently-executed %kind0 must be marked as '@Sendable'",
56035608
(const ValueDecl *))
@@ -8089,7 +8094,7 @@ ERROR(pack_iteration_where_clause_not_supported, none,
80898094

80908095

80918096
//------------------------------------------------------------------------------
8092-
// MARK: Lifetime Dependence Diagnostics
8097+
// MARK: Lifetime Dependence Syntax
80938098
//------------------------------------------------------------------------------
80948099

80958100
ERROR(lifetime_dependence_invalid_param_name, none,
@@ -8108,34 +8113,15 @@ ERROR(lifetime_dependence_cannot_use_kind, none,
81088113
ERROR(lifetime_dependence_cannot_use_parsed_scoped_consuming, none,
81098114
"invalid use of scoped lifetime dependence with consuming ownership",
81108115
())
8111-
ERROR(lifetime_dependence_cannot_use_inferred_scoped_consuming, none,
8112-
"invalid use of lifetime dependence on an Escapable parameter with "
8113-
"consuming ownership",
8114-
())
8115-
ERROR(lifetime_dependence_invalid_self_ownership, none,
8116-
"invalid scoped lifetime dependence on an Escapable self with consuming "
8117-
"ownership",
8118-
())
81198116
ERROR(lifetime_dependence_only_on_function_method_init_result, none,
81208117
"lifetime dependence specifiers may only be used on result of "
81218118
"functions, methods, initializers", ())
8122-
ERROR(lifetime_dependence_invalid_type, none,
8123-
"lifetime dependence can only be specified on ~Escapable types", ())
8124-
ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
8125-
"cannot infer lifetime dependence %0, multiple parameters qualifiy as a candidate", (StringRef))
8126-
ERROR(lifetime_dependence_cannot_infer_no_candidates, none,
8127-
"cannot infer lifetime dependence%0, no parameters found that are either "
8128-
"~Escapable or Escapable with a borrowing ownership", (StringRef))
8129-
ERROR(lifetime_dependence_ctor_non_self_or_nil_return, none,
8130-
"expected nil or self as return values in an initializer with "
8131-
"lifetime dependent specifiers",
8132-
())
8133-
ERROR(lifetime_dependence_cannot_be_applied_to_tuple_elt, none,
8134-
"lifetime dependence specifiers cannot be applied to tuple elements", ())
8135-
ERROR(lifetime_dependence_method_escapable_bitwisecopyable_self, none,
8136-
"cannot infer lifetime dependence on a self which is BitwiseCopyable & "
8137-
"Escapable",
8119+
ERROR(lifetime_dependence_ctor_non_self_or_nil_return, none,
8120+
"expected 'nil' or 'self' as return values in an initializer with "
8121+
"lifetime dependent specifiers",
81388122
())
8123+
ERROR(lifetime_dependence_cannot_be_applied_to_tuple_elt, none,
8124+
"lifetime dependence specifiers cannot be applied to tuple elements", ())
81398125
ERROR(lifetime_dependence_immortal_conflict_name, none,
81408126
"conflict between the parameter name and 'immortal' contextual keyword", ())
81418127
ERROR(lifetime_dependence_function_type, none,
@@ -8144,18 +8130,75 @@ ERROR(lifetime_dependence_function_type, none,
81448130
ERROR(lifetime_dependence_immortal_alone, none,
81458131
"cannot specify any other dependence source along with immortal", ())
81468132
ERROR(lifetime_dependence_invalid_inherit_escapable_type, none,
8147-
"invalid lifetime dependence on a source of Escapable type, use borrow "
8148-
"dependence instead",
8149-
())
8133+
"cannot copy the lifetime of an Escapable type, use "
8134+
"'@lifetime(borrow %0)' instead",
8135+
(StringRef))
81508136
ERROR(lifetime_dependence_cannot_use_parsed_borrow_consuming, none,
81518137
"invalid use of borrow dependence with consuming ownership",
81528138
())
8139+
ERROR(lifetime_dependence_cannot_use_parsed_borrow_inout, none,
8140+
"invalid use of borrow dependence on the same inout parameter",
8141+
())
81538142
ERROR(lifetime_dependence_duplicate_target, none,
81548143
"invalid duplicate target lifetime dependencies on function", ())
8144+
ERROR(lifetime_parameter_requires_inout, none,
8145+
"lifetime-dependent parameter must be 'inout'", (Identifier))
8146+
8147+
//------------------------------------------------------------------------------
8148+
// MARK: Lifetime Dependence Requirements
8149+
//------------------------------------------------------------------------------
8150+
8151+
ERROR(lifetime_dependence_feature_required_return, none,
8152+
"%0 with a ~Escapable result requires "
8153+
"'-enable-experimental-feature LifetimeDependence'", (StringRef))
8154+
ERROR(lifetime_dependence_feature_required_mutating, none,
8155+
"%0 with ~Escapable 'self' requires "
8156+
"'-enable-experimental-feature LifetimeDependence'", (StringRef))
8157+
ERROR(lifetime_dependence_feature_required_inout, none,
8158+
"%0 with a ~Escapable 'inout' parameter requires "
8159+
"'-enable-experimental-feature LifetimeDependence'",
8160+
// arg list is interchangable with lifetime_dependence_cannot_infer_inout
8161+
(StringRef, Identifier))
81558162

8156-
ERROR(lifetime_dependence_feature_required, none,
8157-
"returning ~Escapable type requires '-enable-experimental-feature "
8158-
"LifetimeDependence'", ())
8163+
ERROR(lifetime_dependence_cannot_infer_return, none,
8164+
"%0 with a ~Escapable result requires '@lifetime(...)'", (StringRef))
8165+
ERROR(lifetime_dependence_cannot_infer_mutating, none,
8166+
"%0 with a ~Escapable 'self' requires '@lifetime(self: ...)'", (StringRef))
8167+
ERROR(lifetime_dependence_cannot_infer_inout, none,
8168+
"%0 with a ~Escapable 'inout' parameter requires '@lifetime(%1: ...)'",
8169+
(StringRef, Identifier))
8170+
8171+
//------------------------------------------------------------------------------
8172+
// MARK: Lifetime Dependence Inference - refinements to the requirements above
8173+
//------------------------------------------------------------------------------
8174+
8175+
ERROR(lifetime_dependence_cannot_infer_return_no_param, none,
8176+
"%0 with a ~Escapable result needs a parameter to depend on",
8177+
(StringRef))
8178+
NOTE(lifetime_dependence_cannot_infer_return_immortal, none,
8179+
"'@lifetime(immortal)' can be used to indicate that values produced by "
8180+
"this initializer have no lifetime dependencies", ())
8181+
ERROR(lifetime_dependence_cannot_infer_bitwisecopyable, none,
8182+
"cannot infer lifetime dependence on %0 because '%1' is BitwiseCopyable, "
8183+
"specify '@lifetime(borrow self)'",
8184+
(StringRef, StringRef))
8185+
ERROR(lifetime_dependence_cannot_infer_kind, none,
8186+
"cannot infer the lifetime dependence scope on %0 with a ~Escapable "
8187+
"parameter, specify '@lifetime(borrow %1)' or '@lifetime(copy %1)'",
8188+
(StringRef, StringRef))
8189+
ERROR(lifetime_dependence_cannot_infer_scope_ownership, none,
8190+
"cannot borrow the lifetime of '%0', which has consuming ownership on %1",
8191+
(StringRef, StringRef))
8192+
8193+
//------------------------------------------------------------------------------
8194+
// MARK: Lifetime Dependence Experimental Inference
8195+
//------------------------------------------------------------------------------
8196+
8197+
ERROR(lifetime_dependence_cannot_infer_no_candidates, none,
8198+
"cannot infer lifetime dependence%0, no parameters found that are either "
8199+
"~Escapable or Escapable with a borrowing ownership", (StringRef))
8200+
ERROR(lifetime_dependence_cannot_infer_ambiguous_candidate, none,
8201+
"cannot infer lifetime dependence%0, multiple parameters qualify as a candidate", (StringRef))
81598202

81608203
//===----------------------------------------------------------------------===//
81618204
// MARK: Sending

0 commit comments

Comments
 (0)