Skip to content

Commit f715d99

Browse files
authored
Merge branch 'apple:main' into main
2 parents 2ec4ad3 + 877f8a7 commit f715d99

File tree

190 files changed

+3862
-1089
lines changed

Some content is hidden

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

190 files changed

+3862
-1089
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,19 @@ the export name.
437437

438438
It's the equivalent of clang's `__attribute__((export_name))`.
439439

440-
## `@extern(<language>)`
440+
## `@_extern(<language>)`
441441

442442
Indicates that a particular declaration should be imported
443443
from the external environment.
444444

445-
### `@extern(wasm, module: <"moduleName">, name: <"fieldName">)`
445+
### `@_extern(wasm, module: <"moduleName">, name: <"fieldName">)`
446446

447447
Indicates that a particular declaration should be imported
448448
through WebAssembly's import interface.
449449

450450
It's the equivalent of clang's `__attribute__((import_module("module"), import_name("field")))`.
451451

452-
### `@extern(c, [, <"cName">])`
452+
### `@_extern(c, [, <"cName">])`
453453

454454
Indicates that a particular declaration should refer to a
455455
C declaration with the given name. If the optional "cName"
@@ -462,7 +462,7 @@ C declarations from Swift, while `@_cdecl` is used to define
462462
Swift functions that can be referenced from C.
463463

464464
Also similar to `@_silgen_name`, but a function declared with
465-
`@extern(c)` is assumed to use the C ABI, while `@_silgen_name`
465+
`@_extern(c)` is assumed to use the C ABI, while `@_silgen_name`
466466
assumes the Swift ABI.
467467

468468
## `@_fixed_layout`

docs/SIL.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,6 +4799,71 @@ eliminated. However, a memory location ``%a`` must not be accessed
47994799
after ``destroy_addr %a`` (which has not yet been eliminated)
48004800
regardless of its type.
48014801

