diff --git a/docs/ReferenceGuides/UnderscoredAttributes.md b/docs/ReferenceGuides/UnderscoredAttributes.md index a9db7c7ea998e..8a21289f45882 100644 --- a/docs/ReferenceGuides/UnderscoredAttributes.md +++ b/docs/ReferenceGuides/UnderscoredAttributes.md @@ -1117,12 +1117,6 @@ if it is never explicitly bound using a typed pointer method like bound, it must only be used with compatible typed memory accesses for as long as the binding is active. -## `@_section("section_name")` - -Places a global variable or a top-level function into a section of the object -file with the given name. It's the equivalent of clang's -`__attribute__((section))`. - ## `@_semantics("uniquely.recognized.id")` Allows the optimizer to make use of some key invariants in performance critical @@ -1320,12 +1314,6 @@ for more details. This `async` function uses the pre-SE-0338 semantics of unsafely inheriting the caller's executor. This is an underscored feature because the right way of inheriting an executor is to pass in the required executor and switch to it. Unfortunately, there are functions in the standard library which need to inherit their caller's executor but cannot change their ABI because they were not defined as `@_alwaysEmitIntoClient` in the initial release. -## `@_used` - -Marks a global variable or a top-level function as "used externally" even if it -does not have visible users in the compilation unit. It's the equivalent of -clang's `__attribute__((used))`. - ## `@_weakLinked` Allows a declaration to be weakly-referenced, i.e., any references emitted by diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index 9b563fe3cc366..3c3b3593c8010 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -714,7 +714,7 @@ class SILGenNameAttr : public DeclAttribute { } }; -/// Defines the @_section attribute. +/// Defines the @section attribute. class SectionAttr : public DeclAttribute { public: SectionAttr(StringRef Name, SourceLoc AtLoc, SourceRange Range, bool Implicit) diff --git a/include/swift/AST/DeclAttr.def b/include/swift/AST/DeclAttr.def index 632cdebe58d95..7aca39268496c 100644 --- a/include/swift/AST/DeclAttr.def +++ b/include/swift/AST/DeclAttr.def @@ -753,12 +753,12 @@ DECL_ATTR(attached, MacroRole, 142) DECL_ATTR_ALIAS(freestanding, MacroRole) -SIMPLE_DECL_ATTR(_used, Used, +SIMPLE_DECL_ATTR(used, Used, OnAbstractFunction | OnVar, UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove | ForbiddenInABIAttr, 143) -DECL_ATTR(_section, Section, +DECL_ATTR(section, Section, OnAbstractFunction | OnVar, UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove | ForbiddenInABIAttr, 144) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index c070e1e0c42de..2b40623271926 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -826,29 +826,29 @@ ERROR(expect_compile_time_literal,none, "expect a compile-time constant literal", ()) ERROR(const_unsupported_enum_associated_value,none, - "enums with associated values not supported in a '@const' expression", ()) + "enums with associated values not supported in a constant expression", ()) ERROR(const_unsupported_operator,none, - "unsupported operator in a '@const' expression", ()) + "unsupported operator in a constant expression", ()) ERROR(const_unsupported_type,none, - "unsupported type in a '@const' expression", ()) + "unsupported type in a constant expression", ()) ERROR(const_unsupported_type_expr,none, - "type expressions not supported in a '@const' expression", ()) + "type expressions not supported in a constant expression", ()) ERROR(const_unsupported_closure,none, - "closures not supported in a '@const' expression", ()) + "closures not supported in a constant expression", ()) ERROR(const_unsupported_keypath,none, - "keypaths not supported in a '@const' expression", ()) + "keypaths not supported in a constant expression", ()) ERROR(const_opaque_decl_ref,none, - "unable to resolve variable reference in a '@const' expression", ()) + "unable to resolve variable reference in a constant expression", ()) ERROR(const_opaque_func_decl_ref,none, - "unable to resolve function reference in a '@const' expression", ()) + "unable to resolve function reference in a constant expression", ()) ERROR(const_non_convention_c_conversion,none, - "only 'convention(c)' function values are supported in a '@const' expression", ()) + "only 'convention(c)' function values are supported in a constant expression", ()) ERROR(const_opaque_callee,none, - "unable to resolve callee in a '@const' expression", ()) + "unable to resolve callee in a constant expression", ()) ERROR(const_non_const_param,none, - "reference to a non-'@const' parameter in a '@const' expression", ()) + "reference to a non-'@const' parameter in a constant expression", ()) ERROR(const_unknown_default,none, - "not supported in a '@const' expression", ()) + "not supported in a constant expression", ()) //------------------------------------------------------------------------------ // MARK: Import Resolution @@ -2097,11 +2097,9 @@ ERROR(cdecl_feature_required,none, "'@c' requires '-enable-experimental-feature CDecl'", ()) -// @_used and @_section -ERROR(section_linkage_markers_disabled,none, - "attribute requires '-enable-experimental-feature SymbolLinkageMarkers'", ()) +// @used and @section ERROR(section_empty_name,none, - "'@_section' section name cannot be empty", ()) + "'@section' section name cannot be empty", ()) // @_silgen_name and friends WARNING(reserved_runtime_symbol_name,none, diff --git a/include/swift/Basic/Features.def b/include/swift/Basic/Features.def index 9ce683decdb39..45824a1662c24 100644 --- a/include/swift/Basic/Features.def +++ b/include/swift/Basic/Features.def @@ -323,9 +323,6 @@ EXPERIMENTAL_FEATURE(FullTypedThrows, false) EXPERIMENTAL_FEATURE(SameElementRequirements, false) EXPERIMENTAL_FEATURE(KeyPathWithMethodMembers, false) -// Whether to enable @_used and @_section attributes -EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true) - // Whether to emit an Embedded Swift module with "deferred" code generation, // meaning that the only code that will be emitted into the object file is // code that was marked as "never emit into client". For everything else, diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h index 7570d5ac7c3fd..b13af85cf2d24 100644 --- a/include/swift/IRGen/Linking.h +++ b/include/swift/IRGen/Linking.h @@ -1850,7 +1850,7 @@ class LinkEntity { /// /// This applies only in the Embedded Swift linkage model, and is used for /// any symbols that have not been explicitly requested to have unique - /// definitions (e.g., with @_used). + /// definitions (e.g., with @used). bool hasNonUniqueDefinition() const; #undef LINKENTITY_GET_FIELD diff --git a/include/swift/SIL/SILFunction.h b/include/swift/SIL/SILFunction.h index d85e3e833c963..6f250c6aee0bc 100644 --- a/include/swift/SIL/SILFunction.h +++ b/include/swift/SIL/SILFunction.h @@ -325,7 +325,7 @@ class SILFunction /// If empty, use the SIL function's name directly. StringRef AsmName; - /// Name of a section if @_section attribute was used, otherwise empty. + /// Name of a section if @section attribute was used, otherwise empty. StringRef Section; /// Name of a Wasm export if @_expose(wasm) attribute was used, otherwise @@ -396,7 +396,7 @@ class SILFunction /// would indicate. unsigned HasCReferences : 1; - /// Whether attribute @_used was present + /// Whether attribute @used was present unsigned MarkedAsUsed : 1; /// Whether cross-module references to this function should always use weak @@ -1424,7 +1424,7 @@ class SILFunction return V && V->getAttrs().hasAttribute(); } - /// Return whether this function has attribute @_used on it + /// Return whether this function has attribute @used on it bool markedAsUsed() const { return MarkedAsUsed; } void setMarkedAsUsed(bool value) { MarkedAsUsed = value; } @@ -1432,7 +1432,7 @@ class SILFunction StringRef asmName() const { return AsmName; } void setAsmName(StringRef value) { AsmName = value; } - /// Return custom section name if @_section was used, otherwise empty + /// Return custom section name if @section was used, otherwise empty StringRef section() const { return Section; } void setSection(StringRef value) { Section = value; } diff --git a/include/swift/SIL/SILGlobalVariable.h b/include/swift/SIL/SILGlobalVariable.h index 895236b7136a4..9f3f6fd548ecf 100644 --- a/include/swift/SIL/SILGlobalVariable.h +++ b/include/swift/SIL/SILGlobalVariable.h @@ -64,7 +64,7 @@ class SILGlobalVariable /// the mangled name of the variable will be used instead. StringRef AsmName; - /// Name of a section if @_section attribute was used, otherwise empty. + /// Name of a section if @section attribute was used, otherwise empty. StringRef Section; /// The lowered type of the variable. @@ -86,7 +86,7 @@ class SILGlobalVariable /// once (either in its declaration, or once later), making it immutable. unsigned IsLet : 1; - /// Whether this declaration was marked `@_used`, meaning that it should be + /// Whether this declaration was marked `@used`, meaning that it should be /// added to the llvm.used list. unsigned IsUsed : 1; @@ -162,7 +162,7 @@ class SILGlobalVariable StringRef asmName() const { return AsmName; } void setAsmName(StringRef value) { AsmName = value; } - /// Return custom section name if @_section was used, otherwise empty + /// Return custom section name if @section was used, otherwise empty StringRef section() const { return Section; } void setSection(StringRef value) { Section = value; } @@ -242,7 +242,7 @@ class SILGlobalVariable StaticInitializerBlock.eraseAllInstructions(Module); } - /// Returns true if this global variable has `@_used` attribute. + /// Returns true if this global variable has `@used` attribute. bool markedAsUsed() const { return IsUsed; } void setMarkedAsUsed(bool used) { IsUsed = used; } diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index b234e816e43a2..3d220566ba5ae 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -1323,7 +1323,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options, } case DeclAttrKind::Section: - Printer.printAttrName("@_section"); + Printer.printAttrName("@section"); Printer << "(\"" << cast(this)->Name << "\")"; break; @@ -1977,7 +1977,7 @@ StringRef DeclAttribute::getAttrName() const { case DeclAttrKind::Expose: return "_expose"; case DeclAttrKind::Section: - return "_section"; + return "section"; case DeclAttrKind::Documentation: return "_documentation"; case DeclAttrKind::Nonisolated: diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index a90887793eced..a6c01aa21d307 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1342,7 +1342,7 @@ bool AbstractStorageDecl::isCompileTimeLiteral() const { } bool AbstractStorageDecl::isConstValue() const { - return getAttrs().hasAttribute(); + return getAttrs().hasAttribute() || getAttrs().hasAttribute(); } bool AbstractStorageDecl::isTransparent() const { diff --git a/lib/AST/FeatureSet.cpp b/lib/AST/FeatureSet.cpp index 2ab8faf37a8b1..3293d493511d2 100644 --- a/lib/AST/FeatureSet.cpp +++ b/lib/AST/FeatureSet.cpp @@ -83,7 +83,6 @@ UNINTERESTING_FEATURE(FlowSensitiveConcurrencyCaptures) UNINTERESTING_FEATURE(CodeItemMacros) UNINTERESTING_FEATURE(PreambleMacros) UNINTERESTING_FEATURE(TupleConformances) -UNINTERESTING_FEATURE(SymbolLinkageMarkers) UNINTERESTING_FEATURE(DeferredCodeGen) UNINTERESTING_FEATURE(LazyImmediate) UNINTERESTING_FEATURE(MoveOnlyClasses) diff --git a/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift b/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift index 249102a15d66d..526ae4394f6f9 100644 --- a/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift +++ b/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift @@ -1024,7 +1024,7 @@ extension ASTGenVisitor { /// E.g. /// ``` - /// @_section("__TEXT,__mysection") + /// @section("__TEXT,__mysection") /// ``` func generateSectionAttr(attribute node: AttributeSyntax) -> BridgedSectionAttr? { return self.generateWithLabeledExprListArguments(attribute: node) { args in diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index cf41c9e353d0c..a6ce68ae51be5 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -2860,7 +2860,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var, if (!forDefinition) gvar->setComdat(nullptr); - // Mark as llvm.used if @_used, set section if @_section + // Mark as llvm.used if @used, set section if @section if (var->markedAsUsed()) addUsedGlobal(gvar); else if (var->shouldBePreservedForDebugger() && forDefinition) @@ -3734,7 +3734,7 @@ llvm::Function *IRGenModule::getAddrOfSILFunction( fn = createFunction(*this, link, signature, insertBefore, f->getOptimizationMode(), shouldEmitStackProtector(f)); - // Mark as llvm.used if @_used, set section if @_section + // Mark as llvm.used if @used, set section if @section if (f->markedAsUsed()) addUsedGlobal(fn); diff --git a/lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift b/lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift index 4483bf7a0c9c2..f19a6e4ca0b71 100644 --- a/lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift +++ b/lib/Macros/Sources/SwiftMacros/DebugDescriptionMacro.swift @@ -252,17 +252,17 @@ extension _DebugDescriptionPropertyMacro: PeerMacro { let summaryString = summarySegments.joined() // Serialize the type summary into a global record, in a custom section, for LLDB to load. + let (encodedValue, encodedType) = encodeTypeSummaryRecord(typeIdentifier, summaryString) let decl: DeclSyntax = """ #if !os(Windows) #if os(Linux) - @_section(".lldbsummaries") + @section(".lldbsummaries") #else - @_section("__TEXT,__lldbsummaries") + @section("__TEXT,__lldbsummaries") #endif - @_used - static let _lldb_summary = ( - \(raw: encodeTypeSummaryRecord(typeIdentifier, summaryString)) - ) + @used + static let _lldb_summary: \(raw: encodedType) = + \(raw: encodedValue) #endif """ @@ -303,23 +303,33 @@ fileprivate let ENCODING_VERSION: UInt = 1 /// /// The strings (type identifier and summary) are encoded with both a length prefix (also ULEB) /// and with a null terminator. -fileprivate func encodeTypeSummaryRecord(_ typeIdentifier: String, _ summaryString: String) -> String { +fileprivate func encodeTypeSummaryRecord(_ typeIdentifier: String, _ summaryString: String) -> (valueString: String, typeString: String) { let encodedIdentifier = typeIdentifier.byteEncoded let encodedSummary = summaryString.byteEncoded let recordSize = UInt(encodedIdentifier.count + encodedSummary.count) - return """ + return (valueString: """ + ( /* version */ \(swiftLiteral: ENCODING_VERSION.ULEBEncoded), /* record size */ \(swiftLiteral: recordSize.ULEBEncoded), /* "\(typeIdentifier)" */ \(swiftLiteral: encodedIdentifier), /* "\(summaryString)" */ \(swiftLiteral: encodedSummary) + ) + """, + typeString: """ + ( + \(Array(repeating: "UInt8", count: ENCODING_VERSION.ULEBEncoded.count + + recordSize.ULEBEncoded.count + encodedIdentifier.count + + encodedSummary.count).joined(separator: ", ")) + ) """ + ) } extension DefaultStringInterpolation { /// Generate a _partial_ Swift literal from the given bytes. It is partial in that must be embedded /// into some other syntax, specifically as a tuple. fileprivate mutating func appendInterpolation(swiftLiteral bytes: [UInt8]) { - let literalBytes = bytes.map({ "\($0) as UInt8" }).joined(separator: ", ") + let literalBytes = bytes.map({ "\($0)" }).joined(separator: ", ") appendInterpolation(literalBytes) } } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index b9eff0334f045..dd926e32b4337 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3211,7 +3211,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes, return makeParserSuccess(); } - // @_section in a local scope is not allowed. + // @section in a local scope is not allowed. if (CurDeclContext->isLocalContext()) { diagnose(Loc, diag::attr_name_only_at_non_local_scope, AttrName); } @@ -4349,6 +4349,12 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes, checkInvalidAttrName("_functionBuilder", "resultBuilder", DeclAttrKind::ResultBuilder, diag::attr_renamed_warning); + // Historical name for @section and @used + checkInvalidAttrName("_section", "section", DeclAttrKind::Section, + diag::attr_renamed_warning); + checkInvalidAttrName("_used", "used", DeclAttrKind::Used, + diag::attr_renamed_warning); + // Historical name for 'nonisolated'. if (!DK && Tok.getText() == "actorIndependent") { diagnose( diff --git a/lib/SIL/IR/SILDeclRef.cpp b/lib/SIL/IR/SILDeclRef.cpp index 096260f622623..e50acbce6d4ef 100644 --- a/lib/SIL/IR/SILDeclRef.cpp +++ b/lib/SIL/IR/SILDeclRef.cpp @@ -1217,7 +1217,7 @@ bool SILDeclRef::declHasNonUniqueDefinition(const ValueDecl *decl) { return false; } - // - @_section and @_used imply that external tools will look for this symbol. + // - @section and @used imply that external tools will look for this symbol. if (decl->getAttrs().hasAttribute() || decl->getAttrs().hasAttribute()) { return false; diff --git a/lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp b/lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp index 9ebc9edb64ce9..d76adf18daf96 100644 --- a/lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp +++ b/lib/SILOptimizer/Mandatory/PerformanceDiagnostics.cpp @@ -723,7 +723,7 @@ class PerformanceDiagnosticsPass : public SILModuleTransform { PerformanceDiagnostics diagnoser(*module, getAnalysis()); - // Check that @_section, @_silgen_name is only on constant globals + // Check that @section, @_silgen_name is only on constant globals for (SILGlobalVariable &g : module->getSILGlobals()) { if (!g.getStaticInitializerValue() && g.mustBeInitializedStatically()) { PrettyStackTraceSILGlobal stackTrace( @@ -733,7 +733,7 @@ class PerformanceDiagnosticsPass : public SILModuleTransform { if (!g.section().empty()) { module->getASTContext().Diags.diagnose( g.getDecl()->getLoc(), diag::bad_attr_on_non_const_global, - "@_section"); + "@section"); } else if (decl && g.isDefinition() && decl->getAttrs().hasAttribute()) { module->getASTContext().Diags.diagnose( diff --git a/lib/SILOptimizer/UtilityPasses/Link.cpp b/lib/SILOptimizer/UtilityPasses/Link.cpp index 2e60fa11780e6..e3666ee9e9d00 100644 --- a/lib/SILOptimizer/UtilityPasses/Link.cpp +++ b/lib/SILOptimizer/UtilityPasses/Link.cpp @@ -52,7 +52,7 @@ class SILLinker : public SILModuleTransform { linkEmbeddedConcurrency(); } - // In embedded Swift, we need to explicitly link any @_used globals and + // In embedded Swift, we need to explicitly link any @used globals and // functions from imported modules. if (M.getOptions().EmbeddedSwift && LinkUsedFunctions) { linkUsedGlobalsAndFunctions(); @@ -230,7 +230,7 @@ class SILLinker : public SILModuleTransform { } else if (VarDecl *G = dyn_cast(D)) { Globals.push_back(G); } else { - assert(false && "only funcs and globals can be @_used"); + assert(false && "only funcs and globals can be @used"); } } } diff --git a/lib/Sema/LegalConstExprVerifier.cpp b/lib/Sema/LegalConstExprVerifier.cpp index 76dee5ac9a9c9..ddf7be87368bd 100644 --- a/lib/Sema/LegalConstExprVerifier.cpp +++ b/lib/Sema/LegalConstExprVerifier.cpp @@ -45,7 +45,7 @@ enum IllegalConstErrorDiagnosis { UnsupportedUnaryOperator, TypeExpression, KeyPath, - Closue, + Closure, OpaqueDeclRef, OpaqueFuncDeclRef, NonConventionCFunc, @@ -79,7 +79,7 @@ static void diagnoseError(const Expr *errorExpr, case KeyPath: diags.diagnose(errorLoc, diag::const_unsupported_keypath); break; - case Closue: + case Closure: diags.diagnose(errorLoc, diag::const_unsupported_closure); break; case OpaqueDeclRef: @@ -134,13 +134,152 @@ static bool supportedOperator(const ApplyExpr *operatorApplyExpr) { return true; } +// Per SE-0492: +// A constant expression is syntactically one of: +// - an integer literal using any of standard integer types (Int, UInt, +// Int8/16/32/64/128, UInt8/16/32/64/128) +// - a floating-point literal of type Float or Double +// - a boolean literal of type Bool +// - a direct reference to a non-generic function using its name (the function +// itself is not generic, and also it must not be defined in a generic +// context) +// - a direct reference to a non-generic metatype using the type name directly +// (the type itself is not generic, and also it must not be defined in a +// generic context), where the type is non-resilient +// - a tuple composed of only other constant expressions +// - an array literal of type InlineArray composed of only other constant +// expressions +static std::optional> +checkSupportedWithSectionAttribute(const Expr *expr, + const DeclContext *declContext) { + SmallVector expressionsToCheck; + expressionsToCheck.push_back(expr); + while (!expressionsToCheck.empty()) { + const Expr *expr = expressionsToCheck.pop_back_val(); + + // Tuples composed of constant expressions are allowed + if (const TupleExpr *tupleExpr = dyn_cast(expr)) { + for (const Expr *element : tupleExpr->getElements()) + expressionsToCheck.push_back(element); + continue; + } + + // Array literals of type InlineArray composed of constant expressions are + // allowed + if (const ArrayExpr *arrayExpr = dyn_cast(expr)) { + auto arrayType = arrayExpr->getType(); + if (arrayType && arrayType->isInlineArray()) { + for (const Expr *element : arrayExpr->getElements()) + expressionsToCheck.push_back(element); + continue; + } + // Non-InlineArray arrays are not allowed + return std::make_pair(expr, TypeNotSupported); + } + + // Operators are not allowed in @section expressions + if (isa(expr)) { + return std::make_pair(expr, UnsupportedBinaryOperator); + } + if (isa(expr) || isa(expr)) { + return std::make_pair(expr, UnsupportedUnaryOperator); + } + + // Optionals are not allowed + if (isa(expr)) { + return std::make_pair(expr, TypeNotSupported); + } + + // Literal expressions are okay if they are standard types + if (const LiteralExpr *literal = dyn_cast(expr)) { + auto literalType = literal->getType(); + if (literalType) { + // Allow integer literals of standard integer types + if (isIntegerType(literalType)) + continue; + // Allow floating-point literals of Float or Double + if (literalType->isFloat() || literalType->isDouble()) + continue; + // Allow boolean literals + if (literalType->isBool()) + continue; + } + // Other literal types are not supported + return std::make_pair(expr, TypeNotSupported); + } + + // Keypath expressions not supported in constant expressions + if (isa(expr)) + return std::make_pair(expr, KeyPath); + + // Closure expressions are not supported in constant expressions + if (isa(expr)) + return std::make_pair(expr, Closure); + + // Function conversions are not allowed in constant expressions + if (isa(expr)) + return std::make_pair(expr, Default); + + // Direct references to non-generic functions are allowed + if (const DeclRefExpr *declRef = dyn_cast(expr)) { + auto decl = declRef->getDecl(); + + // Function references are allowed if they are non-generic + if (auto *funcDecl = dyn_cast(decl)) { + if (!funcDecl->isGeneric() && + !funcDecl->getDeclContext()->isGenericContext()) { + continue; + } + return std::make_pair(expr, OpaqueFuncDeclRef); + } + + // Variable references are not allowed + return std::make_pair(expr, OpaqueDeclRef); + } + + // DotSelfExpr for metatype references (but only a direct TypeExpr inside) + if (const DotSelfExpr *dotSelfExpr = dyn_cast(expr)) { + if (const TypeExpr *typeExpr = + dyn_cast(dotSelfExpr->getSubExpr())) { + auto baseType = typeExpr->getType(); + if (baseType && baseType->is()) { + auto instanceType = baseType->getMetatypeInstanceType(); + if (auto nominal = instanceType->getNominalOrBoundGenericNominal()) { + // Allow non-generic, non-resilient types + if (!nominal->isGeneric() && !nominal->isResilient()) { + continue; + } + } + } + } + return std::make_pair(expr, TypeExpression); + } + + // Look through IdentityExpr, but only after DotSelfExpr, which is also an + // IdentityExpr. + if (const IdentityExpr *identityExpr = dyn_cast(expr)) { + expressionsToCheck.push_back(identityExpr->getSubExpr()); + continue; + } + + // Function calls and constructors are not allowed + if (isa(expr)) + return std::make_pair(expr, Default); + + // Anything else is not allowed + return std::make_pair(expr, Default); + } + + return std::nullopt; +} + static std::optional> checkSupportedInConst(const Expr *expr, const DeclContext *declContext) { SmallVector expressionsToCheck; expressionsToCheck.push_back(expr); while (!expressionsToCheck.empty()) { const Expr *expr = expressionsToCheck.pop_back_val(); - // Lookthrough IdentityExpr, Tuple, Array, and InjectIntoOptional + // Look through IdentityExpr, Tuple, Array, and InjectIntoOptional // expressions. if (const IdentityExpr *identityExpr = dyn_cast(expr)) { expressionsToCheck.push_back(identityExpr->getSubExpr()); @@ -196,7 +335,7 @@ checkSupportedInConst(const Expr *expr, const DeclContext *declContext) { // Closure expressions are not supported in `@const` expressions // TODO: `@const`-evaluable closures if (isa(expr)) - return std::make_pair(expr, Closue); + return std::make_pair(expr, Closure); // Function conversions, as long as the conversion is to a 'convention(c)' // then consider the operand sub-expression @@ -370,10 +509,26 @@ static void verifyConstArguments(const CallExpr *callExpr, void swift::diagnoseInvalidConstExpressions(const Expr *expr, const DeclContext *declContext, bool isConstInitExpr) { + if (declContext->getASTContext().LangOpts.hasFeature( + Feature::CompileTimeValuesPreview)) { + // No syntactic checking + return; + } + if (isConstInitExpr) { - if (auto error = checkSupportedInConst(expr, declContext)) - diagnoseError(error->first, error->second, - declContext->getASTContext().Diags); - } else if (auto *callExpr = dyn_cast(expr)) + if (declContext->getASTContext().LangOpts.hasFeature( + Feature::CompileTimeValues)) { + // Syntactic checking for preview of compile-time values (@const) + if (auto error = checkSupportedInConst(expr, declContext)) + diagnoseError(error->first, error->second, + declContext->getASTContext().Diags); + } else { + // Syntactic checking for SE-0492 + if (auto error = checkSupportedWithSectionAttribute(expr, declContext)) + diagnoseError(error->first, error->second, + declContext->getASTContext().Diags); + } + } else if (auto *callExpr = dyn_cast(expr)) { verifyConstArguments(callExpr, declContext); + } } diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index 5823e41de508a..8678f6338af53 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -6500,9 +6500,7 @@ void swift::performSyntacticExprDiagnostics(const Expr *E, if (ctx.LangOpts.EnableObjCInterop) diagDeprecatedObjCSelectors(DC, E); diagnoseConstantArgumentRequirement(E, DC); - if (ctx.LangOpts.hasFeature(Feature::CompileTimeValues) && - !ctx.LangOpts.hasFeature(Feature::CompileTimeValuesPreview)) - diagnoseInvalidConstExpressions(E, DC, isConstInitExpr); + diagnoseInvalidConstExpressions(E, DC, isConstInitExpr); diagUnqualifiedAccessToMethodNamedSelf(E, DC); diagnoseDictionaryLiteralDuplicateKeyEntries(E, DC); diagnoseMissingMemberImports(E, DC); diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index d7f039864f12a..f9ff76cd06d94 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -2632,36 +2632,6 @@ void AttributeChecker::visitExternAttr(ExternAttr *attr) { } } -static bool allowSymbolLinkageMarkers(ASTContext &ctx, Decl *D) { - if (ctx.LangOpts.hasFeature(Feature::SymbolLinkageMarkers)) - return true; - - auto *sourceFile = D->getDeclContext()->getParentModule() - ->getSourceFileContainingLocation(D->getStartLoc()); - if (!sourceFile) - return false; - - auto expansion = sourceFile->getMacroExpansion(); - auto *macroAttr = sourceFile->getAttachedMacroAttribute(); - if (!expansion || !macroAttr) - return false; - - auto *decl = expansion.dyn_cast(); - if (!decl) - return false; - - auto *macroDecl = macroAttr->getResolvedMacro(); - if (!macroDecl) - return false; - - if (macroDecl->getParentModule()->isStdlibModule() && - macroDecl->getName().getBaseIdentifier() - .str() == "_DebugDescriptionProperty") - return true; - - return false; -} - void AttributeChecker::visitSILGenNameAttr(SILGenNameAttr *A) { if (!canDeclareSymbolName(A->Name, D->getModuleContext())) { diagnose(A->getLocation(), diag::reserved_runtime_symbol_name, @@ -2674,11 +2644,6 @@ void AttributeChecker::visitSILGenNameAttr(SILGenNameAttr *A) { } void AttributeChecker::visitUsedAttr(UsedAttr *attr) { - if (!allowSymbolLinkageMarkers(Ctx, D)) { - diagnoseAndRemoveAttr(attr, diag::section_linkage_markers_disabled); - return; - } - if (D->getDeclContext()->isLocalContext()) diagnose(attr->getLocation(), diag::attr_only_at_non_local_scope, attr); else if (D->getDeclContext()->isGenericContext() && @@ -2697,11 +2662,6 @@ void AttributeChecker::visitUsedAttr(UsedAttr *attr) { } void AttributeChecker::visitSectionAttr(SectionAttr *attr) { - if (!allowSymbolLinkageMarkers(Ctx, D)) { - diagnoseAndRemoveAttr(attr, diag::section_linkage_markers_disabled); - return; - } - // The name must not be empty. if (attr->Name.empty()) diagnose(attr->getLocation(), diag::section_empty_name); diff --git a/test/ASTGen/attrs.swift b/test/ASTGen/attrs.swift index 7f3bca52c1ddf..7cd37f9b570c3 100644 --- a/test/ASTGen/attrs.swift +++ b/test/ASTGen/attrs.swift @@ -4,7 +4,6 @@ // RUN: -enable-experimental-feature Extern \ // RUN: -enable-experimental-feature Lifetimes \ // RUN: -enable-experimental-feature RawLayout \ -// RUN: -enable-experimental-feature SymbolLinkageMarkers \ // RUN: -enable-experimental-feature CDecl \ // RUN: -enable-experimental-concurrency \ // RUN: -enable-experimental-move-only \ @@ -15,7 +14,6 @@ // RUN: -enable-experimental-feature Extern \ // RUN: -enable-experimental-feature Lifetimes \ // RUN: -enable-experimental-feature RawLayout \ -// RUN: -enable-experimental-feature SymbolLinkageMarkers \ // RUN: -enable-experimental-feature CDecl \ // RUN: -enable-experimental-concurrency \ // RUN: -enable-experimental-move-only \ @@ -29,7 +27,6 @@ // RUN: -enable-experimental-feature Extern \ // RUN: -enable-experimental-feature Lifetimes \ // RUN: -enable-experimental-feature RawLayout \ -// RUN: -enable-experimental-feature SymbolLinkageMarkers \ // RUN: -enable-experimental-feature CDecl \ // RUN: -enable-experimental-concurrency \ // RUN: -enable-experimental-move-only @@ -40,7 +37,6 @@ // REQUIRES: swift_feature_Extern // REQUIRES: swift_feature_Lifetimes // REQUIRES: swift_feature_RawLayout -// REQUIRES: swift_feature_SymbolLinkageMarkers // REQUIRES: swift_feature_CDecl // rdar://116686158 @@ -143,7 +139,7 @@ class ExclusivityAttrClass { @_extern(c) func externCFn() struct SectionStruct { - @_section("__TEXT,__mysection") @_used func foo() {} + @section("__TEXT,__mysection") @used func foo() {} } protocol ImplementsProto { diff --git a/test/Concurrency/global_function_pointer.swift b/test/Concurrency/global_function_pointer.swift index 169080d5d8b50..543a96981835f 100644 --- a/test/Concurrency/global_function_pointer.swift +++ b/test/Concurrency/global_function_pointer.swift @@ -1,5 +1,5 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -Xllvm -sil-print-types -emit-sil -target %target-swift-5.1-abi-triple -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-SIL -// RUN: %target-build-swift -enable-experimental-feature SymbolLinkageMarkers -target %target-swift-5.1-abi-triple -Xfrontend -parse-as-library %s -o %t_binary +// RUN: %target-swift-frontend -Xllvm -sil-print-types -emit-sil -target %target-swift-5.1-abi-triple -parse-as-library %s | %FileCheck %s --check-prefix=CHECK-SIL +// RUN: %target-build-swift -target %target-swift-5.1-abi-triple -Xfrontend -parse-as-library %s -o %t_binary // RUN: %target-codesign %t_binary // RUN: %target-run %t_binary | %FileCheck %s --check-prefix=CHECK-EXEC @@ -10,7 +10,6 @@ // rdar://76038845 // REQUIRES: concurrency_runtime -// REQUIRES: swift_feature_SymbolLinkageMarkers // UNSUPPORTED: back_deployment_runtime @MainActor @@ -29,7 +28,7 @@ public func callAsync() async { // CHECK-SIL-NEXT: %initval = thin_to_thick_function %0 : $@convention(thin) @async () -> () to $@async @callee_guaranteed () -> () // CHECK-SIL-NEXT: } -@_section("__DATA,__mysection") +@section("__DATA,__mysection") public var gfptr = callAsync @main struct MyProgram { @@ -44,4 +43,3 @@ public var gfptr = callAsync // CHECK-EXEC: 42 // CHECK-EXEC-NEXT: Hello World! // CHECK-EXEC-NEXT: 43 - diff --git a/test/ConstValues/DiagModulesSyntactic.swift b/test/ConstValues/DiagModulesSyntactic.swift index 742b65fffbaf0..8c9344c1536f9 100644 --- a/test/ConstValues/DiagModulesSyntactic.swift +++ b/test/ConstValues/DiagModulesSyntactic.swift @@ -17,4 +17,4 @@ public func foo() -> Int { import MyModule @const let constGlobal1: Int = foo() -// expected-error@-1 {{not supported in a '@const' expression}} +// expected-error@-1 {{not supported in a constant expression}} diff --git a/test/ConstValues/DiagNotConstSyntactic.swift b/test/ConstValues/DiagNotConstSyntactic.swift index 8d522281f4b4d..85e5246394d59 100644 --- a/test/ConstValues/DiagNotConstSyntactic.swift +++ b/test/ConstValues/DiagNotConstSyntactic.swift @@ -3,11 +3,11 @@ // RUN: %target-swift-frontend -emit-ir -primary-file %s -parse-as-library -verify -enable-experimental-feature CompileTimeValues @const let a: Bool = Bool.random() -// expected-error@-1 {{not supported in a '@const' expression}} +// expected-error@-1 {{not supported in a constant expression}} func foo() -> Int { return 42 * Int.random(in: 0 ..< 10) } @const let b: Int = foo() -// expected-error@-1 {{not supported in a '@const' expression}} +// expected-error@-1 {{not supported in a constant expression}} diff --git a/test/ConstValues/FunctionTypesSyntactic.swift b/test/ConstValues/FunctionTypesSyntactic.swift index 3f969f516ac8e..c6c91777d04f1 100644 --- a/test/ConstValues/FunctionTypesSyntactic.swift +++ b/test/ConstValues/FunctionTypesSyntactic.swift @@ -6,25 +6,25 @@ func foo_void_to_void() {} func foo_int_to_int(x: Int) -> Int { return 42 } @const let constGlobalA1: ()->() = { } -// expected-error@-1{{closures not supported in a '@const' expression}} +// expected-error@-1{{closures not supported in a constant expression}} @const let constGlobalA2: @convention(c) ()->() = { } -// expected-error@-1{{closures not supported in a '@const' expression}} +// expected-error@-1{{closures not supported in a constant expression}} @const let constGlobalA3: @convention(thin) ()->() = { } -// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}} +// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}} @const let constGlobalB1: ()->() = foo_void_to_void // TODO: Diagnose the type of the variable as not eligigle for '@const' (not the init expression) @const let constGlobalB2: @convention(c) ()->() = foo_void_to_void @const let constGlobalB3: @convention(thin) ()->() = foo_void_to_void -// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}} +// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}} @const let constGlobalC1: (Int)->(Int) = { _ in return 42 } -// expected-error@-1{{closures not supported in a '@const' expression}} +// expected-error@-1{{closures not supported in a constant expression}} @const let constGlobalC2: @convention(c) (Int)->(Int) = { _ in return 42 } -// expected-error@-1{{closures not supported in a '@const' expression}} +// expected-error@-1{{closures not supported in a constant expression}} @const let constGlobalC3: @convention(thin) (Int)->(Int) = { _ in return 42 } -// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}} +// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}} @const let constGlobalD1: (Int)->(Int) = foo_int_to_int @const let constGlobalD2: @convention(c) (Int)->(Int) = foo_int_to_int @const let constGlobalD3: @convention(thin) (Int)->(Int) = foo_int_to_int -// expected-error@-1{{only 'convention(c)' function values are supported in a '@const' expression}} +// expected-error@-1{{only 'convention(c)' function values are supported in a constant expression}} diff --git a/test/ConstValues/IntegerExpressionsSyntactic.swift b/test/ConstValues/IntegerExpressionsSyntactic.swift index c9ca04662a9a1..823b705c47028 100644 --- a/test/ConstValues/IntegerExpressionsSyntactic.swift +++ b/test/ConstValues/IntegerExpressionsSyntactic.swift @@ -5,7 +5,7 @@ @const let constGlobal1: Int = (42 + 42 + 42) / 3 @const let constGlobal2: Int = MemoryLayout.size + 4 -// expected-error@-1{{in a '@const' expression}} +// expected-error@-1{{in a constant expression}} @const let constGlobal3: Int = Int(17.0 / 3.5) @const let constGlobal4: Int = constGlobal1 + 1 @const let constGlobal5: Int = -constGlobal1 + 1 diff --git a/test/ConstValues/ParametersSyntactic.swift b/test/ConstValues/ParametersSyntactic.swift index 896c7b9f6ad1b..3574d94b6d8fa 100644 --- a/test/ConstValues/ParametersSyntactic.swift +++ b/test/ConstValues/ParametersSyntactic.swift @@ -14,5 +14,5 @@ func foo() { #endif let _ = bar(UInt.random(in: 0..<10)) // expected-error@-1 {{expected a compile-time value argument for a '@const' parameter}} - // expected-error@-2 {{not supported in a '@const' expression}} + // expected-error@-2 {{not supported in a constant expression}} } diff --git a/test/ConstValues/SectionIR.swift b/test/ConstValues/SectionIR.swift new file mode 100644 index 0000000000000..731a3a1063f9c --- /dev/null +++ b/test/ConstValues/SectionIR.swift @@ -0,0 +1,62 @@ +// Constant globals using @section +// RUN: %target-swift-frontend -emit-ir -primary-file %s -parse-as-library | %FileCheck %s + +// integer literals +@section("mysection") let intLiteral1 = 42 // ok +@section("mysection") let intLiteral2: Int8 = 127 // ok +@section("mysection") let intLiteral3: Int16 = 32767 // ok +@section("mysection") let intLiteral4: Int32 = 2147483647 // ok +@section("mysection") let intLiteral5: Int64 = 9223372036854775807 // ok +@section("mysection") let intLiteral6: UInt = 42 // ok +@section("mysection") let intLiteral7: UInt8 = 255 // ok +@section("mysection") let intLiteral8: UInt16 = 65535 // ok +@section("mysection") let intLiteral9: UInt32 = 4294967295 // ok +@section("mysection") let intLiteral10: UInt64 = 18446744073709551615 // ok + +// floating-point literals +@section("mysection") let floatLiteral1: Float = 3.14 // ok +@section("mysection") let floatLiteral2: Double = 2.718 // ok + +// boolean literals +@section("mysection") let boolLiteral1 = true // ok +@section("mysection") let boolLiteral2 = false // ok + +func foo() -> Int { return 42 } +func bar(x: Int) -> String { return "test" } + +// function references +@section("mysection") let funcRef1 = foo // ok +@section("mysection") let funcRef2 = bar // ok + +// metatypes - TODO +//@section("mysection") let metatype1 = Int.self + +// tuples +@section("mysection") let tuple1 = (1, 2, 3, 2.718, true) // ok +@section("mysection") let tuple2: (Int, Float, Bool) = (42, 3.14, false) // ok +@section("mysection") let tuple3 = (foo, bar) // ok (function references in tuple) + +// inline array +@available(SwiftStdlib 6.2, *) +@section("mysection") let inlineArray: InlineArray = [1, 2, 3] // ok + +// CHECK: @"$s9SectionIR11intLiteral1Sivp" = {{.*}}constant %TSi <{ i64 42 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral2s4Int8Vvp" = {{.*}}constant %Ts4Int8V <{ i8 127 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral3s5Int16Vvp" = {{.*}}constant %Ts5Int16V <{ i16 32767 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral4s5Int32Vvp" = {{.*}}constant %Ts5Int32V <{ i32 2147483647 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral5s5Int64Vvp" = {{.*}}constant %Ts5Int64V <{ i64 9223372036854775807 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral6Suvp" = {{.*}}constant %TSu <{ i64 42 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral7s5UInt8Vvp" = {{.*}}constant %Ts5UInt8V <{ i8 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral8s6UInt16Vvp" = {{.*}}constant %Ts6UInt16V <{ i16 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral9s6UInt32Vvp" = {{.*}}constant %Ts6UInt32V <{ i32 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR12intLiteral10s6UInt64Vvp" = {{.*}}constant %Ts6UInt64V <{ i64 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR13floatLiteral1Sfvp" = {{.*}}constant %TSf <{ float 0x40091EB860000000 }>, section "mysection" +// CHECK: @"$s9SectionIR13floatLiteral2Sdvp" = {{.*}}constant %TSd <{ double 2.718000e+00 }>, section "mysection" +// CHECK: @"$s9SectionIR12boolLiteral1Sbvp" = {{.*}}constant %TSb <{ i1 true }>, section "mysection" +// CHECK: @"$s9SectionIR12boolLiteral2Sbvp" = {{.*}}constant %TSb zeroinitializer, section "mysection" +// CHECK: @"$s9SectionIR8funcRef1Siycvp" = {{.*}}constant %swift.function { ptr @"$s9SectionIR3fooSiyF", ptr null }, section "mysection" +// CHECK: @"$s9SectionIR8funcRef2ySSSicvp" = {{.*}}constant %swift.function { ptr @"$s9SectionIR3bar1xSSSi_tF", ptr null }, section "mysection" +// CHECK: @"$s9SectionIR6tuple1Si_S2iSdSbtvp" = {{.*}}constant <{ %TSi, %TSi, %TSi, %TSd, %TSb }> <{ %TSi <{ i64 1 }>, %TSi <{ i64 2 }>, %TSi <{ i64 3 }>, %TSd <{ double 2.718000e+00 }>, %TSb <{ i1 true }> }>, section "mysection" +// CHECK: @"$s9SectionIR6tuple2Si_SfSbtvp" = {{.*}}constant <{ %TSi, %TSf, %TSb }> <{ %TSi <{ i64 42 }>, %TSf <{ float 0x40091EB860000000 }>, %TSb zeroinitializer }>, section "mysection" +// CHECK: @"$s9SectionIR6tuple3Siyc_SSSictvp" = {{.*}}constant <{ %swift.function, %swift.function }> <{ %swift.function { ptr @"$s9SectionIR3fooSiyF", ptr null }, %swift.function { ptr @"$s9SectionIR3bar1xSSSi_tF", ptr null } }>, section "mysection" +// CHECK: @"$s9SectionIR11inlineArrays06InlineD0Vy$2_SiGvp" = {{.*}}constant %"Ts11InlineArrayVy$2_SiG" <{ [3 x %TSi] [%TSi <{ i64 1 }>, %TSi <{ i64 2 }>, %TSi <{ i64 3 }>] }>, section "mysection" diff --git a/test/ConstValues/SectionSyntactic.swift b/test/ConstValues/SectionSyntactic.swift new file mode 100644 index 0000000000000..0ff8b3e651aee --- /dev/null +++ b/test/ConstValues/SectionSyntactic.swift @@ -0,0 +1,144 @@ +// Constant globals using @section +// RUN: %target-swift-frontend -emit-ir -primary-file %s -parse-as-library -verify + +// integer literals +@section("mysection") let intLiteral1 = 42 // ok +@section("mysection") let intLiteral2: Int8 = 127 // ok +@section("mysection") let intLiteral3: Int16 = 32767 // ok +@section("mysection") let intLiteral4: Int32 = 2147483647 // ok +@section("mysection") let intLiteral5: Int64 = 9223372036854775807 // ok +@section("mysection") let intLiteral6: UInt = 42 // ok +@section("mysection") let intLiteral7: UInt8 = 255 // ok +@section("mysection") let intLiteral8: UInt16 = 65535 // ok +@section("mysection") let intLiteral9: UInt32 = 4294967295 // ok +@section("mysection") let intLiteral10: UInt64 = 18446744073709551615 // ok + +// floating-point literals +@section("mysection") let floatLiteral1: Float = 3.14 // ok +@section("mysection") let floatLiteral2: Double = 2.718 // ok + +// boolean literals +@section("mysection") let boolLiteral1 = true // ok +@section("mysection") let boolLiteral2 = false // ok + +// magic literals +@section("mysection") let invalidNonLiteral4 = #line + +// operators (should be rejected) +@section("mysection") let invalidOperator1 = 1 + 1 +// expected-error@-1{{unsupported operator in a constant expression}} +@section("mysection") let invalidOperator2 = 3.14 * 2.0 +// expected-error@-1{{unsupported operator in a constant expression}} +@section("mysection") let invalidOperator3: Int = -(1) +// expected-error@-1{{unsupported operator in a constant expression}} + +// non-literal expressions (should be rejected) +@section("mysection") let invalidNonLiteral1 = Int.max +// expected-error@-1{{not supported in a constant expression}} +@section("mysection") let invalidNonLiteral2 = UInt8(42) +// expected-error@-1{{not supported in a constant expression}} +@section("mysection") let invalidNonLiteral3 = true.hashValue +// expected-error@-1{{not supported in a constant expression}} + +func foo() -> Int { return 42 } +func bar(x: Int) -> String { return "test" } + +// function references +@section("mysection") let funcRef1 = foo // ok +@section("mysection") let funcRef2 = bar // ok + +// invalid function references (should be rejected) +@section("mysection") let invalidFuncRef1 = foo() +// expected-error@-1{{not supported in a constant expression}} +@section("mysection") let invalidFuncRef2 = Bool.self.random +// expected-error@-1{{closures not supported in a constant expression}} +@section("mysection") let invalidFuncRef3 = (Bool.self as Bool.Type).random +// expected-error@-1{{not supported in a constant expression}} + +// generic function references (should be rejected) +@section("mysection") let invalidGenericFunc = [Int].randomElement +// expected-error@-1{{not supported in a constant expression}} + +// closures (should be rejected) +@section("mysection") let invalidClosure1 = { } +// expected-error@-1{{closures not supported in a constant expression}} +@section("mysection") let invalidClosure2 = { return 42 } +// expected-error@-1{{closures not supported in a constant expression}} + +struct S { } +enum E { case a } + +// metatypes +@section("mysection") let metatype1 = Int.self // ok + +// invalid metatype references +@section("mysection") let invalidMetatype1 = Int.self.self +// expected-error@-1{{type expressions not supported in a constant expression}} +@section("mysection") let invalidMetatype2 = (1 == 1 ? Int.self : Int.self).self +// expected-error@-1{{type expressions not supported in a constant expression}} +@section("mysection") let invalidMetatype3 = Array.self // generic +// expected-error@-1{{type expressions not supported in a constant expression}} +@section("mysection") let invalidMetatype4 = Mirror.self // resilient +// expected-error@-1{{type expressions not supported in a constant expression}} + +// tuples +@section("mysection") let tuple1 = (1, 2, 3, 2.718, true) // ok +@section("mysection") let tuple2: (Int, Float, Bool) = (42, 3.14, false) // ok +@section("mysection") let tuple3 = (foo, bar) // ok (function references in tuple) + +// invalid tuples (should be rejected) +@section("mysection") let invalidTuple1 = (1, 2, Int.max) +// expected-error@-1{{not supported in a constant expression}} +@section("mysection") let invalidTuple2 = (1 + 1, 2) +// expected-error@-1{{unsupported operator in a constant expression}} + +let someVar = 42 + +// variables (should be rejected) +@section("mysection") let invalidVarRef = someVar +// expected-error@-1{{unable to resolve variable reference in a constant expression}} + +struct MyCustomExpressibleByIntegerLiteral: ExpressibleByIntegerLiteral { + init(integerLiteral value: Int) {} +} + +// custom types (should be rejected) +@section("mysection") let invalidCustomType1: MyCustomExpressibleByIntegerLiteral = 42 +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let invalidCustomType2: E = E.a +// expected-error@-1{{not supported in a constant expression}} +@section("mysection") let invalidCustomType3: S = S() +// expected-error@-1{{not supported in a constant expression}} + +// other standard types (should be rejected) +@section("mysection") let invalidString = "hello" +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let invalidArray = [1, 2, 3] +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let invalidDict = ["key": "value"] +// expected-error@-1{{not supported in a constant expression}} + +// inline array +@available(SwiftStdlib 6.2, *) +@section("mysection") let inlineArray: InlineArray = [1, 2, 3] // ok + +// invalid inline array (should be rejected) +@available(SwiftStdlib 6.2, *) +@section("mysection") let invalidInlineArray: InlineArray = [1, 2, 3, Int.max] +// expected-error@-1{{not supported in a constant expression}} + +// optionals (should be rejected) +@section("mysection") let optional1: Int? = 42 +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let optional2: Int? = nil +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let optional3: Double? = 3.14 +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let optional4: Bool? = true +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let optional5: Bool? = false +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let optional6: Int? = 1 + 1 +// expected-error@-1{{unsupported type in a constant expression}} +@section("mysection") let optional7: Int? = Int.max +// expected-error@-1{{unsupported type in a constant expression}} diff --git a/test/ConstValues/SectionTopLevel.swift b/test/ConstValues/SectionTopLevel.swift new file mode 100644 index 0000000000000..014a1a9079e29 --- /dev/null +++ b/test/ConstValues/SectionTopLevel.swift @@ -0,0 +1,60 @@ +// Constant globals using @section +// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s + +// TODO +// XFAIL: * + +// integer literals +@section("mysection") let intLiteral1 = 42 // ok +@section("mysection") let intLiteral2: Int8 = 127 // ok +@section("mysection") let intLiteral3: Int16 = 32767 // ok +@section("mysection") let intLiteral4: Int32 = 2147483647 // ok +@section("mysection") let intLiteral5: Int64 = 9223372036854775807 // ok +@section("mysection") let intLiteral6: UInt = 42 // ok +@section("mysection") let intLiteral7: UInt8 = 255 // ok +@section("mysection") let intLiteral8: UInt16 = 65535 // ok +@section("mysection") let intLiteral9: UInt32 = 4294967295 // ok +@section("mysection") let intLiteral10: UInt64 = 18446744073709551615 // ok + +// floating-point literals +@section("mysection") let floatLiteral1: Float = 3.14 // ok +@section("mysection") let floatLiteral2: Double = 2.718 // ok + +// boolean literals +@section("mysection") let boolLiteral1 = true // ok +@section("mysection") let boolLiteral2 = false // ok + +func foo() -> Int { return 42 } +func bar(x: Int) -> String { return "test" } + +// function references +@section("mysection") let funcRef1 = foo // ok +@section("mysection") let funcRef2 = bar // ok + +// metatypes - TODO +//@section("mysection") let metatype1 = Int.self + +// tuples +@section("mysection") let tuple1 = (1, 2, 3, 2.718, true) // ok +@section("mysection") let tuple2: (Int, Float, Bool) = (42, 3.14, false) // ok +@section("mysection") let tuple3 = (foo, bar) // ok (function references in tuple) + +// CHECK: @"$s9SectionIR11intLiteral1Sivp" = {{.*}}constant %TSi <{ i64 42 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral2s4Int8Vvp" = {{.*}}constant %Ts4Int8V <{ i8 127 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral3s5Int16Vvp" = {{.*}}constant %Ts5Int16V <{ i16 32767 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral4s5Int32Vvp" = {{.*}}constant %Ts5Int32V <{ i32 2147483647 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral5s5Int64Vvp" = {{.*}}constant %Ts5Int64V <{ i64 9223372036854775807 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral6Suvp" = {{.*}}constant %TSu <{ i64 42 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral7s5UInt8Vvp" = {{.*}}constant %Ts5UInt8V <{ i8 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral8s6UInt16Vvp" = {{.*}}constant %Ts6UInt16V <{ i16 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR11intLiteral9s6UInt32Vvp" = {{.*}}constant %Ts6UInt32V <{ i32 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR12intLiteral10s6UInt64Vvp" = {{.*}}constant %Ts6UInt64V <{ i64 -1 }>, section "mysection" +// CHECK: @"$s9SectionIR13floatLiteral1Sfvp" = {{.*}}constant %TSf <{ float 0x40091EB860000000 }>, section "mysection" +// CHECK: @"$s9SectionIR13floatLiteral2Sdvp" = {{.*}}constant %TSd <{ double 2.718000e+00 }>, section "mysection" +// CHECK: @"$s9SectionIR12boolLiteral1Sbvp" = {{.*}}constant %TSb <{ i1 true }>, section "mysection" +// CHECK: @"$s9SectionIR12boolLiteral2Sbvp" = {{.*}}constant %TSb zeroinitializer, section "mysection" +// CHECK: @"$s9SectionIR8funcRef1Siycvp" = {{.*}}constant %swift.function { ptr @"$s9SectionIR3fooSiyF", ptr null }, section "mysection" +// CHECK: @"$s9SectionIR8funcRef2ySSSicvp" = {{.*}}constant %swift.function { ptr @"$s9SectionIR3bar1xSSSi_tF", ptr null }, section "mysection" +// CHECK: @"$s9SectionIR6tuple1Si_S2iSdSbtvp" = {{.*}}constant <{ %TSi, %TSi, %TSi, %TSd, %TSb }> <{ %TSi <{ i64 1 }>, %TSi <{ i64 2 }>, %TSi <{ i64 3 }>, %TSd <{ double 2.718000e+00 }>, %TSb <{ i1 true }> }>, section "mysection" +// CHECK: @"$s9SectionIR6tuple2Si_SfSbtvp" = {{.*}}constant <{ %TSi, %TSf, %TSb }> <{ %TSi <{ i64 42 }>, %TSf <{ float 0x40091EB860000000 }>, %TSb zeroinitializer }>, section "mysection" +// CHECK: @"$s9SectionIR6tuple3Siyc_SSSictvp" = {{.*}}constant <{ %swift.function, %swift.function }> <{ %swift.function { ptr @"$s9SectionIR3fooSiyF", ptr null }, %swift.function { ptr @"$s9SectionIR3bar1xSSSi_tF", ptr null } }>, section "mysection" diff --git a/test/ConstValues/Tuples.swift b/test/ConstValues/Tuples.swift index 7bf569da66905..7b05515769035 100644 --- a/test/ConstValues/Tuples.swift +++ b/test/ConstValues/Tuples.swift @@ -11,4 +11,4 @@ @const let constGlobal5: (Int, Float) = (42, 42.0) // Closure call not supported in syntactically-validated mode -@const let constGlobal7: (UInt64, StaticString, @convention(c) ()->Int) = (42, "hi", { return 42 }) // expected-error {{not supported in a '@const' expression}} +@const let constGlobal7: (UInt64, StaticString, @convention(c) ()->Int) = (42, "hi", { return 42 }) // expected-error {{not supported in a constant expression}} diff --git a/test/IRGen/linker_set_low_level.swift b/test/IRGen/linker_set_low_level.swift index 77bbd71fd37d8..b93ffe8c12dfd 100644 --- a/test/IRGen/linker_set_low_level.swift +++ b/test/IRGen/linker_set_low_level.swift @@ -1,14 +1,13 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers %s -emit-ir -parse-as-library | %FileCheck %s +// RUN: %target-swift-frontend %s -emit-ir -parse-as-library | %FileCheck %s // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers -@_used -@_section("__TEXT,__mysection") +@used +@section("__TEXT,__mysection") let my_global1: Int = 42 -@_used -@_section("__TEXT,__mysection") +@used +@section("__TEXT,__mysection") let my_global2: Int = 46 @_silgen_name(raw: "section$start$__TEXT$__mysection") diff --git a/test/IRGen/linker_set_low_level_exec.swift b/test/IRGen/linker_set_low_level_exec.swift index ed84f6b047004..9a666be1be534 100644 --- a/test/IRGen/linker_set_low_level_exec.swift +++ b/test/IRGen/linker_set_low_level_exec.swift @@ -1,25 +1,24 @@ -// RUN: %target-run-simple-swift(-parse-as-library -enable-experimental-feature SymbolLinkageMarkers) | %FileCheck %s +// RUN: %target-run-simple-swift(-parse-as-library) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers // https://github.com/apple/swift/issues/73321 // UNSUPPORTED: OS=windows-msvc -@_used +@used #if canImport(Darwin) -@_section("__TEXT,__mysection") +@section("__TEXT,__mysection") #else -@_section("__mysection") +@section("__mysection") #endif let my_global1: Int = 42 -@_used +@used #if canImport(Darwin) -@_section("__TEXT,__mysection") +@section("__TEXT,__mysection") #else -@_section("__mysection") +@section("__mysection") #endif let my_global2: Int = 46 diff --git a/test/IRGen/section.swift b/test/IRGen/section.swift index 89d146ca5ae94..e1053618e955b 100644 --- a/test/IRGen/section.swift +++ b/test/IRGen/section.swift @@ -1,36 +1,36 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -emit-sil -parse-as-library | %FileCheck %s --check-prefix=SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -emit-ir -parse-as-library | %FileCheck %s --check-prefix=IR +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -primary-file %s -emit-sil -parse-as-library | %FileCheck %s --check-prefix=SIL +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -primary-file %s -emit-ir -parse-as-library | %FileCheck %s --check-prefix=IR // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview -@_section("__DATA,__mysection") var g0: Int = 1 -@_section("__DATA,__mysection") var g1: (Int, Int) = (42, 43) -@_section("__DATA,__mysection") var g2: Bool = true -@_section("__DATA,__mysection") public var g3: Bool = true -@_section("__DATA,__mysection") var g4: UnsafeMutablePointer? = nil -@_section("__DATA,__mysection") var g5: UnsafeMutablePointer? = UnsafeMutablePointer(bitPattern: 0x42424242) -@_section("__TEXT,__mysection") @_used func foo() {} +@section("__DATA,__mysection") var g0: Int = 1 +@section("__DATA,__mysection") var g1: (Int, Int) = (42, 43) +@section("__DATA,__mysection") var g2: Bool = true +@section("__DATA,__mysection") public var g3: Bool = true +@section("__DATA,__mysection") var g4: UnsafeMutablePointer? = nil +@section("__DATA,__mysection") var g5: UnsafeMutablePointer? = UnsafeMutablePointer(bitPattern: 0x42424242) +@section("__TEXT,__mysection") @used func foo() {} struct MyStruct { - @_section("__DATA,__mysection") static var static0: Int = 1 - @_section("__TEXT,__mysection") @_used func foo() {} + @section("__DATA,__mysection") static var static0: Int = 1 + @section("__TEXT,__mysection") @used func foo() {} } -@_section("__TEXT,__mysection") +@section("__TEXT,__mysection") var functionptr = testit func testit(_ e: consuming Any) -> Any { e } -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g0: Int { get set } -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g1: (Int, Int) { get set } -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g2: Bool { get set } -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue public var g3: Bool { get set } -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g4: UnsafeMutablePointer? { get set } -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g5: UnsafeMutablePointer? { get set } -// SIL: @_section("__TEXT,__mysection") @_used func foo() +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g0: Int { get set } +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g1: (Int, Int) { get set } +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g2: Bool { get set } +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue public var g3: Bool { get set } +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g4: UnsafeMutablePointer? { get set } +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue var g5: UnsafeMutablePointer? { get set } +// SIL: @section("__TEXT,__mysection") @used func foo() // SIL: struct MyStruct { -// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue static var static0: Int { get set } -// SIL: @_section("__TEXT,__mysection") @_used func foo() +// SIL: @section("__DATA,__mysection") @_hasStorage @_hasInitialValue static var static0: Int { get set } +// SIL: @section("__TEXT,__mysection") @used func foo() // SIL: sil private [global_init_once_fn] @$s7section2g0_WZ : $@convention(c) // SIL: sil hidden [global_init] @$s7section2g0Sivau : $@convention(thin) diff --git a/test/IRGen/section_asm.swift b/test/IRGen/section_asm.swift index c440f67d64ee6..827a91a419b05 100644 --- a/test/IRGen/section_asm.swift +++ b/test/IRGen/section_asm.swift @@ -1,7 +1,7 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %S/section.swift -S -parse-as-library | %FileCheck --check-prefix CHECK%target-os-binfmt-elf %s +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -primary-file %S/section.swift -S -parse-as-library | %FileCheck --check-prefix CHECK%target-os-binfmt-elf %s // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview // UNSUPPORTED: CPU=wasm32 // CHECK: .section{{.*}}__TEXT,__mysection diff --git a/test/IRGen/section_bridging_header.swift b/test/IRGen/section_bridging_header.swift index fede2263c538b..ccc1fe15e6518 100644 --- a/test/IRGen/section_bridging_header.swift +++ b/test/IRGen/section_bridging_header.swift @@ -1,9 +1,9 @@ // RUN: %empty-directory(%t) // RUN: %{python} %utils/split_file.py -o %t %s -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enforce-exclusivity=unchecked -parse-as-library -emit-sil -import-objc-header %t/bridge.h %t/file.swift -o /dev/null +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -enforce-exclusivity=unchecked -parse-as-library -emit-sil -import-objc-header %t/bridge.h %t/file.swift -o /dev/null // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview // BEGIN bridge.h struct MyStruct1 { @@ -16,7 +16,7 @@ struct MyStruct1 { // BEGIN file.swift func foo() { } -@_section("__TEXT,__mysection") var my_global1 = MyStruct1( +@section("__TEXT,__mysection") var my_global1 = MyStruct1( x: 42, fptr1: foo, fptr2: nil, diff --git a/test/IRGen/section_errors.swift b/test/IRGen/section_errors.swift index fd2bfb5ca1696..f4fa844c72340 100644 --- a/test/IRGen/section_errors.swift +++ b/test/IRGen/section_errors.swift @@ -1,34 +1,34 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -parse-as-library -emit-sil %s -o /dev/null -verify +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -parse-as-library -emit-sil %s -o /dev/null -verify // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview -@_used @_section("__TEXT,__mysection") var g0: Int = 1 // ok +@used @section("__TEXT,__mysection") var g0: Int = 1 // ok struct MyStruct { - @_used @_section("__TEXT,__mysection") static var static0: Int = 1 // ok + @used @section("__TEXT,__mysection") static var static0: Int = 1 // ok } struct MyStruct2 { - @_section("__TEXT,__mysection") var member0: Int = 1 // expected-error {{properties with attribute @_section must be static}} + @section("__TEXT,__mysection") var member0: Int = 1 // expected-error {{properties with attribute @section must be static}} - @_section("__TEXT,__mysection") static var static1: Int { return 1 } // expected-error {{'@_section' must not be used on computed properties}} + @section("__TEXT,__mysection") static var static1: Int { return 1 } // expected-error {{'@section' must not be used on computed properties}} } struct MyStruct3 { static var member1: Int = 1 // expected-error {{static stored properties not supported in generic types}} - @_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute @_section cannot be used in a generic context}} + @section("__TEXT,__mysection") func foo() {} // expected-error {{attribute @section cannot be used in a generic context}} } struct MyStruct4 { struct InnerStruct { static var member2: Int = 1 // expected-error {{static stored properties not supported in generic types}} - @_section("__TEXT,__mysection") static var member3: Int = 1 // expected-error {{static stored properties not supported in generic types}} - // expected-error@-1 {{attribute @_section cannot be used in a generic context}} + @section("__TEXT,__mysection") static var member3: Int = 1 // expected-error {{static stored properties not supported in generic types}} + // expected-error@-1 {{attribute @section cannot be used in a generic context}} - @_section("__TEXT,__mysection") func foo() {} // expected-error {{attribute @_section cannot be used in a generic context}} + @section("__TEXT,__mysection") func foo() {} // expected-error {{attribute @section cannot be used in a generic context}} } } @@ -36,39 +36,39 @@ struct MyStruct5 { } extension MyStruct5 where T == Never { - @_used @_section("__TEXT,__mysection") static let static3: Int = 1 // ok + @used @section("__TEXT,__mysection") static let static3: Int = 1 // ok } -@_section("__TEXT,__mysection") // expected-error {{'@_section' attribute cannot be applied to this declaration}} +@section("__TEXT,__mysection") // expected-error {{'@section' attribute cannot be applied to this declaration}} struct SomeStruct {} -@_section("") var g1: Int = 1 // expected-error {{'@_section' section name cannot be empty}} +@section("") var g1: Int = 1 // expected-error {{'@section' section name cannot be empty}} func function() { - @_section("__TEXT,__mysection") var l0: Int = 1 // expected-error {{attribute '_section' can only be used in a non-local scope}} + @section("__TEXT,__mysection") var l0: Int = 1 // expected-error {{attribute 'section' can only be used in a non-local scope}} l0 += 1 _ = l0 - @_used var l1: Int = 1 // expected-error {{attribute @_used can only be used in a non-local scope}} + @used var l1: Int = 1 // expected-error {{attribute @used can only be used in a non-local scope}} l1 += 1 _ = l1 } func function_with_type() { class MyClass { - @_section("__TEXT,__mysection") static var member: Int = 1 // ok + @section("__TEXT,__mysection") static var member: Int = 1 // ok } do { class MyClass { - @_section("__TEXT,__mysection") static var member: Int = 1 // ok + @section("__TEXT,__mysection") static var member: Int = 1 // ok } } } func function_with_type_generic() -> T { class MyClass { // expected-error {{type 'MyClass' cannot be nested in generic function}} - @_section("__TEXT,__mysection") static var member: Int = 1 // expected-error {{static stored properties not supported in generic types}} - // expected-error@-1 {{attribute @_section cannot be used in a generic context}} + @section("__TEXT,__mysection") static var member: Int = 1 // expected-error {{static stored properties not supported in generic types}} + // expected-error@-1 {{attribute @section cannot be used in a generic context}} } } diff --git a/test/IRGen/section_non_const.swift b/test/IRGen/section_non_const.swift index bbc77181ef02a..7a7e79b5868c6 100644 --- a/test/IRGen/section_non_const.swift +++ b/test/IRGen/section_non_const.swift @@ -1,28 +1,35 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -parse-as-library -emit-sil %s -o /dev/null -verify +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -parse-as-library -emit-sil %s -o /dev/null -verify // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview -@_section("__TEXT,__mysection") var g0: Int = 1 -@_section("__TEXT,__mysection") var g1: (Int, Int) = (1, 2) -@_section("__TEXT,__mysection") var g2: [Int] = [1, 2, 3] // expected-error {{global variable must be a compile-time constant to use @_section attribute}} -@_section("__TEXT,__mysection") var g3: [Int:Int] = [:] // expected-error {{global variable must be a compile-time constant to use @_section attribute}} -@_section("__TEXT,__mysection") var g4: UInt = 42 -@_section("__TEXT,__mysection") var g5: String = "hello" // expected-error {{global variable must be a compile-time constant to use @_section attribute}} -@_section("__TEXT,__mysection") var g6: Any = 1 // expected-error {{global variable must be a compile-time constant to use @_section attribute}} -@_section("__TEXT,__mysection") var g7: UInt8 = 42 -@_section("__TEXT,__mysection") var g8: Int = 5 * 5 -@_section("__TEXT,__mysection") var g9 = MemoryLayout.size -@_section("__TEXT,__mysection") var g10 = MemoryLayout.stride -@_section("__TEXT,__mysection") var g11 = MemoryLayout.alignment -@_section("__TEXT,__mysection") var g12 = MemoryLayout.size * 2 +// TODO: this should only emit one error per bad compile-time expression, not two -@_section("__TEXT,__mysection") var s: StaticString = "hello" +@section("__TEXT,__mysection") var g0: Int = 1 +@section("__TEXT,__mysection") var g1: (Int, Int) = (1, 2) +@section("__TEXT,__mysection") var g2: [Int] = [1, 2, 3] // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} +@section("__TEXT,__mysection") var g3: [Int:Int] = [:] // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} +@section("__TEXT,__mysection") var g4: UInt = 42 +@section("__TEXT,__mysection") var g5: String = "hello" // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} +@section("__TEXT,__mysection") var g6: Any = 1 // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} +@section("__TEXT,__mysection") var g7: UInt8 = 42 +@section("__TEXT,__mysection") var g8: Int = 5 * 5 +@section("__TEXT,__mysection") var g9 = MemoryLayout.size +@section("__TEXT,__mysection") var g10 = MemoryLayout.stride +@section("__TEXT,__mysection") var g11 = MemoryLayout.alignment +@section("__TEXT,__mysection") var g12 = MemoryLayout.size * 2 + +@section("__TEXT,__mysection") var s: StaticString = "hello" struct MyStruct1 { var a: [Int] } -@_section("__TEXT,__mysection") var g_MyStruct1: MyStruct1 = MyStruct1(a: [1, 2, 3]) // expected-error {{global variable must be a compile-time constant to use @_section attribute}} +@section("__TEXT,__mysection") var g_MyStruct1: MyStruct1 = MyStruct1(a: [1, 2, 3]) // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} struct MyStruct2 { struct SubStruct { var x: Int } @@ -33,7 +40,7 @@ struct MyStruct2 { self.b = SubStruct(x: self.a) } } -@_section("__TEXT,__mysection") var g_MyStruct2: MyStruct2 = MyStruct2(a: 42) +@section("__TEXT,__mysection") var g_MyStruct2: MyStruct2 = MyStruct2(a: 42) struct MyStruct3 { struct SubStruct { var x: Int } @@ -44,7 +51,7 @@ struct MyStruct3 { self.b = b } } -@_section("__TEXT,__mysection") var g_MyStruct3: MyStruct3 = MyStruct3(a: 42, b: MyStruct3.SubStruct(x: 77)) +@section("__TEXT,__mysection") var g_MyStruct3: MyStruct3 = MyStruct3(a: 42, b: MyStruct3.SubStruct(x: 77)) // Check that we don't end up infinitely inlining struct MyStruct4 { @@ -54,7 +61,8 @@ struct MyStruct4 { self.a = a } } -@_section("__TEXT,__mysection") var g_MyStruct4: MyStruct4 = MyStruct4(a: 42) // expected-error {{global variable must be a compile-time constant to use @_section attribute}} +@section("__TEXT,__mysection") var g_MyStruct4: MyStruct4 = MyStruct4(a: 42) // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} struct MyStruct5 { struct SubStruct { var x: Int } @@ -63,7 +71,7 @@ struct MyStruct5 { self.a = (SubStruct(x: a), SubStruct(x: a)) } } -@_section("__TEXT,__mysection") var g_MyStruct5: MyStruct5 = MyStruct5(a: 42) +@section("__TEXT,__mysection") var g_MyStruct5: MyStruct5 = MyStruct5(a: 42) // Check that we don't end up infinitely inlining struct MyStruct6 { @@ -79,7 +87,8 @@ struct MyStruct6 { self.a = (SubStruct(x: a), SubStruct(x: a)) } } -@_section("__TEXT,__mysection") var g_MyStruct6: MyStruct6 = MyStruct6(a: 42) // expected-error {{global variable must be a compile-time constant to use @_section attribute}} +@section("__TEXT,__mysection") var g_MyStruct6: MyStruct6 = MyStruct6(a: 42) // expected-error {{global variable must be a compile-time constant to use @section attribute}} +// expected-error@-1 {{'@const' value should be initialized with a compile-time value}} -@_section("__TEXT,__mysection") var gp1: UnsafeMutablePointer? = nil -@_section("__TEXT,__mysection") var gp2: UnsafeMutablePointer? = UnsafeMutablePointer(bitPattern: 0x42424242) +@section("__TEXT,__mysection") var gp1: UnsafeMutablePointer? = nil +@section("__TEXT,__mysection") var gp2: UnsafeMutablePointer? = UnsafeMutablePointer(bitPattern: 0x42424242) diff --git a/test/IRGen/section_structs.swift b/test/IRGen/section_structs.swift index d6018d5854064..b41c30865a77e 100644 --- a/test/IRGen/section_structs.swift +++ b/test/IRGen/section_structs.swift @@ -1,10 +1,10 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -parse-as-library -emit-ir %s -o - | %FileCheck %s +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -parse-as-library -emit-ir %s -o - | %FileCheck %s // REQUIRES: swift_in_compiler // Fails without optimized stdlib (rdar://119899895) // REQUIRES: optimized_stdlib -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview // The `StaticString("hello").utf8Start` test fails on 32 bit // UNSUPPORTED: PTRSIZE=32 @@ -12,13 +12,13 @@ struct MyStruct1 { var a, b: Int } -@_section("__TEXT,__mysection") var g_MyStruct1: MyStruct1 = MyStruct1(a: 42, b: 66) +@section("__TEXT,__mysection") var g_MyStruct1: MyStruct1 = MyStruct1(a: 42, b: 66) struct MyStruct2 { var a: Int var b: (Int, Int) } -@_section("__TEXT,__mysection") var g_MyStruct2: MyStruct2 = MyStruct2(a: 42, b: (66, 67)) +@section("__TEXT,__mysection") var g_MyStruct2: MyStruct2 = MyStruct2(a: 42, b: (66, 67)) struct MyStruct3 { var a, b: Int @@ -27,13 +27,13 @@ struct MyStruct3 { self.b = b } } -@_section("__TEXT,__mysection") var g_MyStruct3: MyStruct3 = MyStruct3(a: 42, b: 77) +@section("__TEXT,__mysection") var g_MyStruct3: MyStruct3 = MyStruct3(a: 42, b: 77) struct MyStruct4 { var a: Int var s: MyStruct1 } -@_section("__TEXT,__mysection") var g_MyStruct4: MyStruct4 = MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)) +@section("__TEXT,__mysection") var g_MyStruct4: MyStruct4 = MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)) struct MyStruct5 { var q: MyStruct4 @@ -43,9 +43,9 @@ struct MyStruct5 { self.r = r } } -@_section("__TEXT,__mysection") var g_MyStruct5: MyStruct5 = MyStruct5(q: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)), r: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44))) +@section("__TEXT,__mysection") var g_MyStruct5: MyStruct5 = MyStruct5(q: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)), r: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44))) -@_section("__TEXT,__mysection") let utf8OfStaticString = StaticString("hello").utf8Start +@section("__TEXT,__mysection") let utf8OfStaticString = StaticString("hello").utf8Start // CHECK: @"{{.*}}g_MyStruct1{{.*}}Vvp" = hidden global {{.*}} <{ %TSi <{ {{(i32|i64)}} 42 }>, %TSi <{ {{(i32|i64)}} 66 }> }> // CHECK: @"{{.*}}g_MyStruct2{{.*}}Vvp" = hidden global {{.*}} <{ %TSi <{ {{(i32|i64)}} 42 }>, <{ %TSi, %TSi }> <{ %TSi <{ {{(i32|i64)}} 66 }>, %TSi <{ {{(i32|i64)}} 67 }> }> }> @@ -55,4 +55,3 @@ struct MyStruct5 { // CHECK: [[HELLOSTR:@.*]] = private {{.*}}constant [6 x i8] c"hello\00" // CHECK: @"{{.*}}utf8OfStaticString{{.*}}VGvp" = hidden constant {{.*}} <{ ptr [[HELLOSTR]] }> - diff --git a/test/IRGen/section_structs_generic.swift b/test/IRGen/section_structs_generic.swift index 8a80578b493f0..e48f6fc99cb80 100644 --- a/test/IRGen/section_structs_generic.swift +++ b/test/IRGen/section_structs_generic.swift @@ -1,18 +1,18 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -parse-as-library -emit-ir %s -o - | %FileCheck %s +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -parse-as-library -emit-ir %s -o - | %FileCheck %s // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview struct MyStruct1 { var a, b: T } -@_section("__TEXT,__mysection") var g_MyStruct1 = MyStruct1(a: 42, b: 66) +@section("__TEXT,__mysection") var g_MyStruct1 = MyStruct1(a: 42, b: 66) struct MyStruct2 { var a: T var b: (T, T) } -@_section("__TEXT,__mysection") var g_MyStruct2 = MyStruct2(a: 42, b: (66, 67)) +@section("__TEXT,__mysection") var g_MyStruct2 = MyStruct2(a: 42, b: (66, 67)) struct MyStruct3 { var a, b: T @@ -21,13 +21,13 @@ struct MyStruct3 { self.b = b } } -@_section("__TEXT,__mysection") var g_MyStruct3 = MyStruct3(a: 42, b: 77) +@section("__TEXT,__mysection") var g_MyStruct3 = MyStruct3(a: 42, b: 77) struct MyStruct4 { var a: T var s: MyStruct1 } -@_section("__TEXT,__mysection") var g_MyStruct4 = MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)) +@section("__TEXT,__mysection") var g_MyStruct4 = MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)) struct MyStruct5 { var q: MyStruct4 @@ -37,7 +37,7 @@ struct MyStruct5 { self.r = r } } -@_section("__TEXT,__mysection") var g_MyStruct5 = MyStruct5(q: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)), r: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44))) +@section("__TEXT,__mysection") var g_MyStruct5 = MyStruct5(q: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44)), r: MyStruct4(a: 42, s: MyStruct1(a: 43, b: 44))) // CHECK: @"{{.*}}g_MyStruct1{{.*}}Gvp" = hidden global {{.*}} <{ %TSi <{ {{(i32|i64)}} 42 }>, %TSi <{ {{(i32|i64)}} 66 }> }> // CHECK: @"{{.*}}g_MyStruct2{{.*}}Gvp" = hidden global {{.*}} <{ %TSi <{ {{(i32|i64)}} 42 }>, <{ %TSi, %TSi }> <{ %TSi <{ {{(i32|i64)}} 66 }>, %TSi <{ {{(i32|i64)}} 67 }> }> }> diff --git a/test/IRGen/section_wasm.swift b/test/IRGen/section_wasm.swift index 4638a60839d9b..3286535dc482e 100644 --- a/test/IRGen/section_wasm.swift +++ b/test/IRGen/section_wasm.swift @@ -1,7 +1,7 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %S/section.swift -S -parse-as-library | %FileCheck %s --check-prefix=ASM --check-prefix ASM-%target-os +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -primary-file %S/section.swift -S -parse-as-library | %FileCheck %s --check-prefix=ASM --check-prefix ASM-%target-os // REQUIRES: CPU=wasm32 // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview // Wasm cannot have user defined section name for code sections // diff --git a/test/IRGen/silgen_name_non_const.swift b/test/IRGen/silgen_name_non_const.swift index b44d9e6ed38be..c45f8785a77cf 100644 --- a/test/IRGen/silgen_name_non_const.swift +++ b/test/IRGen/silgen_name_non_const.swift @@ -1,7 +1,7 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -parse-as-library -emit-sil %s -o /dev/null -verify +// RUN: %target-swift-frontend -enable-experimental-feature CompileTimeValuesPreview -parse-as-library -emit-sil %s -o /dev/null -verify // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview @_silgen_name("g0") var g0: Int = 1 @_silgen_name("g1") var g1: (Int, Int) = (1, 2) diff --git a/test/IRGen/used.swift b/test/IRGen/used.swift index 3b3460910e770..9fd80a0fc35de 100644 --- a/test/IRGen/used.swift +++ b/test/IRGen/used.swift @@ -1,24 +1,23 @@ -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -emit-sil | %FileCheck %s --check-prefix=SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -O -emit-sil | %FileCheck %s --check-prefix=SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -emit-ir | %FileCheck %s --check-prefix=IR -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=IR -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -emit-sil -parse-as-library | %FileCheck %s --check-prefix=SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -O -emit-sil -parse-as-library | %FileCheck %s --check-prefix=SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -emit-ir -parse-as-library | %FileCheck %s --check-prefix=IR -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -primary-file %s -O -emit-ir -parse-as-library | %FileCheck %s --check-prefix=IR +// RUN: %target-swift-frontend -primary-file %s -emit-sil | %FileCheck %s --check-prefix=SIL +// RUN: %target-swift-frontend -primary-file %s -O -emit-sil | %FileCheck %s --check-prefix=SIL +// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=IR +// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=IR +// RUN: %target-swift-frontend -primary-file %s -emit-sil -parse-as-library | %FileCheck %s --check-prefix=SIL +// RUN: %target-swift-frontend -primary-file %s -O -emit-sil -parse-as-library | %FileCheck %s --check-prefix=SIL +// RUN: %target-swift-frontend -primary-file %s -emit-ir -parse-as-library | %FileCheck %s --check-prefix=IR +// RUN: %target-swift-frontend -primary-file %s -O -emit-ir -parse-as-library | %FileCheck %s --check-prefix=IR // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers -@_used var g0: Int = 1 -@_used var g1: (Int, Int) = (42, 43) -@_used var g2: Bool = true -@_used func foo() {} +@used var g0: Int = 1 +@used var g1: (Int, Int) = (42, 43) +@used var g2: Bool = true +@used func foo() {} -// SIL: @_used @_hasStorage @_hasInitialValue var g0: Int { get set } -// SIL: @_used @_hasStorage @_hasInitialValue var g1: (Int, Int) { get set } -// SIL: @_used @_hasStorage @_hasInitialValue var g2: Bool { get set } -// SIL: @_used func foo() +// SIL: @used @_hasStorage @_hasInitialValue var g0: Int { get set } +// SIL: @used @_hasStorage @_hasInitialValue var g1: (Int, Int) { get set } +// SIL: @used @_hasStorage @_hasInitialValue var g2: Bool { get set } +// SIL: @used func foo() // SIL: sil_global hidden [used] @$s4used2g0Sivp : $Int // SIL: sil_global hidden [used] @$s4used2g1Si_Sitvp : $(Int, Int) diff --git a/test/Macros/DebugDescription/dollar_handling.swift b/test/Macros/DebugDescription/dollar_handling.swift index bf5dcb4cb8187..c86e164c7e615 100644 --- a/test/Macros/DebugDescription/dollar_handling.swift +++ b/test/Macros/DebugDescription/dollar_handling.swift @@ -9,11 +9,14 @@ struct MyStruct { var name: String = "thirty" var debugDescription: String { "${\(self.name)}" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 32 as UInt8, -// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8, -// CHECK: /* "\${${var.name}}" */ 16 as UInt8, 92 as UInt8, 36 as UInt8, 123 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 32, +// CHECK: /* "main.MyStruct" */ 14, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 0, +// CHECK: /* "\${${var.name}}" */ 16, 92, 36, 123, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 125, 125, 0 // CHECK: ) @DebugDescription @@ -21,10 +24,12 @@ class MyClass { var name: String = "thirty" var lldbDescription: String { "${var.name}" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 27 as UInt8, -// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8, -// CHECK: /* "${var.name}" */ 12 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 27, +// CHECK: /* "main.MyClass" */ 13, 109, 97, 105, 110, 46, 77, 121, 67, 108, 97, 115, 115, 0, +// CHECK: /* "${var.name}" */ 12, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 125, 0 // CHECK: ) - diff --git a/test/Macros/DebugDescription/explicit_self_property.swift b/test/Macros/DebugDescription/explicit_self_property.swift index c556008b5fdc4..3a112366ac0e6 100644 --- a/test/Macros/DebugDescription/explicit_self_property.swift +++ b/test/Macros/DebugDescription/explicit_self_property.swift @@ -9,11 +9,14 @@ struct MyStruct: CustomDebugStringConvertible { var name: String = "thirty" var debugDescription: String { "name: \(self.name)" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 34 as UInt8, -// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8, -// CHECK: /* "name: ${var.name}" */ 18 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 58 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 34, +// CHECK: /* "main.MyStruct" */ 14, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 0, +// CHECK: /* "name: ${var.name}" */ 18, 110, 97, 109, 101, 58, 32, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 125, 0 // CHECK: ) @DebugDescription @@ -21,10 +24,12 @@ class MyClass: CustomDebugStringConvertible { var name: String = "thirty" var debugDescription: String { "name: \(self.name)" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 33 as UInt8, -// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8, -// CHECK: /* "name: ${var.name}" */ 18 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 58 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 33, +// CHECK: /* "main.MyClass" */ 13, 109, 97, 105, 110, 46, 77, 121, 67, 108, 97, 115, 115, 0, +// CHECK: /* "name: ${var.name}" */ 18, 110, 97, 109, 101, 58, 32, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 125, 0 // CHECK: ) - diff --git a/test/Macros/DebugDescription/extension.swift b/test/Macros/DebugDescription/extension.swift index 1bec03222ee7b..411cdcca3a1e1 100644 --- a/test/Macros/DebugDescription/extension.swift +++ b/test/Macros/DebugDescription/extension.swift @@ -10,9 +10,12 @@ struct MyStruct {} extension MyStruct { var debugDescription: String { "thirty" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 34 as UInt8, -// CHECK: /* "^main[.]MyStruct(<.+>)?$" */ 25 as UInt8, 94 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 91 as UInt8, 46 as UInt8, 93 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 40 as UInt8, 60 as UInt8, 46 as UInt8, 43 as UInt8, 62 as UInt8, 41 as UInt8, 63 as UInt8, 36 as UInt8, 0 as UInt8, -// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 34, +// CHECK: /* "^main[.]MyStruct(<.+>)?$" */ 25, 94, 109, 97, 105, 110, 91, 46, 93, 77, 121, 83, 116, 114, 117, 99, 116, 40, 60, 46, 43, 62, 41, 63, 36, 0, +// CHECK: /* "thirty" */ 7, 116, 104, 105, 114, 116, 121, 0 // CHECK: ) diff --git a/test/Macros/DebugDescription/implicit_self_property.swift b/test/Macros/DebugDescription/implicit_self_property.swift index 94f9d4661968e..a3e7835280ffa 100644 --- a/test/Macros/DebugDescription/implicit_self_property.swift +++ b/test/Macros/DebugDescription/implicit_self_property.swift @@ -9,11 +9,14 @@ struct MyStruct: CustomDebugStringConvertible { var name: String = "thirty" var debugDescription: String { "name: \(name)" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 34 as UInt8, -// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8, -// CHECK: /* "name: ${var.name}" */ 18 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 58 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 34, +// CHECK: /* "main.MyStruct" */ 14, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 0, +// CHECK: /* "name: ${var.name}" */ 18, 110, 97, 109, 101, 58, 32, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 125, 0 // CHECK: ) @DebugDescription @@ -21,9 +24,12 @@ class MyClass: CustomDebugStringConvertible { var name: String = "thirty" var debugDescription: String { "name: \(name)" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 33 as UInt8, -// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8, -// CHECK: /* "name: ${var.name}" */ 18 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 58 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 33, +// CHECK: /* "main.MyClass" */ 13, 109, 97, 105, 110, 46, 77, 121, 67, 108, 97, 115, 115, 0, +// CHECK: /* "name: ${var.name}" */ 18, 110, 97, 109, 101, 58, 32, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 125, 0 // CHECK: ) diff --git a/test/Macros/DebugDescription/linkage.swift b/test/Macros/DebugDescription/linkage.swift index 323ab6302b0d1..332a58fcc7892 100644 --- a/test/Macros/DebugDescription/linkage.swift +++ b/test/Macros/DebugDescription/linkage.swift @@ -10,16 +10,18 @@ struct MyStruct: CustomDebugStringConvertible { } // CHECK: #if !os(Windows) // CHECK: #if os(Linux) -// CHECK: @_section(".lldbsummaries") +// CHECK: @section(".lldbsummaries") // CHECK: #else -// CHECK: @_section("__TEXT,__lldbsummaries") +// CHECK: @section("__TEXT,__lldbsummaries") // CHECK: #endif -// CHECK: @_used -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 23 as UInt8, -// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8, -// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8 +// CHECK: @used +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 23, +// CHECK: /* "main.MyStruct" */ 14, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 0, +// CHECK: /* "thirty" */ 7, 116, 104, 105, 114, 116, 121, 0 // CHECK: ) // CHECK: #endif - diff --git a/test/Macros/DebugDescription/long_string.swift b/test/Macros/DebugDescription/long_string.swift index 0898f98261e0a..8f7b3c705cc7a 100644 --- a/test/Macros/DebugDescription/long_string.swift +++ b/test/Macros/DebugDescription/long_string.swift @@ -15,7 +15,10 @@ struct MyStruct: CustomDebugStringConvertible { """ } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 192 as UInt8, 2 as UInt8, -// CHECK: 8-bit integer. See https://en.wikipedia.org/wiki/LEB128" */ 175 as UInt8, 2 as UInt8, 65 as UInt8, +/// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 192, 2, +// CHECK: 8-bit integer. See https://en.wikipedia.org/wiki/LEB128" */ 175, 2, 65, diff --git a/test/Macros/DebugDescription/property_chain.swift b/test/Macros/DebugDescription/property_chain.swift index 837e39ba8f991..f55862c7c91b0 100644 --- a/test/Macros/DebugDescription/property_chain.swift +++ b/test/Macros/DebugDescription/property_chain.swift @@ -9,11 +9,14 @@ struct MyStruct: CustomDebugStringConvertible { var name: String = "thirty" var debugDescription: String { "\(self.name.count) \(name.count)" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 52 as UInt8, -// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8, -// CHECK: /* "${var.name.count} ${var.name.count}" */ 36 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 46 as UInt8, 99 as UInt8, 111 as UInt8, 117 as UInt8, 110 as UInt8, 116 as UInt8, 125 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 46 as UInt8, 99 as UInt8, 111 as UInt8, 117 as UInt8, 110 as UInt8, 116 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 52, +// CHECK: /* "main.MyStruct" */ 14, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 0, +// CHECK: /* "${var.name.count} ${var.name.count}" */ 36, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 46, 99, 111, 117, 110, 116, 125, 32, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 46, 99, 111, 117, 110, 116, 125, 0 // CHECK: ) @DebugDescription @@ -21,10 +24,12 @@ class MyClass: CustomDebugStringConvertible { var name: String = "thirty" var debugDescription: String { "\(self.name.count) \(name.count)" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 51 as UInt8, -// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8, -// CHECK: /* "${var.name.count} ${var.name.count}" */ 36 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 46 as UInt8, 99 as UInt8, 111 as UInt8, 117 as UInt8, 110 as UInt8, 116 as UInt8, 125 as UInt8, 32 as UInt8, 36 as UInt8, 123 as UInt8, 118 as UInt8, 97 as UInt8, 114 as UInt8, 46 as UInt8, 110 as UInt8, 97 as UInt8, 109 as UInt8, 101 as UInt8, 46 as UInt8, 99 as UInt8, 111 as UInt8, 117 as UInt8, 110 as UInt8, 116 as UInt8, 125 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 51, +// CHECK: /* "main.MyClass" */ 13, 109, 97, 105, 110, 46, 77, 121, 67, 108, 97, 115, 115, 0, +// CHECK: /* "${var.name.count} ${var.name.count}" */ 36, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 46, 99, 111, 117, 110, 116, 125, 32, 36, 123, 118, 97, 114, 46, 110, 97, 109, 101, 46, 99, 111, 117, 110, 116, 125, 0 // CHECK: ) - diff --git a/test/Macros/DebugDescription/static_string.swift b/test/Macros/DebugDescription/static_string.swift index 8776a40ff0b3d..a71882d43452b 100644 --- a/test/Macros/DebugDescription/static_string.swift +++ b/test/Macros/DebugDescription/static_string.swift @@ -8,31 +8,40 @@ struct MyStruct: CustomDebugStringConvertible { var debugDescription: String { "thirty" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 23 as UInt8, -// CHECK: /* "main.MyStruct" */ 14 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 0 as UInt8, -// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 23, +// CHECK: /* "main.MyStruct" */ 14, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 0, +// CHECK: /* "thirty" */ 7, 116, 104, 105, 114, 116, 121, 0 // CHECK: ) @DebugDescription class MyClass: CustomDebugStringConvertible { var debugDescription: String { "thirty" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 22 as UInt8, -// CHECK: /* "main.MyClass" */ 13 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 67 as UInt8, 108 as UInt8, 97 as UInt8, 115 as UInt8, 115 as UInt8, 0 as UInt8, -// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 22, +// CHECK: /* "main.MyClass" */ 13, 109, 97, 105, 110, 46, 77, 121, 67, 108, 97, 115, 115, 0, +// CHECK: /* "thirty" */ 7, 116, 104, 105, 114, 116, 121, 0 // CHECK: ) @DebugDescription class MyEnum: CustomDebugStringConvertible { var debugDescription: String { "thirty" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 21 as UInt8, -// CHECK: /* "main.MyEnum" */ 12 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 69 as UInt8, 110 as UInt8, 117 as UInt8, 109 as UInt8, 0 as UInt8, -// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 21, +// CHECK: /* "main.MyEnum" */ 12, 109, 97, 105, 110, 46, 77, 121, 69, 110, 117, 109, 0, +// CHECK: /* "thirty" */ 7, 116, 104, 105, 114, 116, 121, 0 // CHECK: ) diff --git a/test/Macros/DebugDescription/supported_description.swift b/test/Macros/DebugDescription/supported_description.swift index 83d022179ebd7..75c9d8e9666c9 100644 --- a/test/Macros/DebugDescription/supported_description.swift +++ b/test/Macros/DebugDescription/supported_description.swift @@ -8,11 +8,14 @@ struct MyStruct1: CustomStringConvertible { var description: String { "thirty" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 24 as UInt8, -// CHECK: /* "main.MyStruct1" */ 15 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 49 as UInt8, 0 as UInt8, -// CHECK: /* "thirty" */ 7 as UInt8, 116 as UInt8, 104 as UInt8, 105 as UInt8, 114 as UInt8, 116 as UInt8, 121 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 24, +// CHECK: /* "main.MyStruct1" */ 15, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 49, 0, +// CHECK: /* "thirty" */ 7, 116, 104, 105, 114, 116, 121, 0 // CHECK: ) @DebugDescription @@ -20,11 +23,14 @@ struct MyStruct2: CustomDebugStringConvertible { var description: String { "thirty" } var debugDescription: String { "eleven" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 24 as UInt8, -// CHECK: /* "main.MyStruct2" */ 15 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 50 as UInt8, 0 as UInt8, -// CHECK: /* "eleven" */ 7 as UInt8, 101 as UInt8, 108 as UInt8, 101 as UInt8, 118 as UInt8, 101 as UInt8, 110 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 24, +// CHECK: /* "main.MyStruct2" */ 15, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 50, 0, +// CHECK: /* "eleven" */ 7, 101, 108, 101, 118, 101, 110, 0 // CHECK: ) @DebugDescription @@ -33,8 +39,11 @@ struct MyStruct3: CustomDebugStringConvertible { var debugDescription: String { "eleven" } var lldbDescription: String { "two" } } -// CHECK: static let _lldb_summary = ( -// CHECK: /* version */ 1 as UInt8, -// CHECK: /* record size */ 21 as UInt8, -// CHECK: /* "main.MyStruct3" */ 15 as UInt8, 109 as UInt8, 97 as UInt8, 105 as UInt8, 110 as UInt8, 46 as UInt8, 77 as UInt8, 121 as UInt8, 83 as UInt8, 116 as UInt8, 114 as UInt8, 117 as UInt8, 99 as UInt8, 116 as UInt8, 51 as UInt8, 0 as UInt8, -// CHECK: /* "two" */ 4 as UInt8, 116 as UInt8, 119 as UInt8, 111 as UInt8, 0 as UInt8 +// CHECK: static let _lldb_summary: ( +// CHECK: {{UInt8(, UInt8)*}} +// CHECK: ) = +// CHECK: ( +// CHECK: /* version */ 1, +// CHECK: /* record size */ 21, +// CHECK: /* "main.MyStruct3" */ 15, 109, 97, 105, 110, 46, 77, 121, 83, 116, 114, 117, 99, 116, 51, 0, +// CHECK: /* "two" */ 4, 116, 119, 111, 0 diff --git a/test/Parse/const.swift b/test/Parse/const.swift index e9ee4521d865a..d3bbd3dbc92e0 100644 --- a/test/Parse/const.swift +++ b/test/Parse/const.swift @@ -21,11 +21,11 @@ func takeIntConst(@const _ a: Int) {} struct Article { let id: String } -@const let keypath = \Article.id // expected-error{{keypaths not supported in a '@const' expression}} +@const let keypath = \Article.id // expected-error{{keypaths not supported in a constant expression}} func LocalConstVarUser() -> Int { @const let localConst = 3 return localConst + 1 } -@const let a: Bool = Bool.random() // expected-error{{not supported in a '@const' expression}} +@const let a: Bool = Bool.random() // expected-error{{not supported in a constant expression}} diff --git a/test/SIL/Serialization/section.sil b/test/SIL/Serialization/section.sil index 5575d7106f09a..385330f301c8f 100644 --- a/test/SIL/Serialization/section.sil +++ b/test/SIL/Serialization/section.sil @@ -1,10 +1,8 @@ // First parse this and then emit a *.sib. Then read in the *.sib, then recreate // RUN: %empty-directory(%t) -// RUN: %target-sil-opt -sil-print-types -enable-experimental-feature SymbolLinkageMarkers %s -emit-sib -o %t/tmp.sib -module-name borrow -// RUN: %target-sil-opt -sil-print-types -enable-experimental-feature SymbolLinkageMarkers %t/tmp.sib -o %t/tmp.2.sib -module-name borrow -// RUN: %target-sil-opt -sil-print-types -enable-experimental-feature SymbolLinkageMarkers %t/tmp.2.sib -module-name asmname -emit-sorted-sil | %FileCheck %s - -// REQUIRES: swift_feature_SymbolLinkageMarkers +// RUN: %target-sil-opt -sil-print-types %s -emit-sib -o %t/tmp.sib -module-name borrow +// RUN: %target-sil-opt -sil-print-types %t/tmp.sib -o %t/tmp.2.sib -module-name borrow +// RUN: %target-sil-opt -sil-print-types %t/tmp.2.sib -module-name asmname -emit-sorted-sil | %FileCheck %s import Swift diff --git a/test/SILOptimizer/mandatory_perfopt_multimodule.swift b/test/SILOptimizer/mandatory_perfopt_multimodule.swift index eca029d0a6cd3..d92528e563d42 100644 --- a/test/SILOptimizer/mandatory_perfopt_multimodule.swift +++ b/test/SILOptimizer/mandatory_perfopt_multimodule.swift @@ -1,9 +1,9 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t // RUN: %target-swift-frontend -emit-module -parse-as-library -enable-library-evolution %t/module.swift -emit-module-path=%t/Module.swiftmodule -module-name=Module -// RUN: %target-swift-frontend -emit-sil -o /dev/null -parse-as-library %t/main.swift -I%t -enable-experimental-feature SymbolLinkageMarkers +// RUN: %target-swift-frontend -emit-sil -o /dev/null -parse-as-library %t/main.swift -I%t -enable-experimental-feature CompileTimeValuesPreview -// REQUIRES: swift_feature_SymbolLinkageMarkers +// REQUIRES: swift_feature_CompileTimeValuesPreview // Check that this compiles successfully @@ -20,5 +20,5 @@ public struct X: ~Copyable { import Module -@_section("__TEXT,__mysection") +@section("__TEXT,__mysection") var g: () -> () = { _ = X() } diff --git a/test/Serialization/attr-section.swift b/test/Serialization/attr-section.swift index 5126897707c3d..9e9390c6051fb 100644 --- a/test/Serialization/attr-section.swift +++ b/test/Serialization/attr-section.swift @@ -1,13 +1,12 @@ // REQUIRES: swift_in_compiler -// REQUIRES: swift_feature_SymbolLinkageMarkers // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend -parse-as-library -enable-experimental-feature SymbolLinkageMarkers -emit-module-path %t/a.swiftmodule -module-name a %s +// RUN: %target-swift-frontend -parse-as-library -emit-module-path %t/a.swiftmodule -module-name a %s // RUN: llvm-bcanalyzer -dump %t/a.swiftmodule | %FileCheck --check-prefix BC-CHECK --implicit-check-not UnknownCode %s // RUN: %target-swift-ide-test -print-module -module-to-print a -source-filename x -I %t | %FileCheck --check-prefix MODULE-CHECK %s // BC-CHECK: Double { 0 } internal func clib_func4() -> Double { 0 } // --------------------------------------------------------------------------- -// @_section causes symbol emission +// @section causes symbol emission // --------------------------------------------------------------------------- // CHECK: define {{(protected |dllexport )?}}swiftcc void @"$e1c15symbolInSectionyyF" -@_section("__TEXT,__mysection") +@section("__TEXT,__mysection") public func symbolInSection() { } // CHECK: define hidden swiftcc void @"$e1c23internalSymbolInSectionyyF" -@_section("__TEXT,__mysection") +@section("__TEXT,__mysection") func internalSymbolInSection() { } // --------------------------------------------------------------------------- -// @_used causes symbol emission +// @used causes symbol emission // --------------------------------------------------------------------------- // CHECK: define hidden swiftcc void @"$e1c10usedSymbolyyF" -@_used +@used func usedSymbol() { } diff --git a/test/embedded/modules-used.swift b/test/embedded/modules-used.swift index 71157af083a72..1ec6badef2bb1 100644 --- a/test/embedded/modules-used.swift +++ b/test/embedded/modules-used.swift @@ -1,9 +1,9 @@ // RUN: %empty-directory(%t) // RUN: %{python} %utils/split_file.py -o %t %s -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o // RUN: %target-clang %t/a.o -o %t/a.out // RUN: %target-run %t/a.out | %FileCheck %s @@ -11,12 +11,11 @@ // REQUIRES: executable_test // REQUIRES: OS=macosx // REQUIRES: swift_feature_Embedded -// REQUIRES: swift_feature_SymbolLinkageMarkers // BEGIN MyModule.swift -@_used -@_section("__DATA,__mysection") +@used +@section("__DATA,__mysection") let i_am_not_referenced = 42 // BEGIN Main.swift diff --git a/test/embedded/modules-used2.swift b/test/embedded/modules-used2.swift index d94162b3a2543..ff62698302725 100644 --- a/test/embedded/modules-used2.swift +++ b/test/embedded/modules-used2.swift @@ -1,27 +1,26 @@ // RUN: %empty-directory(%t) // RUN: %{python} %utils/split_file.py -o %t %s -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL -// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL +// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o // RUN: %target-clang %target-clang-resource-dir-opt %t/a.o -o %t/a.out // RUN: %target-run %t/a.out | %FileCheck %s // REQUIRES: swift_in_compiler // REQUIRES: executable_test // REQUIRES: swift_feature_Embedded -// REQUIRES: swift_feature_SymbolLinkageMarkers // BEGIN MyModule.swift -@_used +@used @_cdecl("main") func main() -> CInt { print("main in a submodule") return 0 } -@_used +@used func foo() { }