Skip to content

Commit c1660bc

Browse files
authored
Merge pull request #1353 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents a970a73 + 918f674 commit c1660bc

File tree

12 files changed

+263
-35
lines changed

12 files changed

+263
-35
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,16 @@ bool ExtensionDecl::isConstrainedExtension() const {
13251325

13261326
bool ExtensionDecl::isEquivalentToExtendedContext() const {
13271327
auto decl = getExtendedNominal();
1328-
return getParentModule() == decl->getParentModule()
1328+
bool extendDeclFromSameModule = false;
1329+
if (!decl->getAlternateModuleName().empty()) {
1330+
// if the extended type was defined in the same module with the extension,
1331+
// we should consider them as the same module to preserve ABI stability.
1332+
extendDeclFromSameModule = decl->getAlternateModuleName() ==
1333+
getParentModule()->getNameStr();
1334+
} else {
1335+
extendDeclFromSameModule = decl->getParentModule() == getParentModule();
1336+
}
1337+
return extendDeclFromSameModule
13291338
&& !isConstrainedExtension()
13301339
&& !getDeclaredInterfaceType()->isExistentialType();
13311340
}

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ bool ArgsToFrontendOptionsConverter::convert(
8989
Opts.RemarkOnRebuildFromModuleInterface |=
9090
Args.hasArg(OPT_Rmodule_interface_rebuild);
9191

92-
Opts.DisableInterfaceFileLock |= Args.hasArg(OPT_disable_interface_lockfile);
93-
9492
computePrintStatsOptions();
9593
computeDebugTimeOptions();
9694
computeTBDOptions();
@@ -143,6 +141,15 @@ bool ArgsToFrontendOptionsConverter::convert(
143141
Opts.RequestedAction = determineRequestedAction(Args);
144142
}
145143

144+
if (Opts.RequestedAction == FrontendOptions::ActionType::CompileModuleFromInterface) {
145+
// The situations where we use this action, e.g. explicit module building and
146+
// generating prebuilt module cache, don't need synchronization. We should avoid
147+
// using lock files for them.
148+
Opts.DisableInterfaceFileLock = true;
149+
} else {
150+
Opts.DisableInterfaceFileLock |= Args.hasArg(OPT_disable_interface_lockfile);
151+
}
152+
146153
if (Opts.RequestedAction == FrontendOptions::ActionType::Immediate &&
147154
Opts.InputsAndOutputs.hasPrimaryInputs()) {
148155
Diags.diagnose(SourceLoc(), diag::error_immediate_mode_primary_file);

lib/Sema/ConstraintGraph.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,24 +442,15 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
442442
llvm::function_ref<bool(Constraint *)> acceptConstraintFn) {
443443
llvm::TinyPtrVector<Constraint *> constraints;
444444
// Whether we should consider this constraint at all.
445-
auto rep = CS.getRepresentative(typeVar);
446445
auto shouldConsiderConstraint = [&](Constraint *constraint) {
447-
// For a one-way constraint, only consider it when the type variable
448-
// is on the right-hand side of the the binding, and the left-hand side of
449-
// the binding is one of the type variables currently under consideration.
446+
// For a one-way constraint, only consider it when the left-hand side of
447+
// the binding is one of the type variables currently under consideration,
448+
// as only such constraints need solving for this component. Note that we
449+
// don't perform any other filtering, as the constraint system should be
450+
// responsible for checking any other conditions.
450451
if (constraint->isOneWayConstraint()) {
451-
auto lhsTypeVar =
452-
constraint->getFirstType()->castTo<TypeVariableType>();
453-
if (!CS.isActiveTypeVariable(lhsTypeVar))
454-
return false;
455-
456-
SmallVector<TypeVariableType *, 2> rhsTypeVars;
457-
constraint->getSecondType()->getTypeVariables(rhsTypeVars);
458-
for (auto rhsTypeVar : rhsTypeVars) {
459-
if (CS.getRepresentative(rhsTypeVar) == rep)
460-
return true;
461-
}
462-
return false;
452+
auto lhsTypeVar = constraint->getFirstType()->castTo<TypeVariableType>();
453+
return CS.isActiveTypeVariable(lhsTypeVar);
463454
}
464455

465456
return true;

stdlib/public/Darwin/CoreGraphics/CGFloat.swift.gyb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ public struct CGFloat {
6161
}
6262

6363
extension CGFloat : SignedNumeric {
64+
@_alwaysEmitIntoClient // availability
65+
public init<T: BinaryInteger>(_ source: T) {
66+
self.native = NativeType(source)
67+
}
6468

6569
@_transparent
66-
public init?<T : BinaryInteger>(exactly source: T) {
70+
public init?<T: BinaryInteger>(exactly source: T) {
6771
guard let native = NativeType(exactly: source) else { return nil }
6872
self.native = native
6973
}
@@ -72,7 +76,6 @@ extension CGFloat : SignedNumeric {
7276
public var magnitude: CGFloat {
7377
return CGFloat(native.magnitude)
7478
}
75-
7679
}
7780

7881
extension CGFloat : BinaryFloatingPoint {

stdlib/public/core/FloatingPoint.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,6 @@ extension BinaryFloatingPoint {
17421742
)
17431743
}
17441744

1745-
@inlinable
17461745
public // @testable
17471746
static func _convert<Source: BinaryFloatingPoint>(
17481747
from source: Source
@@ -1931,7 +1930,6 @@ extension BinaryFloatingPoint {
19311930

19321931
extension BinaryFloatingPoint where Self.RawSignificand: FixedWidthInteger {
19331932

1934-
@inlinable
19351933
public // @testable
19361934
static func _convert<Source: BinaryInteger>(
19371935
from source: Source

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ extension ${Self} {
10331033
_value = Builtin.sitofp_Int${word_bits}_FPIEEE${bits}(v._value)
10341034
}
10351035

1036-
// Fast-path for conversion when the source is representable as a 64-bit int,
1036+
// Fast-path for conversion when the source is representable as int,
10371037
// falling back on the generic _convert operation otherwise.
10381038
@inlinable // FIXME(inline-always)
10391039
@inline(__always)
@@ -1043,14 +1043,64 @@ extension ${Self} {
10431043
let asInt = Int(truncatingIfNeeded: value)
10441044
_value = Builtin.sitofp_Int${word_bits}_FPIEEE${bits}(asInt._value)
10451045
} else {
1046-
let asUInt = Int(truncatingIfNeeded: value)
1046+
let asUInt = UInt(truncatingIfNeeded: value)
10471047
_value = Builtin.uitofp_Int${word_bits}_FPIEEE${bits}(asUInt._value)
10481048
}
10491049
} else {
1050+
// TODO: we can do much better than the generic _convert here for Float
1051+
// and Double by pulling out the high-order 32/64b of the integer, ORing
1052+
// in a sticky bit, and then using the builtin.
10501053
self = ${Self}._convert(from: value).value
10511054
}
10521055
}
10531056

1057+
// Fast-path for conversion when the source is representable as int,
1058+
// falling back on the generic _convert operation otherwise.
1059+
@_alwaysEmitIntoClient @inline(never)
1060+
public init?<Source: BinaryInteger>(exactly value: Source) {
1061+
if value.bitWidth <= ${word_bits} {
1062+
// If the source is small enough to fit in a word, we can use the LLVM
1063+
// conversion intrinsic, then check if we can round-trip back to the
1064+
// the original value; if so, the conversion was exact. We need to be
1065+
// careful, however, to make sure that the first conversion does not
1066+
// round to a value that is out of the defined range of the second
1067+
// converion. E.g. Float(Int.max) rounds to Int.max + 1, and converting
1068+
// that back to Int will trap. For Float, Double, and Float80, this is
1069+
// only an issue for the upper bound (because the lower bound of [U]Int
1070+
// is either zero or a power of two, both of which are exactly
1071+
// representable). For Float16, we also need to check for overflow to
1072+
// -.infinity.
1073+
if Source.isSigned {
1074+
let extended = Int(truncatingIfNeeded: value)
1075+
_value = Builtin.sitofp_Int${word_bits}_FPIEEE${bits}(extended._value)
1076+
% if bits == 16:
1077+
guard self.isFinite && Int(self) == extended else {
1078+
% else:
1079+
guard self < 0x1.0p${word_bits-1} && Int(self) == extended else {
1080+
% end
1081+
return nil
1082+
}
1083+
} else {
1084+
let extended = UInt(truncatingIfNeeded: value)
1085+
_value = Builtin.uitofp_Int${word_bits}_FPIEEE${bits}(extended._value)
1086+
% if bits == 16:
1087+
guard self.isFinite && UInt(self) == extended else {
1088+
% else:
1089+
guard self < 0x1.0p${word_bits} && UInt(self) == extended else {
1090+
% end
1091+
return nil
1092+
}
1093+
}
1094+
} else {
1095+
// TODO: we can do much better than the generic _convert here for Float
1096+
// and Double by pulling out the high-order 32/64b of the integer, ORing
1097+
// in a sticky bit, and then using the builtin.
1098+
let (value_, exact) = Self._convert(from: value)
1099+
guard exact else { return nil }
1100+
self = value_
1101+
}
1102+
}
1103+
10541104
% for src_type in all_floating_point_types():
10551105
% srcBits = src_type.bits
10561106
% That = src_type.stdlib_name

test/Constraints/rdar64890308.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-typecheck-verify-swift -parse-stdlib
2+
3+
// rdar://64890308: Make sure we don't leave one-way constraints unsolved.
4+
5+
import Swift
6+
7+
@_functionBuilder
8+
class ArrayBuilder<Element> {
9+
static func buildBlock() -> [Element] { [] }
10+
static func buildBlock(_ elt: Element) -> [Element] { [elt] }
11+
static func buildBlock(_ elts: Element...) -> [Element] { elts }
12+
}
13+
14+
func foo<T>(@ArrayBuilder<T> fn: () -> [T]) {}
15+
foo {
16+
""
17+
}
18+
19+
struct S<T> {
20+
init(_: T.Type) {}
21+
func overloaded() -> [T] { [] }
22+
func overloaded(_ x: T) -> [T] { [x] }
23+
func overloaded(_ x: T...) -> [T] { x }
24+
}
25+
26+
func bar<T>(_ x: T, _ fn: (T, T.Type) -> [T]) {}
27+
bar("") { x, ty in
28+
(Builtin.one_way(S(ty).overloaded(x)))
29+
}

test/IRGen/osx-targets.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %swift %s -emit-ir | %FileCheck %s
22
// RUN: %swift -target x86_64-apple-macosx10.51 %s -emit-ir | %FileCheck -check-prefix=CHECK-SPECIFIC %s
3-
// RUN: %swift -target x86_64-apple-darwin55 %s -emit-ir | %FileCheck -check-prefix=CHECK-SPECIFIC %s
3+
4+
// disable this test until macOS 11 support lands in Swift.
5+
// : %swift -target x86_64-apple-darwin55 %s -emit-ir | %FileCheck -check-prefix=CHECK-SPECIFIC %s
46

57
// REQUIRES: OS=macosx
68

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
func foo() {}
2+
foo()
3+
4+
// RUN: %sourcekitd-test -req=open %s -- %s \
5+
// RUN: == -req=edit -offset=0 -replace="" -length=0 %s \
6+
// RUN: == -req=edit -offset=0 -replace="" -length=0 %s \
7+
// RUN: == -req=edit -pos=3:1 -replace="foo()" -length=0 %s \
8+
// RUN: == -req=edit -offset=0 -replace="" -length=0 %s \
9+
// RUN: == -req=edit -offset=0 -replace="" -length=0 %s > %t.response
10+
// RUN: %diff -u %s.response %t.response
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
key.annotations: [
3+
{
4+
key.kind: source.lang.swift.ref.function.free,
5+
key.offset: 14,
6+
key.length: 3
7+
}
8+
],
9+
key.diagnostic_stage: source.diagnostic.stage.swift.sema,
10+
key.syntaxmap: [
11+
],
12+
key.substructure: [
13+
]
14+
}
15+
{
16+
key.annotations: [
17+
{
18+
key.kind: source.lang.swift.ref.function.free,
19+
key.offset: 14,
20+
key.length: 3
21+
}
22+
],
23+
key.diagnostic_stage: source.diagnostic.stage.swift.sema,
24+
key.syntaxmap: [
25+
],
26+
key.substructure: [
27+
]
28+
}
29+
{
30+
key.annotations: [
31+
{
32+
key.kind: source.lang.swift.ref.function.free,
33+
key.offset: 14,
34+
key.length: 3
35+
},
36+
{
37+
key.kind: source.lang.swift.ref.function.free,
38+
key.offset: 20,
39+
key.length: 3
40+
}
41+
],
42+
key.diagnostic_stage: source.diagnostic.stage.swift.sema,
43+
key.syntaxmap: [
44+
],
45+
key.substructure: [
46+
]
47+
}
48+
{
49+
key.annotations: [
50+
{
51+
key.kind: source.lang.swift.ref.function.free,
52+
key.offset: 14,
53+
key.length: 3
54+
},
55+
{
56+
key.kind: source.lang.swift.ref.function.free,
57+
key.offset: 20,
58+
key.length: 3
59+
}
60+
],
61+
key.diagnostic_stage: source.diagnostic.stage.swift.sema,
62+
key.syntaxmap: [
63+
],
64+
key.substructure: [
65+
]
66+
}

0 commit comments

Comments
 (0)