Skip to content

Commit f76d841

Browse files
committed
Rename to Slab
1 parent 515c64f commit f76d841

28 files changed

+201
-370
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3958,7 +3958,7 @@ class GenericTypeParamDecl final
39583958
/// type parameter.
39593959
///
39603960
/// \code
3961-
/// struct Vector<Element, let N: Int>
3961+
/// struct Slab<let count: Int, Element: ~Copyable>
39623962
/// \endcode
39633963
bool isValue() const {
39643964
return getParamKind() == GenericTypeParamKind::Value;

include/swift/AST/DiagnosticsSema.def

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

81788178
//===----------------------------------------------------------------------===//
8179-
// MARK: Vector
8179+
// MARK: Slab
81808180
//===----------------------------------------------------------------------===//
81818181

8182-
ERROR(vector_literal_incorrect_count,none,
8183-
"expected %0 elements in vector literal, but got %1", (Type, Type))
8182+
ERROR(slab_literal_incorrect_count,none,
8183+
"expected %0 elements in slab literal, but got %1", (Type, Type))
81848184

81858185
//===----------------------------------------------------------------------===//
81868186
// MARK: @abi Attribute

include/swift/AST/KnownStdlibTypes.def

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

9898
KNOWN_STDLIB_TYPE_DECL(Result, NominalTypeDecl, 2)
9999

100-
KNOWN_STDLIB_TYPE_DECL(Vector, NominalTypeDecl, 2)
100+
KNOWN_STDLIB_TYPE_DECL(Slab, NominalTypeDecl, 2)
101101

102102
#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 Vector<Element, let N: Int>
7249+
/// struct Slab<let count: Int, Element: ~Copyable>
72507250
/// \endcode
72517251
bool isValue() const {
72527252
return ParamKind == GenericTypeParamKind::Value;

include/swift/Basic/Features.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
225225
UPCOMING_FEATURE(ExistentialAny, 335, 7)
226226
UPCOMING_FEATURE(InternalImportsByDefault, 409, 7)
227227
UPCOMING_FEATURE(MemberImportVisibility, 444, 7)
228-
UPCOMING_FEATURE(ImportCArraysAsVectors, 453, 7)
229228

230229
EXPERIMENTAL_FEATURE(StaticAssert, false)
231230
EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)

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 'Vector' literal has mismatched number of elements to the
487+
/// Ignore when a 'Slab' literal has mismatched number of elements to the
488488
/// type it's attempting to bind to.
489-
AllowVectorLiteralCountMismatch,
489+
AllowSlabLiteralCountMismatch,
490490
};
491491

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

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

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

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

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

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

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

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ UNINTERESTING_FEATURE(ExistentialAny)
6969
UNINTERESTING_FEATURE(InferSendableFromCaptures)
7070
UNINTERESTING_FEATURE(ImplicitOpenExistentials)
7171
UNINTERESTING_FEATURE(MemberImportVisibility)
72-
UNINTERESTING_FEATURE(ImportCArraysAsVectors) // fixme?
7372

7473
// ----------------------------------------------------------------------------
7574
// MARK: - Experimental Features

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 (isVector())
814+
if (isSlab())
815815
return boundStruct->getGenericArgs()[1];
816816
}
817817
return Type();

lib/ClangImporter/ImportType.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ namespace {
634634
}
635635

