Skip to content

Commit a0bcf6c

Browse files
Merge pull request #4693 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents 84e03bc + 6000578 commit a0bcf6c

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

lib/SILGen/SILGenBackDeploy.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,16 @@ static void emitBackDeployForwardApplyAndReturnOrThrow(
108108
rawResults.push_back(result);
109109

110110
auto token = rawResults.pop_back_val();
111-
SGF.B.createEndApply(loc, token);
112111
SGF.B.createYield(loc, rawResults, resumeBB, unwindBB);
113112

114113
// Emit resume block.
115114
SGF.B.emitBlock(resumeBB);
115+
SGF.B.createEndApply(loc, token);
116116
SGF.B.createBranch(loc, SGF.ReturnDest.getBlock());
117117

118118
// Emit unwind block.
119119
SGF.B.emitBlock(unwindBB);
120+
SGF.B.createEndApply(loc, token);
120121
SGF.B.createBranch(loc, SGF.CoroutineUnwindDest.getBlock());
121122
return;
122123
}

stdlib/public/core/Int128.swift.gyb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,24 @@ extension _${U}Int128: FixedWidthInteger {
350350
) -> (high: Self, low: Magnitude) {
351351
let isNegative = Self.isSigned && (self._isNegative != other._isNegative)
352352

353+
func sum(_ x: Low, _ y: Low) -> (high: Low, low: Low) {
354+
let (sum, overflow) = x.addingReportingOverflow(y)
355+
return (overflow ? 1 : 0, sum)
356+
}
357+
353358
func sum(_ x: Low, _ y: Low, _ z: Low) -> (high: Low, low: Low) {
354-
let (sum1, overflow1) = x.addingReportingOverflow(y)
355-
let (sum2, overflow2) = sum1.addingReportingOverflow(z)
356-
let carry: Low = (overflow1 ? 1 : 0) + (overflow2 ? 1 : 0)
357-
return (carry, sum2)
359+
let s1 = sum(x, y)
360+
let s2 = sum(s1.low, z)
361+
return (s1.high &+ s2.high, s2.low)
362+
}
363+
364+
func sum(
365+
_ x0: Low, _ x1: Low, _ x2: Low, _ x3: Low
366+
) -> (high: Low, low: Low) {
367+
let s1 = sum(x0, x1)
368+
let s2 = sum(x2, x3)
369+
let s = sum(s1.low, s2.low)
370+
return (s1.high &+ s2.high &+ s.high, s.low)
358371
}
359372

360373
let lhs = self.magnitude
@@ -366,12 +379,14 @@ extension _${U}Int128: FixedWidthInteger {
366379
let d = rhs.high.multipliedFullWidth(by: lhs.high)
367380

368381
let mid1 = sum(a.high, b.low, c.low)
369-
let mid2 = sum(b.high, c.high, d.low)
382+
let mid2 = sum(b.high, c.high, mid1.high, d.low)
370383

371-
let low = _UInt128(high: mid1.low, low: a.low)
372384
let high = _${U}Int128(
373-
high: High(mid2.high + d.high),
374-
low: mid1.high + mid2.low)
385+
high: High(d.high &+ mid2.high), // Note: this addition will never wrap
386+
low: mid2.low)
387+
let low = _UInt128(
388+
high: mid1.low,
389+
low: a.low)
375390

376391
if isNegative {
377392
let (lowComplement, overflow) = (~low).addingReportingOverflow(.one)

test/Concurrency/Runtime/clock.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,44 @@ var tests = TestSuite("Time")
102102
expectEqual(twoSeconds, .seconds(2))
103103
}
104104

105+
tests.test("Duration components/whole second increments") {
106+
for i in 0 ..< 1_000_000 {
107+
let d = Duration.seconds(i)
108+
let comps = d.components
109+
expectEqual(comps.seconds, Int64(i))
110+
expectEqual(comps.attoseconds, 0)
111+
}
112+
}
113+
114+
tests.test("Duration components/1ms increments") {
115+
for i in 0 ..< 1_000_000 {
116+
let d = Duration.milliseconds(i)
117+
let comps = d.components
118+
expectEqual(comps.seconds, Int64(i / 1000))
119+
expectEqual(comps.attoseconds, Int64(i % 1000) * 1_000_000_000_000_000)
120+
}
121+
}
122+
123+
tests.test("Duration components/100µs increments") {
124+
for i in 0 ..< 1_000_000 {
125+
let ms = 100 * i
126+
let d = Duration.microseconds(ms)
127+
let comps = d.components
128+
expectEqual(comps.seconds, Int64(ms / 1_000_000))
129+
expectEqual(comps.attoseconds, Int64(ms % 1_000_000) * 1_000_000_000_000)
130+
}
131+
}
132+
133+
tests.test("Duration components/200ns increments") {
134+
for i in 0 ..< 1_000_000 {
135+
let ns = 200 * i
136+
let d = Duration.nanoseconds(ns)
137+
let comps = d.components
138+
expectEqual(comps.seconds, Int64(ns / 1_000_000_000))
139+
expectEqual(comps.attoseconds, Int64(ns % 1_000_000_000) * 1_000_000_000)
140+
}
141+
}
142+
105143
await runAllTestsAsync()
106144
}
107145
}

