@@ -634,25 +634,32 @@ 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-
641637 Type elementType = Impl.importTypeIgnoreIUO (
642638 type->getElementType (), ImportTypeKind::Value, addImportDiagnostic,
643639 AllowNSUIntegerAsInt, Bridgeability::None, ImportTypeAttrs ());
644640 if (!elementType)
645641 return Type ();
646642
647643 auto size = type->getSize ().getZExtValue ();
644+
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+
648658 // An array of size N is imported as an N-element tuple which
649659 // takes very long to compile. We chose 4096 as the upper limit because
650660 // we don't want to break arrays of size PATH_MAX.
651661 if (size > 4096 )
652662 return Type ();
653-
654- if (size == 1 )
655- return elementType;
656663
657664 SmallVector<TupleTypeElt, 8 > elts{static_cast <size_t >(size), elementType};
658665 return TupleType::get (elts, elementType->getASTContext ());
0 commit comments