636636
ImportResult VisitConstantArrayType(const clang::ConstantArrayType *type) {
637+
// FIXME: Map to a real fixed-size Swift array type when we have those.
638+
// Importing as a tuple at least fills the right amount of space, and
639+
// we can cheese static-offset "indexing" using .$n operations.
640+
637641
Type elementType = Impl.importTypeIgnoreIUO(
638642
type->getElementType(), ImportTypeKind::Value, addImportDiagnostic,
639643
AllowNSUIntegerAsInt, Bridgeability::None, ImportTypeAttrs());
@@ -642,25 +646,15 @@ namespace {
642646

643647
auto size = type->getSize().getZExtValue();
644648

645-
if (size == 1)
646-
return elementType;
647-
648-
auto &ctx = elementType->getASTContext();
649-
650-
if (ctx.LangOpts.hasFeature(Feature::ImportCArraysAsVectors)) {
651-
auto vector = cast<StructDecl>(ctx.getVectorDecl());
652-
auto countType = IntegerType::get(std::to_string(size),
653-
/* isNegative */ false, ctx);
654-
return BoundGenericStructType::get(vector, /* parent */ nullptr,
655-
{countType, elementType});
656-
}
657-
658649
// An array of size N is imported as an N-element tuple which
659650
// takes very long to compile. We chose 4096 as the upper limit because
660651
// we don't want to break arrays of size PATH_MAX.
661652
if (size > 4096)
662653
return Type();
663654

655+
if (size == 1)
656+
return elementType;
657+
664658
SmallVector<TupleTypeElt, 8> elts{static_cast<size_t>(size), elementType};
665659
return TupleType::get(elts, elementType->getASTContext());
666660
}

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. 'Vector<3, Int>'.
719+
// Note: This can be a value type, e.g. 'Slab<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
@@ -4598,17 +4598,17 @@ visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *E, SGFContext C) {
45984598
llvm_unreachable("Unhandled MagicIdentifierLiteralExpr in switch.");
45994599
}
46004600

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

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

4611-
SILValue alloc = SGF.emitTemporaryAllocation(E, loweredVectorType);
4611+
SILValue alloc = SGF.emitTemporaryAllocation(E, loweredSlabType);
46124612
SILValue addr = SGF.B.createUncheckedAddrCast(E, alloc,
46134613
loweredElementType.getAddressType());
46144614

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

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

4648-
SILValue vectorVal;
4648+
SILValue slabVal;
46494649

4650-
// If the vector is naturally address-only, then we can adopt the stack slot
4650+
// If the slab is naturally address-only, then we can adopt the stack slot
46514651
// as the value directly.
4652-
if (loweredVectorType.isAddressOnly(SGF.F)) {
4653-
vectorVal = SGF.B.createUncheckedAddrCast(E, alloc, loweredVectorType);
4652+
if (loweredSlabType.isAddressOnly(SGF.F)) {
4653+
slabVal = SGF.B.createUncheckedAddrCast(E, alloc, loweredSlabType);
46544654
} else {
4655-
// Otherwise, this vector is loadable. Load it.
4656-
vectorVal = SGF.B.createTrivialLoadOr(E, alloc, LoadOwnershipQualifier::Take);
4655+
// Otherwise, this slab is loadable. Load it.
4656+
slabVal = SGF.B.createTrivialLoadOr(E, alloc, LoadOwnershipQualifier::Take);
46574657
}
46584658

4659-
auto vectorMV = SGF.emitManagedRValueWithCleanup(vectorVal);
4660-
auto vector = RValue(SGF, E, vectorMV);
4659+
auto slabMV = SGF.emitManagedRValueWithCleanup(slabVal);
4660+
auto slab = RValue(SGF, E, slabMV);
46614661

4662-
return scope.popPreservingValue(std::move(vector));
4662+
return scope.popPreservingValue(std::move(slab));
46634663
}
46644664

