Skip to content

Commit 23ea737

Browse files
authored
Merge pull request #2472 from swiftwasm/maxd/main-merge
Resolve conflicts with the `main` upstream branch
2 parents 7ade9ca + c4b54a1 commit 23ea737

17 files changed

+355
-604
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,23 +1325,6 @@ namespace {
13251325
wrapperInfo.wrappedValuePlaceholder->getOriginalWrappedValue())
13261326
return false;
13271327

1328-
// If we have a nonmutating setter on a value type, the call
1329-
// captures all of 'self' and we cannot rewrite an assignment
1330-
// into an initialization.
1331-
1332-
// Unless this is an assignment to a self parameter inside a
1333-
// constructor, in which case we would like to still emit a
1334-
// assign_by_wrapper because the setter will be deleted by lowering
1335-
// anyway.
1336-
if (!isAssignmentToSelfParamInInit &&
1337-
!VD->isSetterMutating() &&
1338-
VD->getDeclContext()->getSelfNominalTypeDecl() &&
1339-
VD->isInstanceMember() &&
1340-
!VD->getDeclContext()->getDeclaredInterfaceType()
1341-
->hasReferenceSemantics()) {
1342-
return false;
1343-
}
1344-
13451328
// If this property wrapper uses autoclosure in it's initializer,
13461329
// the argument types of the setter and initializer shall be
13471330
// different, so we don't rewrite an assignment into an
@@ -1490,7 +1473,9 @@ namespace {
14901473
}
14911474

14921475
CanSILFunctionType setterTy = setterFRef->getType().castTo<SILFunctionType>();
1493-
SILFunctionConventions setterConv(setterTy, SGF.SGM.M);
1476+
auto substSetterTy = setterTy->substGenericArgs(SGF.SGM.M, Substitutions,
1477+
SGF.getTypeExpansionContext());
1478+
SILFunctionConventions setterConv(substSetterTy, SGF.SGM.M);
14941479

14951480
// Emit captures for the setter
14961481
SmallVector<SILValue, 4> capturedArgs;
@@ -1509,21 +1494,19 @@ namespace {
15091494

15101495
if (setterConv.getSILArgumentConvention(argIdx).isInoutConvention()) {
15111496
capturedBase = base.getValue();
1497+
} else if (base.getType().isAddress() &&
1498+
base.getType().getObjectType() ==
1499+
setterConv.getSILArgumentType(argIdx,
1500+
SGF.getTypeExpansionContext())) {
1501+
// If the base is a reference and the setter expects a value, emit a
1502+
// load. This pattern is emitted for property wrappers with a
1503+
// nonmutating setter, for example.
1504+
capturedBase = SGF.B.createTrivialLoadOr(
1505+
loc, base.getValue(), LoadOwnershipQualifier::Copy);
15121506
} else {
15131507
capturedBase = base.copy(SGF, loc).forward(SGF);
15141508
}
15151509

1516-
// If the base is a reference and the setter expects a value, emit a
1517-
// load. This pattern is emitted for property wrappers with a
1518-
// nonmutating setter, for example.
1519-
if (base.getType().isAddress() &&
1520-
base.getType().getObjectType() ==
1521-
setterConv.getSILArgumentType(argIdx,
1522-
SGF.getTypeExpansionContext())) {
1523-
capturedBase = SGF.B.createTrivialLoadOr(
1524-
loc, capturedBase, LoadOwnershipQualifier::Take);
1525-
}
1526-
15271510
capturedArgs.push_back(capturedBase);
15281511
}
15291512

@@ -1538,8 +1521,6 @@ namespace {
15381521
assert(value.isRValue());
15391522
ManagedValue Mval = std::move(value).asKnownRValue(SGF).
15401523
getAsSingleValue(SGF, loc);
1541-
auto substSetterTy = setterTy->substGenericArgs(SGF.SGM.M, Substitutions,
1542-
SGF.getTypeExpansionContext());
15431524
auto param = substSetterTy->getParameters()[0];
15441525
SILType loweredSubstArgType = Mval.getType();
15451526
if (param.isIndirectInOut()) {

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,22 @@ bool LifetimeChecker::shouldEmitError(const SILInstruction *Inst) {
625625
}))
626626
return false;
627627

