Skip to content

Conversation

@kubamracek
Copy link
Contributor

@kubamracek kubamracek commented Oct 22, 2025

Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:

  • Renamed @_section to @section and @_used to @used
  • Removed the SymbolLinkageMarkers experimental feature
  • Added parsing support for the old underscored names with deprecation warnings
  • Updated all tests and examples to use the new attribute names
  • Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
  • Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
  • Added a testcase for the various allowed and disallowed syntactic forms, test/ConstValues/SectionSyntactic.swift.

Note that there are is no code change for actual constant folding. This is already implemented in MandatoryPerformanceOptimizations based on .mustBeInitializedStatically property being true for any @_section / @section annotated global.

TODO:

  • Add support for metatypes per SE-0492
  • Adjust the diagnostics to not say "@const"
  • Add a IR test for the same set of expressions that we have in test/ConstValues/SectionSyntactic.swift
  • Fix remaining test failures
  • Add the SE-0492 behavior for @section-annotated globals in script mode / top-level mode
  • Support referencing methods, like Bool.random, per SE-0492

Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
@kubamracek
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments, mostly on the constant-value checking, but this is looking great! Thank you!

Comment on lines 271 to 272
if (auto *funcDecl =
dyn_cast<FuncDecl>(memberRef->getMember().getDecl())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will let through references to instance methods, which can't be expressed as constants. Something like 17.negate, perhaps, would slip through the check?

@kubamracek
Copy link
Contributor Author

kubamracek commented Oct 23, 2025

+@kastiglione for the @DebugDescription macro changes

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek kubamracek requested a review from DougGregor October 24, 2025 13:34
@kubamracek
Copy link
Contributor Author

I'm now intending to leave the 2 remaining TODOs listed above as follow-ups:

  • Add the SE-0492 behavior for @section-annotated globals in script mode / top-level mode
  • Support referencing methods, like Bool.random, per SE-0492

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic, thank you!

Copy link
Contributor

@kastiglione kastiglione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DebugDescription macro looks good. Thanks

/// 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: ", ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it idiomatic to use interpolation for the case where a single variable is being converted to a string ("\($0)")?

@kubamracek kubamracek merged commit eb23d3b into swiftlang:main Oct 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants