Skip to content

Commit 9eec63b

Browse files
Merge pull request #50 from kateinoigakukun/merge/44a64755666ed1272e0b0e949ac676ac92667bcd
Merge 44a6475
2 parents 4e9aeef + d222ba3 commit 9eec63b

File tree

29 files changed

+321
-133
lines changed

29 files changed

+321
-133
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ function(add_dependencies_multiple_targets)
2828
endif()
2929
endfunction()
3030

31-
# Compute the library subdirectory to use for the given sdk and
32-
# architecture, placing the result in 'result_var_name'.
33-
function(compute_library_subdir result_var_name sdk arch)
34-
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
35-
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
36-
else()
37-
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
38-
endif()
39-
endfunction()
40-
4131
function(_compute_lto_flag option out_var)
4232
string(TOLOWER "${option}" lowercase_option)
4333
if (lowercase_option STREQUAL "full")
@@ -163,9 +153,12 @@ function(_add_variant_c_compile_link_flags)
163153
endif()
164154

165155
if(IS_DARWIN)
156+
# We collate -F with the framework path to avoid unwanted deduplication
157+
# of options by target_compile_options -- this way no undesired
158+
# side effects are introduced should a new search path be added.
166159
list(APPEND result
167160
"-arch" "${CFLAGS_ARCH}"
168-
"-F" "${SWIFT_SDK_${CFLAGS_SDK}_PATH}/../../../Developer/Library/Frameworks")
161+
"-F${SWIFT_SDK_${CFLAGS_SDK}_PATH}/../../../Developer/Library/Frameworks")
169162

170163
set(add_explicit_version TRUE)
171164

@@ -409,8 +402,11 @@ function(_add_variant_swift_compile_flags
409402
endif()
410403

411404
if(IS_DARWIN)
405+
# We collate -F with the framework path to avoid unwanted deduplication
406+
# of options by target_compile_options -- this way no undesired
407+
# side effects are introduced should a new search path be added.
412408
list(APPEND result
413-
"-F" "${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/../../../Developer/Library/Frameworks")
409+
"-F${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/../../../Developer/Library/Frameworks")
414410
endif()
415411

416412
is_build_type_optimized("${build_type}" optimized)

cmake/modules/SwiftSource.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
include(macCatalystUtils)
22
include(SwiftUtils)
33

4+
# Compute the library subdirectory to use for the given sdk and
5+
# architecture, placing the result in 'result_var_name'.
6+
function(compute_library_subdir result_var_name sdk arch)
7+
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
8+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
9+
else()
10+
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
11+
endif()
12+
endfunction()
13+
414
# Process the sources within the given variable, pulling out any Swift
515
# sources to be compiled with 'swift' directly. This updates
616
# ${sourcesvar} in place with the resulting list and ${externalvar} with the

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ SEMANTICS_ATTR(STRING_PLUS_EQUALS, "string.plusequals")
3434
SEMANTICS_ATTR(FIND_STRING_SWITCH_CASE, "findStringSwitchCase")
3535
SEMANTICS_ATTR(FIND_STRING_SWITCH_CASE_WITH_CACHE, "findStringSwitchCaseWithCache")
3636

37+
SEMANTICS_ATTR(BINARY_INTEGER_DESCRIPTION, "binaryInteger.description")
38+
3739
SEMANTICS_ATTR(SWIFT_CONCURRENT_ASYNC, "swift.concurrent.async")
3840
SEMANTICS_ATTR(SWIFT_CONCURRENT_SAFE, "swift.concurrent.safe")
3941
SEMANTICS_ATTR(SWIFT_CONCURRENT, "swift.concurrent")

include/swift/Runtime/MutexWASI.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
//===--- MutexWin32.h - -----------------------------------------*- C++ -*-===//
1+
//===--- MutexWASI.h - -----------------------------------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// Mutex, ConditionVariable, Read/Write lock, and Scoped lock implementations
14-
// using Windows Slim Reader/Writer Locks and Conditional Variables.
13+
// No-op implementation of locks for the WebAssembly System Interface. The
14+
// implementation does not need to perform locking, because as of January 2020
15+
// WebAssembly does not support threads.
16+
// See the current status at https://github.com/WebAssembly/proposals and
17+
// https://github.com/webassembly/threads
1518
//
1619
//===----------------------------------------------------------------------===//
1720