628+
// Ignore loads used only by an assign_by_wrapper setter. This
629+
// is safe to ignore because assign_by_wrapper will only be
630+
// re-written to use the setter if the value is fully initialized.
631+
if (auto *load = dyn_cast<SingleValueInstruction>(Inst)) {
632+
if (auto Op = load->getSingleUse()) {
633+
if (auto PAI = dyn_cast<PartialApplyInst>(Op->getUser())) {
634+
if (std::find_if(PAI->use_begin(), PAI->use_end(),
635+
[](auto PAIUse) {
636+
return isa<AssignByWrapperInst>(PAIUse->getUser());
637+
}) != PAI->use_end()) {
638+
return false;
639+
}
640+
}
641+
}
642+
}
643+
628644
EmittedErrorLocs.push_back(InstLoc);
629645
return true;
630646
}
@@ -1842,20 +1858,6 @@ void LifetimeChecker::handleLoadUseFailure(const DIMemoryUse &Use,
18421858
TheMemory.isAnyInitSelf() && !TheMemory.isClassInitSelf()) {
18431859
if (!shouldEmitError(Inst)) return;
18441860

1845-
// Ignore loads used only for a set-by-value (nonmutating) setter
1846-
// since it will be deleted by lowering anyway.
1847-
auto load = cast<SingleValueInstruction>(Inst);
1848-
if (auto Op = load->getSingleUse()) {
1849-
if (auto PAI = dyn_cast<PartialApplyInst>(Op->getUser())) {
1850-
if (std::find_if(PAI->use_begin(), PAI->use_end(),
1851-
[](auto PAIUse) {
1852-
return isa<AssignByWrapperInst>(PAIUse->getUser());
1853-
}) != PAI->use_end()) {
1854-
return;
1855-
}
1856-
}
1857-
}
1858-
18591861
diagnose(Module, Inst->getLoc(), diag::use_of_self_before_fully_init);
18601862
noteUninitializedMembers(Use);
18611863
return;

lib/Sema/CSApply.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6828,26 +6828,22 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
68286828
llvm_unreachable("Unhandled coercion");
68296829
}
68306830

