Skip to content

Commit 290e083

Browse files
Merge pull request #4890 from swiftwasm/main
[pull] swiftwasm from main
2 parents e74f0c3 + 435af14 commit 290e083

34 files changed

+3051
-959
lines changed

include/swift/AST/Attr.def

Lines changed: 0 additions & 794 deletions
This file was deleted.

include/swift/AST/Attr.def.gyb

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
%{
2+
# -*- mode: C++ -*-
3+
from gyb_syntax_support import *
4+
from gyb_syntax_support.AttributeKinds import *
5+
# Ignore the following admonition; it applies to the resulting .def file only
6+
}%
7+
//// Automatically Generated From Attr.def.gyb.
8+
//// Do Not Edit Directly!
9+
//===--- Attr.def - Swift Attributes Metaprogramming ------------*- C++ -*-===//
10+
//
11+
// This source file is part of the Swift.org open source project
12+
//
13+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
14+
// Licensed under Apache License v2.0 with Runtime Library Exception
15+
//
16+
// See https://swift.org/LICENSE.txt for license information
17+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
18+
//
19+
//===----------------------------------------------------------------------===//
20+
//
21+
// This file defines macros used for macro-metaprogramming with attributes.
22+
//
23+
//===----------------------------------------------------------------------===//
24+
25+
#ifndef DECL_ATTR
26+
#define DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE)
27+
#endif
28+
29+
#ifndef CONTEXTUAL_DECL_ATTR
30+
#define CONTEXTUAL_DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE) \
31+
DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE)
32+
#endif
33+
34+
#ifndef SIMPLE_DECL_ATTR
35+
#define SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE) \
36+
DECL_ATTR(X, CLASS, OPTIONS, CODE)
37+
#endif
38+
39+
#ifndef CONTEXTUAL_SIMPLE_DECL_ATTR
40+
#define CONTEXTUAL_SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE) \
41+
SIMPLE_DECL_ATTR(X, CLASS, OPTIONS, CODE)
42+
#endif
43+
44+
#ifndef DECL_ATTR_ALIAS
45+
#define DECL_ATTR_ALIAS(SPELLING, CLASS)
46+
#endif
47+
48+
#ifndef CONTEXTUAL_DECL_ATTR_ALIAS
49+
#define CONTEXTUAL_DECL_ATTR_ALIAS(SPELLING, CLASS) \
50+
DECL_ATTR_ALIAS(SPELLING, CLASS)
51+
#endif
52+
53+
#ifndef TYPE_ATTR
54+
#define TYPE_ATTR(X)
55+
#endif
56+
57+
// Type attributes
58+
% for attr in TYPE_ATTR_KINDS:
59+
TYPE_ATTR(${attr.name})
60+
% end
61+
62+
// SIL-specific attributes
63+
TYPE_ATTR(block_storage)
64+
TYPE_ATTR(box)
65+
TYPE_ATTR(dynamic_self)
66+
#define REF_STORAGE(Name, name, ...) TYPE_ATTR(sil_##name)
67+
#include "swift/AST/ReferenceStorage.def"
68+
TYPE_ATTR(error)
69+
TYPE_ATTR(out)
70+
TYPE_ATTR(in)
71+
TYPE_ATTR(inout)
72+
TYPE_ATTR(inout_aliasable)
73+
TYPE_ATTR(in_guaranteed)
74+
TYPE_ATTR(in_constant)
75+
TYPE_ATTR(owned)
76+
TYPE_ATTR(unowned_inner_pointer)
77+
TYPE_ATTR(guaranteed)
78+
TYPE_ATTR(autoreleased)
79+
TYPE_ATTR(callee_owned)
80+
TYPE_ATTR(callee_guaranteed)
81+
TYPE_ATTR(objc_metatype)
82+
TYPE_ATTR(opened)
83+
TYPE_ATTR(pseudogeneric)
84+
TYPE_ATTR(yields)
85+
TYPE_ATTR(yield_once)
86+
TYPE_ATTR(yield_many)
87+
TYPE_ATTR(captures_generics)
88+
// Used at the SIL level to mark a type as moveOnly.
89+
TYPE_ATTR(moveOnly)
90+
91+
// SIL metatype attributes.
92+
TYPE_ATTR(thin)
93+
TYPE_ATTR(thick)
94+
95+
// Declaration Attributes and Modifers
96+
// To add a new entry here, update https://github.com/apple/swift-syntax
97+
% for attr in DECL_ATTR_KINDS + DECL_MODIFIER_KINDS + DEPRECATED_MODIFIER_KINDS:
98+
% if type(attr) is ContextualDeclAttributeAlias:
99+
CONTEXTUAL_DECL_ATTR_ALIAS(${attr.name}, ${attr.class_name})
100+
% elif type(attr) is DeclAttributeAlias:
101+
DECL_ATTR_ALIAS(${attr.name}, ${attr.class_name})
102+
% elif type(attr) is ContextualSimpleDeclAttribute:
103+
CONTEXTUAL_SIMPLE_DECL_ATTR(${attr.name}, ${attr.class_name},
104+
${' | '.join(attr.options)},
105+
${str(attr.code)})
106+
% elif type(attr) is ContextualDeclAttribute:
107+
CONTEXTUAL_DECL_ATTR(${attr.name}, ${attr.class_name},
108+
${' | '.join(attr.options)},
109+
${str(attr.code)})
110+
% elif type(attr) is SimpleDeclAttribute:
111+
SIMPLE_DECL_ATTR(${attr.name}, ${attr.class_name},
112+
${' | '.join(attr.options)},
113+
${str(attr.code)})
114+
% elif type(attr) is DeclAttribute:
115+
DECL_ATTR(${attr.name}, ${attr.class_name},
116+
${' | '.join(attr.options)},
117+
${str(attr.code)})
118+
% elif type(attr) is BuiltinDeclModifier:
119+
% # These are not actually decl attributes, ignore them.
120+
% pass
121+
% else:
122+
% raise RuntimeError(f'Unhandled attribute class {type(attr)}')
123+
% end
124+
% end
125+
126+
#undef TYPE_ATTR
127+
#undef DECL_ATTR_ALIAS
128+
#undef CONTEXTUAL_DECL_ATTR_ALIAS
129+
#undef SIMPLE_DECL_ATTR
130+
#undef CONTEXTUAL_SIMPLE_DECL_ATTR
131+
#undef DECL_ATTR
132+
#undef CONTEXTUAL_DECL_ATTR