lib/AST/Attr.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,10 +1360,19 @@ OriginallyDefinedInAttr::isActivePlatform(const ASTContext &ctx) const {
13601360
Result.Platform = Platform;
13611361
Result.Version = MovedVersion;
13621362
Result.ModuleName = OriginalModuleName;
1363-
if (isPlatformActive(Platform, ctx.LangOpts)) {
1363+
if (isPlatformActive(Platform, ctx.LangOpts, /*TargetVariant*/false)) {
13641364
Result.IsSimulator = ctx.LangOpts.Target.isSimulatorEnvironment();
13651365
return Result;
13661366
}
1367+
1368+
// Also check if the platform is active by using target variant. This ensures
1369+
// we emit linker directives for multiple platforms when building zippered
1370+
// libraries.
1371+
if (ctx.LangOpts.TargetVariant.hasValue() &&
1372+
isPlatformActive(Platform, ctx.LangOpts, /*TargetVariant*/true)) {
1373+
Result.IsSimulator = ctx.LangOpts.TargetVariant->isSimulatorEnvironment();
1374+
return Result;
1375+
}
13671376
return None;
13681377
}
13691378

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,6 +4361,8 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
43614361

43624362
if (subjectType->is<DependentMemberType>()) {
43634363
subjectType = resolveDependentMemberTypes(*this, subjectType);
4364+
} else {
4365+
subjectType = ErrorType::get(subjectType);
43644366
}
43654367

43664368
auto invalidConstraint = Constraint<Type>(

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
18471847
auto DL = llvm::DebugLoc::get(L.Line, L.Column, Scope, InlinedAt);
18481848
Builder.SetCurrentDebugLocation(DL);
18491849
}
1850-
1850+
18511851
void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
18521852
StringRef failureMsg) {
18531853
auto TrapLoc = Builder.getCurrentDebugLocation();
@@ -1864,7 +1864,7 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
18641864
FuncName += failureMsg;
18651865

18661866
llvm::DISubprogram *TrapSP = DBuilder.createFunction(
1867-
MainModule, StringRef(), FuncName, TrapLoc->getFile(), 0, DIFnTy, 0,
1867+
MainModule, FuncName, StringRef(), TrapLoc->getFile(), 0, DIFnTy, 0,
18681868
llvm::DINode::FlagArtificial, llvm::DISubprogram::SPFlagDefinition,
18691869
nullptr, nullptr, nullptr);
18701870

lib/SILGen/SILGenEpilog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void SILGenFunction::prepareEpilog(Type resultType, bool isThrowing,
3030
// emits unreachable if there is no source level return.
3131
NeedsReturn = (fnConv.funcTy->getNumResults() != 0);
3232
for (auto directResult : fnConv.getDirectSILResults()) {
33-
SILType resultType =
34-
F.mapTypeIntoContext(fnConv.getSILType(directResult));
33+
SILType resultType = F.getLoweredType(
34+
F.mapTypeIntoContext(fnConv.getSILType(directResult)));
3535
epilogBB->createPhiArgument(resultType, ValueOwnershipKind::Owned);
3636
}
3737
}

lib/SILOptimizer/Utils/ConstExpr.cpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ enum class WellKnownFunction {
5656
StringEquals,
5757
// String.percentEscapedString.getter
5858
StringEscapePercent,
59+
// BinaryInteger.description.getter
60+
BinaryIntegerDescription,
5961
// _assertionFailure(_: StaticString, _: StaticString, file: StaticString,...)
6062
AssertionFailure,
6163
// A function taking one argument that prints the symbolic value of the
@@ -83,6 +85,8 @@ static llvm::Optional<WellKnownFunction> classifyFunction(SILFunction *fn) {
8385
return WellKnownFunction::StringEquals;
8486
if (fn->hasSemanticsAttr(semantics::STRING_ESCAPE_PERCENT_GET))
8587
return WellKnownFunction::StringEscapePercent;
88+
if (fn->hasSemanticsAttr(semantics::BINARY_INTEGER_DESCRIPTION))
89+
return WellKnownFunction::BinaryIntegerDescription;
8690
if (fn->hasSemanticsAttrThatStartsWith("programtermination_point"))
8791
return WellKnownFunction::AssertionFailure;
8892
// A call to a function with the following semantics annotation will be
@@ -780,6 +784,13 @@ extractStaticStringValue(SymbolicValue staticString) {
780784
return staticStringProps[0].getStringValue();
781785
}
782786

787+
static Optional<StringRef>
788+
extractStringOrStaticStringValue(SymbolicValue stringValue) {
789+
if (stringValue.getKind() == SymbolicValue::String)
790+
return stringValue.getStringValue();
791+
return extractStaticStringValue(stringValue);
792+
}
793+
783794
/// If the specified type is a Swift.Array of some element type, then return the
784795
/// element type. Otherwise, return a null Type.
785796
static Type getArrayElementType(Type ty) {
@@ -789,6 +800,28 @@ static Type getArrayElementType(Type ty) {
789800
return Type();
790801
}
791802

803+
/// Check if the given type \p ty is a stdlib integer type and if so return
804+
/// whether the type is signed. Returns \c None if \p ty is not a stdlib integer
805+
/// type, \c true if it is a signed integer type and \c false if it is an
806+
/// unsigned integer type.
807+
static Optional<bool> getSignIfStdlibIntegerType(Type ty) {
808+
StructDecl *decl = ty->getStructOrBoundGenericStruct();
809+
if (!decl)
810+
return None;
811+
ASTContext &astCtx = ty->getASTContext();
812+
if (decl == astCtx.getIntDecl() || decl == astCtx.getInt8Decl() ||
813+
decl == astCtx.getInt16Decl() || decl == astCtx.getInt32Decl() ||
814+
decl == astCtx.getInt64Decl()) {
815+
return true;
816+
}
817+
if (decl == astCtx.getUIntDecl() || decl == astCtx.getUInt8Decl() ||
818+
decl == astCtx.getUInt16Decl() || decl == astCtx.getUInt32Decl() ||
819+
decl == astCtx.getUInt64Decl()) {
820+
return false;
821+
}
822+
return None;
823+
}
824+
792825
/// Given a call to a well known function, collect its arguments as constants,
793826
/// fold it, and return None. If any of the arguments are not constants, marks
794827
/// the call's results as Unknown, and return an Unknown with information about
@@ -803,8 +836,8 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
803836
for (unsigned i = 0; i < apply->getNumArguments(); i++) {
804837
SILValue argument = apply->getArgument(i);
805838
SymbolicValue argValue = getConstantValue(argument);
806-
Optional<StringRef> stringOpt = extractStaticStringValue(argValue);
807-
839+
Optional<StringRef> stringOpt =
840+
extractStringOrStaticStringValue(argValue);
808841
// The first argument is a prefix that specifies the kind of failure
809842
// this is.
810843
if (i == 0) {
@@ -816,7 +849,6 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
816849
}
817850
continue;
818851
}
819-
820852
if (stringOpt) {
821853
message += ": ";
822854
message += stringOpt.getValue();
@@ -1064,6 +1096,42 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
10641096
setValue(apply, resultVal);
10651097
return None;
10661098
}
1099+
case WellKnownFunction::BinaryIntegerDescription: {
1100+
// BinaryInteger.description.getter
1101+
assert(conventions.getNumDirectSILResults() == 1 &&
1102+
conventions.getNumIndirectSILResults() == 0 &&
1103+
conventions.getNumParameters() == 1 && apply->hasSubstitutions() &&
1104+
"unexpected BinaryInteger.description.getter signature");
1105+
// Get the type of the argument and check if it is a signed or
1106+
// unsigned integer.
1107+
SILValue integerArgument = apply->getOperand(1);
1108+
CanType argumentType = substituteGenericParamsAndSimpify(
1109+
integerArgument->getType().getASTType());
1110+
Optional<bool> isSignedIntegerType =
1111+
getSignIfStdlibIntegerType(argumentType);
1112+
if (!isSignedIntegerType.hasValue()) {
1113+
return getUnknown(evaluator, (SILInstruction *)apply,
1114+
UnknownReason::InvalidOperandValue);
1115+
}
1116+
// Load the stdlib integer's value and convert it to a string.
1117+
SymbolicValue stdlibIntegerValue =
1118+
getConstAddrAndLoadResult(integerArgument);
1119+
if (!stdlibIntegerValue.isConstant()) {
1120+
return stdlibIntegerValue;
1121+
}
1122+
SymbolicValue builtinIntegerValue =
1123+
stdlibIntegerValue.lookThroughSingleElementAggregates();
1124+
assert(builtinIntegerValue.getKind() == SymbolicValue::Integer &&
1125+
"stdlib integer type must store only a builtin integer");
1126+
APInt integer = builtinIntegerValue.getIntegerValue();
1127+
SmallString<8> integerString;
1128+
isSignedIntegerType.getValue() ? integer.toStringSigned(integerString)
1129+
: integer.toStringUnsigned(integerString);
1130+
SymbolicValue resultVal =
1131+
SymbolicValue::getString(integerString.str(), evaluator.getAllocator());
1132+
setValue(apply, resultVal);
1133+
return None;
1134+
}
10671135
case WellKnownFunction::DebugPrint: {
10681136
assert(apply->getNumArguments() == 1 &&
10691137
"debug_print function must take exactly one argument");

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,21 +1296,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
12961296
}
12971297
}
12981298

1299-
// Let's check whether this is a situation when callee expects
1300-
// no arguments but N are given. Otherwise, just below
1301-
// `typeCheckArgumentChild*` is going to use `()` is a contextual type which
1302-
// is incorrect.
1303-
if (argType && argType->isVoid()) {
1304-
auto *argExpr = callExpr->getArg();
1305-
if (isa<ParenExpr>(argExpr) ||
1306-
(isa<TupleExpr>(argExpr) &&
1307-
cast<TupleExpr>(argExpr)->getNumElements() > 0)) {
1308-
diagnose(callExpr->getLoc(), diag::extra_argument_to_nullary_call)
1309-
.highlight(argExpr->getSourceRange());
1310-
return true;
1311-
}
1312-
}
1313-
13141299
// Get the expression result of type checking the arguments to the call
13151300
// independently, so we have some idea of what we're working with.
13161301
//

0 commit comments

Comments
 (0)