test/SILGen/back_deploy_attribute_accessor_coroutine.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,27 @@ public struct TopLevelStruct {
3232
// CHECK: [[UNAVAIL_BB]]:
3333
// CHECK: [[FALLBACKFN:%.*]] = function_ref @$s11back_deploy14TopLevelStructV8propertyACvrTwB : $@yield_once @convention(method) (TopLevelStruct) -> @yields TopLevelStruct
3434
// CHECK: ([[YIELD_RES:%.*]], [[YIELD_TOK:%.*]]) = begin_apply [[FALLBACKFN]]([[BB0_ARG]]) : $@yield_once @convention(method) (TopLevelStruct) -> @yields TopLevelStruct
35-
// CHECK: end_apply [[YIELD_TOK]]
3635
// CHECK: yield [[YIELD_RES]] : $TopLevelStruct, resume [[UNAVAIL_RESUME_BB:bb[0-9]+]], unwind [[UNAVAIL_UNWIND_BB:bb[0-9]+]]
3736
//
3837
// CHECK: [[UNAVAIL_UNWIND_BB]]:
38+
// CHECK: end_apply [[YIELD_TOK]]
3939
// CHECK: br [[UNWIND_BB:bb[0-9]+]]
4040
//
4141
// CHECK: [[UNAVAIL_RESUME_BB]]:
42+
// CHECK: end_apply [[YIELD_TOK]]
4243
// CHECK: br [[RETURN_BB:bb[0-9]+]]
4344
//
4445
// CHECK: [[AVAIL_BB]]:
4546
// CHECK: [[ORIGFN:%.*]] = function_ref @$s11back_deploy14TopLevelStructV8propertyACvr : $@yield_once @convention(method) (TopLevelStruct) -> @yields TopLevelStruct
4647
// CHECK: ([[YIELD_RES:%.*]], [[YIELD_TOK:%.*]]) = begin_apply [[ORIGFN]]([[BB0_ARG]]) : $@yield_once @convention(method) (TopLevelStruct) -> @yields TopLevelStruct
47-
// CHECK: end_apply [[YIELD_TOK]]
4848
// CHECK: yield [[YIELD_RES]] : $TopLevelStruct, resume [[AVAIL_RESUME_BB:bb[0-9]+]], unwind [[UAVAIL_UNWIND_BB:bb[0-9]+]]
4949
//
5050
// CHECK: [[UAVAIL_UNWIND_BB]]:
51+
// CHECK: end_apply [[YIELD_TOK]]
5152
// CHECK: br [[UNWIND_BB]]
5253
//
5354
// CHECK: [[AVAIL_RESUME_BB]]:
55+
// CHECK: end_apply [[YIELD_TOK]]
5456
// CHECK: br [[RETURN_BB]]
5557
//
5658
// CHECK: [[RETURN_BB]]:

0 commit comments

Comments
 (0)