Skip to content

Commit 41e6cbe

Browse files
authored
[NFC] Make the StoredIntegerElement<N> storage properties explicit:
specify the accepted field sizes in ctor. This is a follow-up refactoring after discussion in #61726
1 parent ed93529 commit 41e6cbe

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ class StoredIntegerElement: public LocatorPathElt {
521521

522522
template <unsigned Index = 0,
523523
typename = typename std::enable_if<(Index < NumValues)>::type>
524-
static uint64_t packValue(unsigned value) {
525-
return uint64_t(value) << (valueWidth() * (NumValues - Index - 1));
524+
static uint64_t packValue(uint64_t value) {
525+
return value << (valueWidth() * (NumValues - Index - 1));
526526
}
527527

528528
static constexpr uint64_t valueMask =
@@ -531,28 +531,20 @@ class StoredIntegerElement: public LocatorPathElt {
531531
public:
532532
template <unsigned NumNumericInputs = NumValues,
533533
typename = typename std::enable_if<NumNumericInputs == 1>::type>
534-
StoredIntegerElement(ConstraintLocator::PathElementKind kind, unsigned value)
535-
: LocatorPathElt(kind, value) {
536-
assert(value == getValue<0>() && "value truncated");
537-
}
534+
StoredIntegerElement(ConstraintLocator::PathElementKind kind, uint64_t value)
535+
: LocatorPathElt(kind, value) { }
538536

539537
template <unsigned NumNumericInputs = NumValues,
540538
typename = typename std::enable_if<NumNumericInputs == 2>::type>
541-
StoredIntegerElement(ConstraintLocator::PathElementKind kind, unsigned value0, unsigned value1)
542-
: LocatorPathElt(kind, packValue<0>(value0) | packValue<1>(value1)) {
543-
assert(value0 == getValue<0>() && "value0 truncated");
544-
assert(value1 == getValue<1>() && "value1 truncated");
545-
}
539+
StoredIntegerElement(ConstraintLocator::PathElementKind kind, uint32_t value0, uint32_t value1)
540+
: LocatorPathElt(kind, packValue<0>(value0) | packValue<1>(value1)) { }
546541

547542
template <unsigned NumNumericInputs = NumValues,
548543
typename = typename std::enable_if<NumNumericInputs == 3>::type>
549-
StoredIntegerElement(ConstraintLocator::PathElementKind kind, unsigned value0,
550-
unsigned value1, unsigned value2)
551-
: LocatorPathElt(kind, packValue<0>(value0) | packValue<1>(value1) | packValue<2>(value2)) {
552-
assert(value0 == getValue<0>() && "value0 truncated");
553-
assert(value1 == getValue<1>() && "value1 truncated");
554-
assert(value2 == getValue<2>() && "value2 truncated");
555-
}
544+
StoredIntegerElement(ConstraintLocator::PathElementKind kind,
545+
uint16_t value0, uint16_t value1, uint16_t value2)
546+
: LocatorPathElt(kind,
547+
packValue<0>(value0) | packValue<1>(value1) | packValue<2>(value2)) { }
556548

557549
/// Retrieve a value associated with the path element.
558550
template <unsigned Index = 0,
@@ -588,7 +580,7 @@ class StoredPointerElement: public LocatorPathElt {
588580

589581
class LocatorPathElt::ApplyArgToParam final : public StoredIntegerElement<3> {
590582
public:
591-
ApplyArgToParam(unsigned argIdx, unsigned paramIdx, ParameterTypeFlags flags)
583+
ApplyArgToParam(uint16_t argIdx, uint16_t paramIdx, ParameterTypeFlags flags)
592584
: StoredIntegerElement(ConstraintLocator::ApplyArgToParam, argIdx, paramIdx, flags.toRaw()) {}
593585

594586
unsigned getArgIdx() const { return getValue<0>(); }

test/Sema/large_int_array.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %gyb %s -o %t/large_int_array.swift
33
// RUN: %target-swift-frontend -typecheck -verify %t/large_int_array.swift
4+
// RUN: %target-swift-frontend %t/large_int_array.swift -emit-sil -o %t
45

56
% num_elements = 65537
67

0 commit comments

Comments
 (0)