Skip to content

Commit f49b28c

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 785047b + 33d95a3 commit f49b28c

File tree

8 files changed

+109
-37
lines changed

8 files changed

+109
-37
lines changed

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ function (swift_benchmark_compile_archopts)
315315
if (is_darwin)
316316
list(APPEND common_options
317317
"-I" "${srcdir}/utils/ObjectiveCTests"
318+
"-I" "${srcdir}/utils/LibProc"
318319
"-F" "${sdk}/../../../Developer/Library/Frameworks"
319320
"-sdk" "${sdk}"
320321
"-no-link-objc-runtime")
@@ -344,6 +345,7 @@ function (swift_benchmark_compile_archopts)
344345
list(APPEND common_options_driver
345346
"-sdk" "${sdk}"
346347
"-F" "${sdk}/../../../Developer/Library/Frameworks"
348+
"-I" "${srcdir}/utils/LibProc"
347349
"-no-link-objc-runtime")
348350
endif()
349351
set(bench_library_objects)

benchmark/utils/DriverUtils.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import Glibc
1515
#else
1616
import Darwin
17+
import LibProc
1718
#endif
1819

1920
import TestsUtils
@@ -297,6 +298,27 @@ final class SampleRunner {
297298
(start, end, lastYield) = (now, now, now)
298299
}
299300

