Skip to content

Commit

Permalink
Merge pull request #50 from kateinoigakukun/merge/44a64755666ed1272e0…
Browse files Browse the repository at this point in the history
…b0e949ac676ac92667bcd

Merge 44a6475
  • Loading branch information
kateinoigakukun committed Jan 29, 2020
2 parents 4e9aeef + d222ba3 commit 9eec63b
Show file tree
Hide file tree
Showing 29 changed files with 321 additions and 133 deletions.
20 changes: 8 additions & 12 deletions cmake/modules/AddSwift.cmake
Expand Up @@ -28,16 +28,6 @@ function(add_dependencies_multiple_targets)
endif()
endfunction()

# Compute the library subdirectory to use for the given sdk and
# architecture, placing the result in 'result_var_name'.
function(compute_library_subdir result_var_name sdk arch)
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
else()
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
endif()
endfunction()

function(_compute_lto_flag option out_var)
string(TOLOWER "${option}" lowercase_option)
if (lowercase_option STREQUAL "full")
Expand Down Expand Up @@ -163,9 +153,12 @@ function(_add_variant_c_compile_link_flags)
endif()

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

set(add_explicit_version TRUE)

Expand Down Expand Up @@ -409,8 +402,11 @@ function(_add_variant_swift_compile_flags
endif()

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

is_build_type_optimized("${build_type}" optimized)
Expand Down
10 changes: 10 additions & 0 deletions cmake/modules/SwiftSource.cmake
@@ -1,6 +1,16 @@
include(macCatalystUtils)
include(SwiftUtils)

# Compute the library subdirectory to use for the given sdk and
# architecture, placing the result in 'result_var_name'.
function(compute_library_subdir result_var_name sdk arch)
if(sdk IN_LIST SWIFT_APPLE_PLATFORMS OR sdk STREQUAL "MACCATALYST")
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}" PARENT_SCOPE)
else()
set("${result_var_name}" "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}" PARENT_SCOPE)
endif()
endfunction()

# Process the sources within the given variable, pulling out any Swift
# sources to be compiled with 'swift' directly. This updates
# ${sourcesvar} in place with the resulting list and ${externalvar} with the
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/SemanticAttrs.def
Expand Up @@ -34,6 +34,8 @@ SEMANTICS_ATTR(STRING_PLUS_EQUALS, "string.plusequals")
SEMANTICS_ATTR(FIND_STRING_SWITCH_CASE, "findStringSwitchCase")
SEMANTICS_ATTR(FIND_STRING_SWITCH_CASE_WITH_CACHE, "findStringSwitchCaseWithCache")

SEMANTICS_ATTR(BINARY_INTEGER_DESCRIPTION, "binaryInteger.description")

SEMANTICS_ATTR(SWIFT_CONCURRENT_ASYNC, "swift.concurrent.async")
SEMANTICS_ATTR(SWIFT_CONCURRENT_SAFE, "swift.concurrent.safe")
SEMANTICS_ATTR(SWIFT_CONCURRENT, "swift.concurrent")
Expand Down
11 changes: 7 additions & 4 deletions include/swift/Runtime/MutexWASI.h
@@ -1,17 +1,20 @@
//===--- MutexWin32.h - -----------------------------------------*- C++ -*-===//
//===--- MutexWASI.h - -----------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Mutex, ConditionVariable, Read/Write lock, and Scoped lock implementations
// using Windows Slim Reader/Writer Locks and Conditional Variables.
// No-op implementation of locks for the WebAssembly System Interface. The
// implementation does not need to perform locking, because as of January 2020
// WebAssembly does not support threads.
// See the current status at https://github.com/WebAssembly/proposals and
// https://github.com/webassembly/threads
//
//===----------------------------------------------------------------------===//

