Skip to content

Commit e0663cc

Browse files
Merge pull request #5200 from swiftwasm/main
[pull] swiftwasm from main
2 parents 3b8360d + 4eefefa commit e0663cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+616
-416
lines changed

include/swift/AST/Attr.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,55 +2613,6 @@ class DeclAttributes {
26132613
SourceLoc getStartLoc(bool forModifiers = false) const;
26142614
};
26152615

2616-
/// Semantic attributes that are applied to a declaration.
2617-
///
2618-
/// This attribute list can include attributes that are not written in
2619-
/// source on a declaration, such as attributes that are applied during
2620-
/// macro expansion or inferred from the declaration context.
2621-
class SemanticDeclAttributes {
2622-
llvm::SmallVector<DeclAttribute *, 4> attrList;
2623-
2624-
public:
2625-
SemanticDeclAttributes() {}
2626-
2627-
/// Add a constructed DeclAttribute to this list.
2628-
void add(DeclAttribute *attr) {
2629-
attrList.push_back(attr);
2630-
}
2631-
2632-
using SemanticAttrList = llvm::SmallVectorImpl<DeclAttribute *>;
2633-
2634-
template <typename AttrType, bool AllowInvalid>
2635-
using AttributeKindRange =
2636-
OptionalTransformRange<iterator_range<SemanticAttrList::const_iterator>,
2637-
ToAttributeKind<AttrType, AllowInvalid>,
2638-
SemanticAttrList::const_iterator>;
2639-
2640-
template <typename AttrType, bool AllowInvalid = false>
2641-
AttributeKindRange<AttrType, AllowInvalid> getAttributes() const {
2642-
return AttributeKindRange<AttrType, AllowInvalid>(
2643-
make_range(attrList.begin(), attrList.end()),
2644-
ToAttributeKind<AttrType, AllowInvalid>());
2645-
}
2646-
2647-
/// Retrieve the first attribute of the given attribute class.
2648-
template <typename AttrType>
2649-
const AttrType *getAttribute(bool allowInvalid = false) const {
2650-
for (auto attr : attrList)
2651-
if (auto *specificAttr = dyn_cast<AttrType>(attr))
2652-
if (specificAttr->isValid() || allowInvalid)
2653-
return specificAttr;
2654-
2655-
return nullptr;
2656-
}
2657-
2658-
/// Determine whether there is an attribute with the given attribute class.
2659-
template <typename AttrType>
2660-
bool hasAttribute(bool allowInvalid = false) const {
2661-
return getAttribute<AttrType>(allowInvalid) != nullptr;
2662-
}
2663-
};
2664-
26652616
/// TypeAttributes - These are attributes that may be applied to types.
26662617
class TypeAttributes {
26672618
// Get a SourceLoc for every possible attribute that can be parsed in source.

include/swift/AST/Decl.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
850850
return Attrs;
851851
}
852852

853-
/// Returns the semantic attributes attached to this declaration.
854-
///
855-
/// \c getSemanticAttrs is intended to be a requestified replacement
856-
/// for \c getAttrs
857-
SemanticDeclAttributes getSemanticAttrs() const;
853+
/// Returns the semantic attributes attached to this declaration,
854+
/// including attributes that are generated as the result of member
855+
/// attribute macro expansion.
856+
DeclAttributes getSemanticAttrs() const;
858857