6831-
/// Detect if the expression is an assignment to a `self` wrapped property that
6832-
/// has a nonmutating setter, inside a constructor.
6833-
///
6834-
/// We use this to decide when to produce an inout_expr instead of a load_expr
6835-
/// for the sake of emitting a reference required by the assign_by_wrapper
6836-
/// instruction.
6837-
static bool isNonMutatingSetterPWAssignInsideInit(Expr *baseExpr,
6838-
ValueDecl *member,
6839-
DeclContext *UseDC) {
6840-
// Setter is mutating
6841-
if (cast<AbstractStorageDecl>(member)->isSetterMutating())
6842-
return false;
6831+
/// Detect whether an assignment to \c baseExpr.member in the given
6832+
/// decl context can potentially be initialization of a property wrapper.
6833+
static bool isPotentialPropertyWrapperInit(Expr *baseExpr,
6834+
ValueDecl *member,
6835+
DeclContext *UseDC) {
68436836
// Member is not a wrapped property
68446837
auto *VD = dyn_cast<VarDecl>(member);
68456838
if (!(VD && VD->hasAttachedPropertyWrapper()))
68466839
return false;
6847-
// This is not an expression inside a constructor
6840+
6841+
// Assignment to a wrapped property can only be re-written to
6842+
// initialization in an init.
68486843
auto *CD = dyn_cast<ConstructorDecl>(UseDC);
68496844
if (!CD)
68506845
return false;
6846+
68516847
// This is not an assignment on self
68526848
if (!baseExpr->isSelfExprOf(CD))
68536849
return false;
@@ -6887,15 +6883,14 @@ static Type adjustSelfTypeForMember(Expr *baseExpr,
68876883
bool isSettableFromHere =
68886884
SD->isSettable(UseDC) && SD->isSetterAccessibleFrom(UseDC);
68896885

6890-
// If neither the property's getter nor its setter are mutating, and
6891-
// this is not a nonmutating property wrapper setter,
6892-
// the base can be an rvalue.
6893-
// With the exception of assignments to a wrapped property inside a
6894-
// constructor, where we need to produce a reference to be used on
6895-
// the assign_by_wrapper instruction.
6896-
if (!SD->isGetterMutating() &&
6886+
// If neither the property's getter nor its setter are mutating,
6887+
// the base can be an rvalue unless the assignment is potentially
6888+
// initializing a property wrapper. If the assignment can be re-
6889+
// written to property wrapper initialization, the base type should
6890+
// be an lvalue.
6891+
if (!SD->isGetterMutating() &&
68976892
(!isSettableFromHere || !SD->isSetterMutating()) &&
6898-
!isNonMutatingSetterPWAssignInsideInit(baseExpr, member, UseDC))
6893+
!isPotentialPropertyWrapperInit(baseExpr, member, UseDC))
68996894
return baseObjectTy;
69006895

69016896
if (isa<SubscriptDecl>(member))

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,11 @@ namespace {
11411141
return true;
11421142
}
11431143

1144-
case ActorIsolation::Independent:
11451144
case ActorIsolation::IndependentUnsafe:
1145+
// Allow unrestricted use of something in a global actor.
1146+
return false;
1147+
1148+
case ActorIsolation::Independent:
11461149
if (inspectForImplicitlyAsync())
11471150
return false;
11481151

@@ -1168,8 +1171,8 @@ namespace {
11681171
}
11691172
noteIsolatedActorMember(value);
11701173
};
1171-
1172-
if (AbstractFunctionDecl const* fn =
1174+
1175+
if (AbstractFunctionDecl const* fn =
11731176
dyn_cast_or_null<AbstractFunctionDecl>(declContext->getAsDecl())) {
11741177
bool isAsyncContext = fn->isAsyncContext();
11751178

stdlib/public/Platform/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ foreach(sdk ${SWIFT_SDKS})
171171
list(APPEND glibc_modulemap_target_list ${copy_glibc_modulemap_static})
172172
endif()
173173

174+
set(glibc_header_out "${module_dir}/SwiftGlibc.h")
175+
handle_gyb_source_single(glibc_header_target
176+
SOURCE "SwiftGlibc.h.gyb"
177+
OUTPUT "${glibc_header_out}"
178+
FLAGS "-DCMAKE_SDK=${sdk}")
179+
list(APPEND glibc_modulemap_target_list ${glibc_header_target})
180+
174181
# If this SDK is a target for a non-native host, except if it's for Android
175182
# with its own native sysroot, create a native modulemap without a sysroot
176183
# prefix. This is the one we'll install instead.
@@ -202,11 +209,17 @@ foreach(sdk ${SWIFT_SDKS})
202209
swift_install_in_component(FILES "${glibc_modulemap_out}"
203210
DESTINATION "lib/swift/${arch_subdir}"
204211
COMPONENT sdk-overlay)
212+
swift_install_in_component(FILES "${glibc_header_out}"
213+
DESTINATION "lib/swift/${arch_subdir}"
214+
COMPONENT sdk-overlay)
205215

206216
if(SWIFT_BUILD_STATIC_STDLIB)
207217
swift_install_in_component(FILES "${glibc_modulemap_out}"
208218
DESTINATION "lib/swift_static/${arch_subdir}"
209219
COMPONENT sdk-overlay)
220+
swift_install_in_component(FILES "${glibc_header_out}"
221+
DESTINATION "lib/swift_static/${arch_subdir}"
222+
COMPONENT sdk-overlay)
210223
endif()
211224
endforeach()
212225
endforeach()
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
%{
2+
headers = [
3+
'stdc-predef.h',
4+
'features.h',
5+
6+
# C standard library
7+
'complex.h',
8+
'ctype.h',
9+
'errno.h',
10+
'fenv.h',
11+
'float.h',
12+
'inttypes.h',
13+
'iso646.h',
14+
'libutil.h',
15+
'limits.h',
16+
'locale.h',
17+
'math.h',
18+
'pty.h',
19+
'setjmp.h',
20+
'signal.h',
21+
'stdarg.h',
22+
'stdbool.h',
23+
'stddef.h',
24+
'stdint.h',
25+
'stdio.h',
26+
'stdlib.h',
27+
'string.h',
28+
'tgmath.h',
29+
'time.h',
30+
'utmp.h',
31+
'utmpx.h',
32+
33+
# POSIX
34+
'aio.h',
35+
'arpa/inet.h',
36+
'bsd/ifaddrs.h',
37+
'bsd/pty.h',
38+
'cpio.h',
39+
'dirent.h',
40+
'dlfcn.h',
41+
'fcntl.h',
42+
'fmtmsg.h',
43+
'fnmatch.h',
44+
'ftw.h',
45+
'glob.h',
46+
'grp.h',
47+
'iconv.h',
48+
'ifaddrs.h',
49+
'langinfo.h',
50+
'libgen.h',
51+
'link.h',
52+
'monetary.h',
53+
'net/if.h',
54+
'netdb.h',
55+
'netinet/in.h',
56+
'netinet/tcp.h',
57+
'nl_types.h',
58+
'poll.h',
59+
'pthread.h',
60+
'pwd.h',
61+
'regex.h',
62+
'sched.h',
63+
'search.h',
64+
'semaphore.h',
65+
'spawn.h',
66+
'strings.h',
67+
'sys/event.h',
68+
'sys/file.h',
69+
'sys/inotify.h',
70+
'sys/ioctl.h',
71+
'sys/ipc.h',
72+
'sys/mman.h',
73+
'sys/msg.h',
74+
'sys/resource.h',
75+
'sys/select.h',
76+
'sys/sem.h',
77+
'sys/sendfile.h',
78+
'sys/shm.h',
79+
'sys/socket.h',
80+
'sys/stat.h',
81+
'sys/statvfs.h',
82+
'sys/time.h',
83+
'sys/times.h',
84+
'sys/types.h',
85+
'sys/uio.h',
86+
'sys/un.h',
87+
'sys/user.h',
88+
'sys/utsname.h',
89+
'sys/wait.h',
90+
'sysexits.h',
91+
'syslog.h',
92+
'tar.h',
93+
'termios.h',
94+
'ulimit.h',
95+
'unistd.h',
96+
'utime.h',
97+
'utmpx.h',
98+
'wait.h',
99+
'wordexp.h',
100+
]
101+
}%
102+
103+
% for header in headers:
104+
#if __has_include(<${header}>)
105+
#include <${header}>
106+
#endif
107+
% end

0 commit comments

Comments
 (0)