Expand Down
11 changes: 10 additions & 1 deletion lib/AST/Attr.cpp
Expand Up @@ -1360,10 +1360,19 @@ OriginallyDefinedInAttr::isActivePlatform(const ASTContext &ctx) const {
Result.Platform = Platform;
Result.Version = MovedVersion;
Result.ModuleName = OriginalModuleName;
if (isPlatformActive(Platform, ctx.LangOpts)) {
if (isPlatformActive(Platform, ctx.LangOpts, /*TargetVariant*/false)) {
Result.IsSimulator = ctx.LangOpts.Target.isSimulatorEnvironment();
return Result;
}

// Also check if the platform is active by using target variant. This ensures
// we emit linker directives for multiple platforms when building zippered
// libraries.
if (ctx.LangOpts.TargetVariant.hasValue() &&
isPlatformActive(Platform, ctx.LangOpts, /*TargetVariant*/true)) {
Result.IsSimulator = ctx.LangOpts.TargetVariant->isSimulatorEnvironment();
return Result;
}
return None;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/AST/GenericSignatureBuilder.cpp
Expand Up @@ -4361,6 +4361,8 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(

if (subjectType->is<DependentMemberType>()) {
subjectType = resolveDependentMemberTypes(*this, subjectType);
} else {
subjectType = ErrorType::get(subjectType);
}

auto invalidConstraint = Constraint<Type>(
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/IRGenDebugInfo.cpp
Expand Up @@ -1847,7 +1847,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
auto DL = llvm::DebugLoc::get(L.Line, L.Column, Scope, InlinedAt);
Builder.SetCurrentDebugLocation(DL);
}

void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
StringRef failureMsg) {
auto TrapLoc = Builder.getCurrentDebugLocation();
Expand All @@ -1864,7 +1864,7 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
FuncName += failureMsg;

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

Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenEpilog.cpp
Expand Up @@ -30,8 +30,8 @@ void SILGenFunction::prepareEpilog(Type resultType, bool isThrowing,
// emits unreachable if there is no source level return.
NeedsReturn = (fnConv.funcTy->getNumResults() != 0);
for (auto directResult : fnConv.getDirectSILResults()) {
SILType resultType =
F.mapTypeIntoContext(fnConv.getSILType(directResult));
SILType resultType = F.getLoweredType(
F.mapTypeIntoContext(fnConv.getSILType(directResult)));
epilogBB->createPhiArgument(resultType, ValueOwnershipKind::Owned);
}
}
Expand Down
74 changes: 71 additions & 3 deletions lib/SILOptimizer/Utils/ConstExpr.cpp
Expand Up @@ -56,6 +56,8 @@ enum class WellKnownFunction {
StringEquals,
// String.percentEscapedString.getter
StringEscapePercent,
// BinaryInteger.description.getter
BinaryIntegerDescription,
// _assertionFailure(_: StaticString, _: StaticString, file: StaticString,...)
AssertionFailure,
// A function taking one argument that prints the symbolic value of the
Expand Down Expand Up @@ -83,6 +85,8 @@ static llvm::Optional<WellKnownFunction> classifyFunction(SILFunction *fn) {
return WellKnownFunction::StringEquals;
if (fn->hasSemanticsAttr(semantics::STRING_ESCAPE_PERCENT_GET))
return WellKnownFunction::StringEscapePercent;
if (fn->hasSemanticsAttr(semantics::BINARY_INTEGER_DESCRIPTION))
return WellKnownFunction::BinaryIntegerDescription;
if (fn->hasSemanticsAttrThatStartsWith("programtermination_point"))
return WellKnownFunction::AssertionFailure;
// A call to a function with the following semantics annotation will be
Expand Down Expand Up @@ -780,6 +784,13 @@ extractStaticStringValue(SymbolicValue staticString) {
return staticStringProps[0].getStringValue();
}

static Optional<StringRef>
extractStringOrStaticStringValue(SymbolicValue stringValue) {
if (stringValue.getKind() == SymbolicValue::String)
return stringValue.getStringValue();
return extractStaticStringValue(stringValue);
}

/// If the specified type is a Swift.Array of some element type, then return the
/// element type. Otherwise, return a null Type.
static Type getArrayElementType(Type ty) {
Expand All @@ -789,6 +800,28 @@ static Type getArrayElementType(Type ty) {
return Type();
}

/// Check if the given type \p ty is a stdlib integer type and if so return
/// whether the type is signed. Returns \c None if \p ty is not a stdlib integer
/// type, \c true if it is a signed integer type and \c false if it is an
/// unsigned integer type.
static Optional<bool> getSignIfStdlibIntegerType(Type ty) {
StructDecl *decl = ty->getStructOrBoundGenericStruct();
if (!decl)
return None;
ASTContext &astCtx = ty->getASTContext();
if (decl == astCtx.getIntDecl() || decl == astCtx.getInt8Decl() ||
decl == astCtx.getInt16Decl() || decl == astCtx.getInt32Decl() ||
decl == astCtx.getInt64Decl()) {
return true;
}
if (decl == astCtx.getUIntDecl() || decl == astCtx.getUInt8Decl() ||
decl == astCtx.getUInt16Decl() || decl == astCtx.getUInt32Decl() ||
decl == astCtx.getUInt64Decl()) {
return false;
}
return None;
}

/// Given a call to a well known function, collect its arguments as constants,
/// fold it, and return None. If any of the arguments are not constants, marks
/// the call's results as Unknown, and return an Unknown with information about
Expand All @@ -803,8 +836,8 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
for (unsigned i = 0; i < apply->getNumArguments(); i++) {
SILValue argument = apply->getArgument(i);
SymbolicValue argValue = getConstantValue(argument);
Optional<StringRef> stringOpt = extractStaticStringValue(argValue);

Optional<StringRef> stringOpt =
extractStringOrStaticStringValue(argValue);
// The first argument is a prefix that specifies the kind of failure
// this is.
if (i == 0) {
Expand All @@ -816,7 +849,6 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
}
continue;
}

if (stringOpt) {
message += ": ";
message += stringOpt.getValue();
Expand Down Expand Up @@ -1064,6 +1096,42 @@ ConstExprFunctionState::computeWellKnownCallResult(ApplyInst *apply,
setValue(apply, resultVal);
return None;
}
case WellKnownFunction::BinaryIntegerDescription: {
// BinaryInteger.description.getter
assert(conventions.getNumDirectSILResults() == 1 &&
conventions.getNumIndirectSILResults() == 0 &&
conventions.getNumParameters() == 1 && apply->hasSubstitutions() &&
"unexpected BinaryInteger.description.getter signature");
// Get the type of the argument and check if it is a signed or
// unsigned integer.
SILValue integerArgument = apply->getOperand(1);
CanType argumentType = substituteGenericParamsAndSimpify(
integerArgument->getType().getASTType());
Optional<bool> isSignedIntegerType =
getSignIfStdlibIntegerType(argumentType);
if (!isSignedIntegerType.hasValue()) {
return getUnknown(evaluator, (SILInstruction *)apply,
UnknownReason::InvalidOperandValue);
}
// Load the stdlib integer's value and convert it to a string.
SymbolicValue stdlibIntegerValue =
getConstAddrAndLoadResult(integerArgument);
if (!stdlibIntegerValue.isConstant()) {
return stdlibIntegerValue;
}
SymbolicValue builtinIntegerValue =
stdlibIntegerValue.lookThroughSingleElementAggregates();
assert(builtinIntegerValue.getKind() == SymbolicValue::Integer &&
"stdlib integer type must store only a builtin integer");
APInt integer = builtinIntegerValue.getIntegerValue();
SmallString<8> integerString;
isSignedIntegerType.getValue() ? integer.toStringSigned(integerString)
: integer.toStringUnsigned(integerString);
SymbolicValue resultVal =
SymbolicValue::getString(integerString.str(), evaluator.getAllocator());
setValue(apply, resultVal);
return None;
}
case WellKnownFunction::DebugPrint: {
assert(apply->getNumArguments() == 1 &&
"debug_print function must take exactly one argument");
Expand Down
15 changes: 0 additions & 15 deletions lib/Sema/CSDiag.cpp
Expand Up @@ -1296,21 +1296,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
}
}

// Let's check whether this is a situation when callee expects
// no arguments but N are given. Otherwise, just below
// `typeCheckArgumentChild*` is going to use `()` is a contextual type which
// is incorrect.
if (argType && argType->isVoid()) {
auto *argExpr = callExpr->getArg();
if (isa<ParenExpr>(argExpr) ||
(isa<TupleExpr>(argExpr) &&
cast<TupleExpr>(argExpr)->getNumElements() > 0)) {
diagnose(callExpr->getLoc(), diag::extra_argument_to_nullary_call)
.highlight(argExpr->getSourceRange());
return true;
}
}

// Get the expression result of type checking the arguments to the call
// independently, so we have some idea of what we're working with.
//
Expand Down
16 changes: 15 additions & 1 deletion lib/Sema/CSDiagnostics.cpp
Expand Up @@ -4561,7 +4561,21 @@ bool ExtraneousArgumentsFailure::diagnoseAsNote() {
}

bool ExtraneousArgumentsFailure::diagnoseSingleExtraArgument() const {
auto *arguments = getArgumentListExprFor(getLocator());
auto *locator = getLocator();

// This specifically handles a case of `Void(...)` which generates
// constraints differently from other constructor invocations and
// wouldn't have `ApplyArgument` as a last element in the locator.
if (auto *call = dyn_cast<CallExpr>(getRawAnchor())) {
auto *TE = dyn_cast<TypeExpr>(call->getFn());
if (TE && getType(TE)->getMetatypeInstanceType()->isVoid()) {
emitDiagnostic(call->getLoc(), diag::extra_argument_to_nullary_call)
.highlight(call->getArg()->getSourceRange());
return true;
}
}

auto *arguments = getArgumentListExprFor(locator);
if (!arguments)
return false;

Expand Down
25 changes: 15 additions & 10 deletions lib/Sema/CSSimplify.cpp
Expand Up @@ -3331,10 +3331,13 @@ bool ConstraintSystem::repairFailures(
if (lhs->hasHole() || rhs->hasHole())
return true;

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

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

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

// Nothing we can solve yet, since we need to wait until
// type variables will get resolved.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Integers.swift
Expand Up @@ -1557,6 +1557,7 @@ extension BinaryInteger {
}

/// A textual representation of this value.
@_semantics("binaryInteger.description")
public var description: String {
return _description(radix: 10, uppercase: false)
}
Expand Down
4 changes: 1 addition & 3 deletions stdlib/public/stubs/Random.cpp
Expand Up @@ -42,9 +42,7 @@
#include "swift/Runtime/Mutex.h"
#include "../SwiftShims/Random.h"

#ifdef __wasi__
#include <algorithm> // std::min
#endif
#include <algorithm> // required for std::min

#if defined(__APPLE__)

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/stubs/Stubs.cpp
Expand Up @@ -504,7 +504,7 @@ void swift::_swift_stdlib_flockfile_stdout() {
#if defined(_WIN32)
_lock_file(stdout);
#elif defined(__wasi__)
// WebAssembly/WASI doesn't support file locking yet
// WebAssembly/WASI doesn't support file locking yet https://bugs.swift.org/browse/SR-12097
#else
flockfile(stdout);
#endif
Expand All @@ -514,7 +514,7 @@ void swift::_swift_stdlib_funlockfile_stdout() {
#if defined(_WIN32)
_unlock_file(stdout);
#elif defined(__wasi__)
// WebAssembly/WASI doesn't support file locking yet
// WebAssembly/WASI doesn't support file locking yet https://bugs.swift.org/browse/SR-12097
#else
funlockfile(stdout);
#endif
Expand Down

0 comments on commit 9eec63b

Please sign in to comment.