Skip to content

Commit 9eec63b

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

29 files changed

+321
-133
lines changed

Diff for: cmake/modules/AddSwift.cmake

+8-12
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)

Diff for: cmake/modules/SwiftSource.cmake

+10
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

Diff for: include/swift/AST/SemanticAttrs.def

+2
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")

Diff for: include/swift/Runtime/MutexWASI.h

+7-4
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

Diff for: lib/AST/Attr.cpp

+10-1
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

Diff for: lib/AST/GenericSignatureBuilder.cpp

+2
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>(

Diff for: lib/IRGen/IRGenDebugInfo.cpp

+2-2
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

Diff for: lib/SILGen/SILGenEpilog.cpp

+2-2
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
}

Diff for: lib/SILOptimizer/Utils/ConstExpr.cpp

+71-3
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");

Diff for: lib/Sema/CSDiag.cpp

-15
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
//

Diff for: lib/Sema/CSDiagnostics.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -4561,7 +4561,21 @@ bool ExtraneousArgumentsFailure::diagnoseAsNote() {
45614561
}
45624562

45634563
bool ExtraneousArgumentsFailure::diagnoseSingleExtraArgument() const {
4564-
auto *arguments = getArgumentListExprFor(getLocator());
4564+
auto *locator = getLocator();
4565+
4566+
// This specifically handles a case of `Void(...)` which generates
4567+
// constraints differently from other constructor invocations and
4568+
// wouldn't have `ApplyArgument` as a last element in the locator.
4569+
if (auto *call = dyn_cast<CallExpr>(getRawAnchor())) {
4570+
auto *TE = dyn_cast<TypeExpr>(call->getFn());
4571+
if (TE && getType(TE)->getMetatypeInstanceType()->isVoid()) {
4572+
emitDiagnostic(call->getLoc(), diag::extra_argument_to_nullary_call)
4573+
.highlight(call->getArg()->getSourceRange());
4574+
return true;
4575+
}
4576+
}
4577+
4578+
auto *arguments = getArgumentListExprFor(locator);
45654579
if (!arguments)
45664580
return false;
45674581

Diff for: lib/Sema/CSSimplify.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -3331,10 +3331,13 @@ bool ConstraintSystem::repairFailures(
33313331
if (lhs->hasHole() || rhs->hasHole())
33323332
return true;
33333333

3334-
// If dependent members are present here it's because
3335-
// base doesn't conform to associated type's protocol.
3336-
if (lhs->hasDependentMember() || rhs->hasDependentMember())
3337-
break;
3334+
// If dependent members are present here it's because the base doesn't
3335+
// conform to the associated type's protocol. We can only get here if we
3336+
// already applied a fix for the conformance failure.
3337+
if (lhs->hasDependentMember() || rhs->hasDependentMember()) {
3338+
increaseScore(SK_Fix);
3339+
return true;
3340+
}
33383341

33393342
// If requirement is something like `T == [Int]` let's let
33403343
// type matcher a chance to match generic parameters before
@@ -3949,12 +3952,14 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
39493952
llvm_unreachable("type variables should have already been handled by now");
39503953

39513954
case TypeKind::DependentMember: {
3952-
// If one of the dependent member types has no type variables,
3953-
// this comparison is effectively illformed, because dependent
3954-
// member couldn't be simplified down to the actual type, and
3955-
// we wouldn't be able to solve this constraint, so let's just fail.
3956-
if (!desugar1->hasTypeVariable() || !desugar2->hasTypeVariable())
3957-
return getTypeMatchFailure(locator);
3955+
// If one of the dependent member types has no type variables, the
3956+
// dependent member can't be simplified because the base doesn't conform
3957+
// to the associated type's protocol. We can only get here if we already
3958+
// applied a fix for the conformance failure.
3959+
if (!desugar1->hasTypeVariable() || !desugar2->hasTypeVariable()) {
3960+
increaseScore(SK_Fix);
3961+
return getTypeMatchSuccess();
3962+
}
39583963

39593964
// Nothing we can solve yet, since we need to wait until
39603965
// type variables will get resolved.

Diff for: stdlib/public/core/Integers.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ extension BinaryInteger {
15571557
}
15581558

15591559
/// A textual representation of this value.
1560+
@_semantics("binaryInteger.description")
15601561
public var description: String {
15611562
return _description(radix: 10, uppercase: false)
15621563
}

Diff for: stdlib/public/stubs/Random.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
#include "swift/Runtime/Mutex.h"
4343
#include "../SwiftShims/Random.h"
4444

45-
#ifdef __wasi__
46-
#include <algorithm> // std::min
47-
#endif
45+
#include <algorithm> // required for std::min
4846

4947
#if defined(__APPLE__)
5048

Diff for: stdlib/public/stubs/Stubs.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void swift::_swift_stdlib_flockfile_stdout() {
504504
#if defined(_WIN32)
505505
_lock_file(stdout);
506506
#elif defined(__wasi__)
507-
// WebAssembly/WASI doesn't support file locking yet
507+
// WebAssembly/WASI doesn't support file locking yet https://bugs.swift.org/browse/SR-12097
508508
#else
509509
flockfile(stdout);
510510
#endif
@@ -514,7 +514,7 @@ void swift::_swift_stdlib_funlockfile_stdout() {
514514
#if defined(_WIN32)
515515
_unlock_file(stdout);
516516
#elif defined(__wasi__)
517-
// WebAssembly/WASI doesn't support file locking yet
517+
// WebAssembly/WASI doesn't support file locking yet https://bugs.swift.org/browse/SR-12097
518518
#else
519519
funlockfile(stdout);
520520
#endif

0 commit comments

Comments
 (0)