859858
/// Returns the innermost enclosing decl with an availability annotation.
860859
const Decl *getInnermostDeclWithAvailability() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,9 @@ ERROR(unresolved_member_no_inference,none,
38863886
(DeclNameRef))
38873887
ERROR(cannot_infer_base_of_unresolved_member,none,
38883888
"cannot infer contextual base in reference to member %0", (DeclNameRef))
3889+
ERROR(cannot_infer_concrete_for_opaque_result,none,
3890+
"cannot infer concrete type for opaque result %0 from return expression",
3891+
(Type))
38893892
ERROR(unresolved_nil_literal,none,
38903893
"'nil' requires a contextual type", ())
38913894
ERROR(cannot_force_unwrap_nil_literal,none,
@@ -5334,6 +5337,12 @@ ERROR(differentiable_function_type_invalid_result,none,
53345337
"%select{| and satisfy '%0 == %0.TangentVector'}1, but the enclosing "
53355338
"function type is '@differentiable%select{|(_linear)}1'",
53365339
(StringRef, bool))
5340+
ERROR(differentiable_function_type_void_result,
5341+
none,
5342+
"'@differentiable' function returning Void must have at least one "
5343+
"differentiable inout parameter, i.e. a non-'@noDerivative' parameter "
5344+
"whose type conforms to 'Differentiable'",
5345+
())
53375346
ERROR(differentiable_function_type_no_differentiability_parameters,
53385347
none,
53395348
"'@differentiable' function type requires at least one differentiability "

include/swift/AST/SourceFile.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ class SourceFile final : public FileUnit {
500500
/// the \c SourceFileKind is \c MacroExpansion.
501501
ASTNode getMacroExpansion() const;
502502

503+
/// For source files created to hold the source code created by expanding
504+
/// an attached macro, this is the custom attribute that describes the macro
505+
/// expansion.
506+
///
507+
/// The source location of this attribute is the place in the source that
508+
/// triggered the creation of the macro expansion whose resulting source
509+
/// code is in this source file. This will only produce a non-null value when
510+
/// the \c SourceFileKind is \c MacroExpansion , and the macro is an attached
511+
/// macro.
512+
CustomAttr *getAttachedMacroAttribute() const;
513+
503514
/// When this source file is enclosed within another source file, for example
504515
/// because it describes a macro expansion, return the source file it was
505516
/// enclosed in.

include/swift/AST/TypeCheckRequests.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -742,26 +742,6 @@ class AttachedPropertyWrappersRequest :
742742
bool isCached() const { return true; }
743743
};
744744

745-
/// Request the semantic attributes attached to the given declaration.
746-
class AttachedSemanticAttrsRequest :
747-
public SimpleRequest<AttachedSemanticAttrsRequest,
748-
SemanticDeclAttributes(Decl *),
749-
RequestFlags::Cached> {
750-
public:
751-
using SimpleRequest::SimpleRequest;
752-
753-
private:
754-
friend SimpleRequest;
755-
756-
// Evaluation.
757-
SemanticDeclAttributes
758-
evaluate(Evaluator &evaluator, Decl *decl) const;
759-
760-
public:
761-
// Caching
762-
bool isCached() const { return true; }
763-
};
764-
765745
/// Request the raw (possibly unbound generic) type of the property wrapper
766746
/// that is attached to the given variable.
767747
class AttachedPropertyWrapperTypeRequest :
@@ -3840,6 +3820,24 @@ class ExpandMacroExpansionDeclRequest
38403820
bool isCached() const { return true; }
38413821
};
38423822

3823+
/// Expand all member attribute macros attached to the given
3824+
/// declaration.
3825+
class ExpandMemberAttributeMacros
3826+
: public SimpleRequest<ExpandMemberAttributeMacros,
3827+
bool(Decl *),
3828+
RequestFlags::Cached> {
3829+
public:
3830+
using SimpleRequest::SimpleRequest;
3831+
3832+
private:
3833+
friend SimpleRequest;
3834+
3835+
bool evaluate(Evaluator &evaluator, Decl *decl) const;
3836+
3837+
public:
3838+
bool isCached() const { return true; }
3839+
};
3840+
38433841
/// Resolve an external macro given its module and type name.
38443842
class ExternalMacroDefinitionRequest
38453843
: public SimpleRequest<ExternalMacroDefinitionRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ SWIFT_REQUEST(TypeChecker, AttachedPropertyWrapperTypeRequest,
2929
SWIFT_REQUEST(TypeChecker, AttachedPropertyWrappersRequest,
3030
llvm::TinyPtrVector<CustomAttr *>(VarDecl *), Cached,
3131
NoLocationInfo)
32-
SWIFT_REQUEST(TypeChecker, AttachedSemanticAttrsRequest,
33-
SemanticDeclAttributes(Decl *), Cached,
34-
NoLocationInfo)
3532
SWIFT_REQUEST(TypeChecker, CallerSideDefaultArgExprRequest,
3633
Expr *(DefaultArgumentExpr *), SeparatelyCached, NoLocationInfo)
3734
SWIFT_REQUEST(TypeChecker, CheckInconsistentImplementationOnlyImportsRequest,
@@ -455,6 +452,9 @@ SWIFT_REQUEST(TypeChecker, ExternalMacroDefinitionRequest,
455452
SWIFT_REQUEST(TypeChecker, ExpandMacroExpansionDeclRequest,
456453
ArrayRef<Decl *>(MacroExpansionDecl *),
457454
Cached, NoLocationInfo)
455+
SWIFT_REQUEST(TypeChecker, ExpandMemberAttributeMacros,
456+
bool(Decl *),
457+
Cached, NoLocationInfo)
458458
SWIFT_REQUEST(TypeChecker, SynthesizeRuntimeMetadataAttrGenerator,
459459
Expr *(CustomAttr *, ValueDecl *),
460460
Cached, NoLocationInfo)

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ class CompilerInstance {
559559
/// i.e. if it can be found.
560560
bool canImportSwiftConcurrency() const;
561561

562+
/// Whether the Swift Concurrency Shims support Clang library can be imported
563+
/// i.e. if it can be found.
564+
bool canImportSwiftConcurrencyShims() const;
565+
562566
/// Verify that if an implicit import of the `StringProcessing` module if
563567
/// expected, it can actually be imported. Emit a warning, otherwise.
564568
void verifyImplicitStringProcessingImport();

include/swift/Strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ constexpr static const StringLiteral STDLIB_NAME = "Swift";
2424
constexpr static const StringLiteral SWIFT_ONONE_SUPPORT = "SwiftOnoneSupport";
2525
/// The name of the Concurrency module, which supports that extension.
2626
constexpr static const StringLiteral SWIFT_CONCURRENCY_NAME = "_Concurrency";
27+
/// The name of the Concurrency Shims Clang module
28+
constexpr static const StringLiteral SWIFT_CONCURRENCY_SHIMS_NAME = "_SwiftConcurrencyShims";
2729
/// The name of the Distributed module, which supports that extension.
2830
constexpr static const StringLiteral SWIFT_DISTRIBUTED_NAME = "Distributed";
2931
/// The name of the StringProcessing module, which supports that extension.

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5464,7 +5464,10 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
54645464
*bridgedValueType = type;
54655465

54665466
// Find the Objective-C class type we bridge to.
5467-
return conformance.getTypeWitnessByName(type, Id_ObjectiveCType);
5467+
Type witnessTy = conformance.getTypeWitnessByName(type, Id_ObjectiveCType);
5468+
// If Objective-C import is broken, witness type would be a dependent member
5469+
// with `<<error type>>` base.
5470+
return (witnessTy && !witnessTy->hasError()) ? witnessTy : Type();
54685471
}
54695472

54705473
// Do we conform to Error?

lib/AST/Decl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,13 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
365365
llvm_unreachable("bad DescriptiveDeclKind");
366366
}
367367

368-
SemanticDeclAttributes Decl::getSemanticAttrs() const {
368+
DeclAttributes Decl::getSemanticAttrs() const {
369369
auto mutableThis = const_cast<Decl *>(this);
370-
return evaluateOrDefault(getASTContext().evaluator,
371-
AttachedSemanticAttrsRequest{mutableThis},
372-
SemanticDeclAttributes());
370+
evaluateOrDefault(getASTContext().evaluator,
371+
ExpandMemberAttributeMacros{mutableThis},
372+
false);
373+
374+
return getAttrs();
373375
}
374376

375377
const Decl *Decl::getInnermostDeclWithAvailability() const {

lib/AST/Module.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,15 @@ ASTNode SourceFile::getMacroExpansion() const {
887887
return ASTNode::getFromOpaqueValue(genInfo.astNode);
888888
}
889889

890+
CustomAttr *SourceFile::getAttachedMacroAttribute() const {
891+
if (Kind != SourceFileKind::MacroExpansion)
892+
return nullptr;
893+
894+
auto genInfo =
895+
*getASTContext().SourceMgr.getGeneratedSourceInfo(*getBufferID());
896+
return genInfo.attachedMacroCustomAttr;
897+
}
898+
890899
SourceFile *SourceFile::getEnclosingSourceFile() const {
891900
auto macroExpansion = getMacroExpansion();
892901
if (!macroExpansion)

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,6 +5064,9 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
50645064
if (auto cxxRecord =
50655065
dyn_cast<clang::CXXRecordDecl>(recordDecl->getClangDecl())) {
50665066
for (auto base : cxxRecord->bases()) {
5067+
if (base.getAccessSpecifier() != clang::AccessSpecifier::AS_public)
5068+
continue;
5069+
50675070
clang::QualType baseType = base.getType();
50685071
if (auto spectType = dyn_cast<clang::TemplateSpecializationType>(baseType))
50695072
baseType = spectType->desugar();
@@ -5704,12 +5707,16 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
57045707
std::string failedTypesStr;
57055708
llvm::raw_string_ostream failedTypesStrStream(failedTypesStr);
57065709
llvm::interleaveComma(error->failedTypes, failedTypesStrStream);
5710+
5711+
std::string funcName;
5712+
llvm::raw_string_ostream funcNameStream(funcName);
5713+
func->printQualifiedName(funcNameStream);
5714+
57075715
// TODO: Use the location of the apply here.
57085716
// TODO: This error message should not reference implementation details.
57095717
// See: https://github.com/apple/swift/pull/33053#discussion_r477003350
5710-
ctx.Diags.diagnose(SourceLoc(),
5711-
diag::unable_to_convert_generic_swift_types.ID,
5712-
{func->getName(), StringRef(failedTypesStr)});
5718+
ctx.Diags.diagnose(SourceLoc(), diag::unable_to_convert_generic_swift_types,
5719+
funcName, failedTypesStr);
57135720
return nullptr;
57145721
}
57155722

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8442,6 +8442,9 @@ void ClangImporter::Implementation::loadAllMembersOfRecordDecl(
84428442
// If this is a C++ record, look through the base classes too.
84438443
if (auto cxxRecord = dyn_cast<clang::CXXRecordDecl>(clangRecord)) {
84448444
for (auto base : cxxRecord->bases()) {
8445+
if (base.getAccessSpecifier() != clang::AccessSpecifier::AS_public)
8446+
continue;
8447+
84458448
clang::QualType baseType = base.getType();
84468449
if (auto spectType = dyn_cast<clang::TemplateSpecializationType>(baseType))
84478450
baseType = spectType->desugar();

lib/Frontend/Frontend.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,13 @@ bool CompilerInstance::canImportSwiftConcurrency() const {
875875
return getASTContext().canImportModule(modulePath);
876876
}
877877

878+
bool CompilerInstance::canImportSwiftConcurrencyShims() const {
879+
ImportPath::Module::Builder builder(
880+
getASTContext().getIdentifier(SWIFT_CONCURRENCY_SHIMS_NAME));
881+
auto modulePath = builder.get();
882+
return getASTContext().canImportModule(modulePath);
883+
}
884+
878885
void CompilerInstance::verifyImplicitStringProcessingImport() {
879886
if (Invocation.shouldImportSwiftStringProcessing() &&
880887
!canImportSwiftStringProcessing()) {
@@ -935,6 +942,8 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
935942
case ImplicitStdlibKind::Stdlib:
936943
if (canImportSwiftConcurrency())
937944
pushImport(SWIFT_CONCURRENCY_NAME);
945+
if (canImportSwiftConcurrencyShims())
946+
pushImport(SWIFT_CONCURRENCY_SHIMS_NAME);
938947
break;
939948
}
940949
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5963,6 +5963,16 @@ bool MissingGenericArgumentsFailure::hasLoc(GenericTypeParamType *GP) const {
59635963
}
59645964

59655965
bool MissingGenericArgumentsFailure::diagnoseAsError() {
5966+
auto locator = getLocator();
5967+
// Opaque result types that could not be inferred from return expressions.
5968+
if (auto opaqueElt =
5969+
locator->findLast<LocatorPathElt::OpenedOpaqueArchetype>()) {
5970+
auto *opaqueDecl = opaqueElt->getDecl();
5971+
emitDiagnostic(diag::cannot_infer_concrete_for_opaque_result,
5972+
opaqueDecl->getDeclaredInterfaceType());
5973+
return true;
5974+
}
5975+
59665976
llvm::SmallDenseMap<TypeRepr *, SmallVector<GenericTypeParamType *, 4>>
59675977
scopedParameters;
59685978

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7385,45 +7385,6 @@ ValueDecl *RenamedDeclRequest::evaluate(Evaluator &evaluator,
73857385
return renamedDecl;
73867386
}
73877387

7388-
SemanticDeclAttributes
7389-
AttachedSemanticAttrsRequest::evaluate(Evaluator &evaluator, Decl *decl) const {
7390-
// For now, this returns the same thing as 'getAttrs' using
7391-
// the SemanticDeclAttribtues representation.
7392-
SemanticDeclAttributes semanticAttrs;
7393-
for (auto attr : decl->getAttrs()) {
7394-
semanticAttrs.add(attr);
7395-
}
7396-
7397-
auto *parentDecl = decl->getDeclContext()->getAsDecl();
7398-
if (!parentDecl)
7399-
return semanticAttrs;
7400-
7401-
auto parentAttrs = parentDecl->getSemanticAttrs();
7402-
for (auto customAttrConst: parentAttrs.getAttributes<CustomAttr>()) {
7403-
auto customAttr = const_cast<CustomAttr *>(customAttrConst);
7404-
auto customAttrDecl = evaluateOrDefault(
7405-
evaluator,
7406-
CustomAttrDeclRequest{
7407-
customAttr,
7408-
parentDecl->getInnermostDeclContext()
7409-
},
7410-
nullptr);
7411-
if (!customAttrDecl)
7412-
continue;
7413-
7414-
auto macroDecl = customAttrDecl.dyn_cast<MacroDecl *>();
7415-
if (!macroDecl)
7416-
continue;
7417-
7418-
if (!macroDecl->getMacroRoles().contains(MacroRole::MemberAttribute))
7419-
continue;
7420-
7421-
expandAttributes(customAttr, macroDecl, decl, semanticAttrs);
7422-
}
7423-
7424-
return semanticAttrs;
7425-
}
7426-
74277388
template <typename ATTR>
74287389
static void forEachCustomAttribute(
74297390
ValueDecl *decl,

0 commit comments

Comments
 (0)