include/swift/AST/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
2+
set(SWIFT_GYB_FLAGS --line-directive "^\"#line %(line)d \\\"%(file)s\\\"^\"")
3+
else()
4+
set(SWIFT_GYB_FLAGS --line-directive "\'#line" "%(line)d" "\"%(file)s\"\'")
5+
endif()
6+
7+
set(generated_include_sources
8+
Attr.def.gyb)
9+
10+
add_gyb_target(swift-ast-generated-headers
11+
"${generated_include_sources}")
12+
set_property(TARGET swift-ast-generated-headers
13+
PROPERTY FOLDER "Miscellaneous")

include/swift/Basic/FlagSet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class FlagSet {
6666

6767
/// Read a multi-bit field.
6868
template <unsigned FirstBit, unsigned BitWidth, typename FieldType = IntType>
69-
FieldType getField() const {
69+
constexpr FieldType getField() const {
7070
return FieldType((Bits >> FirstBit) & lowMaskFor<BitWidth>());
7171
}
7272

@@ -92,7 +92,7 @@ class FlagSet {
9292
// A convenient macro for defining a getter and setter for a field.
9393
// Intended to be used in the body of a subclass of FlagSet.
9494
#define FLAGSET_DEFINE_FIELD_ACCESSORS(BIT, WIDTH, TYPE, GETTER, SETTER) \
95-
TYPE GETTER() const { \
95+
constexpr TYPE GETTER() const { \
9696
return this->template getField<BIT, WIDTH, TYPE>(); \
9797
} \
9898
void SETTER(TYPE value) { \

include/swift/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ endif()
77
if(SWIFT_INCLUDE_TOOLS)
88
configure_file(Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h
99
ESCAPE_QUOTES @ONLY)
10+
add_subdirectory(AST)
1011
add_subdirectory(Option)
1112
add_subdirectory(Parse)
1213
add_subdirectory(Syntax)

lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,6 @@ endif()
177177
# headers.
178178
# For more information see the comment at the top of lib/CMakeLists.txt.
179179
add_dependencies(swiftAST intrinsics_gen clang-tablegen-targets)
180+
add_dependencies(swiftAST swift-ast-generated-headers)
180181

181182
set_swift_llvm_is_available(swiftAST)

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen clang-tablegen-targets)
1212

1313
# Add generated libSyntax headers to global dependencies.
1414
list(APPEND LLVM_COMMON_DEPENDS swift-syntax-generated-headers)
15+
list(APPEND LLVM_COMMON_DEPENDS swift-ast-generated-headers)
1516
list(APPEND LLVM_COMMON_DEPENDS swift-parse-syntax-generated-headers)
1617

1718
add_subdirectory(APIDigester)

lib/IDE/CompletionLookup.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,9 +2091,7 @@ bool CompletionLookup::handleEnumElement(ValueDecl *D,
20912091
/*HasTypeContext=*/true);
20922092
return true;
20932093
} else if (auto *ED = dyn_cast<EnumDecl>(D)) {
2094-
llvm::DenseSet<EnumElementDecl *> Elements;
2095-
ED->getAllElements(Elements);
2096-
for (auto *Ele : Elements) {
2094+
for (auto *Ele : ED->getAllElements()) {
20972095
addEnumElementRef(Ele, Reason, dynamicLookupInfo,
20982096
/*HasTypeContext=*/true);
20992097
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,8 @@ static bool isCFTypedef(const TypeLowering &tl, clang::QualType type) {
27022702
static ParameterConvention getIndirectCParameterConvention(clang::QualType type) {
27032703
// Non-trivial C++ types would be Indirect_Inout (at least in Itanium).
27042704
// A trivial const * parameter in C should be considered @in.
2705+
if (type->isReferenceType() && type->getPointeeType().isConstQualified())
2706+
return ParameterConvention::Indirect_In_Guaranteed;
27052707
return ParameterConvention::Indirect_In;
27062708
}
27072709

lib/SILGen/LValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class PathComponent {
105105
CoroutineAccessorKind, // coroutine accessor
106106
ValueKind, // random base pointer as an lvalue
107107
PhysicalKeyPathApplicationKind, // applying a key path
108-
ABISafeConversionKind, // unchecked_addr_cast
109108

110109
// Logical LValue kinds
111110
GetterSetterKind, // property or subscript getter/setter
@@ -118,6 +117,7 @@ class PathComponent {
118117
// Translation LValue kinds (a subtype of logical)
119118
OrigToSubstKind, // generic type substitution
120119
SubstToOrigKind, // generic type substitution
120+
UncheckedConversionKind, // unchecked_X_cast
121121

122122
FirstLogicalKind = GetterSetterKind,
123123
FirstTranslationKind = OrigToSubstKind,

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,8 +2224,8 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
22242224
auto bridged = emitNativeToBridgedValue(fd, param, nativeFormalType,
22252225
foreignFormalType,
22262226
foreignLoweredTy);
2227-
// Handle C pointer arguments imported as indirect `self` arguments.
2228-
if (foreignParam.getConvention() == ParameterConvention::Indirect_In) {
2227+
if (foreignParam.getConvention() == ParameterConvention::Indirect_In ||
2228+
foreignParam.getConvention() == ParameterConvention::Indirect_In_Guaranteed) {
22292229
auto temp = emitTemporaryAllocation(fd, bridged.getType());
22302230
bridged.forwardInto(*this, fd, temp);
22312231
bridged = emitManagedBufferWithCleanup(temp);

lib/SILGen/SILGenBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ ManagedValue SILGenBuilder::createUncheckedBitCast(SILLocation loc,
625625
// updated.
626626
assert((isa<UncheckedTrivialBitCastInst>(cast) ||
627627
isa<UncheckedRefCastInst>(cast) ||
628-
isa<UncheckedBitwiseCastInst>(cast)) &&
628+
isa<UncheckedBitwiseCastInst>(cast) ||
629+
isa<ConvertFunctionInst>(cast)) &&
629630
"SILGenBuilder is out of sync with SILBuilder.");
630631

631632
// If we have a trivial inst, just return early.

lib/SILGen/SILGenLValue.cpp

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,26 +2198,82 @@ namespace {
21982198
}
21992199
};
22002200

2201-
/// A physical component which performs an unchecked_addr_cast
2202-
class ABISafeConversionComponent final : public PhysicalPathComponent {
2201+
/// A translation component that performs \c unchecked_*_cast 's as-needed.
2202+
class UncheckedConversionComponent final : public TranslationPathComponent {
2203+
private:
2204+
Type OrigType;
2205+
2206+
/// \returns the type this component is trying to convert \b to
2207+
CanType getTranslatedType() const {
2208+
return getTypeData().SubstFormalType->getCanonicalType();
2209+
}
2210+
2211+
/// \returns the type this component is trying to convert \b from
2212+
CanType getUntranslatedType() const {
2213+
return OrigType->getRValueType()->getCanonicalType();
2214+
}
2215+
2216+
/// perform a conversion of ManagedValue -> ManagedValue
2217+
ManagedValue doUncheckedConversion(SILGenFunction &SGF, SILLocation loc,
2218+
ManagedValue val, CanType toType) {
2219+
auto toTy = SGF.getLoweredType(toType);
2220+
auto fromTy = val.getType();
2221+
2222+
if (fromTy == toTy)
2223+
return val; // nothing to do.
2224+
2225+
// otherwise emit the right kind of cast based on whether it's an address.
2226+
assert(fromTy.isAddress() == toTy.isAddress());
2227+
2228+
if (toTy.isAddress())
2229+
return SGF.B.createUncheckedAddrCast(loc, val, toTy);
2230+
2231+
return SGF.B.createUncheckedBitCast(loc, val, toTy);
2232+
}
2233+
2234+
/// perform a conversion of RValue -> RValue
2235+
RValue doUncheckedConversion(SILGenFunction &SGF, SILLocation loc,
2236+
RValue &&rv, CanType toType) {
2237+
auto val = std::move(rv).getAsSingleValue(SGF, loc);
2238+
val = doUncheckedConversion(SGF, loc, val, toType);
2239+
return RValue(SGF, loc, toType, val);
2240+
}
2241+
22032242
public:
2204-
ABISafeConversionComponent(LValueTypeData typeData)
2205-
: PhysicalPathComponent(typeData, ABISafeConversionKind,
2206-
/*actorIsolation=*/None) {}
2243+
/// \param OrigType is the type we are converting \b from
2244+
/// \param typeData will contain the type we are converting \b to
2245+
UncheckedConversionComponent(LValueTypeData typeData, Type OrigType)
2246+
: TranslationPathComponent(typeData, UncheckedConversionKind),
2247+
OrigType(OrigType) {}
22072248

2208-
ManagedValue project(SILGenFunction &SGF, SILLocation loc,
2209-
ManagedValue base) && override {
2210-
auto toType = SGF.getLoweredType(getTypeData().SubstFormalType)
2211-
.getAddressType();
2249+
bool isLoadingPure() const override { return true; }
22122250

2213-
if (base.getType() == toType)
2214-
return base; // nothing to do
2251+
/// Used during write operations to convert the value prior to writing to
2252+
/// the base.
2253+
RValue untranslate(SILGenFunction &SGF, SILLocation loc,
2254+
RValue &&rv, SGFContext c) && override {
2255+
return doUncheckedConversion(SGF, loc, std::move(rv),
2256+
getUntranslatedType());
2257+
}
22152258

2216-
return SGF.B.createUncheckedAddrCast(loc, base, toType);
2259+
/// Used during read operations to convert the value after reading the base.
2260+
RValue translate(SILGenFunction &SGF, SILLocation loc,
2261+
RValue &&rv, SGFContext c) && override {
2262+
return doUncheckedConversion(SGF, loc, std::move(rv),
2263+
getTranslatedType());
2264+
}
2265+
2266+
std::unique_ptr<LogicalPathComponent>
2267+
clone(SILGenFunction &SGF, SILLocation loc) const override {
2268+
return std::make_unique<UncheckedConversionComponent>(getTypeData(),
2269+
OrigType);
22172270
}
22182271

22192272
void dump(raw_ostream &OS, unsigned indent) const override {
2220-
OS.indent(indent) << "ABISafeConversionComponent\n";
2273+
OS.indent(indent) << "UncheckedConversionComponent"
2274+
<< "\n\tfromType: " << getUntranslatedType()
2275+
<< "\n\ttoType: " << getTranslatedType()
2276+
<< "\n";
22212277
}
22222278
};
22232279
} // end anonymous namespace
@@ -3756,7 +3812,9 @@ LValue SILGenLValue::visitABISafeConversionExpr(ABISafeConversionExpr *e,
37563812
LValue lval = visitRec(e->getSubExpr(), accessKind, options);
37573813
auto typeData = getValueTypeData(SGF, accessKind, e);
37583814

3759-
lval.add<ABISafeConversionComponent>(typeData);
3815+
auto OrigType = e->getSubExpr()->getType();
3816+
3817+
lval.add<UncheckedConversionComponent>(typeData, OrigType);
37603818

37613819
return lval;
37623820
}

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ extension _ArrayBufferProtocol {
166166
// so as not to self-clobber.
167167
newTailStart.moveInitialize(from: oldTailStart, count: tailCount)
168168

169-
// Assign over the original subrange
169+
// Update the original subrange
170170
var i = newValues.startIndex
171171
for j in subrange {
172172
elements[j] = newValues[i]
@@ -199,17 +199,17 @@ extension _ArrayBufferProtocol {
199199
let shrinkage = -growth
200200
if tailCount > shrinkage { // If the tail length exceeds the shrinkage
201201

202-
// Assign over the rest of the replaced range with the first
202+
// Update the rest of the replaced range with the first
203203
// part of the tail.
204-
newTailStart.moveAssign(from: oldTailStart, count: shrinkage)
204+
newTailStart.moveUpdate(from: oldTailStart, count: shrinkage)
205205

206206
// Slide the rest of the tail back
207207
oldTailStart.moveInitialize(
208208
from: oldTailStart + shrinkage, count: tailCount - shrinkage)
209209
}
210210
else { // Tail fits within erased elements
211-
// Assign over the start of the replaced range with the tail
212-
newTailStart.moveAssign(from: oldTailStart, count: tailCount)
211+
// Update the start of the replaced range with the tail
212+
newTailStart.moveUpdate(from: oldTailStart, count: tailCount)
213213

214214
// Destroy elements remaining after the tail in subrange
215215
(newTailStart + tailCount).deinitialize(

stdlib/public/core/Bitset.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ extension _UnsafeBitset {
118118
@inlinable
119119
@inline(__always)
120120
internal func clear() {
121-
words.assign(repeating: .empty, count: wordCount)
121+
words.update(repeating: .empty, count: wordCount)
122122
}
123123
}
124124

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ set(SWIFTLIB_SOURCES
227227
CommandLine.swift
228228
SliceBuffer.swift
229229
UnfoldSequence.swift
230+
UnsafeBufferPointerSlice.swift
230231
VarArgs.swift
231232
Zip.swift
232233
"${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c"

0 commit comments

Comments
 (0)