Skip to content

Commit 072c378

Browse files
authored
Merge pull request swiftlang#709 from swiftwasm/master
[pull] swiftwasm from master
2 parents 7fab66c + 364d2dc commit 072c378

20 files changed

+597
-139
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,9 @@ function(_add_swift_host_library_single target)
626626
PROPERTIES
627627
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/cygwin")
628628
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
629-
# Only set the install RPATH if cross-compiling the host tools, in which
630-
# case both the NDK and Sysroot paths must be set.
631-
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "" AND
632-
NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
633-
set_target_properties("${target}"
634-
PROPERTIES
635-
INSTALL_RPATH "$ORIGIN")
636-
endif()
629+
set_target_properties("${target}"
630+
PROPERTIES
631+
INSTALL_RPATH "$ORIGIN")
637632
endif()
638633

639634
set_target_properties("${target}" PROPERTIES BUILD_WITH_INSTALL_RPATH YES)

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern)
4747
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
4848
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
4949
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
50+
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperLValueness>,
51+
PropertyWrapperLValueness)
5052
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
5153
PropertyWrapperMutability)
5254
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PrefixOperatorDecl;
4949
struct PropertyWrapperBackingPropertyInfo;
5050
struct PropertyWrapperTypeInfo;
5151
enum class CtorInitializerKind;
52+
struct PropertyWrapperLValueness;
5253
struct PropertyWrapperMutability;
5354
class ProtocolDecl;
5455
class Requirement;

include/swift/AST/DiagnosticsSIL.def

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ ERROR(oslog_constant_eval_trap, none, "%0", (StringRef))
585585
ERROR(oslog_too_many_instructions, none, "interpolated expression and arguments "
586586
"are too complex", ())
587587

588-
ERROR(oslog_invalid_log_message, none, "invalid log message; do not define "
589-
"extensions to types defined in the os module", ())
588+
ERROR(oslog_invalid_log_message, none, "invalid log message; extending "
589+
"types defined in the os module is not supported", ())
590590

591591
NOTE(oslog_const_evaluable_fun_error, none, "'%0' failed evaluation", (StringRef))
592592

@@ -599,8 +599,9 @@ ERROR(oslog_non_constant_interpolation, none, "'OSLogInterpolation' instance "
599599
ERROR(oslog_property_not_constant, none, "'OSLogInterpolation.%0' is not a "
600600
"constant", (StringRef))
601601

602-
ERROR(oslog_message_alive_after_opts, none, "os log string interpolation cannot "
603-
"be used in this context", ())
602+
ERROR(oslog_message_alive_after_opts, none, "string interpolation cannot "
603+
"be used in this context; if you are calling an os_log function, "
604+
"try a different overload", ())
604605

605606
ERROR(oslog_message_explicitly_created, none, "'OSLogMessage' must be "
606607
" created from a string interpolation or string literal", ())
@@ -609,7 +610,7 @@ WARNING(oslog_call_in_unreachable_code, none, "os log call will never be "
609610
"executed and may have undiagnosed errors", ())
610611

611612
ERROR(global_string_pointer_on_non_constant, none, "globalStringTablePointer "
612-
"builtin must used only on string literals", ())
613+
"builtin must be used only on string literals", ())
613614

