Skip to content

Commit c7af9a7

Browse files
authored
Merge pull request #79294 from Azoy/bye-bye-slab
[stdlib] Rename Slab to InlineArray
2 parents dff88f9 + c673a07 commit c7af9a7

25 files changed

+143
-137
lines changed

Runtimes/Core/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ add_library(swiftCore
8686
HashTable.swift
8787
Identifiable.swift
8888
Indices.swift
89+
InlineArray.swift
8990
InputStream.swift
9091
IntegerParsing.swift
9192
Integers.swift
@@ -145,7 +146,6 @@ add_library(swiftCore
145146
SetVariant.swift
146147
ShadowProtocols.swift
147148
Shims.swift
148-
Slab.swift
149149
Slice.swift
150150
SmallString.swift
151151
Sort.swift

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3994,7 +3994,7 @@ class GenericTypeParamDecl final
39943994
/// type parameter.
39953995
///
39963996
/// \code
3997-
/// struct Slab<let count: Int, Element: ~Copyable>
3997+
/// struct InlineArray<let count: Int, Element: ~Copyable>
39983998
/// \endcode
39993999
bool isValue() const {
40004000
return getParamKind() == GenericTypeParamKind::Value;

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8212,11 +8212,11 @@ ERROR(invalid_value_for_type_same_type,none,
82128212
"cannot constrain type parameter %0 to be integer %1", (Type, Type))
82138213

82148214
//===----------------------------------------------------------------------===//
8215-
// MARK: Slab
8215+
// MARK: InlineArray
82168216
//===----------------------------------------------------------------------===//
82178217

8218-
ERROR(slab_literal_incorrect_count,none,
8219-
"expected %0 elements in slab literal, but got %1", (Type, Type))
8218+
ERROR(inlinearray_literal_incorrect_count,none,
8219+
"expected %0 elements in inline array literal, but got %1", (Type, Type))
82208220

82218221
//===----------------------------------------------------------------------===//
82228222
// MARK: @abi Attribute

include/swift/AST/KnownStdlibTypes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ KNOWN_STDLIB_TYPE_DECL(DecodingError, NominalTypeDecl, 0)
9999

100100
KNOWN_STDLIB_TYPE_DECL(Result, NominalTypeDecl, 2)
101101

102-
KNOWN_STDLIB_TYPE_DECL(Slab, NominalTypeDecl, 2)
102+
KNOWN_STDLIB_TYPE_DECL(InlineArray, NominalTypeDecl, 2)
103103

104104
#undef KNOWN_STDLIB_TYPE_DECL

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7246,7 +7246,7 @@ class GenericTypeParamType : public SubstitutableType,
72467246
/// Returns \c true if this type parameter is declared as a value.
72477247
///
72487248
/// \code
7249-
/// struct Slab<let count: Int, Element: ~Copyable>
7249+
/// struct InlineArray<let count: Int, Element: ~Copyable>
72507250
/// \endcode
72517251
bool isValue() const {
72527252
return ParamKind == GenericTypeParamKind::Value;

include/swift/Sema/CSFix.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ enum class FixKind : uint8_t {
484484
/// result.
485485
AllowSendingMismatch,
486486

487-
/// Ignore when a 'Slab' literal has mismatched number of elements to the
488-
/// type it's attempting to bind to.
489-
AllowSlabLiteralCountMismatch,
487+
/// Ignore when an 'InlineArray' literal has mismatched number of elements to
488+
/// the type it's attempting to bind to.
489+
AllowInlineArrayLiteralCountMismatch,
490490
};
491491

492492
class ConstraintFix {
@@ -3841,12 +3841,12 @@ class IgnoreKeyPathSubscriptIndexMismatch final : public ConstraintFix {
38413841
}
38423842
};
38433843

3844-
class AllowSlabLiteralCountMismatch final : public ConstraintFix {
3844+
class AllowInlineArrayLiteralCountMismatch final : public ConstraintFix {
38453845
Type lhsCount, rhsCount;
38463846

3847-
AllowSlabLiteralCountMismatch(ConstraintSystem &cs, Type lhsCount,
3847+
AllowInlineArrayLiteralCountMismatch(ConstraintSystem &cs, Type lhsCount,
38483848
Type rhsCount, ConstraintLocator *locator)
3849-
: ConstraintFix(cs, FixKind::AllowSlabLiteralCountMismatch, locator),
3849+
: ConstraintFix(cs, FixKind::AllowInlineArrayLiteralCountMismatch, locator),
38503850
lhsCount(lhsCount), rhsCount(rhsCount) {}
38513851

38523852
public:
@@ -3856,12 +3856,12 @@ class AllowSlabLiteralCountMismatch final : public ConstraintFix {
38563856

38573857
bool diagnose(const Solution &solution, bool asNote = false) const override;
38583858

3859-
static AllowSlabLiteralCountMismatch *
3859+
static AllowInlineArrayLiteralCountMismatch *
38603860
create(ConstraintSystem &cs, Type lhsCount, Type rhsCount,
38613861
ConstraintLocator *locator);
38623862

38633863
static bool classof(const ConstraintFix *fix) {
3864-
return fix->getKind() == FixKind::AllowSlabLiteralCountMismatch;
3864+
return fix->getKind() == FixKind::AllowInlineArrayLiteralCountMismatch;
38653865
}
38663866
};
38673867

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ Type TypeBase::isArrayType() {
811811
if (isArray())
812812
return boundStruct->getGenericArgs()[0];
813813

814-
if (isSlab())
814+
if (isInlineArray())
815815
return boundStruct->getGenericArgs()[1];
816816
}
817817
return Type();

lib/Parse/ParseType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ ParserStatus Parser::parseGenericArguments(SmallVectorImpl<TypeRepr *> &Args,
716716
// variadic generic types.
717717
if (!startsWithGreater(Tok)) {
718718
while (true) {
719-
// Note: This can be a value type, e.g. 'Slab<3, Int>'.
719+
// Note: This can be a value type, e.g. 'InlineArray<3, Int>'.
720720
ParserResult<TypeRepr> Ty = parseTypeOrValue(diag::expected_type);
721721
if (Ty.isNull() || Ty.hasCodeCompletion()) {
722722
// Skip until we hit the '>'.

lib/SILGen/SILGenExpr.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,17 +4599,17 @@ visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
45994599
llvm_unreachable("Unhandled MagicIdentifierLiteralExpr in switch.");
46004600
}
46014601

4602-
static RValue emitSlabLiteral(SILGenFunction &SGF, CollectionExpr *E,
4602+
static RValue emitInlineArrayLiteral(SILGenFunction &SGF, CollectionExpr *E,
46034603
SGFContext C) {
46044604
ArgumentScope scope(SGF, E);
46054605

4606-
auto slabType = E->getType()->castTo<BoundGenericType>();
4607-
auto loweredSlabType = SGF.getLoweredType(slabType);
4608-
auto elementType = slabType->getGenericArgs()[1]->getCanonicalType();
4606+
auto iaTy = E->getType()->castTo<BoundGenericType>();
4607+
auto loweredIAType = SGF.getLoweredType(iaTy);
4608+
auto elementType = iaTy->getGenericArgs()[1]->getCanonicalType();
46094609
auto loweredElementType = SGF.getLoweredType(elementType);
46104610
auto &eltTL = SGF.getTypeLowering(AbstractionPattern::getOpaque(), elementType);
46114611

4612-
SILValue alloc = SGF.emitTemporaryAllocation(E, loweredSlabType);
4612+
SILValue alloc = SGF.emitTemporaryAllocation(E, loweredIAType);
46134613
SILValue addr = SGF.B.createUncheckedAddrCast(E, alloc,
46144614
loweredElementType.getAddressType());
46154615

@@ -4642,31 +4642,31 @@ static RValue emitSlabLiteral(SILGenFunction &SGF, CollectionExpr *E,
46424642
.forwardInto(SGF, AbstractionPattern::getOpaque(), &init, eltTL);
46434643
}
46444644

4645-
// Kill the per-element cleanups. The slab will take ownership of them.
4645+
// Kill the per-element cleanups. The inline array will take ownership of them.
46464646
for (auto destCleanup : cleanups)
46474647
SGF.Cleanups.setCleanupState(destCleanup, CleanupState::Dead);
46484648

4649-
SILValue slabVal;
4649+
SILValue iaVal;
46504650

4651-
// If the slab is naturally address-only, then we can adopt the stack slot
4652-
// as the value directly.
4653-
if (loweredSlabType.isAddressOnly(SGF.F)) {
4654-
slabVal = SGF.B.createUncheckedAddrCast(E, alloc, loweredSlabType);
4651+
// If the inline array is naturally address-only, then we can adopt the stack
4652+
// slot as the value directly.
4653+
if (loweredIAType.isAddressOnly(SGF.F)) {
4654+
iaVal = SGF.B.createUncheckedAddrCast(E, alloc, loweredIAType);
46554655
} else {
4656-
// Otherwise, this slab is loadable. Load it.
4657-
slabVal = SGF.B.createTrivialLoadOr(E, alloc, LoadOwnershipQualifier::Take);
4656+
// Otherwise, this inline array is loadable. Load it.
4657+
iaVal = SGF.B.createTrivialLoadOr(E, alloc, LoadOwnershipQualifier::Take);
46584658
}
46594659

4660-
auto slabMV = SGF.emitManagedRValueWithCleanup(slabVal);
4661-
auto slab = RValue(SGF, E, slabMV);
4660+
auto iaMV = SGF.emitManagedRValueWithCleanup(iaVal);
4661+
auto ia = RValue(SGF, E, iaMV);
46624662

4663-
return scope.popPreservingValue(std::move(slab));
4663+
return scope.popPreservingValue(std::move(ia));
46644664
}
46654665

46664666
RValue RValueEmitter::visitCollectionExpr(CollectionExpr *E, SGFContext C) {
4667-
// Handle 'Slab' literals separately.
4668-
if (E->getType()->isSlab()) {
4669-
return emitSlabLiteral(SGF, E, C);
4667+
// Handle 'InlineArray' literals separately.
4668+
if (E->getType()->isInlineArray()) {
4669+
return emitInlineArrayLiteral(SGF, E, C);
46704670
}
46714671

46724672
auto loc = SILLocation(E);

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3804,7 +3804,7 @@ namespace {
38043804
Type arrayTy = cs.getType(expr);
38053805
Type elementType;
38063806

3807-
if (arrayTy->isSlab()) {
3807+
if (arrayTy->isInlineArray()) {
38083808
// <let count: Int, Element>
38093809
elementType = arrayTy->castTo<BoundGenericStructType>()->getGenericArgs()[1];
38103810
} else {

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9572,7 +9572,7 @@ bool InvalidTypeAsKeyPathSubscriptIndex::diagnoseAsError() {
95729572
return true;
95739573
}
95749574

9575-
bool IncorrectSlabLiteralCount::diagnoseAsError() {
9576-
emitDiagnostic(diag::slab_literal_incorrect_count, lhsCount, rhsCount);
9575+
bool IncorrectInlineArrayLiteralCount::diagnoseAsError() {
9576+
emitDiagnostic(diag::inlinearray_literal_incorrect_count, lhsCount, rhsCount);
95779577
return true;
95789578
}

lib/Sema/CSDiagnostics.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,17 +3234,17 @@ class InvalidTypeAsKeyPathSubscriptIndex final : public FailureDiagnostic {
32343234
bool diagnoseAsError() override;
32353235
};
32363236

3237-
/// Diagnose when a slab literal has an incorrect number of elements for the
3238-
/// contextual slab type it's initializing.
3237+
/// Diagnose when an inline array literal has an incorrect number of elements
3238+
/// for the contextual inline array type it's initializing.
32393239
///
32403240
/// \code
3241-
/// let x: Slab<4, Int> = [1, 2] // expected '4' elements but got '2'
3241+
/// let x: InlineArray<4, Int> = [1, 2] // expected '4' elements but got '2'
32423242
/// \endcode
3243-
class IncorrectSlabLiteralCount final : public FailureDiagnostic {
3243+
class IncorrectInlineArrayLiteralCount final : public FailureDiagnostic {
32443244
Type lhsCount, rhsCount;
32453245

32463246
public:
3247-
IncorrectSlabLiteralCount(const Solution &solution, Type lhsCount,
3247+
IncorrectInlineArrayLiteralCount(const Solution &solution, Type lhsCount,
32483248
Type rhsCount, ConstraintLocator *locator)
32493249
: FailureDiagnostic(solution, locator), lhsCount(resolveType(lhsCount)),
32503250
rhsCount(resolveType(rhsCount)) {}

lib/Sema/CSFix.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,16 +2723,17 @@ IgnoreKeyPathSubscriptIndexMismatch::create(ConstraintSystem &cs, Type argType,
27232723
IgnoreKeyPathSubscriptIndexMismatch(cs, argType, locator);
27242724
}
27252725

2726-
AllowSlabLiteralCountMismatch *
2727-
AllowSlabLiteralCountMismatch::create(ConstraintSystem &cs, Type lhsCount,
2728-
Type rhsCount,
2729-
ConstraintLocator *locator) {
2726+
AllowInlineArrayLiteralCountMismatch *
2727+
AllowInlineArrayLiteralCountMismatch::create(ConstraintSystem &cs, Type lhsCount,
2728+
Type rhsCount,
2729+
ConstraintLocator *locator) {
27302730
return new (cs.getAllocator())
2731-
AllowSlabLiteralCountMismatch(cs, lhsCount, rhsCount, locator);
2731+
AllowInlineArrayLiteralCountMismatch(cs, lhsCount, rhsCount, locator);
27322732
}
27332733

2734-
bool AllowSlabLiteralCountMismatch::diagnose(const Solution &solution,
2735-
bool asNote) const {
2736-
IncorrectSlabLiteralCount failure(solution, lhsCount, rhsCount, getLocator());
2734+
bool AllowInlineArrayLiteralCountMismatch::diagnose(const Solution &solution,
2735+
bool asNote) const {
2736+
IncorrectInlineArrayLiteralCount failure(solution, lhsCount, rhsCount,
2737+
getLocator());
27372738
return failure.diagnose(asNote);
27382739
}

lib/Sema/CSSimplify.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8709,30 +8709,30 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
87098709
auto anchor = loc->getAnchor();
87108710
auto arrayLiteral = getAsExpr<ArrayExpr>(anchor);
87118711

8712-
// If we're attempting to bind an array literal to a 'Slab' parameter,
8713-
// then check if the counts are equal and solve.
8712+
// If we're attempting to bind an array literal to an 'InlineArray'
8713+
// parameter, then check if the counts are equal and solve.
87148714
if (kind == ConstraintKind::LiteralConformsTo &&
87158715
protocol == arrayLiteralProto &&
8716-
type->isSlab() &&
8716+
type->isInlineArray() &&
87178717
arrayLiteral) {
8718-
auto slabTy = type->castTo<BoundGenericStructType>();
8718+
auto iaTy = type->castTo<BoundGenericStructType>();
87198719

87208720
// <let count: Int, Element>
87218721
// Attempt to bind the number of elements in the literal with the
87228722
// contextual count. This will diagnose if the literal does not enough
87238723
// or too many elements.
8724-
auto contextualCount = slabTy->getGenericArgs()[0];
8724+
auto contextualCount = iaTy->getGenericArgs()[0];
87258725
auto literalCount = IntegerType::get(
87268726
std::to_string(arrayLiteral->getNumElements()),
87278727
/* isNegative */ false,
8728-
slabTy->getASTContext());
8728+
iaTy->getASTContext());
87298729

87308730
// If the counts are already equal, '2' == '2', then we're done.
87318731
if (contextualCount->isEqual(literalCount)) {
87328732
return SolutionKind::Solved;
87338733
}
87348734

8735-
// If our contextual count is not known, e.g., Slab<_, Int> = [1, 2],
8735+
// If our contextual count is not known, e.g., InlineArray<_, Int> = [1, 2],
87368736
// then just eagerly bind the count to what the literal count is.
87378737
if (contextualCount->isTypeVariableOrMember()) {
87388738
addConstraint(ConstraintKind::Bind, contextualCount, literalCount,
@@ -8744,8 +8744,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
87448744
if (!shouldAttemptFixes())
87458745
return SolutionKind::Error;
87468746

8747-
auto fix = AllowSlabLiteralCountMismatch::create(*this, contextualCount,
8748-
literalCount, loc);
8747+
auto fix = AllowInlineArrayLiteralCountMismatch::create(*this,
8748+
contextualCount,
8749+
literalCount, loc);
87498750
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
87508751
}
87518752
} break;
@@ -15640,7 +15641,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1564015641
case FixKind::IgnoreInvalidPlaceholder:
1564115642
case FixKind::IgnoreOutOfPlaceThenStmt:
1564215643
case FixKind::IgnoreMissingEachKeyword:
15643-
case FixKind::AllowSlabLiteralCountMismatch:
15644+
case FixKind::AllowInlineArrayLiteralCountMismatch:
1564415645
llvm_unreachable("handled elsewhere");
1564515646
}
1564615647

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ struct TypeSimplifier {
16691669
// Special case: When building slab literals, we go through the same
16701670
// array literal machinery, so there will be a conversion constraint
16711671
// for the element to ExpressibleByArrayLiteral.ArrayLiteralType.
1672-
if (lookupBaseType->isSlab()) {
1672+
if (lookupBaseType->isInlineArray()) {
16731673
auto &ctx = CS.getASTContext();
16741674
auto arrayProto =
16751675
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral);

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ split_embedded_sources(
9292
EMBEDDED HashTable.swift
9393
EMBEDDED Identifiable.swift
9494
EMBEDDED Indices.swift
95+
EMBEDDED InlineArray.swift
9596
EMBEDDED InputStream.swift
9697
EMBEDDED IntegerParsing.swift
9798
EMBEDDED Integers.swift
@@ -151,7 +152,6 @@ split_embedded_sources(
151152
EMBEDDED SetVariant.swift
152153
EMBEDDED ShadowProtocols.swift
153154
NORMAL Shims.swift
154-
EMBEDDED Slab.swift
155155
EMBEDDED Slice.swift
156156
EMBEDDED SmallString.swift
157157
EMBEDDED Sort.swift

stdlib/public/core/GroupInfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
"EmbeddedRuntime.swift",
258258
"EmbeddedStubs.swift",
259259
"EmbeddedPrint.swift",
260-
"Slab.swift"
260+
"InlineArray.swift"
261261
],
262262
"Result": [
263263
"Result.swift"

0 commit comments

Comments
 (0)