301+
#if os(Linux)
302+
private static func getExecutedInstructions() -> UInt64 {
303+
// FIXME: there is a Linux PMC API you can use to get this, but it's
304+
// not quite so straightforward.
305+
return 0
306+
}
307+
#else
308+
private static func getExecutedInstructions() -> UInt64 {
309+
if #available(OSX 10.9, iOS 7.0, *) {
310+
var u = rusage_info_v4()
311+
let p = UnsafeMutablePointer(&u)
312+
p.withMemoryRebound(to: Optional<rusage_info_t>.self, capacity: 1) { up in
313+
let _ = proc_pid_rusage(getpid(), RUSAGE_INFO_V4, up)
314+
}
315+
return u.ri_instructions
316+
} else {
317+
return 0
318+
}
319+
}
320+
#endif
321+
300322
private static func getResourceUtilization() -> rusage {
301323
var u = rusage(); getrusage(RUSAGE_SELF, &u); return u
302324
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===--- LibProcIncludeSystemHeader.h -------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This file exists to include the not-yet-modularized libproc.h system header.
14+
15+
#if __has_include(<libproc.h>)
16+
#include <libproc.h>
17+
#else
18+
#include <Availability.h>
19+
#include <sys/resource.h>
20+
// Some SDKs are missing the libproc.h header, despite this symbol being present.
21+
int proc_pid_rusage(int pid, int flavor, rusage_info_t *buffer) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
22+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===--- module.modulemap -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
module LibProc {
14+
header "LibProcIncludeSystemHeader.h"
15+
export *
16+
}

lib/Sema/CSBindings.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,45 @@ void ConstraintSystem::PotentialBindings::addPotentialBinding(
209209
if (auto *literalProtocol = binding.DefaultedProtocol)
210210
foundLiteralBinding(literalProtocol);
211211

212+
// If the type variable can't bind to an lvalue, make sure the
213+
// type we pick isn't an lvalue.
214+
if (!TypeVar->getImpl().canBindToLValue() &&
215+
binding.BindingType->hasLValueType()) {
216+
binding = binding.withType(binding.BindingType->getRValueType());
217+
}
218+
219+
if (!isViable(binding))
220+
return;
221+
212222
Bindings.push_back(std::move(binding));
213223
}
214224

225+
bool ConstraintSystem::PotentialBindings::isViable(
226+
PotentialBinding &binding) const {
227+
// Prevent against checking against the same bound generic type
228+
// over and over again. Doing so means redundant work in the best
229+
// case. In the worst case, we'll produce lots of duplicate solutions
230+
// for this constraint system, which is problematic for overload
231+
// resolution.
232+
auto type = binding.BindingType;
233+
if (type->hasTypeVariable()) {
234+
auto *BGT = type->getAs<BoundGenericType>();
235+
if (!BGT)
236+
return true;
237+
238+
for (auto &existing : Bindings) {
239+
auto existingBGT = existing.BindingType->getAs<BoundGenericType>();
240+
if (!existingBGT)
241+
continue;
242+
243+
if (BGT != existingBGT && BGT->getDecl() == existingBGT->getDecl())
244+
return false;
245+
}
246+
}
247+
248+
return true;
249+
}
250+
215251
Optional<ConstraintSystem::PotentialBinding>
216252
ConstraintSystem::getPotentialBindingForRelationalConstraint(
217253
PotentialBindings &result, Constraint *constraint,

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -580,42 +580,10 @@ bool ConstraintSystem::tryTypeVariableBindings(
580580
continue;
581581

582582
auto type = binding.BindingType;
583-
584-
// If the type variable can't bind to an lvalue, make sure the
585-
// type we pick isn't an lvalue.
586-
if (!typeVar->getImpl().canBindToLValue())
587-
type = type->getRValueType();
588-
589-
// Remove parentheses. They're insignificant here.
590-
type = type->getWithoutParens();
591-
592583
// If we've already tried this binding, move on.
593584
if (!boundTypes.insert(type.getPointer()).second)
594585
continue;
595586

596-
// Prevent against checking against the same bound generic type
597-
// over and over again. Doing so means redundant work in the best
598-
// case. In the worst case, we'll produce lots of duplicate solutions
599-
// for this constraint system, which is problematic for overload
600-
// resolution.
601-
if (type->hasTypeVariable()) {
602-
auto triedBinding = false;
603-
if (auto BGT = type->getAs<BoundGenericType>()) {
604-
for (auto bt : boundTypes) {
605-
if (auto BBGT = bt->getAs<BoundGenericType>()) {
606-
if (BGT != BBGT &&
607-
BGT->getDecl() == BBGT->getDecl()) {
608-
triedBinding = true;
609-
break;
610-
}
611-
}
612-
}
613-
}
614-
615-
if (triedBinding)
616-
continue;
617-
}
618-
619587
if (tc.getLangOpts().DebugConstraintSolver) {
620588
auto &log = getASTContext().TypeCheckerDebug->getStream();
621589
log.indent(depth * 2)
@@ -679,8 +647,7 @@ bool ConstraintSystem::tryTypeVariableBindings(
679647
// Enumerate the supertypes of each of the types we tried.
680648
for (auto binding : bindings) {
681649
const auto type = binding.BindingType;
682-
if (type->hasError())
683-
continue;
650+
assert(!type->hasError());
684651

685652
// After our first pass, note that we've explored these
686653
// types.

lib/Sema/ConstraintSystem.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,11 +2774,15 @@ class ConstraintSystem {
27742774
ConstraintKind bindingSource,
27752775
ProtocolDecl *defaultedProtocol = nullptr,
27762776
ConstraintLocator *defaultableBinding = nullptr)
2777-
: BindingType(type), Kind(kind), BindingSource(bindingSource),
2778-
DefaultedProtocol(defaultedProtocol),
2777+
: BindingType(type->getWithoutParens()), Kind(kind),
2778+
BindingSource(bindingSource), DefaultedProtocol(defaultedProtocol),
27792779
DefaultableBinding(defaultableBinding) {}
27802780

27812781
bool isDefaultableBinding() const { return DefaultableBinding != nullptr; }
2782+
2783+
PotentialBinding withType(Type type) const {
2784+
return {type, Kind, BindingSource, DefaultedProtocol, DefaultableBinding};
2785+
}
27822786
};
27832787

27842788
struct PotentialBindings {
@@ -2869,6 +2873,9 @@ class ConstraintSystem {
28692873
void addPotentialBinding(PotentialBinding binding,
28702874
bool allowJoinMeet = true);
28712875

2876+
/// Check if this binding is viable for inclusion in the set.
2877+
bool isViable(PotentialBinding &binding) const;
2878+
28722879
void dump(llvm::raw_ostream &out,
28732880
unsigned indent = 0) const LLVM_ATTRIBUTE_USED {
28742881
out.indent(indent);

validation-test/Sema/type_checker_perf/slow/rdar19181998.swift.gyb renamed to validation-test/Sema/type_checker_perf/fast/rdar19181998.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %scale-test --invert-result --begin 1 --end 4 --step 1 --select incrementScopeCounter %s
1+
// RUN: %scale-test --begin 1 --end 30 --step 1 --select incrementScopeCounter %s
22
// REQUIRES: OS=macosx
33
// REQUIRES: asserts
44

0 commit comments

Comments
 (0)