614615
ERROR(polymorphic_builtin_passed_non_trivial_non_builtin_type, none, "Argument "
615616
"of type %0 can not be passed as an argument to a Polymorphic "

include/swift/AST/PropertyWrappers.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ struct PropertyWrapperMutability {
127127

128128
void simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m);
129129

130+
/// Describes whether the reference to a property wrapper instance used for
131+
/// accessing a wrapped property should be an l-value or not.
132+
struct PropertyWrapperLValueness {
133+
llvm::SmallVector<bool, 4> isLValueForGetAccess;
134+
llvm::SmallVector<bool, 4> isLValueForSetAccess;
135+
136+
PropertyWrapperLValueness(unsigned numWrappers)
137+
: isLValueForGetAccess(numWrappers), isLValueForSetAccess(numWrappers) {}
138+
139+
bool operator==(PropertyWrapperLValueness other) const {
140+
return (isLValueForGetAccess == other.isLValueForGetAccess &&
141+
isLValueForSetAccess == other.isLValueForSetAccess);
142+
}
143+
};
144+
145+
void simple_display(llvm::raw_ostream &os, PropertyWrapperLValueness l);
146+
130147
/// Describes the backing property of a property that has an attached wrapper.
131148
struct PropertyWrapperBackingPropertyInfo {
132149
/// The backing property.

include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ClosureExpr;
4141
class GenericParamList;
4242
class PrecedenceGroupDecl;
4343
struct PropertyWrapperBackingPropertyInfo;
44+
struct PropertyWrapperLValueness;
4445
struct PropertyWrapperMutability;
4546
class RequirementRepr;
4647
class SpecializeAttr;
@@ -632,6 +633,26 @@ class PropertyWrapperMutabilityRequest :
632633
bool isCached() const;
633634
};
634635

636+
/// Request information about the l-valueness of composed property wrappers.
637+
class PropertyWrapperLValuenessRequest :
638+
public SimpleRequest<PropertyWrapperLValuenessRequest,
639+
Optional<PropertyWrapperLValueness> (VarDecl *),
640+
RequestFlags::Cached> {
641+
public:
642+
using SimpleRequest::SimpleRequest;
643+
644+
private:
645+
friend SimpleRequest;
646+
647+
// Evaluation.
648+
Optional<PropertyWrapperLValueness>
649+
evaluate(Evaluator &evaluator, VarDecl *var) const;
650+
651+
public:
652+
// Caching
653+
bool isCached() const;
654+
};
655+
635656
/// Request information about the backing property for properties that have
636657
/// attached property wrappers.
637658
class PropertyWrapperBackingPropertyInfoRequest :

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ SWIFT_REQUEST(TypeChecker, PropertyWrapperBackingPropertyInfoRequest,
150150
NoLocationInfo)
151151
SWIFT_REQUEST(TypeChecker, PropertyWrapperBackingPropertyTypeRequest,
152152
Type(VarDecl *), Cached, NoLocationInfo)
153+
SWIFT_REQUEST(TypeChecker, PropertyWrapperLValuenessRequest,
154+
Optional<PropertyWrapperLValueness>(VarDecl *), Cached,
155+
NoLocationInfo)
153156
SWIFT_REQUEST(TypeChecker, PropertyWrapperMutabilityRequest,
154157
Optional<PropertyWrapperMutability>(VarDecl *), Cached,
155158
NoLocationInfo)

lib/AST/TypeCheckRequests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ bool PropertyWrapperMutabilityRequest::isCached() const {
573573
return !var->getAttrs().isEmpty();
574574
}
575575

576+
bool PropertyWrapperLValuenessRequest::isCached() const {
577+
auto var = std::get<0>(getStorage());
578+
return !var->getAttrs().isEmpty();
579+
}
580+
576581
void swift::simple_display(
577582
llvm::raw_ostream &out, const PropertyWrapperTypeInfo &propertyWrapper) {
578583
out << "{ ";
@@ -615,6 +620,14 @@ void swift::simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m) {
615620
os << "getter " << names[m.Getter] << ", setter " << names[m.Setter];
616621
}
617622

623+
void swift::simple_display(llvm::raw_ostream &out, PropertyWrapperLValueness l) {
624+
out << "is lvalue for get: {";
625+
simple_display(out, l.isLValueForGetAccess);
626+
out << "}, is lvalue for set: {";
627+
simple_display(out, l.isLValueForSetAccess);
628+
out << "}";
629+
}
630+
618631
void swift::simple_display(llvm::raw_ostream &out,
619632
ResilienceExpansion value) {
620633
switch (value) {

lib/SIL/IR/SILConstants.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ llvm::cl::opt<unsigned>
2828
template <typename... T, typename... U>
2929
static InFlightDiagnostic diagnose(ASTContext &Context, SourceLoc loc,
3030
Diag<T...> diag, U &&... args) {
31+
// The lifetime of StringRef arguments will be extended as necessary by this
32+
// utility. The copy happens in onTentativeDiagnosticFlush at the bottom of
33+
// DiagnosticEngine.cpp, which is called when the destructor of the
34+
// InFlightDiagnostic returned by diagnose runs.
3135
return Context.Diags.diagnose(loc, diag, std::forward<U>(args)...);
3236
}
3337

@@ -939,8 +943,8 @@ void SymbolicValue::emitUnknownDiagnosticNotes(SILLocation fallbackLoc) {
939943
triggerLocSkipsInternalLocs);
940944
return;
941945
case UnknownReason::Trap: {
942-
const char *message = unknownReason.getTrapMessage();
943-
diagnose(ctx, diagLoc, diag::constexpr_trap, StringRef(message));
946+
diagnose(ctx, diagLoc, diag::constexpr_trap,
947+
unknownReason.getTrapMessage());
944948
if (emitTriggerLocInDiag)
945949
diagnose(ctx, triggerLoc, diag::constexpr_trap_operation,
946950
triggerLocSkipsInternalLocs);
@@ -987,7 +991,7 @@ void SymbolicValue::emitUnknownDiagnosticNotes(SILLocation fallbackLoc) {
987991
std::string demangledCalleeName =
988992
demangleSymbolNameForDiagnostics(callee->getName());
989993
diagnose(ctx, diagLoc, diag::constexpr_found_callee_with_no_body,
990-
StringRef(demangledCalleeName));
994+
demangledCalleeName);
991995
if (emitTriggerLocInDiag)
992996
diagnose(ctx, triggerLoc, diag::constexpr_callee_with_no_body,
993997
triggerLocSkipsInternalLocs);
@@ -1040,7 +1044,7 @@ void SymbolicValue::emitUnknownDiagnosticNotes(SILLocation fallbackLoc) {
10401044
witnessMethodName);
10411045

10421046
diagnose(ctx, diagLoc, diag::constexpr_unresolvable_witness_call,
1043-
StringRef(witnessMethodName));
1047+
witnessMethodName);
10441048
if (emitTriggerLocInDiag)
10451049
diagnose(ctx, triggerLoc, diag::constexpr_no_witness_table_entry,
10461050
triggerLocSkipsInternalLocs);

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ using namespace Lowering;
108108
template <typename... T, typename... U>
109109
static void diagnose(ASTContext &Context, SourceLoc loc, Diag<T...> diag,
110110
U &&... args) {
111+
// The lifetime of StringRef arguments will be extended as necessary by this
112+
// utility. The copy happens in onTentativeDiagnosticFlush at the bottom of
113+
// DiagnosticEngine.cpp, which is called when the destructor of the
114+
// InFlightDiagnostic returned by diagnose runs.
111115
Context.Diags.diagnose(loc, diag, std::forward<U>(args)...);
112116
}
113117

@@ -365,9 +369,8 @@ static bool diagnoseSpecialErrors(SILInstruction *unevaluableInst,
365369

366370
if (unknownReason.getKind() == UnknownReason::Trap) {
367371
// We have an assertion failure or fatal error.
368-
const char *message = unknownReason.getTrapMessage();
369372
diagnose(ctx, sourceLoc, diag::oslog_constant_eval_trap,
370-
StringRef(message));
373+
unknownReason.getTrapMessage());
371374
return true;
372375
}
373376
if (unknownReason.getKind() == UnknownReason::TooManyInstructions) {
@@ -1207,7 +1210,9 @@ static void deleteInstructionWithUsersAndFixLifetimes(
12071210
/// Try to dead-code eliminate the OSLogMessage instance \c oslogMessage passed
12081211
/// to the os log call and clean up its dependencies. If the instance cannot be
12091212
/// eliminated, emit diagnostics.
1210-
static void tryEliminateOSLogMessage(SingleValueInstruction *oslogMessage) {
1213+
/// \returns true if elimination is successful and false if it is not successful
1214+
/// and diagnostics is emitted.
1215+
static bool tryEliminateOSLogMessage(SingleValueInstruction *oslogMessage) {
12111216
InstructionDeleter deleter;
12121217
// List of instructions that are possibly dead.
12131218
SmallVector<SILInstruction *, 4> worklist = {oslogMessage};
@@ -1246,13 +1251,15 @@ static void tryEliminateOSLogMessage(SingleValueInstruction *oslogMessage) {
12461251
SILFunction *fun = oslogMessage->getFunction();
12471252
diagnose(fun->getASTContext(), oslogMessage->getLoc().getSourceLoc(),
12481253
diag::oslog_message_alive_after_opts);
1254+
return false;
12491255
}
1256+
return true;
12501257
}
12511258

12521259
/// Constant evaluate instructions starting from \p start and fold the uses
12531260
/// of the SIL value \p oslogMessage.
1254-
/// \returns true if the body of the function containing \p oslogMessage is
1255-
/// modified. Returns false otherwise.
1261+
/// \returns true if folding is successful and false if it is not successful and
1262+
/// diagnostics is emitted.
12561263
static bool constantFold(SILInstruction *start,
12571264
SingleValueInstruction *oslogMessage,
12581265
unsigned assertConfig) {
@@ -1279,9 +1286,7 @@ static bool constantFold(SILInstruction *start,
12791286
return false;
12801287

12811288
substituteConstants(state);
1282-
1283-
tryEliminateOSLogMessage(oslogMessage);
1284-
return true;
1289+
return tryEliminateOSLogMessage(oslogMessage);
12851290
}
12861291

12871292
/// Given a call to the initializer of OSLogMessage, which conforms to
@@ -1431,19 +1436,28 @@ suppressGlobalStringTablePointerError(SingleValueInstruction *oslogMessage) {
14311436
SmallVector<SILInstruction *, 8> users;
14321437
getTransitiveUsers(oslogMessage, users);
14331438

1439+
// Collect all globalStringTablePointer instructions.
1440+
SmallVector<BuiltinInst *, 4> globalStringTablePointerInsts;
14341441
for (SILInstruction *user : users) {
14351442
BuiltinInst *bi = dyn_cast<BuiltinInst>(user);
1436-
if (!bi ||
1437-
bi->getBuiltinInfo().ID != BuiltinValueKind::GlobalStringTablePointer)
1438-
continue;
1439-
// Replace this builtin by a string_literal instruction for an empty string.
1443+
if (bi &&
1444+
bi->getBuiltinInfo().ID == BuiltinValueKind::GlobalStringTablePointer)
1445+
globalStringTablePointerInsts.push_back(bi);
1446+
}
1447+
1448+
// Replace the globalStringTablePointer builtins by a string_literal
1449+
// instruction for an empty string and clean up dead code.
1450+
InstructionDeleter deleter;
1451+
for (BuiltinInst *bi : globalStringTablePointerInsts) {
14401452
SILBuilderWithScope builder(bi);
14411453
StringLiteralInst *stringLiteral = builder.createStringLiteral(
14421454
bi->getLoc(), StringRef(""), StringLiteralInst::Encoding::UTF8);
14431455
bi->replaceAllUsesWith(stringLiteral);
1444-
// Here, the bulitin instruction is dead, so clean it up.
1445-
eliminateDeadInstruction(bi);
1456+
// The bulitin instruction is likely dead. But since we are iterating over
1457+
// many instructions, do the cleanup at the end.
1458+
deleter.trackIfDead(bi);
14461459
}
1460+
deleter.cleanUpDeadInstructions();
14471461
}
14481462

14491463
/// If the SILInstruction is an initialization of OSLogMessage, return the
@@ -1536,14 +1550,14 @@ class OSLogOptimization : public SILFunctionTransform {
15361550
// The log call is in unreachable code here.
15371551
continue;
15381552
}
1539-
bool bodyModified =
1553+
bool foldingSucceeded =
15401554
constantFold(interpolationStart, oslogInit, assertConfig);
1541-
// If body was not modified, it implies that an error was diagnosed.
1555+
// If folding did not succeeded, it implies that an error was diagnosed.
15421556
// However, this will also trigger a diagnostics later on since
15431557
// _globalStringTablePointerBuiltin would not be passed a string literal.
15441558
// Suppress this error by synthesizing a dummy string literal for the
15451559
// builtin.
1546-
if (!bodyModified)
1560+
if (!foldingSucceeded)
15471561
suppressGlobalStringTablePointerError(oslogInit);
15481562
madeChange = true;
15491563
}

lib/Sema/ConstantnessSemaDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ static Expr *checkConstantness(Expr *expr) {
162162
if (!isa<ApplyExpr>(expr))
163163
return expr;
164164

165+
if (NominalTypeDecl *nominal =
166+
expr->getType()->getNominalOrBoundGenericNominal()) {
167+
if (nominal->getName() == nominal->getASTContext().Id_OSLogMessage)
168+
return expr;
169+
}
170+
165171
ApplyExpr *apply = cast<ApplyExpr>(expr);
166172
ValueDecl *calledValue = apply->getCalledValue();
167173
if (!calledValue)

0 commit comments

Comments
 (0)