4802+
tuple_addr_constructor
4803+
``````````````````````
4804+
4805+
::
4806+
4807+
sil-instruction ::= 'tuple_addr_constructor' sil-tuple-addr-constructor-init sil-operand 'with' sil-tuple-addr-constructor-elements
4808+
sil-tuple-addr-constructor-init ::= init|assign
4809+
sil-tuple-addr-constructor-elements ::= '(' (sil-operand (',' sil-operand)*)? ')'
4810+
4811+
// %destAddr has the type $*(Type1, Type2, Type3). Note how we convert all of the types
4812+
// to their address form.
4813+
%1 = tuple_addr_constructor [init] %destAddr : $*(Type1, Type2, Type3) with (%a : $Type1, %b : $*Type2, %c : $Type3)
4814+
4815+
Creates a new tuple in memory from an exploded list of object and address
4816+
values. The SSA values form the leaf elements of the exploded tuple. So for a
4817+
simple tuple that only has top level tuple elements, then the instruction lowers
4818+
as follows::
4819+
4820+
%1 = tuple_addr_constructor [init] %destAddr : $*(Type1, Type2, Type3) with (%a : $Type1, %b : $*Type2, %c : $Type3)
4821+
4822+
-->
4823+
4824+
%0 = tuple_element_addr %destAddr : $*(Type1, Type2, Type3), 0
4825+
store %a to [init] %0 : $*Type1
4826+
%1 = tuple_element_addr %destAddr : $*(Type1, Type2, Type3), 1
4827+
copy_addr %b to [init] %1 : $*Type2
4828+
%2 = tuple_element_addr %destAddr : $*(Type1, Type2, Type3), 2
4829+
store %2 to [init] %2 : $*Type3
4830+
4831+
A ``tuple_addr_constructor`` is lowered similarly with each store/copy_addr
4832+
being changed to their dest assign form.
4833+
4834+
In contrast, if we have a more complicated form of tuple with sub-tuples, then
4835+
we read one element from the list as we process the tuple recursively from left
4836+
to right. So for instance we would lower as follows a more complicated tuple::
4837+
4838+
%1 = tuple_addr_constructor [init] %destAddr : $*((), (Type1, ((), Type2)), Type3) with (%a : $Type1, %b : $*Type2, %c : $Type3)
4839+
4840+
->
4841+
4842+
%0 = tuple_element_addr %destAddr : $*((), (Type1, ((), Type2)), Type3), 1
4843+
%1 = tuple_element_addr %0 : $*(Type1, ((), Type2)), 0
4844+
store %a to [init] %1 : $*Type1
4845+
%2 = tuple_element_addr %0 : $*(Type1, ((), Type2)), 1
4846+
%3 = tuple_element_addr %2 : $*((), Type2), 1
4847+
copy_addr %b to [init] %3 : $*Type2
4848+
%4 = tuple_element_addr %destAddr : $*((), (Type1, ((), Type2)), Type3), 2
4849+
store %c to [init] %4 : $*Type3
4850+
4851+
This instruction exists to enable for SILGen to init and assign RValues into
4852+
tuples with a single instruction. Since an RValue is a potentially exploded
4853+
tuple, we are forced to use our representation here. If SILGen instead just uses
4854+
separate address projections and stores when it sees such an aggregate,
4855+
diagnostic SIL passes can not tell the difference semantically in between
4856+
initializing a tuple in parts or at once::
4857+
4858+
var arg = (Type1(), Type2())
4859+
4860+
// This looks the same at the SIL level...
4861+
arg = (a, b)
4862+
4863+
// to assigning in pieces even though we have formed a new tuple.
4864+
arg.0 = a
4865+
arg.1 = a
4866+
48024867
index_addr
48034868
``````````
48044869
::

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ DECL_ATTR(_section, Section,
421421
DECL_ATTR(_rawLayout, RawLayout,
422422
OnStruct | UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
423423
146)
424-
DECL_ATTR(extern, Extern,
424+
DECL_ATTR(_extern, Extern,
425425
OnFunc | AllowMultipleAttributes | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
426426
147)
427427
SIMPLE_DECL_ATTR(_nonEscapable, NonEscapable,

include/swift/AST/Attr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ class ExposeAttr : public DeclAttribute {
23432343
}
23442344
};
23452345

2346-
/// Define the `@extern` attribute, used to import external declarations in
2346+
/// Define the `@_extern` attribute, used to import external declarations in
23472347
/// the specified way to interoperate with Swift.
23482348
class ExternAttr : public DeclAttribute {
23492349
SourceLoc LParenLoc, RParenLoc;
@@ -2368,7 +2368,7 @@ class ExternAttr : public DeclAttribute {
23682368
const llvm::Optional<StringRef> ModuleName;
23692369

23702370
/// The declaration name to import
2371-
/// std::nullopt if the declaration name is not specified with @extern(c)
2371+
/// std::nullopt if the declaration name is not specified with @_extern(c)
23722372
const llvm::Optional<StringRef> Name;
23732373

23742374
SourceLoc getLParenLoc() const { return LParenLoc; }

include/swift/AST/AttrKind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ enum class ExposureKind: uint8_t {
112112
enum : unsigned { NumExposureKindBits =
113113
countBitsUsed(static_cast<unsigned>(ExposureKind::Last_ExposureKind)) };
114114

115-
/// This enum represents the possible values of the @extern attribute.
115+
/// This enum represents the possible values of the @_extern attribute.
116116
enum class ExternKind: uint8_t {
117117
/// Reference an externally defined C function.
118118
/// The imported function has C function pointer representation,

include/swift/AST/Decl.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ namespace swift {
9494
class NamedPattern;
9595
class EnumCaseDecl;
9696
class EnumElementDecl;
97+
struct InverseMarking;
9798
class ParameterList;
9899
class ParameterTypeFlags;
99100
class Pattern;
@@ -3117,15 +3118,6 @@ class TypeDecl : public ValueDecl {
31173118
private:
31183119
ArrayRef<InheritedEntry> Inherited;
31193120

3120-
struct {
3121-
/// Whether the "hasNoncopyableAnnotation" bit has been computed yet.
3122-
unsigned isNoncopyableAnnotationComputed : 1;
3123-
3124-
/// Whether this declaration had a noncopyable inverse written somewhere.
3125-
unsigned hasNoncopyableAnnotation : 1;
3126-
} LazySemanticInfo = { };
3127-
friend class HasNoncopyableAnnotationRequest;
3128-
31293121
protected:
31303122
TypeDecl(DeclKind K, llvm::PointerUnion<DeclContext *, ASTContext *> context,
31313123
Identifier name, SourceLoc NameLoc,
@@ -3153,9 +3145,13 @@ class TypeDecl : public ValueDecl {
31533145

31543146
void setInherited(ArrayRef<InheritedEntry> i) { Inherited = i; }
31553147

3156-
/// Is this type _always_ noncopyable? Will answer 'false' if the type is
3157-
/// conditionally copyable.
3158-
bool isNoncopyable() const;
3148+
/// Is it possible for this type to lack a Copyable constraint?
3149+
/// If you need a more precise answer, ask this Decl's corresponding
3150+
/// Type if it `isNoncopyable` instead of using this.
3151+
bool canBeNoncopyable() const;
3152+
3153+
/// Determine how the ~Copyable was applied to this TypeDecl, if at all.
3154+
InverseMarking getNoncopyableMarking() const;
31593155

31603156
static bool classof(const Decl *D) {
31613157
return D->getKind() >= DeclKind::First_TypeDecl &&

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ ERROR(destructor_decl_outside_class_or_noncopyable,none,
429429
"deinitializers may only be declared within a class, actor, or noncopyable type", ())
430430
ERROR(destructor_decl_on_noncopyable_enum,none,
431431
"deinitializers are not yet supported on noncopyable enums", ())
432-
ERROR(destructor_decl_on_objc_enum,none,
433-
"deinitializers cannot be declared on an @objc enum type", ())
434432
ERROR(expected_lbrace_destructor,PointsToFirstBadToken,
435433
"expected '{' for deinitializer", ())
436434
ERROR(destructor_has_name,PointsToFirstBadToken,
@@ -1869,7 +1867,7 @@ ERROR(attr_rawlayout_expected_params,none,
18691867
"expected %1 argument after %0 argument in @_rawLayout attribute", (StringRef, StringRef))
18701868

18711869
ERROR(attr_extern_expected_label,none,
1872-
"expected %0 argument to @extern attribute", (StringRef))
1870+
"expected %0 argument to @_extern attribute", (StringRef))
18731871
//------------------------------------------------------------------------------
18741872
// MARK: Generics parsing diagnostics
18751873
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,17 +1900,17 @@ ERROR(section_not_at_top_level,none,
19001900
ERROR(section_empty_name,none,
19011901
"@_section section name cannot be empty", ())
19021902

1903-
// @extern
1903+
// @_extern
19041904
ERROR(attr_extern_experimental,none,
1905-
"@extern requires '-enable-experimental-feature Extern'", ())
1905+
"@_extern requires '-enable-experimental-feature Extern'", ())
19061906
ERROR(extern_not_at_top_level_func,none,
1907-
"@extern attribute can only be applied to global functions", ())
1907+
"@_extern attribute can only be applied to global functions", ())
19081908
ERROR(extern_empty_c_name,none,
1909-
"expected non-empty C name in @extern attribute", ())
1909+
"expected non-empty C name in @_extern attribute", ())
19101910
ERROR(extern_only_non_other_attr,none,
1911-
"@extern attribute cannot be applied to an '@%0' declaration", (StringRef))
1911+
"@_extern attribute cannot be applied to an '@%0' declaration", (StringRef))
19121912
WARNING(extern_c_maybe_invalid_name, none,
1913-
"C name '%0' may be invalid; explicitly specify the name in @extern(c) to suppress this warning",
1913+
"C name '%0' may be invalid; explicitly specify the name in @_extern(c) to suppress this warning",
19141914
(StringRef))
19151915

19161916
ERROR(c_func_variadic, none,
@@ -3170,7 +3170,7 @@ ERROR(recursive_superclass_constraint,none,
31703170
ERROR(requires_same_concrete_type,none,
31713171
"generic signature requires types %0 and %1 to be the same", (Type, Type))
31723172
WARNING(redundant_conformance_constraint,none,
3173-
"redundant conformance constraint %0 : %1", (Type, ProtocolDecl *))
3173+
"redundant conformance constraint %0 : %1", (Type, Type))
31743174

31753175
WARNING(missing_protocol_refinement, none,
31763176
"protocol %0 should be declared to refine %1 due to a same-type constraint on 'Self'",
@@ -7533,22 +7533,34 @@ ERROR(accessor_macro_not_single_var, none,
75337533
//------------------------------------------------------------------------------
75347534
// MARK: Noncopyable Types Diagnostics
75357535
//------------------------------------------------------------------------------
7536-
7536+
ERROR(noncopyable_but_copyable, none,
7537+
"%kind0 required to be 'Copyable' but is marked with '~Copyable'",
7538+
(const ValueDecl *))
75377539
ERROR(noncopyable_class, none,
75387540
"classes cannot be noncopyable",
75397541
())
7542+
ERROR(inverse_extension, none,
7543+
"cannot apply inverse %0 to extension",
7544+
(Type))
7545+
ERROR(copyable_illegal_deinit, none,
7546+
"deinitializer cannot be declared in %kind0 that conforms to 'Copyable'",
7547+
(const ValueDecl *))
75407548
ERROR(noncopyable_type_member_in_copyable,none,
75417549
"%select{stored property %2|associated value %2}1 of "
75427550
"'Copyable'-conforming %kind3 has noncopyable type %0",
75437551
(Type, bool, DeclName, const ValueDecl *))
7544-
NOTE(add_inverse_for_containment,none,
7545-
"consider removing implicit '%1' conformance from %kind0",
7552+
NOTE(add_inverse,none,
7553+
"consider adding '~%1' to %kind0",
75467554
(const ValueDecl *, StringRef))
7547-
NOTE(remove_inverse_on_generic_parameter_for_conformance,none,
7548-
"consider removing '~%1' from generic parameter %0 so it conforms to the '%1' protocol",
7555+
NOTE(note_inverse_preventing_conformance,none,
7556+
"%0 has '~%1' constraint preventing implicit '%1' conformance",
75497557
(Type, StringRef))
7550-
NOTE(remove_inverse_on_nominal_for_conformance,none,
7551-
"consider removing '~%1' from %kind0 so it conforms to the '%1' protocol",
7558+
NOTE(note_inverse_preventing_conformance_implicit,none,
7559+
"%kind0 has '~%1' constraint on a generic parameter, "
7560+
"making its '%1' conformance conditional",
7561+
(const ValueDecl *, StringRef))
7562+
NOTE(note_inverse_preventing_conformance_explicit,none,
7563+
"%kind0 has '~%1' constraint preventing '%1' conformance",
75527564
(const ValueDecl *, StringRef))
75537565
NOTE(add_explicit_protocol_for_conformance,none,
75547566
"consider making %kind0 explicitly conform to the '%1' protocol",

include/swift/AST/InverseMarking.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//===- InverseMarking.h - Utilities for tracking inverse types -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_LIB_SEMA_INVERSEMARKING_H
14+
#define SWIFT_LIB_SEMA_INVERSEMARKING_H
15+
16+
#include "swift/AST/KnownProtocols.h"
17+
#include "swift/Basic/SourceLoc.h"
18+
#include "swift/Basic/OptionalEnum.h"
19+
20+
namespace swift {
21+
22+
/// Describes the way an inverse and its corresponding positive contraint
23+
/// appears on a TypeDecl, i.e., the way it was marked.
24+
struct InverseMarking {
25+
enum class Kind : uint8_t {
26+
None, // No inverse marking is present
27+
Inferred, // Inverse is inferred based on generic parameters.
28+
Explicit, // Inverse is explicitly present.
29+
30+
LAST = Explicit
31+
};
32+
33+
// Describes what kind of mark was found, if any.
34+
struct Mark {
35+
private:
36+
OptionalEnum<Kind> kind;
37+
SourceLoc loc;
38+
public:
39+
// Creates an empty mark.
40+
Mark() {};
41+
42+
// Creates a mark.
43+
Mark(Kind k, SourceLoc l = SourceLoc())
44+
: kind(k), loc(l) {};
45+
46+
// Is there an inferred or explicit marking?
47+
bool isPresent() const {
48+
return getKind() != Kind::None;
49+
}
50+
operator bool() { return isPresent(); }
51+
52+
Kind getKind() const {
53+
return kind.getValueOr(Kind::None);
54+
}
55+
56+
SourceLoc getLoc() const { return loc; }
57+
58+
void set(Kind k, SourceLoc l = SourceLoc()) {
59+
assert(!kind.hasValue());
60+
kind = k;
61+
loc = l;
62+
}
63+
64+
void setIfUnset(Kind k, SourceLoc l = SourceLoc()) {
65+
if (kind.hasValue())
66+
return;
67+
set(k, l);
68+
}
69+
70+
void setIfUnset(Mark other) {
71+
if (kind.hasValue())
72+
return;
73+
kind = other.kind;
74+
loc = other.loc;
75+
}
76+
77+
Mark with(Kind k) {
78+
kind = k;
79+
return *this;
80+
}
81+
};
82+
83+
private:
84+
Mark inverse;
85+
Mark positive;
86+
public:
87+
88+
// Creates an empty marking.
89+
InverseMarking() {}
90+
91+
Mark &getInverse() { return inverse; }
92+
Mark &getPositive() { return positive; }
93+
94+
// Merge the results of another marking into this one.
95+
void merge(InverseMarking other) const {
96+
other.inverse.setIfUnset(other.inverse);
97+
other.positive.setIfUnset(other.positive);
98+
}
99+
100+
static InverseMarking forInverse(Kind kind, SourceLoc loc = SourceLoc()) {
101+
InverseMarking marking;
102+
marking.inverse.set(kind, loc);
103+
marking.positive.set(Kind::None);
104+
return marking;
105+
}
106+
};
107+
108+
}
109+
110+
#endif //SWIFT_LIB_SEMA_INVERSEMARKING_H

0 commit comments

Comments
 (0)