Skip to content

Commit e6855ea

Browse files
authored
Merge pull request #2657 from swiftwasm/release/5.4
[pull] swiftwasm-release/5.4 from release/5.4
2 parents eca6087 + 57d601f commit e6855ea

24 files changed

+417
-22
lines changed

include/swift/SIL/SILConstants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,11 @@ class SymbolicValue {
604604
/// version. This only works for valid constants.
605605
SymbolicValue cloneInto(SymbolicValueAllocator &allocator) const;
606606

607+
/// Check that all nested SymbolicValues are constant. Symbolic values such as arrays,
608+
/// aggregates and pointers can contain non-constant symbolic values, when instructions
609+
/// are skipped during evaluation.
610+
bool containsOnlyConstants() const;
611+
607612
void print(llvm::raw_ostream &os, unsigned indent = 0) const;
608613
void dump() const;
609614
};

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ class ConstraintSystem {
27842784
void
27852785
filterSolutions(SmallVectorImpl<Solution> &solutions,
27862786
bool minimize = false) {
2787-
if (solutions.size() < 2)
2787+
if (solutions.size() < 2 || isForCodeCompletion())
27882788
return;
27892789

27902790
if (auto best = findBestSolution(solutions, minimize)) {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,18 +1292,28 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
12921292
// required by sourcekitd.
12931293
subClangImporterOpts.DetailedPreprocessingRecord =
12941294
clangImporterOpts.DetailedPreprocessingRecord;
1295+
12951296
// We need to add these extra clang flags because explict module building
12961297
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
12971298
// and -fmodule-file=.
12981299
// If we don't add these flags, the interface will be built with implicit
12991300
// PCMs.
1300-
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
1301-
for (auto arg: subClangImporterOpts.ExtraArgs) {
1302-
GenericArgs.push_back("-Xcc");
1303-
GenericArgs.push_back(ArgSaver.save(arg));
1301+
// FIXME: With Implicit Module Builds, if sub-invocations inherit `-fmodule-map-file=` options,
1302+
// those modulemaps become File dependencies of all downstream PCMs and their depending Swift
1303+
// modules, triggering unnecessary re-builds. We work around this by only inheriting these options
1304+
// when building with explicit modules. While this problem will not manifest with Explicit Modules
1305+
// (which do not use the ClangImporter to build PCMs), we may still need a better way to
1306+
// decide which options must be inherited here.
1307+
if (LoaderOpts.disableImplicitSwiftModule) {
1308+
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
1309+
for (auto arg : subClangImporterOpts.ExtraArgs) {
1310+
GenericArgs.push_back("-Xcc");
1311+
GenericArgs.push_back(ArgSaver.save(arg));
1312+
}
13041313
}
13051314

1306-
// Tell the genericSubInvocation to serialize dependency hashes if asked to do so.
1315+
// Tell the genericSubInvocation to serialize dependency hashes if asked to do
1316+
// so.
13071317
auto &frontendOpts = genericSubInvocation.getFrontendOptions();
13081318
frontendOpts.SerializeModuleInterfaceDependencyHashes =
13091319
serializeDependencyHashes;

lib/IRGen/GenBuiltin.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ getLoweredTypeAndTypeInfo(IRGenModule &IGM, Type unloweredType) {
120120
/// emitBuiltinCall - Emit a call to a builtin function.
121121
void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
122122
Identifier FnId, SILType resultType,
123+
ArrayRef<SILType> argTypes,
123124
Explosion &args, Explosion &out,
124125
SubstitutionMap substitutions) {
125126
if (Builtin.ID == BuiltinValueKind::COWBufferForReading) {
@@ -1074,7 +1075,18 @@ if (Builtin.ID == BuiltinValueKind::id) { \
10741075

10751076
if (Builtin.ID == BuiltinValueKind::TSanInoutAccess) {
10761077
auto address = args.claimNext();
1077-
IGF.emitTSanInoutAccessCall(address);
1078+
1079+
// The tsanInoutAccess builtin takes a single argument, the address
1080+
// of the accessed storage
1081+
SILType accessedType = argTypes[0];
1082+
1083+
// Empty types (such as structs without stored properties) have a
1084+
// meaningless value for their address. We not should call into the
1085+
// TSan runtime to check for data races on accesses on such addresses.
1086+
if (!IGF.IGM.getTypeInfo(accessedType)
1087+
.isKnownEmpty(ResilienceExpansion::Maximal)) {
1088+
IGF.emitTSanInoutAccessCall(address);
1089+
}
10781090
return;
10791091
}
10801092

lib/IRGen/GenBuiltin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace irgen {
3333
/// Emit a call to a builtin function.
3434
void emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &builtin,
3535
Identifier fnId, SILType resultType,
36+
ArrayRef<SILType> argTypes,
3637
Explosion &args, Explosion &result,
3738
SubstitutionMap substitutions);
3839

lib/IRGen/GenClangDecl.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "IRGenModule.h"
14+
#include "swift/AST/IRGenOptions.h"
1415
#include "clang/AST/Decl.h"
1516
#include "clang/AST/DeclGroup.h"
1617
#include "clang/AST/GlobalDecl.h"
@@ -118,14 +119,20 @@ IRGenModule::getAddrOfClangGlobalDecl(clang::GlobalDecl global,
118119
}
119120

120121
void IRGenModule::finalizeClangCodeGen() {
121-
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
122-
// always guaranteed to be directly below the TranslationUnitDecl.)
123-
// In Clang, this happens automatically during the Sema phase, but here we
124-
// need to take care of it manually because our Clang CodeGenerator is not
125-
// attached to Clang Sema as an ASTConsumer.
126-
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
127-
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
128-
emitClangDecl(PCD);
122+
// FIXME: We try to avoid looking for PragmaCommentDecls unless we need to,
123+
// since clang::DeclContext::decls_begin() can trigger expensive
124+
// de-serialization.
125+
if (Triple.isWindowsMSVCEnvironment() || Triple.isWindowsItaniumEnvironment() ||
126+
IRGen.Opts.LLVMLTOKind != IRGenLLVMLTOKind::None) {
127+
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
128+
// always guaranteed to be directly below the TranslationUnitDecl.)
129+
// In Clang, this happens automatically during the Sema phase, but here we
130+
// need to take care of it manually because our Clang CodeGenerator is not
131+
// attached to Clang Sema as an ASTConsumer.
132+
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
133+
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
134+
emitClangDecl(PCD);
135+
}
129136
}
130137
}
131138

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2680,18 +2680,21 @@ void IRGenSILFunction::visitBuiltinInst(swift::BuiltinInst *i) {
26802680

26812681
auto argValues = i->getArguments();
26822682
Explosion args;
2683+
SmallVector<SILType, 4> argTypes;
26832684

26842685
for (auto idx : indices(argValues)) {
26852686
auto argValue = argValues[idx];
26862687

26872688
// Builtin arguments should never be substituted, so use the value's type
26882689
// as the parameter type.
26892690
emitApplyArgument(*this, argValue, argValue->getType(), args);
2691+
2692+
argTypes.push_back(argValue->getType());
26902693
}
26912694

26922695
Explosion result;
26932696
emitBuiltinCall(*this, builtin, i->getName(), i->getType(),
2694-
args, result, i->getSubstitutions());
2697+
argTypes, args, result, i->getSubstitutions());
26952698

26962699
setLoweredExplosion(i, result);
26972700
}

lib/SIL/IR/SILConstants.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,52 @@ SymbolicValue::cloneInto(SymbolicValueAllocator &allocator) const {
260260
llvm_unreachable("covered switch");
261261
}
262262

263+
bool SymbolicValue::containsOnlyConstants() const {
264+
if (!isConstant())
265+
return false;
266+
267+
auto thisRK = representationKind;
268+
switch (thisRK) {
269+
case RK_UninitMemory:
270+
case RK_Unknown:
271+
case RK_Metatype:
272+
case RK_Function:
273+
case RK_Enum:
274+
case RK_IntegerInline:
275+
case RK_Integer:
276+
case RK_String:
277+
case RK_Closure:
278+
return true;
279+
case RK_Aggregate: {
280+
auto elts = getAggregateMembers();
281+
for (auto elt : elts)
282+
if (!elt.containsOnlyConstants())
283+
return false;
284+
return true;
285+
}
286+
case RK_EnumWithPayload: {
287+
return getEnumPayloadValue().containsOnlyConstants();
288+
}
289+
case RK_DirectAddress:
290+
case RK_DerivedAddress: {
291+
auto *memObject = getAddressValueMemoryObject();
292+
return memObject->getValue().containsOnlyConstants();
293+
}
294+
case RK_ArrayStorage: {
295+
CanType elementType;
296+
ArrayRef<SymbolicValue> elts = getStoredElements(elementType);
297+
for (auto elt : elts)
298+
if (!elt.containsOnlyConstants())
299+
return false;
300+
return true;
301+
}
302+
case RK_Array: {
303+
return getStorageOfArray().containsOnlyConstants();
304+
}
305+
}
306+
llvm_unreachable("covered switch");
307+
}
308+
263309
//===----------------------------------------------------------------------===//
264310
// SymbolicValueMemoryObject implementation
265311
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ static bool isFoldableArray(SILValue value, ASTContext &astContext) {
322322
return true;
323323
SILFunction *callee = cast<ApplyInst>(constructorInst)->getCalleeFunction();
324324
return !callee ||
325-
(!callee->hasSemanticsAttr("array.init.empty") &&
326-
!callee->hasSemanticsAttr("array.uninitialized_intrinsic"));
325+
(!callee->hasSemanticsAttr(semantics::ARRAY_INIT_EMPTY) &&
326+
!callee->hasSemanticsAttr(semantics::ARRAY_UNINITIALIZED_INTRINSIC) &&
327+
!callee->hasSemanticsAttr(semantics::ARRAY_FINALIZE_INTRINSIC));
327328
}
328329

329330
/// Return true iff the given value is a closure but is not a creation of a
@@ -997,6 +998,14 @@ static void substituteConstants(FoldState &foldState) {
997998
for (SILValue constantSILValue : foldState.getConstantSILValues()) {
998999
SymbolicValue constantSymbolicVal =
9991000
evaluator.lookupConstValue(constantSILValue).getValue();
1001+
// Make sure that the symbolic value tracked in the foldState is a constant.
1002+
// In the case of ArraySymbolicValue, the array storage could be a non-constant
1003+
// if some instruction in the array initialization sequence was not evaluated
1004+
// and skipped.
1005+
if (!constantSymbolicVal.containsOnlyConstants()) {
1006+
assert(constantSymbolicVal.getKind() != SymbolicValue::String && "encountered non-constant string symbolic value");
1007+
continue;
1008+
}
10001009

10011010
SILInstruction *definingInst = constantSILValue->getDefiningInstruction();
10021011
assert(definingInst);

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ static void finishPropertyWrapperImplInfo(VarDecl *var,
29212921
return;
29222922
}
29232923

2924-
if (var->hasObservers()) {
2924+
if (var->hasObservers() || var->getDeclContext()->isLocalContext()) {
29252925
info = StorageImplInfo::getMutableComputed();
29262926
} else {
29272927
info = StorageImplInfo(ReadImplKind::Get, WriteImplKind::Set,

0 commit comments

Comments
 (0)