46654665
RValue RValueEmitter::visitCollectionExpr(CollectionExpr *E, SGFContext C) {
4666-
// Handle 'Vector' literals separately.
4667-
if (E->getType()->isVector()) {
4668-
return emitVectorLiteral(SGF, E, C);
4666+
// Handle 'Slab' literals separately.
4667+
if (E->getType()->isSlab()) {
4668+
return emitSlabLiteral(SGF, E, C);
46694669
}
46704670

46714671
auto loc = SILLocation(E);

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,8 +3794,8 @@ namespace {
37943794
Type arrayTy = cs.getType(expr);
37953795
Type elementType;
37963796

3797-
if (arrayTy->isVector()) {
3798-
// <let Count: Int, Element>
3797+
if (arrayTy->isSlab()) {
3798+
// <let count: Int, Element>
37993799
elementType = arrayTy->castTo<BoundGenericStructType>()->getGenericArgs()[1];
38003800
} else {
38013801
ProtocolDecl *arrayProto = TypeChecker::getProtocol(

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 IncorrectVectorLiteralCount::diagnoseAsError() {
9576-
emitDiagnostic(diag::vector_literal_incorrect_count, lhsCount, rhsCount);
9575+
bool IncorrectSlabLiteralCount::diagnoseAsError() {
9576+
emitDiagnostic(diag::slab_literal_incorrect_count, lhsCount, rhsCount);
95779577
return true;
95789578
}

lib/Sema/CSDiagnostics.h

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

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

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

lib/Sema/CSFix.cpp

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

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

2734-
bool AllowVectorLiteralCountMismatch::diagnose(const Solution &solution,
2735-
bool asNote) const {
2736-
IncorrectVectorLiteralCount failure(solution, lhsCount, rhsCount, getLocator());
2734+
bool AllowSlabLiteralCountMismatch::diagnose(const Solution &solution,
2735+
bool asNote) const {
2736+
IncorrectSlabLiteralCount failure(solution, lhsCount, rhsCount, getLocator());
27372737
return failure.diagnose(asNote);
27382738
}

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8704,30 +8704,30 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
87048704
auto anchor = loc->getAnchor();
87058705
auto arrayLiteral = getAsExpr<ArrayExpr>(anchor);
87068706

8707-
// If we're attempting to bind an array literal to a 'Vector' parameter,
8707+
// If we're attempting to bind an array literal to a 'Slab' parameter,
87088708
// then check if the counts are equal and solve.
87098709
if (kind == ConstraintKind::LiteralConformsTo &&
87108710
protocol == arrayLiteralProto &&
8711-
type->isVector() &&
8711+
type->isSlab() &&
87128712
arrayLiteral) {
8713-
auto vectorTy = type->castTo<BoundGenericStructType>();
8713+
auto slabTy = type->castTo<BoundGenericStructType>();
87148714

8715-
// <let Count: Int, Element>
8715+
// <let count: Int, Element>
87168716
// Attempt to bind the number of elements in the literal with the
87178717
// contextual count. This will diagnose if the literal does not enough
87188718
// or too many elements.
8719-
auto contextualCount = vectorTy->getGenericArgs()[0];
8719+
auto contextualCount = slabTy->getGenericArgs()[0];
87208720
auto literalCount = IntegerType::get(
87218721
std::to_string(arrayLiteral->getNumElements()),
87228722
/* isNegative */ false,
8723-
vectorTy->getASTContext());
8723+
slabTy->getASTContext());
87248724

87258725
// If the counts are already equal, '2' == '2', then we're done.
87268726
if (contextualCount->isEqual(literalCount)) {
87278727
return SolutionKind::Solved;
87288728
}
87298729

8730-
// If our contextual count is not known, e.g., Vector<_, Int> = [1, 2],
8730+
// If our contextual count is not known, e.g., Slab<_, Int> = [1, 2],
87318731
// then just eagerly bind the count to what the literal count is.
87328732
if (contextualCount->isTypeVariableOrMember()) {
87338733
addConstraint(ConstraintKind::Bind, contextualCount, literalCount,
@@ -8739,8 +8739,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
87398739
if (!shouldAttemptFixes())
87408740
return SolutionKind::Error;
87418741

8742-
auto fix = AllowVectorLiteralCountMismatch::create(*this, contextualCount,
8743-
literalCount, loc);
8742+
auto fix = AllowSlabLiteralCountMismatch::create(*this, contextualCount,
8743+
literalCount, loc);
87448744
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
87458745
}
87468746
} break;
@@ -15654,7 +15654,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1565415654
case FixKind::IgnoreInvalidPlaceholder:
1565515655
case FixKind::IgnoreOutOfPlaceThenStmt:
1565615656
case FixKind::IgnoreMissingEachKeyword:
15657-
case FixKind::AllowVectorLiteralCountMismatch:
15657+
case FixKind::AllowSlabLiteralCountMismatch:
1565815658
llvm_unreachable("handled elsewhere");
1565915659
}
1566015660

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,10 +1666,10 @@ struct TypeSimplifier {
16661666
auto *proto = assocType->getProtocol();
16671667
auto conformance = CS.lookupConformance(lookupBaseType, proto);
16681668
if (!conformance) {
1669-
// Special case: When building vector literals, we go through the same
1669+
// 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->isVector()) {
1672+
if (lookupBaseType->isSlab()) {
16731673
auto &ctx = CS.getASTContext();
16741674
auto arrayProto =
16751675
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral);

0 commit comments

Comments
 (0)